Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | 1x 37x 1x 15x 15x 15x 15x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { map, isNil } from 'lodash'; import React, { useState } from 'react'; import { Meta } from '@storybook/react'; import SingleSelect from './SingleSelect'; import DangerIcon from '../Icon/DangerIcon/DangerIcon'; import PlusIcon from '../Icon/PlusIcon/PlusIcon'; import SuccessIcon from '../Icon/SuccessIcon/SuccessIcon'; import InfoIcon from '../Icon/InfoIcon/InfoIcon'; //π Provide Storybook with the component name, 'section', any subcomponents and a description export default { title: 'Controls/SingleSelect', component: SingleSelect, subcomponents: { 'SingleSelect.Placeholder': SingleSelect.Placeholder, 'SingleSelect.Option': SingleSelect.Option, 'SingleSelect.Option.Selected': SingleSelect.Option.Selected, 'SingleSelect.OptionGroup': SingleSelect.OptionGroup, }, parameters: { docs: { description: { component: SingleSelect.peek.description, }, }, }, } as Meta; //π Destructure any child components that we will need const { Option, OptionGroup } = SingleSelect; //π Add a key prop to each element of the array function addKeys(children) { return map(children, (child, index) => ({ ...child, key: index })); } //π Create a βtemplateβ of how args map to rendering const Template: any = (args) => { const [selectedIndex, setSelectedIndex] = useState<number | null>(null); const [selectedOptionName, setSelectedOptionName] = useState<string | null>( null ); const handleSelect = (optionIndex: number | null) => { const name = !isNil(optionIndex) ? args.children[optionIndex].props.name : null; setSelectedIndex(optionIndex); setSelectedOptionName(name); }; return ( <section style={{ minHeight: '10em' }}> <SingleSelect {...args} onSelect={(e) => handleSelect(e)}></SingleSelect> {!isNil(selectedIndex) && ( <section style={{ paddingTop: 9, paddingLeft: 9 }}> Selected Index: {JSON.stringify(selectedIndex)} </section> )} {selectedOptionName && ( <section style={{ paddingLeft: 9 }}> <p>Selected Option Name: {JSON.stringify(selectedOptionName)}</p> </section> )} </section> ); }; /** Basic */ export const Basic = Template.bind({}); Basic.args = { Placeholder: 'Select Color', children: addKeys([ <Option>Red</Option>, <Option>Green</Option>, <Option>Blue</Option>, ]), }; /** Named Options */ export const NamedOptions = Template.bind({}); NamedOptions.args = { ...Basic.args, children: addKeys([ <Option name='red'>Red</Option>, <Option name='green'>Green</Option>, <Option name='blue'>Blue</Option>, ]), }; NamedOptions.parameters = { docs: { description: { story: `Use named options when you need to display different values within the dropdown and elsewhere on the screen after the user makes a selection. `, }, }, }; /** Formatted Options */ const OptionCols = ({ col1, col2 }: { col1: string; col2: string }) => ( <div style={{ display: 'flex' }}> <div style={{ width: 100 }}>{col1}</div> <div>{col2}</div> </div> ); export const FormattedOptions = Template.bind({}); FormattedOptions.args = { ...Basic.args, children: addKeys([ <OptionGroup> <OptionCols col1='NAME' col2='ID' /> <Option Selected='Red (#FF0000)'> <OptionCols col1='Red' col2='#FF0000' /> </Option> <Option Selected='Green (#00FF00)'> <OptionCols col1='Green' col2='#00FF00' /> </Option> <Option Selected='Blue (#0000FF)'> <OptionCols col1='Blue' col2='#0000FF' /> </Option> </OptionGroup>, ]), }; FormattedOptions.parameters = { docs: { description: { story: `Use multiple columns of data in your dropdown when additional information is needed to make a selection. `, }, }, }; /** Grouped Options */ export const GroupedOptions = Template.bind({}); GroupedOptions.args = { ...Basic.args, children: addKeys([ <OptionGroup> Screen <Option>Red</Option> <Option>Green</Option> <Option>Blue</Option> </OptionGroup>, <OptionGroup> Print <Option>Cyan</Option> <Option>Yellow</Option> <Option>Magenta</Option> <Option>Black</Option> </OptionGroup>, ]), }; GroupedOptions.parameters = { docs: { description: { story: `Grouped options allows you to have sections within your dropdown. Use this to help frame users' understanding of the options. `, }, }, }; /** Disabled Options */ export const DisabledOptions = Template.bind({}); DisabledOptions.args = { ...Basic.args, children: addKeys([ <Option isDisabled>Red</Option>, <Option>Green</Option>, <Option isDisabled>Blue</Option>, ]), }; DisabledOptions.parameters = { docs: { description: { story: `Apply \`isDisabled\` to dropdown options that aren't currently available. `, }, }, }; /** Disabled Select */ export const DisabledSelect = Template.bind({}); DisabledSelect.args = { ...Basic.args, isDisabled: true, }; DisabledSelect.parameters = { docs: { description: { story: `Apply \`isDisabled\` to the dropdown if none of the options are currently available. `, }, }, }; /** No Unselect */ export const NoUnselect = Template.bind({}); NoUnselect.args = { ...Basic.args, hasReset: false, }; NoUnselect.parameters = { docs: { description: { story: `This removes the default state, displayed as the \`Placeholder\`. Use \`hasReset="false"\` to prevent users from deselecting a setting. `, }, }, }; /** Max Menu Height */ export const MaxMenuHeight = Template.bind({}); MaxMenuHeight.args = { ...Basic.args, maxMenuHeight: '7em', children: addKeys([ <Option>Aliceblue</Option>, <Option>Antiquewhite</Option>, <Option>Aqua</Option>, <Option>Aquamarine</Option>, <Option>Azure</Option>, <Option>Beige</Option>, <Option>Bisque</Option>, <Option>Black</Option>, <Option>Blanchedalmond</Option>, <Option>Blue</Option>, <Option>Blueviolet</Option>, <Option>Brown</Option>, <Option>Burlywood</Option>, <Option>Cadetblue</Option>, <Option>Chartreuse</Option>, ]), }; MaxMenuHeight.parameters = { docs: { description: { story: `Provide a fixed menu height with the \`maxMenuHeight\` prop. It will allow users to scroll through the options within a fixed height. `, }, }, }; /** Rich Content */ export const RichContent = Template.bind({}); RichContent.args = { ...Basic.args, Placeholder: ( <> <PlusIcon style={{ marginRight: 4 }} /> Add Color </> ), children: addKeys([ <Option> <DangerIcon style={{ marginRight: 4 }} /> Red </Option>, <Option> <SuccessIcon style={{ marginRight: 4 }} /> Green </Option>, <Option> <InfoIcon style={{ marginRight: 4 }} /> Blue </Option>, ]), }; RichContent.parameters = { docs: { description: { story: `You can include rich content in the dropdown. Use icons or other rich content where an image will help users make a selection: a company logo near the company name, for example. `, }, }, }; /** No Selection Highlighting */ export const NoSelectionHighlighting = Template.bind({}); NoSelectionHighlighting.args = { ...Basic.args, isSelectionHighlighted: false, }; NoSelectionHighlighting.parameters = { docs: { description: { story: `Use \`isSelectionHighlighted="false"\` when the dropdown defaults to null selections such as 'All' or 'Any'. The grey outline indicates that this selection does not need users' attention. `, }, }, }; /** Array Options */ export const ArrayOptions = Template.bind({}); ArrayOptions.args = { Placeholder: 'Select a Number', Option: addKeys([<Option>1</Option>, <Option>2</Option>, <Option>3</Option>]), }; ArrayOptions.parameters = { docs: { description: { story: `If needed, you can pass your dropdown option data as an array. `, }, }, }; /** Stateless */ export const Stateless = Template.bind({}); Stateless.args = { ...Basic.args, selectedIndex: 1, DropMenu: { focusedIndex: 2, isExpanded: true }, style: { minHeight: 220 }, children: addKeys([ <OptionGroup> Preferred <Option>Red</Option> <Option>Green</Option> <Option>Blue</Option> </OptionGroup>, <Option>Orange</Option>, <Option isDisabled>Violet</Option>, <Option isDisabled>Brown</Option>, ]), }; Stateless.parameters = { docs: { description: { story: ` This example shows the various states available in \`SingleSelect\`. `, }, }, }; /** Invisible */ export const Invisible = Template.bind({}); Invisible.args = { ...Basic.args, isInvisible: true, }; Invisible.parameters = { docs: { description: { story: `Setting the \`IsInvisible\` prop to 'true' removes the dropdown border. The lack of a border gives the dropdown a lighter visual weight within a data-intense layout. `, }, }, }; /** Invisible and Disabled */ export const InvisibleAndDisabled = Template.bind({}); InvisibleAndDisabled.args = { ...Basic.args, isInvisible: true, isDisabled: true, }; InvisibleAndDisabled.parameters = { docs: { description: { story: `Setting the \`IsInvisible\` prop to 'true' removes the dropdown border, and \`isDisabled\` indicates that the dropdown option isn't currently available. `, }, }, }; /** With Title */ export const Title = Template.bind({}); Title.args = { ...Basic.args, Title: 'Sample Title', }; Title.parameters = { docs: { description: { story: `Setting the \`Title\` prop to 'Sample Title' adds a title to the single select.`, }, }, }; |