UNPKG

@antv/s2-react

Version:
24 lines 1.07 kB
import { getIcon, S2_PREFIX_CLS } from '@antv/s2'; import cx from 'classnames'; import React from 'react'; import './html-icon.less'; export const HtmlIcon = (props) => { const { style = {}, width, height, className, name } = props; const svgIcon = () => getIcon(name); // fix: Uncaught TypeError: Cannot assign to read only property 'width' of object '#<Object>' const newStyle = Object.assign({}, style); /* * html-icon 和 gui-icon 的接口趋于一致,都有 width 和 height 的便携属性 * 但在 html-icon 中,需要将 width 和 height 合入 style 中,且 width 比 style.width 优先级高 */ if (width) { newStyle.width = `${width}px`; } if (height) { newStyle.height = `${height}px`; } return (React.createElement("span", { style: newStyle, className: cx(`${S2_PREFIX_CLS}-html-icon`, className), // svg icon 都要求是本地文件,所以暂不担心 xss 问题了 dangerouslySetInnerHTML: { __html: svgIcon() } })); }; //# sourceMappingURL=html-icon.js.map