From fa6a43c6e592a1b077ffb63143cb3cf090fe5a15 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com> Date: Wed, 15 Apr 2020 10:11:25 +0200 Subject: [PATCH] Docs: Select (#23398) * Start Select docs * Writ emore docs * Apply suggestions from code review Co-Authored-By: Alex Khomenko Co-authored-by: Alex Khomenko --- .../src/components/Select/Select.mdx | 133 ++++++++++++++++++ .../src/components/Select/Select.story.tsx | 7 + .../src/components/Select/mockOptions.tsx | 3 +- .../grafana-ui/src/components/Select/types.ts | 6 + 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 packages/grafana-ui/src/components/Select/Select.mdx diff --git a/packages/grafana-ui/src/components/Select/Select.mdx b/packages/grafana-ui/src/components/Select/Select.mdx new file mode 100644 index 00000000000..5ca57e225c5 --- /dev/null +++ b/packages/grafana-ui/src/components/Select/Select.mdx @@ -0,0 +1,133 @@ +import { Props, Preview } from "@storybook/addon-docs/blocks"; +import { Select, AsyncSelect, MultiSelect, AsyncMultiSelect } from "./Select"; +import { generateOptions } from "./mockOptions"; + +# Select variants + +Select is an input with the ability to search and create new values. It should be used when you have a list of options. If the data has a tree structure, consider using `Cascader` instead. +Select has some features: + +- Search a list of values +- Select multiple values +- Select from async data +- Create custom values that aren't in the list + +## Select + +Select is the base for every component on this page. The approaches mentioned here are also applicable to `AsyncSelect`, `MultiSelect`, `AsyncMultiSelect`. + +### Options format + +There are four properties for each option: + +- `label` - Text that is visible in the menu. +- `value` - Could be anything, but is usually a string. Used to identify what is **actually** selected. +- `description` - Longer description that describes the choice. Use this sparingly. +- `imgUrl` - URL to an image. Use this when an image or icon provides more context for the option. + +```jsx +const options = [ + { label: "Basic option", value: 0 }, + { label: "Option with description", value: 1, description: "this is a description" }, + { + label: "Option with description and image", + value: 2, + description: "This is a very elaborate description, describing all the wonders in the world.", + imgUrl: "https://placekitten.com/40/40", + }, +]; +``` + +### Creatable option + +Creatable option is used when you want to be able to add a custom value to the list of options. `allowCustomValue` needs to be true and you must handle the value creation with `onCreateOption`. + +```jsx +import { Select } from "@grafana/ui"; + +const SelectComponent = () => { + const [value, setValue] = useState>(); + + return ( +