diff --git a/packages/@react-spectrum/picker/stories/Picker.stories.tsx b/packages/@react-spectrum/picker/stories/Picker.stories.tsx index 47d836874ba..ec30826419c 100644 --- a/packages/@react-spectrum/picker/stories/Picker.stories.tsx +++ b/packages/@react-spectrum/picker/stories/Picker.stories.tsx @@ -15,21 +15,20 @@ import {ActionButton} from '@react-spectrum/button'; import AlignCenter from '@spectrum-icons/workflow/AlignCenter'; import AlignLeft from '@spectrum-icons/workflow/AlignLeft'; import AlignRight from '@spectrum-icons/workflow/AlignRight'; +import {ComponentMeta, ComponentStoryObj} from '@storybook/react'; import {Content} from '@react-spectrum/view'; import {ContextualHelp} from '@react-spectrum/contextualhelp'; import Copy from '@spectrum-icons/workflow/Copy'; import Cut from '@spectrum-icons/workflow/Cut'; import {Flex} from '@react-spectrum/layout'; import {Heading} from '@react-spectrum/text'; -import {Item, Picker, Section} from '../'; +import {Item, Picker, Section, SpectrumPickerProps} from '../'; import Paste from '@spectrum-icons/workflow/Paste'; -import React, {useState} from 'react'; -import {storiesOf} from '@storybook/react'; +import React, {useState} from 'react'; import {Text} from '@react-spectrum/text'; import {useAsyncList} from '@react-stately/data'; import {View} from '@react-spectrum/view'; - let flatOptions = [ {id: 1, name: 'Aardvark'}, {id: 2, name: 'Kangaroo'}, @@ -42,6 +41,22 @@ let flatOptions = [ {id: 9, name: 'Floof'} ]; +let longItemText = [ + {id: 'short', name: 'One'}, + {id: 'long', name: 'your text here long long long long'}, + {id: 'underscores', name: 'your_text_here_long_long_long_long'}, + {id: 'hypens', name: 'your-text-here-long-long-long-long'}, + {id: 'singleWord', name: 'supercalifragilisticexpialidocious'}, + {id: 'always', name: 'This item is very long and word wraps poorly'} +]; + +let falsyKey = [ + {id: '', name: 'None'}, + {id: 'One', name: 'One'}, + {id: 'Two', name: 'Two'}, + {id: 'Three', name: 'Three'} +]; + let withSection = [ {name: 'Animals', children: [ {name: 'Aardvark'}, @@ -55,552 +70,317 @@ let withSection = [ ]} ]; -storiesOf('Picker', module) - .add( - 'default', - () => ( - - Short - Normal - This item is very long and word wraps poorly - - ) - ) - .add( - 'disabled keys', - () => ( - - Short - Normal - This item is very long and word wraps poorly - - ) - ) - .add( - 'sections', - () => ( - -
- Aardvark - Kangaroo - Snake -
-
- Danni - Devon - Ross -
-
- ) - ) - .add( - 'dynamic', - () => ( - - {item => {item.name}} - - ) - ) - .add( - 'dynamic with sections', - () => ( - - {item => ( -
- {item => {item.name}} -
- )} -
- ) - ) - .add( - 'isDisabled', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isDisabled, selectedKey', - () => ( - - One - Two - Three - - ) - ) - .add( - 'labelAlign: end', - () => ( - - One - Two - Three - - ) - ) - .add( - 'labelPosition: side', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isRequired', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isRequired, necessityIndicator: label', - () => ( - - One - Two - Three - - ) - ) - .add( - 'optional, necessityIndicator: label', - () => ( - - One - Two - Three - - ) - ) - .add( - 'validationState: invalid', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isQuiet', - () => ( - - One hundred - Two thousand and twelve - Three - - ) - ) - .add( - 'isQuiet, isDisabled', - () => ( - - One - Two million - Three - - ) - ) - .add( - 'isQuiet, labelAlign: end', - () => ( - - One - Two dollary-doos - Three - - ) - ) - .add( - 'isQuiet, labelPosition: side', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isQuiet, isRequired', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isQuiet, isRequired, necessityIndicator: label', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isQuiet, optional, necessityIndicator: label', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isQuiet, validationState: invalid', - () => ( - - One - Two - Three - +export type PickerStory = ComponentStoryObj; + +export default { + title: 'Picker', + component: Picker, + excludeStories: [], + args: { + 'label': 'Test', + onSelectionChange: action('onSelectionChange'), + onOpenChange: action('onOpenChange') + }, + argTypes: { + layout: { + table: { + disable: true + } + }, + children: { + table: { + disable: true + } + }, + onSelectionChange: { + table: { + disable: true + } + }, + onOpenChange: { + table: { + disable: true + } + }, + label: { + control: 'text' + }, + description: { + control: 'text' + }, + errorMessage: { + control: 'text' + }, + isDisabled: { + control: 'boolean', + defaultValue: false + }, + labelAlign: { + control: 'radio', + defaultValue: 'start', + options: ['end', 'start'] + }, + labelPosition: { + control: 'radio', + defaultValue: 'top', + options: ['side', 'top'] + }, + necessityIndicator: { + control: 'radio', + defaultValue: 'icon', + options: ['icon', 'label'] + }, + isRequired: { + control: 'boolean', + defaultValue: false + }, + validationState: { + control: { + type: 'radio', + options: [null, 'valid', 'invalid'] + } + }, + isQuiet: { + control: 'boolean', + defaultValue: false + }, + width: { + control: { + type: 'radio', + options: [null, '100px', '480px', 'size-4600'] + } + }, + menuWidth: { + control: { + type: 'radio', + options: [null, '100px', '480px', 'size-4600'] + } + }, + isLoading: { + control: 'boolean', + defaultValue: false + }, + autoFocus: { + control: 'boolean', + defaultValue: false + }, + isOpen: { + control: 'boolean' + }, + defaultOpen: { + control: 'boolean' + } + } +} as ComponentMeta; + +export type DefaultStory = ComponentStoryObj; +export const Default: DefaultStory = { + render: (args) => +}; + +export const Disabled: DefaultStory = { + render: (args) => , + name: 'disabled keys' +}; + +export const Sections: PickerStory = { + args: { + children: ( +
+ Aardvark + Kangaroo + Snake +
) - ) - .add( - 'complex items', - () => ( - -
- - - Copy - - - - Cut - - - - Paste - -
-
- - - Puppy - Puppy description super long as well geez - - - - Doggo with really really really long long long text - - - - Floof - + } +}; + +export const Dynamic: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: flatOptions + }, + name: 'dynamic' +}; + +export const DynamicSections: PickerStory = { + args: { + children: ( + (item: any) => ( +
+ {(item: any) => {item.name}}
- - ) - ) - .add( - 'long item text', - () => ( - - One - your text here long long long long - your_text_here_long_long_long_long - your-text-here-long-long-long-long - supercalifragilisticexpialidocious - This item is very long and word wraps poorly - - ) - ) - .add( - 'falsy item key', - () => ( - - None - One - Two - Three - - ) - ) - .add( - 'no visible label', - () => ( - - One - Two - Three - - ) - ) - .add( - 'with description', - () => ( - - One - Two - Three - - ) - ) - .add( - 'with error message', - () => ( - - One - Two - Three - - ) - ) - .add( - 'contextual help', - () => ( - - What is a segment? - Segments identify who your visitors are, what devices and services they use, where they navigated from, and much more. - - )} - onSelectionChange={action('selectionChange')}> - One - Two - Three - - ) - ) - .add( - 'isQuiet, no visible label', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isQuiet, align: end', - () => ( - - One - Two - Three - - ) - ) - .add( - 'custom widths', - () => ( - - - One - Two - Three - - - One - Two - Three - - - ) - ) - .add( - 'custom widths, labelPosition: side', - () => ( - - - One - Two - Three - - - One - Two - Three - - - ) - ) - .add( - 'custom menu widths', - () => ( - - - One - Two - Three - - - One - Two - Three - - - ) - ) - .add( - 'custom menu widths, isQuiet', - () => ( - - - One - Two - Three - - - One - Two - Three - - - ) - ) - .add( - 'custom menu width, align: end', - () => ( - - One - Two - Three - - ) - ) - .add( - 'isOpen (controlled)', - () => ( - - One - Two - Three - - ) - ) - .add( - 'defaultOpen (uncontrolled)', - () => ( - - One - Two - Three - - ) - ) - .add( - 'selectedKey (controlled)', - () => ( - - One - Two - Three - - ) - ) - .add( - 'defaultSelectedKey (uncontrolled)', - () => ( - - One - Two - Three - - ) - ) - .add( - 'picker closes on blur', - () => ( - <> -
- - - - One - Two - Three - - - -
- - ) - ) - .add( - 'isLoading', - () => ( - - {item => {item.name}} - - ) - ) - .add( - 'isLoading, isQuiet', - () => ( - - {item => {item.name}} - - ) - ) - .add( - 'isLoading more', - () => ( - - {item => {item.name}} - - ) - ) - .add( - 'async loading', - () => ( - - ) - ).add( - 'focus', - () => ( -
- - - - {item => {item.name}} - - - -
- ) - ) - .add('resize', () => ) - .add('autofocus', () => ( - - One - Two - Three - - )) - .add('scrolling container', () => ( + ) + ), + items: withSection + }, + name: 'dynamic with sections' +}; + +export type ComplexItemsStory = ComponentStoryObj; +export const ComplexItems: ComplexItemsStory = { + render: (args) => , + name: 'complex items' +}; + +export const LongItemText: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: longItemText + }, + name: 'long item text' +}; + +export const FalsyKey: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: falsyKey + }, + name: 'falsy item key' +}; + +export const NoLabel: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: flatOptions, + 'aria-label': 'Test', + label: null + }, + name: 'no visible label' +}; + +export const ContextualHelpPicker: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: flatOptions, + contextualHelp: ( + + What is a segment? + Segments identify who your visitors are, what devices and services they use, where they navigated from, and much more. + + ) + }, + name: 'contextual help' +}; + +export const SelectedKey: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: flatOptions, + selectedKey: 7 + }, + name: 'selectedKey' +}; + +export const DefaultSelectedKey: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: flatOptions, + defaultSelectedKey: 7 + }, + name: 'defaultSelectedKey (uncontrolled)' +}; + +export const Loading: PickerStory = { + args: { + children: (item: any) => {item.name}, + items: [], + isLoading: true + }, + name: 'isLoading, no items' +}; + +export type AsyncLoadingStory = ComponentStoryObj; +export const AsyncLoading: AsyncLoadingStory = { + render: (args) => , + name: 'async loading' +}; + +export type FocusStory = ComponentStoryObj; +export const Focus: FocusStory = { + render: (args) => ( +
+ + + + {(item: any) => {item.name}} + + + +
+ ), + name: 'keyboard tab focus' +}; + +export type ResizePickerStory = ComponentStoryObj; +export const Resize: ResizePickerStory = { + render: (args) => , + name: 'resize' +}; + +export type ScrollingStory = ComponentStoryObj; +export const Scrolling: ScrollingStory = { + render: (args) => ( - + One Two Three - )); + ), + name: 'scrolling container' +}; + +function DefaultPicker(props: SpectrumPickerProps) { + return ( + + Short + Normal + This item is very long and word wraps poorly + + ); +} + +function ComplexItemsPicker(props: SpectrumPickerProps) { + return ( + +
+ + + Copy + + + + Cut + + + + Paste + +
+
+ + + Puppy + Puppy description super long as well geez + + + + Doggo with really really really long long long text + + + + Floof + +
+
+ ); +} -function AsyncLoadingExample() { +function AsyncLoadingExample(props) { interface Pokemon { name: string, url: string @@ -620,19 +400,19 @@ function AsyncLoadingExample() { }); return ( - - {item => {item.name}} + + {(item: any) => {item.name}} ); } -function ResizePicker() { +function ResizePicker(props) { const [state, setState] = useState(true); return (
- + A1 A2 A3