2020-05-11 22:28:18 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import SortArrowUp from '../images/sort-arrow-up.svg';
|
|
|
|
import SortArrowDown from '../images/sort-arrow-down.svg';
|
|
|
|
import Github from '../images/github.svg';
|
|
|
|
import Google from '../images/google.svg';
|
|
|
|
import Plus from '../images/plus-icon.svg';
|
|
|
|
import Close from '../images/close.svg';
|
|
|
|
import DropdownArrow from '../images/down-filled-triangle.svg';
|
|
|
|
|
|
|
|
// HOC that adds the right web accessibility props
|
|
|
|
// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
|
|
|
|
|
|
|
|
// could also give these a default size, color, etc. based on the theme
|
|
|
|
// Need to add size to these - like small icon, medium icon, large icon. etc.
|
2020-05-19 18:31:36 +02:00
|
|
|
function withLabel(SvgComponent) {
|
|
|
|
const Icon = (props) => {
|
2020-05-11 22:28:18 +02:00
|
|
|
const { 'aria-label': ariaLabel } = props;
|
|
|
|
if (ariaLabel) {
|
2020-05-19 18:31:36 +02:00
|
|
|
return (<SvgComponent
|
2020-05-11 22:28:18 +02:00
|
|
|
{...props}
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
role="img"
|
|
|
|
focusable="false"
|
|
|
|
/>);
|
|
|
|
}
|
2020-05-19 18:31:36 +02:00
|
|
|
return (<SvgComponent
|
2020-05-11 22:28:18 +02:00
|
|
|
{...props}
|
|
|
|
aria-hidden
|
|
|
|
focusable="false"
|
|
|
|
/>);
|
|
|
|
};
|
|
|
|
|
2020-05-19 18:31:36 +02:00
|
|
|
Icon.propTypes = {
|
2020-05-11 22:28:18 +02:00
|
|
|
'aria-label': PropTypes.string
|
|
|
|
};
|
|
|
|
|
2020-05-19 18:31:36 +02:00
|
|
|
Icon.defaultProps = {
|
2020-05-11 22:28:18 +02:00
|
|
|
'aria-label': null
|
|
|
|
};
|
|
|
|
|
2020-05-19 18:31:36 +02:00
|
|
|
return Icon;
|
2020-05-11 22:28:18 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 18:31:36 +02:00
|
|
|
export const SortArrowUpIcon = withLabel(SortArrowUp);
|
|
|
|
export const SortArrowDownIcon = withLabel(SortArrowDown);
|
|
|
|
export const GithubIcon = withLabel(Github);
|
|
|
|
export const GoogleIcon = withLabel(Google);
|
|
|
|
export const PlusIcon = withLabel(Plus);
|
|
|
|
export const CloseIcon = withLabel(Close);
|
|
|
|
export const DropdownArrowIcon = withLabel(DropdownArrow);
|