|
| 1 | +import * as React from 'react' |
| 2 | +import { Dropdown } from '@stardust-ui/react' |
| 3 | + |
| 4 | +const inputItems = [ |
| 5 | + { |
| 6 | + header: 'Bruce Wayne', |
| 7 | + image: 'public/images/avatar/small/matt.jpg', |
| 8 | + content: 'Software Engineer', |
| 9 | + }, |
| 10 | + { |
| 11 | + header: 'Natasha Romanoff', |
| 12 | + image: 'public/images/avatar/small/jenny.jpg', |
| 13 | + content: 'UX Designer 2', |
| 14 | + }, |
| 15 | + { |
| 16 | + header: 'Steven Strange', |
| 17 | + image: 'public/images/avatar/small/joe.jpg', |
| 18 | + content: 'Principal Software Engineering Manager', |
| 19 | + }, |
| 20 | + { |
| 21 | + header: 'Alfred Pennyworth', |
| 22 | + image: 'public/images/avatar/small/justen.jpg', |
| 23 | + content: 'Technology Consultant', |
| 24 | + }, |
| 25 | + { |
| 26 | + header: `Scarlett O'Hara`, |
| 27 | + image: 'public/images/avatar/small/laura.jpg', |
| 28 | + content: 'Software Engineer 2', |
| 29 | + }, |
| 30 | + { |
| 31 | + header: 'Imperator Furiosa', |
| 32 | + image: 'public/images/avatar/small/veronika.jpg', |
| 33 | + content: 'Boss', |
| 34 | + }, |
| 35 | + { |
| 36 | + header: 'Bruce Banner', |
| 37 | + image: 'public/images/avatar/small/chris.jpg', |
| 38 | + content: 'Senior Computer Scientist', |
| 39 | + }, |
| 40 | + { |
| 41 | + header: 'Peter Parker', |
| 42 | + image: 'public/images/avatar/small/daniel.jpg', |
| 43 | + content: 'Partner Software Engineer', |
| 44 | + }, |
| 45 | + { |
| 46 | + header: 'Selina Kyle', |
| 47 | + image: 'public/images/avatar/small/ade.jpg', |
| 48 | + content: 'Graphic Designer', |
| 49 | + }, |
| 50 | +] |
| 51 | + |
| 52 | +class DropdownExample extends React.Component { |
| 53 | + render() { |
| 54 | + return ( |
| 55 | + <Dropdown |
| 56 | + multiple |
| 57 | + getA11yStatusMessage={getA11yStatusMessage} |
| 58 | + search |
| 59 | + getA11ySelectionMessage={getA11ySelectionMessage} |
| 60 | + noResultsMessage="We couldn't find any matches." |
| 61 | + placeholder="Start typing a name" |
| 62 | + items={inputItems} |
| 63 | + /> |
| 64 | + ) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +const getA11ySelectionMessage = { |
| 69 | + onAdd: item => `${item.header} has been selected.`, |
| 70 | + onRemove: item => `${item.header} has been removed.`, |
| 71 | +} |
| 72 | + |
| 73 | +const getA11yStatusMessage = ({ |
| 74 | + isOpen, |
| 75 | + itemToString, |
| 76 | + previousResultCount, |
| 77 | + resultCount, |
| 78 | + selectedItem, |
| 79 | +}) => { |
| 80 | + if (!isOpen) { |
| 81 | + return selectedItem ? itemToString(selectedItem) : '' |
| 82 | + } |
| 83 | + if (!resultCount) { |
| 84 | + return 'No results are available.' |
| 85 | + } |
| 86 | + if (resultCount !== previousResultCount) { |
| 87 | + return `${resultCount} result${ |
| 88 | + resultCount === 1 ? ' is' : 's are' |
| 89 | + } available, use up and down arrow keys to navigate. Press Enter key to select.` |
| 90 | + } |
| 91 | + return '' |
| 92 | +} |
| 93 | + |
| 94 | +export default DropdownExample |
0 commit comments