diff --git a/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx b/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx index f1cc467d8af..f1c05cfe4f6 100644 --- a/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx +++ b/packages/grafana-ui/src/components/Cascader/Cascader.story.tsx @@ -48,6 +48,15 @@ export const withInitialValue = () => ( console.log(val)} /> ); -export const withCustomValue = () => ( - console.log(val)} /> -); +export const withCustomValue = () => { + const onCreateLabel = text('Custom value creation label', 'Create new value: '); + return ( + onCreateLabel + val} + initialValue="Custom Initial Value" + onSelect={val => console.log(val)} + /> + ); +}; diff --git a/packages/grafana-ui/src/components/Cascader/Cascader.tsx b/packages/grafana-ui/src/components/Cascader/Cascader.tsx index ee904a19fa6..8f29db1cc43 100644 --- a/packages/grafana-ui/src/components/Cascader/Cascader.tsx +++ b/packages/grafana-ui/src/components/Cascader/Cascader.tsx @@ -8,14 +8,17 @@ import { FormInputSize } from '../Forms/types'; import { Input } from '../Forms/Input/Input'; import { SelectableValue } from '@grafana/data'; import { css } from 'emotion'; - interface CascaderProps { + /** The seperator between levels in the search */ separator?: string; + placeholder?: string; options: CascaderOption[]; onSelect(val: string): void; size?: FormInputSize; initialValue?: string; allowCustomValue?: boolean; + /** A function for formatting the message for custom value creation. Only applies when allowCustomValue is set to true*/ + formatCreateLabel?: (val: string) => string; } interface CascaderState { @@ -30,11 +33,11 @@ interface CascaderState { export interface CascaderOption { value: any; label: string; - // Items will be just flattened into the main list of items recursively. + /** Items will be just flattened into the main list of items recursively. */ items?: CascaderOption[]; disabled?: boolean; title?: string; - // Children will be shown in a submenu. + /** Children will be shown in a submenu. Use 'items' instead, as 'children' exist to ensure backwards compability.*/ children?: CascaderOption[]; } @@ -168,7 +171,7 @@ export class Cascader extends React.PureComponent }; render() { - const { size, allowCustomValue } = this.props; + const { size, allowCustomValue, placeholder } = this.props; const { focusCascade, isSearching, searchableOptions, rcValue, activeLabel } = this.state; return ( @@ -176,13 +179,14 @@ export class Cascader extends React.PureComponent {isSearching ? ( {}} diff --git a/packages/grafana-ui/src/components/UnitPicker/UnitPicker.story.tsx b/packages/grafana-ui/src/components/UnitPicker/UnitPicker.story.tsx index 84ad89678b6..28639719405 100644 --- a/packages/grafana-ui/src/components/UnitPicker/UnitPicker.story.tsx +++ b/packages/grafana-ui/src/components/UnitPicker/UnitPicker.story.tsx @@ -13,4 +13,5 @@ export default { }, }; -export const simple = () => console.log(val)} />; +export const simple = () => console.log(val)} />; +export const old = () => console.log(val)} />; diff --git a/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx b/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx index 169e493cd8f..b29f6c46e4b 100644 --- a/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx +++ b/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx @@ -1,13 +1,15 @@ import React, { PureComponent } from 'react'; import { Select } from '../Select/Select'; - +import { Cascader, CascaderOption } from '../Cascader/Cascader'; import { getValueFormats, SelectableValue } from '@grafana/data'; interface Props { onChange: (item?: string) => void; value?: string; width?: number; + /** Temporary flag that uses the new form styles. */ + useNewForms?: boolean; } function formatCreateLabel(input: string) { @@ -24,7 +26,7 @@ export class UnitPicker extends PureComponent { }; render() { - const { value, width } = this.props; + const { value, width, useNewForms } = this.props; // Set the current selection let current: SelectableValue | undefined = undefined; @@ -44,7 +46,13 @@ export class UnitPicker extends PureComponent { } return sel; }); - + if (useNewForms) { + return { + label: group.text, + value: group.text, + items: options, + }; + } return { label: group.text, options, @@ -56,7 +64,16 @@ export class UnitPicker extends PureComponent { current = { value, label: value }; } - return ( + return useNewForms ? ( + + ) : (