diff --git a/client/common/icons.jsx b/client/common/icons.tsx similarity index 81% rename from client/common/icons.jsx rename to client/common/icons.tsx index bd5a673e2a..80411bf937 100644 --- a/client/common/icons.jsx +++ b/client/common/icons.tsx @@ -26,13 +26,25 @@ import Filter from '../images/filter.svg'; import Cross from '../images/cross.svg'; import Copy from '../images/copy.svg'; +export interface IconColors { + default?: string; + hover?: string; +} + +export interface IconProps extends React.SVGProps { + 'aria-label'?: string; + Icon?: IconColors; +} + // 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. -function withLabel(SvgComponent) { - const StyledIcon = styled(SvgComponent)` +function withLabel( + SvgComponent: React.ComponentType> +) { + const StyledIcon = styled(SvgComponent)` &&& { color: ${(props) => props.Icon?.default}; & g, @@ -53,27 +65,27 @@ function withLabel(SvgComponent) { } `; - const Icon = (props) => { - const { 'aria-label': ariaLabel } = props; + // Necessary because styled components inject a different type for the ref prop + type StyledIconProps = Omit< + React.ComponentProps, + 'ref' + > & { + ref?: React.Ref; + }; + + const Icon = (props: StyledIconProps) => { + const { 'aria-label': ariaLabel, ...rest } = props; if (ariaLabel) { return ( ); } - return ; - }; - - Icon.propTypes = { - 'aria-label': PropTypes.string - }; - - Icon.defaultProps = { - 'aria-label': null + return ; }; return Icon; diff --git a/client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap b/client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap index 02e4776b1c..382e49aadd 100644 --- a/client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap +++ b/client/modules/IDE/components/Header/__snapshots__/Nav.unit.test.jsx.snap @@ -351,7 +351,7 @@ exports[`Nav renders dashboard version for mobile 1`] = ` >