Skip to content

Commit cd6d95a

Browse files
committed
RE: #1244, change case of common/Icon to common/icon
1 parent 85163bd commit cd6d95a

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Diff for: client/common/icons.jsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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);

Diff for: client/common/icons.stories.jsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import { select } from '@storybook/addon-knobs';
3+
4+
import * as icons from './icons';
5+
6+
export default {
7+
title: 'Common/Icons',
8+
component: icons
9+
};
10+
11+
export const AllIcons = () => {
12+
const names = Object.keys(icons);
13+
14+
const SelectedIcon = icons[select('name', names, names[0])];
15+
return (
16+
<SelectedIcon />
17+
);
18+
};

0 commit comments

Comments
 (0)