@@ -26,13 +26,25 @@ import Filter from '../images/filter.svg';
2626import Cross from '../images/cross.svg' ;
2727import Copy from '../images/copy.svg' ;
2828
29+ export interface IconColors {
30+ default ?: string ;
31+ hover ?: string ;
32+ }
33+
34+ export interface IconProps extends React . SVGProps < SVGSVGElement > {
35+ 'aria-label' ?: string ;
36+ Icon ?: IconColors ;
37+ }
38+
2939// HOC that adds the right web accessibility props
3040// https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html
3141
3242// could also give these a default size, color, etc. based on the theme
3343// Need to add size to these - like small icon, medium icon, large icon. etc.
34- function withLabel ( SvgComponent ) {
35- const StyledIcon = styled ( SvgComponent ) `
44+ function withLabel (
45+ SvgComponent : React . ComponentType < React . SVGProps < SVGSVGElement > >
46+ ) {
47+ const StyledIcon = styled ( SvgComponent ) < IconProps > `
3648 &&& {
3749 color: ${ ( props ) => props . Icon ?. default } ;
3850 & g,
@@ -53,27 +65,27 @@ function withLabel(SvgComponent) {
5365 }
5466 ` ;
5567
56- const Icon = ( props ) => {
57- const { 'aria-label' : ariaLabel } = props ;
68+ // Necessary because styled components inject a different type for the ref prop
69+ type StyledIconProps = Omit <
70+ React . ComponentProps < typeof StyledIcon > ,
71+ 'ref'
72+ > & {
73+ ref ?: React . Ref < SVGSVGElement > ;
74+ } ;
75+
76+ const Icon = ( props : StyledIconProps ) => {
77+ const { 'aria-label' : ariaLabel , ...rest } = props ;
5878 if ( ariaLabel ) {
5979 return (
6080 < StyledIcon
61- { ...props }
81+ { ...rest }
6282 aria-label = { ariaLabel }
6383 role = "img"
6484 focusable = "false"
6585 />
6686 ) ;
6787 }
68- return < StyledIcon { ...props } aria-hidden focusable = "false" /> ;
69- } ;
70-
71- Icon . propTypes = {
72- 'aria-label' : PropTypes . string
73- } ;
74-
75- Icon . defaultProps = {
76- 'aria-label' : null
88+ return < StyledIcon { ...rest } aria-hidden focusable = "false" /> ;
7789 } ;
7890
7991 return Icon ;
0 commit comments