import * as React from 'react'; import {iconData, IconIntent} from '@unidata/icon'; import {createHtmlPropsFilter} from '../../utils/createHtmlPropsFilter'; import {getSizeThemeKey} from '../../utils/getSizeThemeKey'; import {getIntentThemeKey} from '../../utils/getIntentThemeKey'; import {joinClassNames} from '../../utils/joinClassNames'; import {SIZE, TRIGGER} from '../../constants'; import {Props} from './Icon.types'; import * as theme from './icon.m.scss'; import {Tooltip} from '../tooltip/Tooltip'; const filterProps = createHtmlPropsFilter>([ 'name', 'size', 'intent', 'title' ]); export class Icon extends React.Component { override render () { const props = this.props; const {name, size = SIZE.MIDDLE, intent = IconIntent.DEFAULT} = props; const sizeThemeKey = getSizeThemeKey('icon', size); const intentThemeKey = getIntentThemeKey('icon', intent); const className = joinClassNames(theme.icon, theme[sizeThemeKey], theme[intentThemeKey]); const iconSvgProps = iconData[name] ? iconData[name].svg : {}; const svgProps: React.SVGProps = { ...iconSvgProps, ...filterProps(props), className, dangerouslySetInnerHTML: iconData[name] && iconData[name].content ? {__html: iconData[name].content} : undefined }; if (props.title) { return ( ); } return ; } }