@instructure/ui-options 10.2.1-snapshot-2 → 10.2.1-snapshot-11

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.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [10.2.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1-snapshot-2) (2024-08-30)
6
+ ## [10.2.1-snapshot-11](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1-snapshot-11) (2024-08-30)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-options
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-options",
3
- "version": "10.2.1-snapshot-2",
3
+ "version": "10.2.1-snapshot-11",
4
4
  "description": "A view-only component for composing interactive lists and menus.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,21 +23,21 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "10.2.1-snapshot-2",
27
- "@instructure/ui-color-utils": "10.2.1-snapshot-2",
28
- "@instructure/ui-test-locator": "10.2.1-snapshot-2",
29
- "@instructure/ui-test-utils": "10.2.1-snapshot-2",
30
- "@instructure/ui-themes": "10.2.1-snapshot-2"
26
+ "@instructure/ui-babel-preset": "10.2.1-snapshot-11",
27
+ "@instructure/ui-color-utils": "10.2.1-snapshot-11",
28
+ "@instructure/ui-test-locator": "10.2.1-snapshot-11",
29
+ "@instructure/ui-test-utils": "10.2.1-snapshot-11",
30
+ "@instructure/ui-themes": "10.2.1-snapshot-11"
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.24.5",
34
- "@instructure/emotion": "10.2.1-snapshot-2",
35
- "@instructure/shared-types": "10.2.1-snapshot-2",
36
- "@instructure/ui-icons": "10.2.1-snapshot-2",
37
- "@instructure/ui-prop-types": "10.2.1-snapshot-2",
38
- "@instructure/ui-react-utils": "10.2.1-snapshot-2",
39
- "@instructure/ui-testable": "10.2.1-snapshot-2",
40
- "@instructure/ui-view": "10.2.1-snapshot-2",
34
+ "@instructure/emotion": "10.2.1-snapshot-11",
35
+ "@instructure/shared-types": "10.2.1-snapshot-11",
36
+ "@instructure/ui-icons": "10.2.1-snapshot-11",
37
+ "@instructure/ui-prop-types": "10.2.1-snapshot-11",
38
+ "@instructure/ui-react-utils": "10.2.1-snapshot-11",
39
+ "@instructure/ui-testable": "10.2.1-snapshot-11",
40
+ "@instructure/ui-view": "10.2.1-snapshot-11",
41
41
  "prop-types": "^15.8.1"
42
42
  },
43
43
  "peerDependencies": {
@@ -88,80 +88,156 @@ 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
- ---
93
- type: example
94
- ---
95
- class Example extends React.Component {
96
- constructor (props) {
97
- super(props)
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
+ }
98
101
 
99
- this.state = {
100
- highlighted: -1,
101
- selected: -1
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 })
102
127
  }
103
- }
104
128
 
105
- handleKeyDown = (event) => {
106
- const { highlighted } = this.state
107
- let index = highlighted
108
-
109
- if (event.keyCode === 40 && highlighted < this.props.options.length - 1) {
110
- // down arrow
111
- event.preventDefault()
112
- index = highlighted + 1
113
- } else if (event.keyCode === 38 && highlighted > 0) {
114
- // up arrow
115
- event.preventDefault()
116
- index = highlighted - 1
117
- } else if (event.keyCode === 13 && highlighted > -1) {
118
- // enter
129
+ handleClick = (event, index) => {
119
130
  this.setState({ selected: index })
120
131
  }
121
- this.setState({ highlighted: index })
122
- }
123
132
 
124
- handleFocus = (event, index) => {
125
- this.setState({ highlighted: index })
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
+ }
126
165
  }
127
166
 
128
- handleMouseOver = (event, index) => {
129
- this.setState({ highlighted: index })
130
- }
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
+ }
131
200
 
132
- handleClick = (event, index) => {
133
- this.setState({ selected: index })
134
- }
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
+ }
135
215
 
