@@ -6,7 +6,13 @@ import { IconButton, InputGroup } from '../../../../components/input';
66import SelectNext from '../../../../components/input/SelectNext' ;
77import Library from '../../Library' ;
88
9- const defaultItems = [
9+ type ItemType = {
10+ id : string ;
11+ name : string ;
12+ disabled ?: boolean ;
13+ } ;
14+
15+ const defaultItems : ItemType [ ] = [
1016 { id : '1' , name : 'All students' } ,
1117 { id : '2' , name : 'Albert Banana' } ,
1218 { id : '3' , name : 'Bernard California' } ,
@@ -25,13 +31,14 @@ function SelectExample({
2531 classes ?: string ;
2632 items ?: typeof defaultItems ;
2733} ) {
28- const [ value , setValue ] = useState < ( typeof items ) [ number ] > ( ) ;
34+ const [ value , setValue ] = useState < ItemType > ( ) ;
2935
3036 return (
3137 < SelectNext
3238 value = { value }
3339 onChange = { setValue }
3440 classes = { classes }
41+ disabled = { disabled }
3542 buttonContent = {
3643 value ? (
3744 < >
@@ -51,21 +58,27 @@ function SelectExample({
5158 < > Select one...</ >
5259 )
5360 }
54- disabled = { disabled }
5561 >
5662 { items . map ( item => (
57- < SelectNext . Option value = { item } key = { item . id } >
58- { textOnly ? (
59- item . name
60- ) : (
61- < >
62- { item . name }
63- < div className = "grow" />
64- < div className = "rounded px-2 ml-2 bg-grey-7 text-white" >
65- { item . id }
66- </ div >
67- </ >
68- ) }
63+ < SelectNext . Option value = { item } key = { item . id } disabled = { item . disabled } >
64+ { ( { disabled } ) =>
65+ textOnly ? (
66+ item . name
67+ ) : (
68+ < >
69+ { item . name }
70+ < div className = "grow" />
71+ < div
72+ className = { classnames ( 'rounded px-2 ml-2 text-white' , {
73+ 'bg-grey-7' : ! disabled ,
74+ 'bg-grey-4' : disabled ,
75+ } ) }
76+ >
77+ { item . id }
78+ </ div >
79+ </ >
80+ )
81+ }
6982 </ SelectNext . Option >
7083 ) ) }
7184 </ SelectNext >
@@ -215,14 +228,6 @@ export default function SelectNextPage() {
215228 </ Library . Demo >
216229 </ Library . Example >
217230
218- < Library . Example title = "Disabled Select" >
219- < Library . Demo title = "Disabled Select" >
220- < div className = "w-96 mx-auto" >
221- < SelectExample disabled />
222- </ div >
223- </ Library . Demo >
224- </ Library . Example >
225-
226231 < Library . Example title = "Select with long content" >
227232 < p >
228233 < code > SelectNext</ code > makes sure the button content never
@@ -259,70 +264,75 @@ export default function SelectNextPage() {
259264 </ Library . Example >
260265 </ Library . Pattern >
261266
262- < Library . Pattern title = "Component API" >
267+ < Library . Pattern title = "SelectNext component API" >
263268 < code > SelectNext</ code > accepts all standard{ ' ' }
264269 < Library . Link href = "/using-components#presentational-components-api" >
265270 presentational component props
266271 </ Library . Link >
267- < Library . Example title = "buttonContent " >
272+ < Library . Example title = "value " >
268273 < Library . Info >
269274 < Library . InfoItem label = "description" >
270- The content to be displayed in the toggle button .
275+ Represents currently selected Option .
271276 </ Library . InfoItem >
272277 < Library . InfoItem label = "type" >
273- < code > ComponentChildren </ code >
278+ < code > T </ code >
274279 </ Library . InfoItem >
275280 </ Library . Info >
276281 </ Library . Example >
277- < Library . Example title = "value " >
282+ < Library . Example title = "onChange " >
278283 < Library . Info >
279284 < Library . InfoItem label = "description" >
280- Represents currently selected Option .
285+ A callback invoked every time selected value changes .
281286 </ Library . InfoItem >
282287 < Library . InfoItem label = "type" >
283- < code > T </ code >
288+ < code > (newValue: T) => void </ code >
284289 </ Library . InfoItem >
285290 </ Library . Info >
286291 </ Library . Example >
287- < Library . Example title = "onChange " >
292+ < Library . Example title = "buttonContent " >
288293 < Library . Info >
289294 < Library . InfoItem label = "description" >
290- A callback invoked every time selected value changes .
295+ The content to be displayed in the toggle button .
291296 </ Library . InfoItem >
292297 < Library . InfoItem label = "type" >
293- < code > (newValue: T) => void </ code >
298+ < code > ComponentChildren </ code >
294299 </ Library . InfoItem >
295300 </ Library . Info >
296301 </ Library . Example >
297- < Library . Example title = "disabled " >
302+ < Library . Example title = "buttonId " >
298303 < Library . Info >
299304 < Library . InfoItem label = "description" >
300- Whether the Select is disabled or not .
305+ The toggle button { "'" } s < code > id </ code > .
301306 </ Library . InfoItem >
302307 < Library . InfoItem label = "type" >
303- < code > boolean </ code >
308+ < code > string </ code >
304309 </ Library . InfoItem >
305310 < Library . InfoItem label = "default" >
306311 < code > undefined</ code >
307312 </ Library . InfoItem >
308313 </ Library . Info >
309314 </ Library . Example >
310- < Library . Example title = "buttonId " >
315+ < Library . Example title = "disabled " >
311316 < Library . Info >
312317 < Library . InfoItem label = "description" >
313- The toggle button { "'" } s < code > id </ code > .
318+ Whether the Select is disabled or not .
314319 </ Library . InfoItem >
315320 < Library . InfoItem label = "type" >
316- < code > string </ code >
321+ < code > boolean </ code >
317322 </ Library . InfoItem >
318323 < Library . InfoItem label = "default" >
319324 < code > undefined</ code >
320325 </ Library . InfoItem >
321326 </ Library . Info >
327+ < Library . Demo title = "Disabled Select" >
328+ < div className = "w-96 mx-auto" >
329+ < SelectExample disabled />
330+ </ div >
331+ </ Library . Demo >
322332 </ Library . Example >
323- < p >
324- Every < code > SelectNext.Option </ code > has its own set of props.
325- </ p >
333+ </ Library . Pattern >
334+
335+ < Library . Pattern title = "SelectNext.Option component API" >
326336 < Library . Example title = "children" >
327337 < Library . Info >
328338 < Library . InfoItem label = "description" >
@@ -359,6 +369,15 @@ export default function SelectNextPage() {
359369 < code > undefined</ code >
360370 </ Library . InfoItem >
361371 </ Library . Info >
372+ < Library . Demo title = "Disabled options" >
373+ < div className = "w-96 mx-auto" >
374+ < SelectExample
375+ items = { defaultItems . map ( item =>
376+ item . id !== '4' ? item : { ...item , disabled : true } ,
377+ ) }
378+ />
379+ </ div >
380+ </ Library . Demo >
362381 </ Library . Example >
363382 </ Library . Pattern >
364383
0 commit comments