@instructure/ui-options 11.0.1-snapshot-0 → 11.0.1-snapshot-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,636 +88,322 @@ type: example
88
88
 
89
89
  `Options` does not manage any state or react to any user interaction. The consuming component or app should listen for events on items and update the `variant` props accordingly via its own state.
90
90
 
91
- - ```js
92
- class Example extends React.Component {
93
- constructor(props) {
94
- super(props)
95
-
96
- this.state = {
97
- highlighted: -1,
98
- selected: -1
99
- }
100
- }
101
-
102
- handleKeyDown = (event) => {
103
- const { highlighted } = this.state
104
- let index = highlighted
105
-
106
- if (event.keyCode === 40 && highlighted < this.props.options.length - 1) {
107
- // down arrow
108
- event.preventDefault()
109
- index = highlighted + 1
110
- } else if (event.keyCode === 38 && highlighted > 0) {
111
- // up arrow
112
- event.preventDefault()
113
- index = highlighted - 1
114
- } else if (event.keyCode === 13 && highlighted > -1) {
115
- // enter
116
- this.setState({ selected: index })
117
- }
118
- this.setState({ highlighted: index })
119
- }
120
-
121
- handleFocus = (event, index) => {
122
- this.setState({ highlighted: index })
123
- }
124
-
125
- handleMouseOver = (event, index) => {
126
- this.setState({ highlighted: index })
127
- }
128
-
129
- handleClick = (event, index) => {
130
- this.setState({ selected: index })
91
+ ```js
92
+ ---
93
+ type: example
94
+ ---
95
+ const Example = ({ options }) => {
96
+ const [highlighted, setHighlighted] = useState(-1)
97
+ const [selected, setSelected] = useState(-1)
98
+
99
+ const handleKeyDown = (event) => {
100
+ let index = highlighted
101
+
102
+ if (event.keyCode === 40 && highlighted < options.length - 1) {
103
+ // down arrow
104
+ event.preventDefault()
105
+ index = highlighted + 1
106
+ } else if (event.keyCode === 38 && highlighted > 0) {
107
+ // up arrow
108
+ event.preventDefault()
109
+ index = highlighted - 1
110
+ } else if (event.keyCode === 13 && highlighted > -1) {
111
+ // enter
112
+ setSelected(index)
131
113
  }
132
114
 
133
- render() {
134
- return (
135
- <View display="block" width="300px" shadow="above">
136
- <Options
137
- onKeyDown={this.handleKeyDown}
138
- onMouseOut={(e) => this.setState({ highlighted: -1 })}
139
- tabIndex="0"
140
- >
141
- {this.props.options.map((option, index) => {
142
- let variant = 'default'
143
- if (this.state.highlighted === index) {
144
- variant = 'highlighted'
145
- } else if (this.state.selected === index) {
146
- variant = 'selected'
147
- }
148
- return (
149
- <Options.Item
150
- key={option}
151
- variant={variant}
152
- tabIndex="-1"
153
- onMouseOver={(e) => this.handleMouseOver(e, index)}
154
- onFocus={(e) => this.handleFocus(e, index)}
155
- onClick={(e) => this.handleClick(e, index)}
156
- >
157
- {option}
158
- </Options.Item>
159
- )
160
- })}
161
- </Options>
162
- </View>
163
- )
164
- }
115
+ setHighlighted(index)
165
116
  }
166
117
 
167
- render(
168
- <Example
169
- options={[
170
- 'Option one',
171
- 'Option two',
172
- 'Option three',
173
- 'Option four',
174
- 'Option five'
175
- ]}
176
- />
177
- )
178
- ```
179
-
180
- - ```js
181
- const Example = ({ options }) => {
182
- const [highlighted, setHighlighted] = useState(-1)
183
- const [selected, setSelected] = useState(-1)
184
-
185
- const handleKeyDown = (event) => {
186
- let index = highlighted
187
-
188
- if (event.keyCode === 40 && highlighted < options.length - 1) {
189
- // down arrow
190
- event.preventDefault()
191
- index = highlighted + 1
192
- } else if (event.keyCode === 38 && highlighted > 0) {
193
- // up arrow
194
- event.preventDefault()
195
- index = highlighted - 1
196
- } else if (event.keyCode === 13 && highlighted > -1) {
197
- // enter
198
- setSelected(index)
199
- }
200
-
201
- setHighlighted(index)
202
- }
203
-
204
- const handleFocus = (index) => {
205
- setHighlighted(index)
206
- }
207
-
208
- const handleMouseOver = (index) => {
209
- setHighlighted(index)
210
- }
211
-
212
- const handleClick = (index) => {
213
- setSelected(index)
214
- }
118
+ const handleFocus = (index) => {
119
+ setHighlighted(index)
120
+ }
215
121
 
216
- return (
217
- <View display="block" width="300px" shadow="above">
218
- <Options
219
- onKeyDown={handleKeyDown}
220
- onMouseOut={() => setHighlighted(-1)}
221
- tabIndex="0"
222
- >
223
- {options.map((option, index) => {
224
- let variant = 'default'
225
- if (highlighted === index) {
226
- variant = 'highlighted'
227
- } else if (selected === index) {
228
- variant = 'selected'
229
- }
122
+ const handleMouseOver = (index) => {
123
+ setHighlighted(index)
124
+ }
230
125
 
231
- return (
232
- <Options.Item
233
- key={option}
234
- variant={variant}
235
- tabIndex="-1"
236
- onMouseOver={(e) => handleMouseOver(index)}
237
- onFocus={() => handleFocus(index)}
238
- onClick={() => handleClick(index)}
239
- >
240
- {option}
241
- </Options.Item>
242
- )
243
- })}
244
- </Options>
245
- </View>
246
- )
126
+ const handleClick = (index) => {
127
+ setSelected(index)
247
128
  }
248
129
 
249
- render(
250
- <Example
251
- options={[
252
- 'Option one',
253
- 'Option two',
254
- 'Option three',
255
- 'Option four',
256
- 'Option five'
257
- ]}
258
- />
130
+ return (
131
+ <View display="block" width="300px" shadow="above">
132
+ <Options
133
+ onKeyDown={handleKeyDown}
134
+ onMouseOut={() => setHighlighted(-1)}
135
+ tabIndex="0"
136
+ >
137
+ {options.map((option, index) => {
138
+ let variant = 'default'
139
+ if (highlighted === index) {
140
+ variant = 'highlighted'
141
+ } else if (selected === index) {
142
+ variant = 'selected'
143
+ }
144
+
145
+ return (
146
+ <Options.Item
147
+ key={option}
148
+ variant={variant}
149
+ tabIndex="-1"
150
+ onMouseOver={(e) => handleMouseOver(index)}
151
+ onFocus={() => handleFocus(index)}
152
+ onClick={() => handleClick(index)}
153
+ >
154
+ {option}
155
+ </Options.Item>
156
+ )
157
+ })}
158
+ </Options>
159
+ </View>
259
160
  )
260
- ```
161
+ }
162
+
163
+ render(
164
+ <Example
165
+ options={[
166
+ 'Option one',
167
+ 'Option two',
168
+ 'Option three',
169
+ 'Option four',
170
+ 'Option five'
171
+ ]}
172
+ />
173
+ )
174
+ ```
261
175
 
262
176
  You can recolor the text and the background of the items for their `default`, `highlighted` and `selected` variants.
263
177
 
264
178
  By default, the icons in the `Option.Item` have the same color as the text. If you want to set the color of the icon separately, pass a function to the `renderBeforeLabel` or `renderAfterLabel` prop. This function will have a `props` parameter, so you can access the properties of that `Option.Item` (e.g. the current `variant`). The available props are: `[ variant, as, role, children ]`.
265
179
 
266
- - ```js
267
- class Example extends React.Component {
268
- constructor(props) {
269
- super(props)
270
-
271
- this.state = {
272
- highlighted: -1,
273
- selected: -1
274
- }
275
- }
276
-
277
- handleKeyDown = (event) => {
278
- const { highlighted } = this.state
279
- let index = highlighted
280
-
281
- if (event.keyCode === 40 && highlighted < this.props.options.length - 1) {
282
- // down arrow
283
- event.preventDefault()
284
- index = highlighted + 1
285
- } else if (event.keyCode === 38 && highlighted > 0) {
286
- // up arrow
287
- event.preventDefault()
288
- index = highlighted - 1
289
- } else if (event.keyCode === 13 && highlighted > -1) {
290
- // enter
291
- this.setState({ selected: index })
292
- }
293
- this.setState({ highlighted: index })
180
+ ```js
181
+ ---
182
+ type: example
183
+ ---
184
+ const Example = ({ options }) => {
185
+ const [highlighted, setHighlighted] = useState(-1)
186
+ const [selected, setSelected] = useState(-1)
187
+
188
+ const handleKeyDown = (event) => {
189
+ let index = highlighted
190
+
191
+ if (event.keyCode === 40 && highlighted < options.length - 1) {
192
+ // down arrow
193
+ event.preventDefault()
194
+ index = highlighted + 1
195
+ } else if (event.keyCode === 38 && highlighted > 0) {
196
+ // up arrow
197
+ event.preventDefault()
198
+ index = highlighted - 1
199
+ } else if (event.keyCode === 13 && highlighted > -1) {
200
+ // enter
201
+ setSelected(index)
294
202
  }
295
203
 
296
- handleFocus = (event, index) => {
297
- this.setState({ highlighted: index })
298
- }
204
+ setHighlighted(index)
205
+ }
299
206
 
300
- handleMouseOver = (event, index) => {
301
- this.setState({ highlighted: index })
302
- }
207
+ const handleFocus = (event, index) => {
208
+ setHighlighted(index)
209
+ }
303
210
 
304
- handleClick = (event, index) => {
305
- this.setState({ selected: index })
306
- }
211
+ const handleMouseOver = (event, index) => {
212
+ setHighlighted(index)
213
+ }
307
214
 
308
- render() {
309
- return (
310
- <View display="block" width="300px" shadow="above">
311
- <Options
312
- onKeyDown={this.handleKeyDown}
313
- onMouseOut={(e) => this.setState({ highlighted: -1 })}
314
- tabIndex="0"
315
- >
316
- {this.props.options.map((option, index) => {
317
- let variant = 'default'
318
- if (this.state.highlighted === index) {
319
- variant = 'highlighted'
320
- } else if (this.state.selected === index) {
321
- variant = 'selected'
322
- }
323
- return (
324
- <Options.Item
325
- key={option.label}
326
- variant={variant}
327
- tabIndex="-1"
328
- onMouseOver={(e) => this.handleMouseOver(e, index)}
329
- onFocus={(e) => this.handleFocus(e, index)}
330
- onClick={(e) => this.handleClick(e, index)}
331
- {...option.extraProps}
332
- >
333
- {option.label}
334
- </Options.Item>
335
- )
336
- })}
337
- </Options>
338
- </View>
339
- )
340
- }
215
+ const handleClick = (event, index) => {
216
+ setSelected(index)
341
217
  }
342
218
 
343
- render(
344
- <Example
345
- options={[
346
- {
347
- label: 'Default item',
348
- extraProps: {
349
- renderBeforeLabel: IconCheckSolid
350
- }
351
- },
352
- {
353
- label: 'Text is green',
354
- extraProps: {
355
- renderBeforeLabel: IconCheckSolid,
356
- themeOverride: { color: '#0B874B' }
357
- }
358
- },
359
- {
360
- label: 'Highlighted text is black',
361
- extraProps: {
362
- renderBeforeLabel: IconCheckSolid,
363
- themeOverride: { highlightedLabelColor: '#2D3B45' }
364
- }
365
- },
366
- {
367
- label: 'Highlighted background is purple',
368
- extraProps: {
369
- renderBeforeLabel: IconCheckSolid,
370
- themeOverride: { highlightedBackground: '#BF32A4' }
371
- }
372
- },
373
- {
374
- label: 'Only the icon is red',
375
- extraProps: {
376
- renderBeforeLabel: (props) => {
377
- return (
378
- <IconCheckSolid
379
- {...(props.variant === 'default' && { color: 'warning' })}
380
- />
381
- )
382
- }
219
+ return (
220
+ <View display="block" width="300px" shadow="above">
221
+ <Options
222
+ onKeyDown={handleKeyDown}
223
+ onMouseOut={() => setHighlighted(-1)}
224
+ tabIndex="0"
225
+ >
226
+ {options.map((option, index) => {
227
+ let variant = 'default'
228
+ if (highlighted === index) {
229
+ variant = 'highlighted'
230
+ } else if (selected === index) {
231
+ variant = 'selected'
383
232
  }
384
- }
385
- ]}
386
- />
387
- )
388
- ```
389
-
390
- - ```js
391
- const Example = ({ options }) => {
392
- const [highlighted, setHighlighted] = useState(-1)
393
- const [selected, setSelected] = useState(-1)
394
-
395
- const handleKeyDown = (event) => {
396
- let index = highlighted
397
-
398
- if (event.keyCode === 40 && highlighted < options.length - 1) {
399
- // down arrow
400
- event.preventDefault()
401
- index = highlighted + 1
402
- } else if (event.keyCode === 38 && highlighted > 0) {
403
- // up arrow
404
- event.preventDefault()
405
- index = highlighted - 1
406
- } else if (event.keyCode === 13 && highlighted > -1) {
407
- // enter
408
- setSelected(index)
409
- }
410
-
411
- setHighlighted(index)
412
- }
413
-
414
- const handleFocus = (event, index) => {
415
- setHighlighted(index)
416
- }
417
-
418
- const handleMouseOver = (event, index) => {
419
- setHighlighted(index)
420
- }
421
-
422
- const handleClick = (event, index) => {
423
- setSelected(index)
424
- }
425
-
426
- return (
427
- <View display="block" width="300px" shadow="above">
428
- <Options
429
- onKeyDown={handleKeyDown}
430
- onMouseOut={() => setHighlighted(-1)}
431
- tabIndex="0"
432
- >
433
- {options.map((option, index) => {
434
- let variant = 'default'
435
- if (highlighted === index) {
436
- variant = 'highlighted'
437
- } else if (selected === index) {
438
- variant = 'selected'
439
- }
440
233
 
234
+ return (
235
+ <Options.Item
236
+ key={option.label}
237
+ variant={variant}
238
+ tabIndex="-1"
239
+ onMouseOver={(e) => handleMouseOver(e, index)}
240
+ onFocus={(e) => handleFocus(e, index)}
241
+ onClick={(e) => handleClick(e, index)}
242
+ {...option.extraProps}
243
+ >
244
+ {option.label}
245
+ </Options.Item>
246
+ )
247
+ })}
248
+ </Options>
249
+ </View>
250
+ )
251
+ }
252
+
253
+ render(
254
+ <Example
255
+ options={[
256
+ {
257
+ label: 'Default item',
258
+ extraProps: {
259
+ renderBeforeLabel: IconCheckSolid
260
+ }
261
+ },
262
+ {
263
+ label: 'Text is green',
264
+ extraProps: {
265
+ renderBeforeLabel: IconCheckSolid,
266
+ themeOverride: { color: '#0B874B' }
267
+ }
268
+ },
269
+ {
270
+ label: 'Highlighted text is black',
271
+ extraProps: {
272
+ renderBeforeLabel: IconCheckSolid,
273
+ themeOverride: { highlightedLabelColor: '#2D3B45' }
274
+ }
275
+ },
276
+ {
277
+ label: 'Highlighted background is purple',
278
+ extraProps: {
279
+ renderBeforeLabel: IconCheckSolid,
280
+ themeOverride: { highlightedBackground: '#BF32A4' }
281
+ }
282
+ },
283
+ {
284
+ label: 'Only the icon is red',
285
+ extraProps: {
286
+ renderBeforeLabel: (props) => {
441
287
  return (
442
- <Options.Item
443
- key={option.label}
444
- variant={variant}
445
- tabIndex="-1"
446
- onMouseOver={(e) => handleMouseOver(e, index)}
447
- onFocus={(e) => handleFocus(e, index)}
448
- onClick={(e) => handleClick(e, index)}
449
- {...option.extraProps}
450
- >
451
- {option.label}
452
- </Options.Item>
288
+ <IconCheckSolid
289
+ {...(props.variant === 'default' && { color: 'warning' })}
290
+ />
453
291
  )
454
- })}
455
- </Options>
456
- </View>
457
- )
458
- }
459
-
460
- render(
461
- <Example
462
- options={[
463
- {
464
- label: 'Default item',
465
- extraProps: {
466
- renderBeforeLabel: IconCheckSolid
467
- }
468
- },
469
- {
470
- label: 'Text is green',
471
- extraProps: {
472
- renderBeforeLabel: IconCheckSolid,
473
- themeOverride: { color: '#0B874B' }
474
- }
475
- },
476
- {
477
- label: 'Highlighted text is black',
478
- extraProps: {
479
- renderBeforeLabel: IconCheckSolid,
480
- themeOverride: { highlightedLabelColor: '#2D3B45' }
481
- }
482
- },
483
- {
484
- label: 'Highlighted background is purple',
485
- extraProps: {
486
- renderBeforeLabel: IconCheckSolid,
487
- themeOverride: { highlightedBackground: '#BF32A4' }
488
- }
489
- },
490
- {
491
- label: 'Only the icon is red',
492
- extraProps: {
493
- renderBeforeLabel: (props) => {
494
- return (
495
- <IconCheckSolid
496
- {...(props.variant === 'default' && { color: 'warning' })}
497
- />
498
- )
499
- }
500
292
  }
501
293
  }
502
- ]}
503
- />
504
- )
505
- ```
294
+ }
295
+ ]}
296
+ />
297
+ )
298
+ ```
506
299
 
507
300
  Additional/secondary text can be added via the `description` prop, and the ARIA role of it can be set with the `descriptionRole` prop.
508
301
 
509
302
  For longer, multi-line options the problem of the vertical alignment comes up. The content of the `renderBeforeLabel` and `renderAfterLabel` props are vertically centered by default. This can be changed with the `beforeLabelContentVAlign` and `afterLabelContentVAlign` props.
510
303
 
511
- - ```js
512
- class Example extends React.Component {
513
- constructor(props) {
514
- super(props)
515
-
516
- this.state = {
517
- highlighted: -1
518
- }
519
- }
520
-
521
- handleMouseOver = (index) => {
522
- this.setState({ highlighted: index })
523
- }
304
+ ```js
305
+ ---
306
+ type: example
307
+ ---
308
+ const Example = () => {
309
+ const [highlighted, setHighlighted] = useState(-1)
524
310
 
525
- render() {
526
- return (
527
- <View display="block" width="300px">
528
- <Options onMouseOut={(e) => this.setState({ highlighted: -1 })}>
529
- <Options.Item
530
- onMouseOver={(e) => this.handleMouseOver(1)}
531
- variant={this.state.highlighted === 1 ? 'highlighted' : 'default'}
532
- description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
533
- renderBeforeLabel={IconCheckSolid}
534
- renderAfterLabel={IconArrowOpenEndSolid}
535
- beforeLabelContentVAlign="start"
536
- afterLabelContentVAlign="start"
537
- >
538
- Option one
539
- </Options.Item>
540
- <Options.Item
541
- onMouseOver={(e) => this.handleMouseOver(2)}
542
- variant={this.state.highlighted === 2 ? 'highlighted' : 'default'}
543
- description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
544
- renderBeforeLabel={IconCheckSolid}
545
- renderAfterLabel={IconArrowOpenEndSolid}
546
- beforeLabelContentVAlign="center"
547
- afterLabelContentVAlign="center"
548
- >
549
- Option two
550
- </Options.Item>
551
- <Options.Item
552
- onMouseOver={(e) => this.handleMouseOver(3)}
553
- variant={this.state.highlighted === 3 ? 'highlighted' : 'default'}
554
- description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
555
- renderBeforeLabel={IconCheckSolid}
556
- renderAfterLabel={IconArrowOpenEndSolid}
557
- beforeLabelContentVAlign="end"
558
- afterLabelContentVAlign="end"
559
- >
560
- Option three
561
- </Options.Item>
562
- </Options>
563
- </View>
564
- )
565
- }
311
+ const handleMouseOver = (index) => {
312
+ setHighlighted(index)
566
313
  }
567
314
 
568
- render(<Example />)
569
- ```
570
-
571
- - ```js
572
- const Example = () => {
573
- const [highlighted, setHighlighted] = useState(-1)
574
-
575
- const handleMouseOver = (index) => {
576
- setHighlighted(index)
577
- }
578
-
579
- return (
580
- <View display="block" width="300px">
581
- <Options onMouseOut={() => setHighlighted(-1)}>
582
- <Options.Item
583
- onMouseOver={() => handleMouseOver(1)}
584
- variant={highlighted === 1 ? 'highlighted' : 'default'}
585
- description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
586
- renderBeforeLabel={IconCheckSolid}
587
- renderAfterLabel={IconArrowOpenEndSolid}
588
- beforeLabelContentVAlign="start"
589
- afterLabelContentVAlign="start"
590
- >
591
- Option one
592
- </Options.Item>
593
- <Options.Item
594
- onMouseOver={() => handleMouseOver(2)}
595
- variant={highlighted === 2 ? 'highlighted' : 'default'}
596
- description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
597
- renderBeforeLabel={IconCheckSolid}
598
- renderAfterLabel={IconArrowOpenEndSolid}
599
- beforeLabelContentVAlign="center"
600
- afterLabelContentVAlign="center"
601
- >
602
- Option two
603
- </Options.Item>
604
- <Options.Item
605
- onMouseOver={() => handleMouseOver(3)}
606
- variant={highlighted === 3 ? 'highlighted' : 'default'}
607
- description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
608
- renderBeforeLabel={IconCheckSolid}
609
- renderAfterLabel={IconArrowOpenEndSolid}
610
- beforeLabelContentVAlign="end"
611
- afterLabelContentVAlign="end"
612
- >
613
- Option three
614
- </Options.Item>
615
- </Options>
616
- </View>
617
- )
618
- }
315
+ return (
316
+ <View display="block" width="300px">
317
+ <Options onMouseOut={() => setHighlighted(-1)}>
318
+ <Options.Item
319
+ onMouseOver={() => handleMouseOver(1)}
320
+ variant={highlighted === 1 ? 'highlighted' : 'default'}
321
+ description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
322
+ renderBeforeLabel={IconCheckSolid}
323
+ renderAfterLabel={IconArrowOpenEndSolid}
324
+ beforeLabelContentVAlign="start"
325
+ afterLabelContentVAlign="start"
326
+ >
327
+ Option one
328
+ </Options.Item>
329
+ <Options.Item
330
+ onMouseOver={() => handleMouseOver(2)}
331
+ variant={highlighted === 2 ? 'highlighted' : 'default'}
332
+ description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
333
+ renderBeforeLabel={IconCheckSolid}
334
+ renderAfterLabel={IconArrowOpenEndSolid}
335
+ beforeLabelContentVAlign="center"
336
+ afterLabelContentVAlign="center"
337
+ >
338
+ Option two
339
+ </Options.Item>
340
+ <Options.Item
341
+ onMouseOver={() => handleMouseOver(3)}
342
+ variant={highlighted === 3 ? 'highlighted' : 'default'}
343
+ description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
344
+ renderBeforeLabel={IconCheckSolid}
345
+ renderAfterLabel={IconArrowOpenEndSolid}
346
+ beforeLabelContentVAlign="end"
347
+ afterLabelContentVAlign="end"
348
+ >
349
+ Option three
350
+ </Options.Item>
351
+ </Options>
352
+ </View>
353
+ )
354
+ }
619
355
 
620
- render(<Example />)
621
- ```
356
+ render(<Example />)
357
+ ```
622
358
 
623
359
  Providing a `href` prop will render the option as `<a>` link element.
624
360
 
625
361
  **WARNING!** Since `Options` is a view-only component, you have to make sure it is accessible, and if set the variant to disabled, disable the links as well!
626
362
 
627
- - ```js
628
- class Example extends React.Component {
629
- constructor(props) {
630
- super(props)
631
-
632
- this.state = {
633
- highlighted: -1
634
- }
635
- }
636
-
637
- handleMouseOver = (index) => {
638
- this.setState({ highlighted: index })
639
- }
363
+ ```js
364
+ ---
365
+ type: example
366
+ ---
367
+ const Example = () => {
368
+ const [highlighted, setHighlighted] = useState(-1)
640
369
 
641
- render() {
642
- return (
643
- <View display="block" width="300px">
644
- <Options onMouseOut={(e) => this.setState({ highlighted: -1 })}>
645
- <Options.Item
646
- onMouseOver={(e) => this.handleMouseOver(1)}
647
- variant={this.state.highlighted === 1 ? 'highlighted' : 'default'}
648
- href="/"
649
- >
650
- Link one
651
- </Options.Item>
652
- <Options.Item
653
- onMouseOver={(e) => this.handleMouseOver(2)}
654
- variant={this.state.highlighted === 2 ? 'highlighted' : 'default'}
655
- href="/"
656
- >
657
- Link two
658
- </Options.Item>
659
- <Options.Item
660
- onMouseOver={(e) => this.handleMouseOver(3)}
661
- variant={this.state.highlighted === 3 ? 'highlighted' : 'default'}
662
- variant="disabled"
663
- aria-disabled="true"
664
- onClick={(e) => {
665
- e.preventDefault()
666
- }}
667
- href="/"
668
- >
669
- Link three
670
- </Options.Item>
671
- </Options>
672
- </View>
673
- )
674
- }
370
+ const handleMouseOver = (index) => {
371
+ setHighlighted(index)
675
372
  }
676
373
 
677
- render(<Example />)
678
- ```
679
-
680
- - ```js
681
- const Example = () => {
682
- const [highlighted, setHighlighted] = useState(-1)
683
-
684
- const handleMouseOver = (index) => {
685
- setHighlighted(index)
686
- }
687
-
688
- return (
689
- <View display="block" width="300px">
690
- <Options onMouseOut={() => setHighlighted(-1)}>
691
- <Options.Item
692
- onMouseOver={() => handleMouseOver(1)}
693
- variant={highlighted === 1 ? 'highlighted' : 'default'}
694
- href="/"
695
- >
696
- Link one
697
- </Options.Item>
698
- <Options.Item
699
- onMouseOver={() => handleMouseOver(2)}
700
- variant={highlighted === 2 ? 'highlighted' : 'default'}
701
- href="/"
702
- >
703
- Link two
704
- </Options.Item>
705
- <Options.Item
706
- onMouseOver={() => handleMouseOver(3)}
707
- variant={highlighted === 3 ? 'highlighted' : 'default'}
708
- variant="disabled"
709
- aria-disabled="true"
710
- onClick={(e) => {
711
- e.preventDefault()
712
- }}
713
- href="/"
714
- >
715
- Link three
716
- </Options.Item>
717
- </Options>
718
- </View>
719
- )
720
- }
374
+ return (
375
+ <View display="block" width="300px">
376
+ <Options onMouseOut={() => setHighlighted(-1)}>
377
+ <Options.Item
378
+ onMouseOver={() => handleMouseOver(1)}
379
+ variant={highlighted === 1 ? 'highlighted' : 'default'}
380
+ href="/"
381
+ >
382
+ Link one
383
+ </Options.Item>
384
+ <Options.Item
385
+ onMouseOver={() => handleMouseOver(2)}
386
+ variant={highlighted === 2 ? 'highlighted' : 'default'}
387
+ href="/"
388
+ >
389
+ Link two
390
+ </Options.Item>
391
+ <Options.Item
392
+ onMouseOver={() => handleMouseOver(3)}
393
+ variant={highlighted === 3 ? 'highlighted' : 'default'}
394
+ variant="disabled"
395
+ aria-disabled="true"
396
+ onClick={(e) => {
397
+ e.preventDefault()
398
+ }}
399
+ href="/"
400
+ >
401
+ Link three
402
+ </Options.Item>
403
+ </Options>
404
+ </View>
405
+ )
406
+ }
721
407
 
722
- render(<Example />)
723
- ```
408
+ render(<Example />)
409
+ ```