|
1 |
| -/* eslint-disable global-require */ |
2 |
| -import InlineSVG from 'react-inlinesvg'; |
3 | 1 | import PropTypes from 'prop-types';
|
4 |
| -import React from 'react'; |
5 |
| -import lodash from 'lodash'; |
6 |
| -import styled from 'styled-components'; |
7 | 2 |
|
8 |
| -const icons = { |
9 |
| - sortArrowUp: require('../images/sort-arrow-up.svg'), |
10 |
| - sortArrowDown: require('../images/sort-arrow-down.svg'), |
11 |
| - github: require('../images/github.svg'), |
12 |
| - google: require('../images/google.svg'), |
13 |
| - plus: require('../images/plus-icon.svg'), |
14 |
| - close: require('../images/close.svg'), |
| 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 | + |
| 10 | +// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html |
| 11 | +// could do something like, if there's an aria-label prop, give it role="img" focusable="false" |
| 12 | +// otherwise, give it aria-hidden="true" focusable="false" |
| 13 | + |
| 14 | +const Icons = { |
| 15 | + SortArrowUp, |
| 16 | + SortArrowDown, |
| 17 | + Github, |
| 18 | + Google, |
| 19 | + Plus, |
| 20 | + Close |
15 | 21 | };
|
16 | 22 |
|
17 |
| -/* |
18 |
| - names will be an mirror-object of icon names: |
19 |
| - { |
20 |
| - github: 'github', |
21 |
| - ... |
22 |
| - } |
23 |
| -*/ |
24 |
| -const names = lodash.mapValues(icons, (value, key) => key); |
| 23 | +export default Icons; |
25 | 24 |
|
26 |
| -export const ValidIconNameType = PropTypes.oneOf(Object.keys(names)); |
27 |
| - |
28 |
| -const StyledInlineSVG = styled(InlineSVG)` |
29 |
| - > svg { |
30 |
| - width: 100%; |
31 |
| - height: 100%; |
32 |
| - } |
33 |
| -`; |
34 |
| - |
35 |
| -function Icon({ name, ...props }) { |
36 |
| - return ( |
37 |
| - <StyledInlineSVG src={icons[name]} {...props} /> |
38 |
| - ); |
39 |
| -} |
40 |
| - |
41 |
| - |
42 |
| -Icon.names = names; |
43 |
| - |
44 |
| -Icon.propTypes = { |
45 |
| - name: ValidIconNameType.isRequired |
46 |
| -}; |
47 |
| - |
48 |
| -export default Icon; |
| 25 | +export const ValidIconNameType = PropTypes.oneOf(Object.keys(Icons)); |
0 commit comments