From 850e6f60afb0f4a6363d9bab8bf9fd917f0333be Mon Sep 17 00:00:00 2001 From: TJ Egan Date: Tue, 25 Aug 2020 13:00:08 -0700 Subject: [PATCH] chore(docs): clean up dropdown stories, finish docs --- .../src/components/Dropdown/Dropdown-story.js | 93 ++++-------------- .../components/Dropdown/Dropdown.Skeleton.js | 12 +-- .../src/components/Dropdown/Dropdown.mdx | 95 +++++++++++++++++++ 3 files changed, 114 insertions(+), 86 deletions(-) diff --git a/packages/react/src/components/Dropdown/Dropdown-story.js b/packages/react/src/components/Dropdown/Dropdown-story.js index 45cee9110793..a73f30a3dd41 100644 --- a/packages/react/src/components/Dropdown/Dropdown-story.js +++ b/packages/react/src/components/Dropdown/Dropdown-story.js @@ -10,7 +10,6 @@ import { action } from '@storybook/addon-actions'; import { withKnobs, boolean, select, text } from '@storybook/addon-knobs'; import Dropdown from '../Dropdown'; import DropdownSkeleton from './Dropdown.Skeleton'; -import WithState from '../../tools/withState'; import mdx from './Dropdown.mdx'; const items = [ @@ -41,15 +40,6 @@ const items = [ }, ]; -const stringItems = [ - 'Option 1', - 'Option 2', - 'Option 3', - 'Lorem, ipsum dolor sit amet consectetur adipisicing elit. Vitae, aliquam. Blanditiis quia nemo enim voluptatibus quos ducimus porro molestiae nesciunt error cumque quaerat, tempore vero unde eum aperiam eligendi repellendus.', - 'Option 5', - 'Option 6', -]; - const sizes = { 'Extra large size (xl)': 'xl', 'Default size': undefined, @@ -69,7 +59,7 @@ const props = () => ({ ariaLabel: text('Aria Label (ariaLabel)', 'Dropdown'), disabled: boolean('Disabled (disabled)', false), light: boolean('Light variant (light)', false), - titleText: text('Title (titleText)', 'This is a dropdown title.'), + titleText: text('Title (titleText)', 'Dropdown label'), helperText: text('Helper text (helperText)', 'This is some helper text.'), invalid: boolean('Show form validation UI (invalid)', false), invalidText: text( @@ -97,7 +87,10 @@ export default { export const Default = () => (
(item ? item.text : '')} onChange={action('onChange')} @@ -105,12 +98,12 @@ export const Default = () => (
); -Default.storyName = 'default'; - export const Inline = () => (
(item ? item.text : '')} @@ -119,70 +112,20 @@ export const Inline = () => (
); -Inline.storyName = 'inline'; - -Inline.parameters = { - info: { - text: 'Dropdown', - }, -}; - -export const ItemsAsStrings = () => ( -
- -
-); - -ItemsAsStrings.storyName = 'items as strings'; - -ItemsAsStrings.parameters = { - info: { - text: 'Rendering an array of strings as `items`', - }, -}; - -export const FullyControlled = () => ( - - {({ state, setState }) => ( -
- (item ? item.text : '')} - onChange={({ selectedItem }) => - setTimeout(() => setState({ selectedItem }), 1000) - } - selectedItem={state.selectedItem} - /> -
- )} -
-); - -FullyControlled.storyName = 'fully controlled'; - -FullyControlled.parameters = { - info: { - text: ` - Sometimes you want to control everything. - `, - }, +export const Playground = () => { + return ( +
+ (item ? item.text : '')} + /> +
+ ); }; export const Skeleton = () => (
-   -
); - -Skeleton.storyName = 'skeleton'; - -Skeleton.parameters = { - info: { - text: ` - Placeholder skeleton state to use when content is loading. - `, - }, -}; diff --git a/packages/react/src/components/Dropdown/Dropdown.Skeleton.js b/packages/react/src/components/Dropdown/Dropdown.Skeleton.js index 880b3f0f128a..8e8081956ad3 100644 --- a/packages/react/src/components/Dropdown/Dropdown.Skeleton.js +++ b/packages/react/src/components/Dropdown/Dropdown.Skeleton.js @@ -12,13 +12,12 @@ import { settings } from 'carbon-components'; const { prefix } = settings; -const DropdownSkeleton = ({ inline, className, ...rest }) => { +const DropdownSkeleton = ({ className, ...rest }) => { const wrapperClasses = cx(className, { [`${prefix}--skeleton`]: true, [`${prefix}--dropdown-v2`]: true, [`${prefix}--list-box`]: true, [`${prefix}--form-item`]: true, - [`${prefix}--list-box--inline`]: inline, }); return ( @@ -35,15 +34,6 @@ DropdownSkeleton.propTypes = { * Specify an optional className to add. */ className: PropTypes.string, - - /** - * Specify whether you want the inline version of this control - */ - inline: PropTypes.bool, -}; - -DropdownSkeleton.defaultProps = { - inline: false, }; export default DropdownSkeleton; diff --git a/packages/react/src/components/Dropdown/Dropdown.mdx b/packages/react/src/components/Dropdown/Dropdown.mdx index 78582e8e2e1e..ab387743264d 100644 --- a/packages/react/src/components/Dropdown/Dropdown.mdx +++ b/packages/react/src/components/Dropdown/Dropdown.mdx @@ -18,6 +18,10 @@ import DropdownSkeleton from './Dropdown.Skeleton'; - [Dropdown `itemToString`](#dropdown-itemtostring) - [Dropdown `items`](#dropdown-items) - [Dropdown `light`](#dropdown-light) + - [Dropdown `selectedItem`](#dropdown-selecteditem) + - [Dropdown `size`](#dropdown-size) + - [Dropdown `titleText`](#dropdown-titletext) + - [Dropdown `type`](#dropdown-type) - [References](#references) - [Feedback](#feedback) @@ -73,6 +77,7 @@ to the top of the screen. To do this, specify `direction="top"` itemToString={(item) => (item ? item.text : '')} label="Select an option..." direction="top" + id="direction" /> ```jsx @@ -120,6 +125,7 @@ dropdown item in a custom element. ) } label="Select an option..." + id="item-to-element" /> ```jsx @@ -190,8 +196,97 @@ to toggle the light variant of the `Dropdown`. ... ``` +### Dropdown `selectedItem` + +You can pass a `selectedItem` to the `Dropdown` to set a value on initial load. +Keep in mind, if you set a value the `Dropdown` will become a controlled +component and you will need to handle state management. + +```jsx +const [currentItem, setCurrentItem] = useState(items[4]); +... + (item ? item.text : '')} + onChange={({ selectedItem }) => setCurrentItem(selectedItem)} + selectedItem={currentItem} +/> +``` + +### Dropdown `size` + +There are three sizes of `Dropdown` available: `sm`, `lg` (the default), and +`xl`. + + +
+ +
+ + +```jsx + + + +``` + +### Dropdown `titleText` + +This is the text that will be used as a label for the `Dropdown` + +```jsx + +``` + +### Dropdown `type` + +Sometimes you will need to place a `Dropdown` inline with other content. To do +that, pass in `type="inline"` to the `Dropdown` + + + +```jsx + +``` + ## References +- [Carbon Usage Guidelines](https://www.carbondesignsystem.com/components/dropdown/usage/) + ## Feedback Help us improve this component by providing feedback, asking questions, and