|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import SortArrowUp from '../images/sort-arrow-up.svg'; |
| 4 | +import SortArrowDown from '../images/sort-arrow-down.svg'; |
| 5 | +import Github from '../images/github.svg'; |
| 6 | +import Google from '../images/google.svg'; |
| 7 | +import Plus from '../images/plus-icon.svg'; |
| 8 | +import Close from '../images/close.svg'; |
| 9 | +import DropdownArrow from '../images/down-filled-triangle.svg'; |
| 10 | + |
| 11 | +// HOC that adds the right web accessibility props |
| 12 | +// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html |
| 13 | + |
| 14 | +// could also give these a default size, color, etc. based on the theme |
| 15 | +// Need to add size to these - like small icon, medium icon, large icon. etc. |
| 16 | +function withLabel(SvgComponent) { |
| 17 | + const Icon = (props) => { |
| 18 | + const { 'aria-label': ariaLabel } = props; |
| 19 | + if (ariaLabel) { |
| 20 | + return (<SvgComponent |
| 21 | + {...props} |
| 22 | + aria-label={ariaLabel} |
| 23 | + role="img" |
| 24 | + focusable="false" |
| 25 | + />); |
| 26 | + } |
| 27 | + return (<SvgComponent |
| 28 | + {...props} |
| 29 | + aria-hidden |
| 30 | + focusable="false" |
| 31 | + />); |
| 32 | + }; |
| 33 | + |
| 34 | + Icon.propTypes = { |
| 35 | + 'aria-label': PropTypes.string |
| 36 | + }; |
| 37 | + |
| 38 | + Icon.defaultProps = { |
| 39 | + 'aria-label': null |
| 40 | + }; |
| 41 | + |
| 42 | + return Icon; |
| 43 | +} |
| 44 | + |
| 45 | +export const SortArrowUpIcon = withLabel(SortArrowUp); |
| 46 | +export const SortArrowDownIcon = withLabel(SortArrowDown); |
| 47 | +export const GithubIcon = withLabel(Github); |
| 48 | +export const GoogleIcon = withLabel(Google); |
| 49 | +export const PlusIcon = withLabel(Plus); |
| 50 | +export const CloseIcon = withLabel(Close); |
| 51 | +export const DropdownArrowIcon = withLabel(DropdownArrow); |
0 commit comments