import React, { type HTMLAttributes } from 'react' import classNames from 'classnames' import { type StringSuggestions } from '~components/types/StringSuggestions' import { handledRtlIcons } from './constants' import { type IconNames } from './types' import styles from './Icon.module.css' type PresentationalIcon = { isPresentational: true alt?: never } type MeaningfulIcon = { isPresentational?: false alt: string } type BaseIconProps = { isFilled?: boolean } & HTMLAttributes & (PresentationalIcon | MeaningfulIcon) type MaterialIconProps = BaseIconProps & { children: React.ReactNode } const MaterialIcon = ({ children, isFilled, isPresentational, alt, className, ...restProps }: MaterialIconProps): JSX.Element => ( {children} ) export type IconProps = BaseIconProps & { /** Options available at https://fonts.google.com/icons */ name: StringSuggestions shouldMirrorInRTL?: boolean } export const Icon = ({ name, shouldMirrorInRTL, ...restProps }: IconProps): JSX.Element => { if (!shouldMirrorInRTL) { return {name} } if (Object.keys(handledRtlIcons).includes(name)) { return ( {name} {handledRtlIcons[name as keyof typeof handledRtlIcons]} ) } return ( {name} ) }