@@ -6,7 +6,13 @@ import { IconButton, InputGroup } from '../../../../components/input';
6
6
import SelectNext from '../../../../components/input/SelectNext' ;
7
7
import Library from '../../Library' ;
8
8
9
- const defaultItems = [
9
+ type ItemType = {
10
+ id : string ;
11
+ name : string ;
12
+ disabled ?: boolean ;
13
+ } ;
14
+
15
+ const defaultItems : ItemType [ ] = [
10
16
{ id : '1' , name : 'All students' } ,
11
17
{ id : '2' , name : 'Albert Banana' } ,
12
18
{ id : '3' , name : 'Bernard California' } ,
@@ -25,13 +31,14 @@ function SelectExample({
25
31
classes ?: string ;
26
32
items ?: typeof defaultItems ;
27
33
} ) {
28
- const [ value , setValue ] = useState < ( typeof items ) [ number ] > ( ) ;
34
+ const [ value , setValue ] = useState < ItemType > ( ) ;
29
35
30
36
return (
31
37
< SelectNext
32
38
value = { value }
33
39
onChange = { setValue }
34
40
classes = { classes }
41
+ disabled = { disabled }
35
42
buttonContent = {
36
43
value ? (
37
44
< >
@@ -51,21 +58,27 @@ function SelectExample({
51
58
< > Select one...</ >
52
59
)
53
60
}
54
- disabled = { disabled }
55
61
>
56
62
{ 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
+ }
69
82
</ SelectNext . Option >
70
83
) ) }
71
84
</ SelectNext >
@@ -215,14 +228,6 @@ export default function SelectNextPage() {
215
228
</ Library . Demo >
216
229
</ Library . Example >
217
230
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
-
226
231
< Library . Example title = "Select with long content" >
227
232
< p >
228
233
< code > SelectNext</ code > makes sure the button content never
@@ -259,70 +264,75 @@ export default function SelectNextPage() {
259
264
</ Library . Example >
260
265
</ Library . Pattern >
261
266
262
- < Library . Pattern title = "Component API" >
267
+ < Library . Pattern title = "SelectNext component API" >
263
268
< code > SelectNext</ code > accepts all standard{ ' ' }
264
269
< Library . Link href = "/using-components#presentational-components-api" >
265
270
presentational component props
266
271
</ Library . Link >
267
- < Library . Example title = "buttonContent " >
272
+ < Library . Example title = "value " >
268
273
< Library . Info >
269
274
< Library . InfoItem label = "description" >
270
- The content to be displayed in the toggle button .
275
+ Represents currently selected Option .
271
276
</ Library . InfoItem >
272
277
< Library . InfoItem label = "type" >
273
- < code > ComponentChildren </ code >
278
+ < code > T </ code >
274
279
</ Library . InfoItem >
275
280
</ Library . Info >
276
281
</ Library . Example >
277
- < Library . Example title = "value " >
282
+ < Library . Example title = "onChange " >
278
283
< Library . Info >
279
284
< Library . InfoItem label = "description" >
280
- Represents currently selected Option .
285
+ A callback invoked every time selected value changes .
281
286
</ Library . InfoItem >
282
287
< Library . InfoItem label = "type" >
283
- < code > T </ code >
288
+ < code > (newValue: T) => void </ code >
284
289
</ Library . InfoItem >
285
290
</ Library . Info >
286
291
</ Library . Example >
287
- < Library . Example title = "onChange " >
292
+ < Library . Example title = "buttonContent " >
288
293
< Library . Info >
289
294
< Library . InfoItem label = "description" >
290
- A callback invoked every time selected value changes .
295
+ The content to be displayed in the toggle button .
291
296
</ Library . InfoItem >
292
297
< Library . InfoItem label = "type" >
293
- < code > (newValue: T) => void </ code >
298
+ < code > ComponentChildren </ code >
294
299
</ Library . InfoItem >
295
300
</ Library . Info >
296
301
</ Library . Example >
297
- < Library . Example title = "disabled " >
302
+ < Library . Example title = "buttonId " >
298
303
< Library . Info >
299
304
< Library . InfoItem label = "description" >
300
- Whether the Select is disabled or not .
305
+ The toggle button { "'" } s < code > id </ code > .
301
306
</ Library . InfoItem >
302
307
< Library . InfoItem label = "type" >
303
- < code > boolean </ code >
308
+ < code > string </ code >
304
309
</ Library . InfoItem >
305
310
< Library . InfoItem label = "default" >
306
311
< code > undefined</ code >
307
312
</ Library . InfoItem >
308
313
</ Library . Info >
309
314
</ Library . Example >
310
- < Library . Example title = "buttonId " >
315
+ < Library . Example title = "disabled " >
311
316
< Library . Info >
312
317
< Library . InfoItem label = "description" >
313
- The toggle button { "'" } s < code > id </ code > .
318
+ Whether the Select is disabled or not .
314
319
</ Library . InfoItem >
315
320
< Library . InfoItem label = "type" >
316
- < code > string </ code >
321
+ < code > boolean </ code >
317
322
</ Library . InfoItem >
318
323
< Library . InfoItem label = "default" >
319
324
< code > undefined</ code >
320
325
</ Library . InfoItem >
321
326
</ Library . Info >
327
+ < Library . Demo title = "Disabled Select" >
328
+ < div className = "w-96 mx-auto" >
329
+ < SelectExample disabled />
330
+ </ div >
331
+ </ Library . Demo >
322
332
</ 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" >
326
336
< Library . Example title = "children" >
327
337
< Library . Info >
328
338
< Library . InfoItem label = "description" >
@@ -359,6 +369,15 @@ export default function SelectNextPage() {
359
369
< code > undefined</ code >
360
370
</ Library . InfoItem >
361
371
</ 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 >
362
381
</ Library . Example >
363
382
</ Library . Pattern >
364
383
0 commit comments