UNPKG

nishant-design-system

Version:
71 lines (60 loc) 1.64 kB
// @flow strict import * as React from 'react'; // get our fontawesome imports import './FontAwesomeLibrary'; import type {ColorTypes} from '../../types/typography'; import {TEXT_COLORS} from '../../types/typography'; import classify from '../../utils/classify'; import typographyStyle from '../../styles/typography.module.css'; export type IconType = 'regular' | 'solid' | 'duotone' | 'brands'; export const ICON_SIZE = Object.freeze({ small: 'small', medium: 'medium', }); export type IconSize = $Keys<typeof ICON_SIZE>; export type IconProps = { type?: IconType, name: string, size?: IconSize, color?: ColorTypes, className?: string, onClick?: ?(SyntheticEvent<HTMLElement>) => mixed, ariaLabel?: string, swapOpacity?: boolean, }; export const Icon: React$AbstractComponent<IconProps, HTMLDivElement> = React.forwardRef<IconProps, HTMLDivElement>( ( { type = 'regular', name = '', size = 'medium', color = TEXT_COLORS.primary, className, onClick, swapOpacity, }: IconProps, forwardRef, ) => ( <> {!!name && ( <div className={classify( typographyStyle.centerAlignFlex, typographyStyle[`${size}Icon`], typographyStyle[color], className, )} onClick={onClick} ref={forwardRef} > <i className={classify(`fa-${type} fa-${name} `, { ['fa-swap-opacity']: swapOpacity, })} /> </div> )} </> ), );