|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
13 |
| -import {Button, Checkbox, CheckboxGroup, Form, Radio, RadioGroup, RangeSlider, SearchField, Slider, Switch, TextArea, TextField} from '../src'; |
| 13 | +import { |
| 14 | + ActionButton, |
| 15 | + Button, |
| 16 | + Checkbox, |
| 17 | + CheckboxGroup, |
| 18 | + ColorField, |
| 19 | + ColorSlider, |
| 20 | + ComboBox, |
| 21 | + ComboBoxItem, |
| 22 | + Content, |
| 23 | + ContextualHelp, |
| 24 | + Divider, |
| 25 | + Form, |
| 26 | + Heading, |
| 27 | + Meter, |
| 28 | + NumberField, |
| 29 | + Picker, |
| 30 | + PickerItem, |
| 31 | + ProgressBar, |
| 32 | + Radio, |
| 33 | + RadioGroup, |
| 34 | + RangeSlider, |
| 35 | + SearchField, |
| 36 | + Slider, |
| 37 | + Switch, |
| 38 | + Tag, |
| 39 | + TagGroup, |
| 40 | + TextArea, |
| 41 | + TextField, |
| 42 | + ToggleButton |
| 43 | +} from '../src'; |
14 | 44 | import {categorizeArgTypes} from './utils';
|
15 | 45 | import type {Meta} from '@storybook/react';
|
| 46 | +import SortDown from '../s2wf-icons/S2_Icon_SortDown_20_N.svg'; |
| 47 | +import SortUp from '../s2wf-icons/S2_Icon_SortUp_20_N.svg'; |
16 | 48 | import {style} from '../style/spectrum-theme' with {type: 'macro'};
|
| 49 | +import {useState} from 'react'; |
17 | 50 |
|
18 | 51 | const meta: Meta<typeof Form> = {
|
19 | 52 | component: Form,
|
@@ -54,3 +87,128 @@ export const Example = (args: any) => (
|
54 | 87 | <Button type="submit" variant="primary" styles={style({gridColumnStart: 'field', width: 'fit'})}>Submit</Button>
|
55 | 88 | </Form>
|
56 | 89 | );
|
| 90 | + |
| 91 | +export const MixedForm = (args: any) => ( |
| 92 | + <Form {...args}> |
| 93 | + <TextField label="First Name" name="firstName" /> |
| 94 | + <TextField label="Last Name" name="firstName" /> |
| 95 | + <TextField label="Email" name="email" type="email" description="Enter an email" /> |
| 96 | + <CheckboxGroup aria-label="Favorite sports"> |
| 97 | + <Checkbox value="soccer">Soccer</Checkbox> |
| 98 | + <Checkbox value="baseball">Baseball</Checkbox> |
| 99 | + <Checkbox value="basketball">Basketball</Checkbox> |
| 100 | + </CheckboxGroup> |
| 101 | + <RadioGroup aria-label="Favorite pet"> |
| 102 | + <Radio value="cat">Cat</Radio> |
| 103 | + <Radio value="dog">Dog</Radio> |
| 104 | + <Radio value="plant" isDisabled>Plant</Radio> |
| 105 | + </RadioGroup> |
| 106 | + <SearchField label="Search" name="search" /> |
| 107 | + </Form> |
| 108 | +); |
| 109 | + |
| 110 | +MixedForm.parameters = { |
| 111 | + docs: { |
| 112 | + disable: true |
| 113 | + } |
| 114 | +}; |
| 115 | + |
| 116 | + |
| 117 | +export const CustomLabelsExample = (args: any) => { |
| 118 | + const [isSortAscending, setIsSortAscending] = useState(true); |
| 119 | + return ( |
| 120 | + <Form {...args}> |
| 121 | + <div role="group" aria-labelledby="sortOrder" className={style({display: 'flex', alignItems: 'center', gap: 8, font: 'ui'})}> |
| 122 | + <span id="sortOrder">Sort order</span> |
| 123 | + <ActionButton aria-label="Sort direction" onPress={() => setIsSortAscending(!isSortAscending)}> |
| 124 | + { |
| 125 | + isSortAscending ? <SortUp /> : <SortDown /> |
| 126 | + } |
| 127 | + </ActionButton> |
| 128 | + <Picker aria-label="Sort by" styles={style({width: 208})}> |
| 129 | + <PickerItem id="name">Name</PickerItem> |
| 130 | + <PickerItem id="created">Created</PickerItem> |
| 131 | + </Picker> |
| 132 | + </div> |
| 133 | + <div role="group" aria-labelledby="filterTerms" className={style({display: 'flex', alignItems: 'center', gap: 8, font: 'ui'})}> |
| 134 | + <span id="filterTerms">Filter terms</span> |
| 135 | + <TagGroup aria-label="Keywords" styles={style({minWidth: 208})}> |
| 136 | + <Tag>keyword 1</Tag> |
| 137 | + <Tag>keyword 2</Tag> |
| 138 | + </TagGroup> |
| 139 | + </div> |
| 140 | + <Divider size="S" /> |
| 141 | + <div role="group" aria-labelledby="colorLabel" className={style({display: 'flex', alignItems: 'center', gap: 8, font: 'ui'})}> |
| 142 | + <span id="colorLabel">Color settings</span> |
| 143 | + <ToggleButton> |
| 144 | + Enable color |
| 145 | + </ToggleButton> |
| 146 | + <ColorField aria-label="Fill color" styles={style({width: 144})} /> |
| 147 | + <ColorSlider channel="alpha" defaultValue="#000" /> |
| 148 | + </div> |
| 149 | + <Divider size="S" /> |
| 150 | + <div role="group" aria-labelledby="searchLabel" className={style({display: 'flex', alignItems: 'center', gap: 8, font: 'ui'})}> |
| 151 | + <span id="searchLabel">Search</span> |
| 152 | + <ToggleButton> |
| 153 | + Enable search |
| 154 | + </ToggleButton> |
| 155 | + <TextField aria-label="Query" styles={style({width: 144})} /> |
| 156 | + <ComboBox aria-label="Search terms" styles={style({width: 144})}> |
| 157 | + <ComboBoxItem>search term 1</ComboBoxItem> |
| 158 | + <ComboBoxItem>search term 2</ComboBoxItem> |
| 159 | + </ComboBox> |
| 160 | + <NumberField aria-label="Number of results" defaultValue={50} styles={style({width: 96})} /> |
| 161 | + </div> |
| 162 | + <div role="group" aria-labelledby="searchParameters" className={style({display: 'flex', alignItems: 'center', gap: 16, font: 'ui'})}> |
| 163 | + <span id="searchParameters">Search parameters</span> |
| 164 | + <RadioGroup aria-label="Search range" orientation="horizontal" styles={style({width: 208})}> |
| 165 | + <Radio value="text">Text</Radio> |
| 166 | + <Radio value="images">Images</Radio> |
| 167 | + <Radio value="video">Video</Radio> |
| 168 | + </RadioGroup> |
| 169 | + <CheckboxGroup aria-label="Content display" orientation="horizontal" styles={style({width: 256})}> |
| 170 | + <Checkbox value="summary">Summary</Checkbox> |
| 171 | + <Checkbox value="date">Date</Checkbox> |
| 172 | + <Checkbox value="author">Author</Checkbox> |
| 173 | + </CheckboxGroup> |
| 174 | + </div> |
| 175 | + <Divider size="S" /> |
| 176 | + <div role="group" aria-label="Progress" className={style({display: 'flex', alignItems: 'center', gap: 16, font: 'ui'})}> |
| 177 | + <span>28% complete</span> |
| 178 | + <ProgressBar aria-label="Percent complete" value={28} styles={style({width: 144})} /> |
| 179 | + <span>44% confidence</span> |
| 180 | + <Meter aria-label="Search confidence" variant="positive" value={44} styles={style({width: 144})} /> |
| 181 | + </div> |
| 182 | + <Divider size="S" /> |
| 183 | + <div role="group" aria-labelledby="sliders" className={style({font: 'ui'})}> |
| 184 | + <div id="sliders">Sliders (with and without label)</div> |
| 185 | + <Slider |
| 186 | + aria-label="Days to search" |
| 187 | + label="With label" |
| 188 | + labelPosition="side" |
| 189 | + contextualHelp={ |
| 190 | + <ContextualHelp> |
| 191 | + <Heading>Help</Heading> |
| 192 | + <Content>Help content</Content> |
| 193 | + </ContextualHelp> |
| 194 | + } /> |
| 195 | + <Slider |
| 196 | + aria-label="Days to search" |
| 197 | + labelPosition="side" |
| 198 | + contextualHelp={ |
| 199 | + <ContextualHelp> |
| 200 | + <Heading>Help</Heading> |
| 201 | + <Content>Help content</Content> |
| 202 | + </ContextualHelp> |
| 203 | + } /> |
| 204 | + </div> |
| 205 | + <Button type="submit" variant="primary" styles={style({gridColumnStart: 'field', width: 'fit'})}>Submit</Button> |
| 206 | + </Form> |
| 207 | + ); |
| 208 | +}; |
| 209 | + |
| 210 | +CustomLabelsExample.parameters = { |
| 211 | + docs: { |
| 212 | + disable: true |
| 213 | + } |
| 214 | +}; |
0 commit comments