diff --git a/public/app/core/components/Picker/Unit/UnitGroup.tsx b/public/app/core/components/Picker/Unit/UnitGroup.tsx new file mode 100644 index 00000000000..4ee17fef87f --- /dev/null +++ b/public/app/core/components/Picker/Unit/UnitGroup.tsx @@ -0,0 +1,43 @@ +import React, { PureComponent } from 'react'; +import { GroupProps } from 'react-select/lib/components/Group'; + +interface ExtendedGroupProps extends GroupProps { + data: any; +} + +interface State { + expanded: boolean; +} + +export default class UnitGroup extends PureComponent { + state = { + expanded: false, + }; + + componentDidUpdate(nextProps) { + if (nextProps.selectProps.inputValue !== '') { + this.setState({ expanded: true }); + } + } + + onToggleChildren = () => { + this.setState(prevState => ({ + expanded: !prevState.expanded, + })); + }; + + render() { + const { children, label } = this.props; + const { expanded } = this.state; + + return ( +
+
+ {label} + {' '} +
+ {expanded && children} +
+ ); + } +} diff --git a/public/app/core/components/Picker/Unit/UnitOption.tsx b/public/app/core/components/Picker/Unit/UnitOption.tsx new file mode 100644 index 00000000000..19986b28670 --- /dev/null +++ b/public/app/core/components/Picker/Unit/UnitOption.tsx @@ -0,0 +1,22 @@ +import React, { SFC } from 'react'; +import { components } from 'react-select'; +import { OptionProps } from 'react-select/lib/components/Option'; + +interface ExtendedOptionProps extends OptionProps { + data: any; +} + +const UnitOption: SFC = props => { + const { children, isSelected, className } = props; + + return ( + +
+ {isSelected &&