136
- render () {
137
216
  return (
138
- <View
139
- display="block"
140
- width="300px"
141
- shadow="above"
142
- >
217
+ <View display="block" width="300px" shadow="above">
143
218
  <Options
144
- onKeyDown={this.handleKeyDown}
145
- onMouseOut={(e) => this.setState({ highlighted: -1 })}
219
+ onKeyDown={handleKeyDown}
220
+ onMouseOut={() => setHighlighted(-1)}
146
221
  tabIndex="0"
147
222
  >
148
- {this.props.options.map((option, index) => {
223
+ {options.map((option, index) => {
149
224
  let variant = 'default'
150
- if (this.state.highlighted === index) {
225
+ if (highlighted === index) {
151
226
  variant = 'highlighted'
152
- } else if (this.state.selected === index) {
227
+ } else if (selected === index) {
153
228
  variant = 'selected'
154
229
  }
230
+
155
231
  return (
156
232
  <Options.Item
157
233
  key={option}
158
234
  variant={variant}
159
235
  tabIndex="-1"
160
- onMouseOver={(e) => this.handleMouseOver(e, index)}
161
- onFocus={(e) => this.handleFocus(e, index)}
162
- onClick={(e) => this.handleClick(e, index)}
236
+ onMouseOver={(e) => handleMouseOver(index)}
237
+ onFocus={() => handleFocus(index)}
238
+ onClick={() => handleClick(index)}
163
239
  >
164
- { option }
240
+ {option}
165
241
  </Options.Item>
166
242
  )
167
243
  })}
@@ -169,98 +245,210 @@ class Example extends React.Component {
169
245
  </View>
170
246
  )
171
247
  }
172
- }
173
-
174
- render(
175
- <Example options={[
176
- 'Option one',
177
- 'Option two',
178
- 'Option three',
179
- 'Option four',
180
- 'Option five'
181
- ]} />
182
- )
183
- ```
248
+
249
+ render(
250
+ <Example
251
+ options={[
252
+ 'Option one',
253
+ 'Option two',
254
+ 'Option three',
255
+ 'Option four',
256
+ 'Option five'
257
+ ]}
258
+ />
259
+ )
260
+ ```
184
261
 
185
262
  You can recolor the text and the background of the items for their `default`, `highlighted` and `selected` variants.
186
263
 
187
264
  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 ]`.
188
265
 
189
- ```js
190
- ---
191
- type: example
192
- ---
193
- class Example extends React.Component {
194
- constructor (props) {
195
- super(props)
266
+ - ```js
267
+ class Example extends React.Component {
268
+ constructor(props) {
269
+ super(props)
196
270
 
197
- this.state = {
198
- highlighted: -1,
199
- selected: -1
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 })
294
+ }
295
+
296
+ handleFocus = (event, index) => {
297
+ this.setState({ highlighted: index })
298
+ }
299
+
300
+ handleMouseOver = (event, index) => {
301
+ this.setState({ highlighted: index })
200
302
  }
201
- }
202
303
 
203
- handleKeyDown = (event) => {
204
- const { highlighted } = this.state
205
- let index = highlighted
206
-
207
- if (event.keyCode === 40 && highlighted < this.props.options.length - 1) {
208
- // down arrow
209
- event.preventDefault()
210
- index = highlighted + 1
211
- } else if (event.keyCode === 38 && highlighted > 0) {
212
- // up arrow
213
- event.preventDefault()
214
- index = highlighted - 1
215
- } else if (event.keyCode === 13 && highlighted > -1) {
216
- // enter
304
+ handleClick = (event, index) => {
217
305
  this.setState({ selected: index })
218
306
  }
219
- this.setState({ highlighted: index })
220
- }
221
307
 
222
- handleFocus = (event, index) => {
223
- this.setState({ highlighted: index })
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
+ }
224
341
  }
225
342
 
226
- handleMouseOver = (event, index) => {
227
- this.setState({ highlighted: index })
228
- }
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
+ }
383
+ }
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
+ }
229
410
 
230
- handleClick = (event, index) => {
231
- this.setState({ selected: index })
232
- }
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
+ }
233
425
 
234
- render () {
235
426
  return (
236
- <View
237
- display="block"
238
- width="300px"
239
- shadow="above"
240
- >
427
+ <View display="block" width="300px" shadow="above">
241
428
  <Options
242
- onKeyDown={this.handleKeyDown}
243
- onMouseOut={(e) => this.setState({ highlighted: -1 })}
429
+ onKeyDown={handleKeyDown}
430
+ onMouseOut={() => setHighlighted(-1)}
244
431
  tabIndex="0"
245
432
  >
246
- {this.props.options.map((option, index) => {
433
+ {options.map((option, index) => {
247
434
  let variant = 'default'
248
- if (this.state.highlighted === index) {
435
+ if (highlighted === index) {
249
436
  variant = 'highlighted'
250
- } else if (this.state.selected === index) {
437
+ } else if (selected === index) {
251
438
  variant = 'selected'
252
439
  }
440
+
253
441
  return (
254
442
  <Options.Item
255
443
  key={option.label}
256
444
  variant={variant}
257
445
  tabIndex="-1"
258
- onMouseOver={(e) => this.handleMouseOver(e, index)}
259
- onFocus={(e) => this.handleFocus(e, index)}
260
- onClick={(e) => this.handleClick(e, index)}
446
+ onMouseOver={(e) => handleMouseOver(e, index)}
447
+ onFocus={(e) => handleFocus(e, index)}
448
+ onClick={(e) => handleClick(e, index)}
261
449
  {...option.extraProps}
262
450
  >
263
- { option.label }
451
+ {option.label}
264
452
  </Options.Item>
265
453
  )
266
454
  })}
@@ -268,80 +456,132 @@ class Example extends React.Component {
268
456
  </View>
269
457
  )
270
458
  }
271
- }
272
-
273
- render(
274
- <Example options={[
275
- {
276
- label: 'Default item',
277
- extraProps: {
278
- renderBeforeLabel: IconCheckSolid
279
- }
280
- },
281
- {
282
- label: 'Text is green',
283
- extraProps: {
284
- renderBeforeLabel: IconCheckSolid,
285
- themeOverride: { color: "#0B874B" }
286
- }
287
- },
288
- {
289
- label: 'Highlighted text is black',
290
- extraProps: {
291
- renderBeforeLabel: IconCheckSolid,
292
- themeOverride: { highlightedLabelColor: "#2D3B45" }
293
459
 
294
- }
295
- },
296
- {
297
- label: 'Highlighted background is purple',
298
- extraProps: {
299
- renderBeforeLabel: IconCheckSolid,
300
- themeOverride: { highlightedBackground: "#BF32A4" }
301
- }
302
- },
303
- {
304
- label: 'Only the icon is red',
305
- extraProps: {
306
- renderBeforeLabel: (props) => {
307
- return <IconCheckSolid
308
- {...(props.variant === "default" && { color: 'warning' }) }
309
- />
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
+ }
310
501
  }
311
- }
312
- }
313
- ]} />
314
- )
315
- ```
502
+ ]}
503
+ />
504
+ )
505
+ ```
316
506
 
317
507
  Additional/secondary text can be added via the `description` prop, and the ARIA role of it can be set with the `descriptionRole` prop.
318
508
 
319
509
  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.
320
510
 
321
- ```js
322
- ---
323
- type: example
324
- ---
325
- class Example extends React.Component {
326
- constructor(props) {
327
- super(props)
511
+ - ```js
512
+ class Example extends React.Component {
513
+ constructor(props) {
514
+ super(props)
328
515
 
329
- this.state = {
330
- highlighted: -1
516
+ this.state = {
517
+ highlighted: -1
518
+ }
519
+ }
520
+
521
+ handleMouseOver = (index) => {
522
+ this.setState({ highlighted: index })
331
523
  }
332
- }
333
524
 
334
- handleMouseOver = (index) => {
335
- this.setState({ highlighted: index })
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
+ }
336
566
  }
337
567
 
338
- render() {
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
+
339
579
  return (
340
580
  <View display="block" width="300px">
341
- <Options onMouseOut={(e) => this.setState({ highlighted: -1 })}>
581
+ <Options onMouseOut={() => setHighlighted(-1)}>
342
582
  <Options.Item
343
- onMouseOver={(e) => this.handleMouseOver(1)}
344
- variant={this.state.highlighted === 1 ? 'highlighted' : 'default'}
583
+ onMouseOver={() => handleMouseOver(1)}
584
+ variant={highlighted === 1 ? 'highlighted' : 'default'}
345
585
  description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
346
586
  renderBeforeLabel={IconCheckSolid}
347
587
  renderAfterLabel={IconArrowOpenEndSolid}
@@ -351,8 +591,8 @@ class Example extends React.Component {
351
591
  Option one
352
592
  </Options.Item>
353
593
  <Options.Item
354
- onMouseOver={(e) => this.handleMouseOver(2)}
355
- variant={this.state.highlighted === 2 ? 'highlighted' : 'default'}
594
+ onMouseOver={() => handleMouseOver(2)}
595
+ variant={highlighted === 2 ? 'highlighted' : 'default'}
356
596
  description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
357
597
  renderBeforeLabel={IconCheckSolid}
358
598
  renderAfterLabel={IconArrowOpenEndSolid}
@@ -362,8 +602,8 @@ class Example extends React.Component {
362
602
  Option two
363
603
  </Options.Item>
364
604
  <Options.Item
365
- onMouseOver={(e) => this.handleMouseOver(3)}
366
- variant={this.state.highlighted === 3 ? 'highlighted' : 'default'}
605
+ onMouseOver={() => handleMouseOver(3)}
606
+ variant={highlighted === 3 ? 'highlighted' : 'default'}
367
607
  description="Curabitur fringilla, urna ut efficitur molestie, nibh lacus tincidunt elit, ut tempor ipsum nunc sit amet massa."
368
608
  renderBeforeLabel={IconCheckSolid}
369
609
  renderAfterLabel={IconArrowOpenEndSolid}
@@ -376,56 +616,100 @@ class Example extends React.Component {
376
616
  </View>
377
617
  )
378
618
  }
379
- }
380
619
 
381
- render(<Example />)
382
- ```
620
+ render(<Example />)
621
+ ```
383
622
 
384
623
  Providing a `href` prop will render the option as `<a>` link element.
385
624
 
386
625
  **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!
387
626
 
388
- ```js
389
- ---
390
- type: example
391
- ---
392
- class Example extends React.Component {
393
- constructor(props) {
394
- super(props)
627
+ - ```js
628
+ class Example extends React.Component {
629
+ constructor(props) {
630
+ super(props)
395
631
 
396
- this.state = {
397
- highlighted: -1
632
+ this.state = {
633
+ highlighted: -1
634
+ }
398
635
  }
399
- }
400
636
 
401
- handleMouseOver = (index) => {
402
- this.setState({ highlighted: index })
637
+ handleMouseOver = (index) => {
638
+ this.setState({ highlighted: index })
639
+ }
640
+
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
+ }
403
675
  }
404
676
 
405
- render() {
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
+
406
688
  return (
407
689
  <View display="block" width="300px">
408
- <Options onMouseOut={(e) => this.setState({ highlighted: -1 })}>
690
+ <Options onMouseOut={() => setHighlighted(-1)}>
409
691
  <Options.Item
410
- onMouseOver={(e) => this.handleMouseOver(1)}
411
- variant={this.state.highlighted === 1 ? 'highlighted' : 'default'}
692
+ onMouseOver={() => handleMouseOver(1)}
693
+ variant={highlighted === 1 ? 'highlighted' : 'default'}
412
694
  href="/"
413
695
  >
414
696
  Link one
415
697
  </Options.Item>
416
698
  <Options.Item
417
- onMouseOver={(e) => this.handleMouseOver(2)}
418
- variant={this.state.highlighted === 2 ? 'highlighted' : 'default'}
699
+ onMouseOver={() => handleMouseOver(2)}
700
+ variant={highlighted === 2 ? 'highlighted' : 'default'}
419
701
  href="/"
420
702
  >
421
703
  Link two
422
704
  </Options.Item>
423
705
  <Options.Item
424
- onMouseOver={(e) => this.handleMouseOver(3)}
425
- variant={this.state.highlighted === 3 ? 'highlighted' : 'default'}
706
+ onMouseOver={() => handleMouseOver(3)}
707
+ variant={highlighted === 3 ? 'highlighted' : 'default'}
426
708
  variant="disabled"
427
709
  aria-disabled="true"
428
- onClick={(e) => { e.preventDefault() }}
710
+ onClick={(e) => {
711
+ e.preventDefault()
712
+ }}
429
713
  href="/"
430
714
  >
431
715
  Link three
@@ -434,7 +718,6 @@ class Example extends React.Component {
434
718
  </View>
435
719
  )
436
720
  }
437
- }
438
721
 
439
- render(<Example />)
440
- ```
722
+ render(<Example />)
723
+ ```