UNPKG

@ant-design/icons

Version:

[![NPM version](https://img.shields.io/npm/v/@ant-design/icons.svg?style=flat)](https://npmjs.org/package/@ant-design/icons) [![NPM downloads](http://img.shields.io/npm/dm/@ant-design/icons.svg?style=flat)](https://npmjs.org/package/@ant-design/icons)

159 lines (149 loc) 5.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generate = generate; exports.getSecondaryColor = getSecondaryColor; exports.iconStyles = void 0; exports.isIconDefinition = isIconDefinition; exports.normalizeAttrs = normalizeAttrs; exports.normalizeTwoToneColors = normalizeTwoToneColors; exports.useInsertStyles = exports.svgBaseProps = void 0; exports.warning = warning; var _colors = require("@ant-design/colors"); var _dynamicCSS = require("@rc-component/util/lib/Dom/dynamicCSS"); var _shadow = require("@rc-component/util/lib/Dom/shadow"); var _warning = _interopRequireDefault(require("@rc-component/util/lib/warning")); var _react = _interopRequireWildcard(require("react")); var _Context = _interopRequireDefault(require("./components/Context")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function camelCase(input) { return input.replace(/-(.)/g, (match, g) => g.toUpperCase()); } function warning(valid, message) { (0, _warning.default)(valid, `[@ant-design/icons] ${message}`); } function isIconDefinition(target) { return typeof target === 'object' && typeof target.name === 'string' && typeof target.theme === 'string' && (typeof target.icon === 'object' || typeof target.icon === 'function'); } function normalizeAttrs(attrs = {}) { return Object.keys(attrs).reduce((acc, key) => { const val = attrs[key]; switch (key) { case 'class': acc.className = val; delete acc.class; break; default: delete acc[key]; acc[camelCase(key)] = val; } return acc; }, {}); } function generate(node, key, rootProps) { if (!rootProps) { return /*#__PURE__*/_react.default.createElement(node.tag, { key, ...normalizeAttrs(node.attrs) }, (node.children || []).map((child, index) => generate(child, `${key}-${node.tag}-${index}`))); } return /*#__PURE__*/_react.default.createElement(node.tag, { key, ...normalizeAttrs(node.attrs), ...rootProps }, (node.children || []).map((child, index) => generate(child, `${key}-${node.tag}-${index}`))); } function getSecondaryColor(primaryColor) { // choose the second color return (0, _colors.generate)(primaryColor)[0]; } function normalizeTwoToneColors(twoToneColor) { if (!twoToneColor) { return []; } return Array.isArray(twoToneColor) ? twoToneColor : [twoToneColor]; } // These props make sure that the SVG behaviours like general text. // Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4 const svgBaseProps = exports.svgBaseProps = { width: '1em', height: '1em', fill: 'currentColor', 'aria-hidden': 'true', focusable: 'false' }; const iconStyles = exports.iconStyles = ` .anticon { display: inline-flex; align-items: center; color: inherit; font-style: normal; line-height: 0; text-align: center; text-transform: none; vertical-align: -0.125em; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .anticon > * { line-height: 1; } .anticon svg { display: inline-block; } .anticon::before { display: none; } .anticon .anticon-icon { display: block; } .anticon[tabindex] { cursor: pointer; } .anticon-spin::before, .anticon-spin { display: inline-block; -webkit-animation: loadingCircle 1s infinite linear; animation: loadingCircle 1s infinite linear; } @-webkit-keyframes loadingCircle { 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } @keyframes loadingCircle { 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } `; const useInsertStyles = eleRef => { const { csp, prefixCls, layer } = (0, _react.useContext)(_Context.default); let mergedStyleStr = iconStyles; if (prefixCls) { mergedStyleStr = mergedStyleStr.replace(/anticon/g, prefixCls); } if (layer) { mergedStyleStr = `@layer ${layer} {\n${mergedStyleStr}\n}`; } (0, _react.useEffect)(() => { const ele = eleRef.current; const shadowRoot = (0, _shadow.getShadowRoot)(ele); (0, _dynamicCSS.updateCSS)(mergedStyleStr, '@ant-design-icons', { prepend: !layer, csp, attachTo: shadowRoot }); }, []); }; exports.useInsertStyles = useInsertStyles;