|
| 1 | +/* eslint-disable react/no-unescaped-entities */ |
1 | 2 | /* eslint-disable @typescript-eslint/no-unsafe-return */ |
2 | 3 | import { useState, useEffect, useRef } from 'react' |
3 | 4 | import styled from 'styled-components' |
@@ -184,17 +185,18 @@ Introduction.args = { |
184 | 185 |
|
185 | 186 | export const Multiple: StoryFn<AutocompleteProps<MyOptionType>> = (args) => { |
186 | 187 | const { options } = args |
| 188 | + |
187 | 189 | return ( |
188 | | - <> |
189 | | - <Autocomplete |
190 | | - label="Select multiple stocks" |
191 | | - options={options} |
192 | | - multiple |
193 | | - optionLabel={optionLabel} |
194 | | - /> |
195 | | - </> |
| 190 | + <Autocomplete |
| 191 | + label="Select multiple stocks" |
| 192 | + options={options} |
| 193 | + multiple |
| 194 | + placeholder="Select your stocks" |
| 195 | + optionLabel={optionLabel} |
| 196 | + /> |
196 | 197 | ) |
197 | 198 | } |
| 199 | + |
198 | 200 | Multiple.args = { |
199 | 201 | options: stocks, |
200 | 202 | } |
@@ -1002,3 +1004,38 @@ Variants.args = { |
1002 | 1004 | label: 'Select a stock', |
1003 | 1005 | options: stocks.map((item) => item.label), |
1004 | 1006 | } |
| 1007 | + |
| 1008 | +export const LargeDatasets: StoryFn<AutocompleteProps<MyOptionType>> = ( |
| 1009 | + args, |
| 1010 | +) => { |
| 1011 | + const { options } = args |
| 1012 | + const [selectedItems, setSelectedItems] = useState<MyOptionType[]>([]) |
| 1013 | + |
| 1014 | + const handleChange = (changes: AutocompleteChanges<MyOptionType>) => { |
| 1015 | + setSelectedItems(changes.selectedItems) |
| 1016 | + } |
| 1017 | + |
| 1018 | + return ( |
| 1019 | + <> |
| 1020 | + <Typography style={{ marginBottom: '1rem' }}> |
| 1021 | + This example simulates an API that returns 13 stocks from a total of |
| 1022 | + 1,500 available stocks. Notice how the selection counter shows "x/1,500 |
| 1023 | + selected" instead of "x/13 selected". |
| 1024 | + </Typography> |
| 1025 | + <Autocomplete |
| 1026 | + label="Select from paginated stock results" |
| 1027 | + options={options} |
| 1028 | + multiple |
| 1029 | + placeholder="Search and select stocks" |
| 1030 | + totalOptions={1500} // Total available options from API |
| 1031 | + selectedOptions={selectedItems} |
| 1032 | + onOptionsChange={handleChange} |
| 1033 | + optionLabel={optionLabel} |
| 1034 | + /> |
| 1035 | + </> |
| 1036 | + ) |
| 1037 | +} |
| 1038 | + |
| 1039 | +LargeDatasets.args = { |
| 1040 | + options: stocks, |
| 1041 | +} |
0 commit comments