From 61a704a64e9418babab2da6b8bf27398e22056e6 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Thu, 15 Nov 2018 17:14:43 +0100 Subject: [PATCH] some progress on groups and options --- .../core/components/Picker/Unit/UnitGroup.tsx | 39 ++ .../core/components/Picker/Unit/UnitMenu.tsx | 17 + .../components/Picker/Unit/UnitOption.tsx | 22 + .../components/Picker/Unit/UnitPicker.tsx | 33 ++ .../app/core/components/Picker/UnitPicker.tsx | 75 --- public/app/core/utils/kbn.ts | 427 +++++++++--------- public/app/features/test/TestPage.tsx | 14 + public/app/plugins/panel/gauge/module.tsx | 2 +- public/app/routes/routes.ts | 7 + public/sass/_grafana.scss | 1 + public/sass/components/_unit-picker.scss | 24 + 11 files changed, 372 insertions(+), 289 deletions(-) create mode 100644 public/app/core/components/Picker/Unit/UnitGroup.tsx create mode 100644 public/app/core/components/Picker/Unit/UnitMenu.tsx create mode 100644 public/app/core/components/Picker/Unit/UnitOption.tsx create mode 100644 public/app/core/components/Picker/Unit/UnitPicker.tsx delete mode 100644 public/app/core/components/Picker/UnitPicker.tsx create mode 100644 public/app/features/test/TestPage.tsx create mode 100644 public/sass/components/_unit-picker.scss 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..8ecc8f9b978 --- /dev/null +++ b/public/app/core/components/Picker/Unit/UnitGroup.tsx @@ -0,0 +1,39 @@ +import React, { PureComponent } from 'react'; +import { GroupProps } from 'react-select/lib/components/Group'; + +interface ExtendedGroupProps extends GroupProps { + data: any; +} + +interface State { + expanded: boolean; +} + +export class UnitGroup extends PureComponent { + state = { + expanded: false, + }; + + onToggleChildren = () => { + this.setState(prevState => ({ + expanded: !prevState.expanded, + })); + }; + + render() { + const { children, label } = this.props; + const { expanded } = this.state; + + console.log(children); + + return ( +
+
+ {label} + {' '} +
+ {expanded && children} +
+ ); + } +} diff --git a/public/app/core/components/Picker/Unit/UnitMenu.tsx b/public/app/core/components/Picker/Unit/UnitMenu.tsx new file mode 100644 index 00000000000..472661277c8 --- /dev/null +++ b/public/app/core/components/Picker/Unit/UnitMenu.tsx @@ -0,0 +1,17 @@ +import React, { SFC } from 'react'; +import { components } from 'react-select'; +import { MenuProps } from 'react-select/lib/components/Menu'; + +interface ExtendedMenuProps extends MenuProps { + data: any; +} + +const UnitMenu: SFC = props => { + return ( + +
{props.children}
+
+ ); +}; + +export default UnitMenu; 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 &&