diff --git a/ui/components/ui/dropdown/README.mdx b/ui/components/ui/dropdown/README.mdx new file mode 100644 index 000000000..f31aca84f --- /dev/null +++ b/ui/components/ui/dropdown/README.mdx @@ -0,0 +1,35 @@ +import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'; + +import Dropdown from '.'; + +# Dropdown + +A toggleable menu that allows the user to choose one value from a predefined list + + + + + +## Component API + + + +## Usage + +### Options Without Names + + + + + +### Options With Long Names + + + + + +### Options With Long Names And Short Width + + + + diff --git a/ui/components/ui/dropdown/dropdown.js b/ui/components/ui/dropdown/dropdown.js index ed207d760..5b678a5fb 100644 --- a/ui/components/ui/dropdown/dropdown.js +++ b/ui/components/ui/dropdown/dropdown.js @@ -4,10 +4,10 @@ import classnames from 'classnames'; const Dropdown = ({ className, - disabled, + disabled = false, onChange, options, - selectedOption, + selectedOption = null, style, title, }) => { @@ -41,26 +41,39 @@ const Dropdown = ({ }; Dropdown.propTypes = { + /** + * Additional css className to add to root of Dropdown component + */ className: PropTypes.string, + /** + * Disable dropdown by setting to true + */ disabled: PropTypes.bool, + /** + * Title of the dropdown + */ title: PropTypes.string, + /** + * On options change handler + */ onChange: PropTypes.func.isRequired, + /** + * Predefined options for component + */ options: PropTypes.arrayOf( PropTypes.exact({ name: PropTypes.string, value: PropTypes.string.isRequired, }), ).isRequired, + /** + * Selected options of dropdown + */ selectedOption: PropTypes.string, + /** + * Add inline style for the component + */ style: PropTypes.object, }; -Dropdown.defaultProps = { - className: undefined, - disabled: false, - title: undefined, - selectedOption: null, - style: undefined, -}; - export default Dropdown; diff --git a/ui/components/ui/dropdown/dropdown.stories.js b/ui/components/ui/dropdown/dropdown.stories.js index a0a9e3fc9..111ac5b65 100644 --- a/ui/components/ui/dropdown/dropdown.stories.js +++ b/ui/components/ui/dropdown/dropdown.stories.js @@ -1,13 +1,7 @@ import React from 'react'; -import { action } from '@storybook/addon-actions'; -import { boolean, select, text } from '@storybook/addon-knobs'; +import README from './README.mdx'; import Dropdown from '.'; -export default { - title: 'Components/UI/Dropdown', - id: __filename, -}; - const unnamedOptions = [...Array(10).keys()].map((index) => { return { value: `option${index}` }; }); @@ -23,65 +17,63 @@ const namedOptionsWithVeryLongNames = unnamedOptions.map((option, index) => { }; }); -export const DefaultStory = () => ( - option.value), - namedOptions[0].value, - )} - /> -); +export default { + title: 'Components/UI/Dropdown', + id: __filename, + component: Dropdown, + parameters: { + docs: { + page: README, + }, + }, + argTypes: { + className: { control: 'text' }, + disabled: { control: 'boolean' }, + title: { control: 'text' }, + onChange: { action: 'onChange' }, + options: { control: 'array' }, + selectedOption: { control: 'text' }, + style: { control: 'object' }, + }, +}; + +export const DefaultStory = (args) => ; DefaultStory.storyName = 'Default'; -export const OptionsWithoutNames = () => ( - option.value), - unnamedOptions[0].value, - )} - /> -); +DefaultStory.args = { + disabled: false, + title: 'Test Dropdown Name', + options: namedOptions, + selectedOption: namedOptions[0].value, +}; -export const OptionsWithLongNames = () => ( - option.value), - namedOptionsWithVeryLongNames[0].value, - )} - /> -); +export const OptionsWithoutNames = (args) => ; + +OptionsWithoutNames.args = { + disabled: false, + title: 'Test Dropdown Name', + options: unnamedOptions, + selectedOption: unnamedOptions[0].value, +}; -export const OptionsWithLongNamesAndShortWidth = () => ( - option.value), - namedOptionsWithVeryLongNames[0].value, - )} - style={{ width: '200px' }} - /> +export const OptionsWithLongNames = (args) => ; + +OptionsWithLongNames.args = { + disabled: false, + title: 'Test Dropdown Name', + options: namedOptionsWithVeryLongNames, + selectedOption: namedOptionsWithVeryLongNames[0].value, +}; + +export const OptionsWithLongNamesAndShortWidth = (args) => ( + ); + +OptionsWithLongNamesAndShortWidth.args = { + disabled: false, + title: 'Test Dropdown Name', + options: namedOptionsWithVeryLongNames, + selectedOption: namedOptionsWithVeryLongNames[0].value, + style: { width: '200px' }, +};