Fix dropdown component for new Storybook format (#12816)

* dropdown

* Updating default props, proptype descriptions and removing required as doesn't do anything

Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
feature/default_network_editable
Etienne Dusseault 3 years ago committed by GitHub
parent 363f81db11
commit c3e7952656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      ui/components/ui/dropdown/README.mdx
  2. 33
      ui/components/ui/dropdown/dropdown.js
  3. 118
      ui/components/ui/dropdown/dropdown.stories.js

@ -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
<Canvas>
<Story id="ui-components-ui-dropdown-dropdown-stories-js--default-story" />
</Canvas>
## Component API
<ArgsTable of={Dropdown} />
## Usage
### Options Without Names
<Canvas>
<Story id="ui-components-ui-dropdown-dropdown-stories-js--options-without-names" />
</Canvas>
### Options With Long Names
<Canvas>
<Story id="ui-components-ui-dropdown-dropdown-stories-js--options-with-long-names" />
</Canvas>
### Options With Long Names And Short Width
<Canvas>
<Story id="ui-components-ui-dropdown-dropdown-stories-js--options-with-long-names-and-short-width" />
</Canvas>

@ -4,10 +4,10 @@ import classnames from 'classnames';
const Dropdown = ({ const Dropdown = ({
className, className,
disabled, disabled = false,
onChange, onChange,
options, options,
selectedOption, selectedOption = null,
style, style,
title, title,
}) => { }) => {
@ -41,26 +41,39 @@ const Dropdown = ({
}; };
Dropdown.propTypes = { Dropdown.propTypes = {
/**
* Additional css className to add to root of Dropdown component
*/
className: PropTypes.string, className: PropTypes.string,
/**
* Disable dropdown by setting to true
*/
disabled: PropTypes.bool, disabled: PropTypes.bool,
/**
* Title of the dropdown
*/
title: PropTypes.string, title: PropTypes.string,
/**
* On options change handler
*/
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
/**
* Predefined options for component
*/
options: PropTypes.arrayOf( options: PropTypes.arrayOf(
PropTypes.exact({ PropTypes.exact({
name: PropTypes.string, name: PropTypes.string,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
}), }),
).isRequired, ).isRequired,
/**
* Selected options of dropdown
*/
selectedOption: PropTypes.string, selectedOption: PropTypes.string,
/**
* Add inline style for the component
*/
style: PropTypes.object, style: PropTypes.object,
}; };
Dropdown.defaultProps = {
className: undefined,
disabled: false,
title: undefined,
selectedOption: null,
style: undefined,
};
export default Dropdown; export default Dropdown;

@ -1,13 +1,7 @@
import React from 'react'; import React from 'react';
import { action } from '@storybook/addon-actions'; import README from './README.mdx';
import { boolean, select, text } from '@storybook/addon-knobs';
import Dropdown from '.'; import Dropdown from '.';
export default {
title: 'Components/UI/Dropdown',
id: __filename,
};
const unnamedOptions = [...Array(10).keys()].map((index) => { const unnamedOptions = [...Array(10).keys()].map((index) => {
return { value: `option${index}` }; return { value: `option${index}` };
}); });
@ -23,65 +17,63 @@ const namedOptionsWithVeryLongNames = unnamedOptions.map((option, index) => {
}; };
}); });
export const DefaultStory = () => ( export default {
<Dropdown title: 'Components/UI/Dropdown',
disabled={boolean('Disabled', false)} id: __filename,
title={text('Title', 'Test dropdown name')} component: Dropdown,
onChange={action('Selection changed')} parameters: {
options={namedOptions} docs: {
required={boolean('Required', false)} page: README,
selectedOption={select( },
'Selected Option', },
namedOptions.map((option) => option.value), argTypes: {
namedOptions[0].value, 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) => <Dropdown {...args} />;
DefaultStory.storyName = 'Default'; DefaultStory.storyName = 'Default';
export const OptionsWithoutNames = () => ( DefaultStory.args = {
<Dropdown disabled: false,
disabled={boolean('Disabled', false)} title: 'Test Dropdown Name',
title={text('Title', 'Test dropdown name')} options: namedOptions,
onChange={action('Selection changed')} selectedOption: namedOptions[0].value,
options={unnamedOptions} };
required={boolean('Required', false)}
selectedOption={select(
'Selected Option',
unnamedOptions.map((option) => option.value),
unnamedOptions[0].value,
)}
/>
);
export const OptionsWithLongNames = () => ( export const OptionsWithoutNames = (args) => <Dropdown {...args} />;
<Dropdown
disabled={boolean('Disabled', false)} OptionsWithoutNames.args = {
title={text('Title', 'Test dropdown name')} disabled: false,
onChange={action('Selection changed')} title: 'Test Dropdown Name',
options={namedOptionsWithVeryLongNames} options: unnamedOptions,
required={boolean('Required', false)} selectedOption: unnamedOptions[0].value,
selectedOption={select( };
'Selected Option',
namedOptionsWithVeryLongNames.map((option) => option.value),
namedOptionsWithVeryLongNames[0].value,
)}
/>
);
export const OptionsWithLongNamesAndShortWidth = () => ( export const OptionsWithLongNames = (args) => <Dropdown {...args} />;
<Dropdown
disabled={boolean('Disabled', false)} OptionsWithLongNames.args = {
title={text('Title', 'Test dropdown name')} disabled: false,
onChange={action('Selection changed')} title: 'Test Dropdown Name',
options={namedOptionsWithVeryLongNames} options: namedOptionsWithVeryLongNames,
required={boolean('Required', false)} selectedOption: namedOptionsWithVeryLongNames[0].value,
selectedOption={select( };
'Selected Option',
namedOptionsWithVeryLongNames.map((option) => option.value), export const OptionsWithLongNamesAndShortWidth = (args) => (
namedOptionsWithVeryLongNames[0].value, <Dropdown {...args} />
)}
style={{ width: '200px' }}
/>
); );
OptionsWithLongNamesAndShortWidth.args = {
disabled: false,
title: 'Test Dropdown Name',
options: namedOptionsWithVeryLongNames,
selectedOption: namedOptionsWithVeryLongNames[0].value,
style: { width: '200px' },
};

Loading…
Cancel
Save