UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

46 lines (45 loc) 1.7 kB
import * as React from 'react'; import { validateIconType } from './utils'; import { createComponent } from '@workday/canvas-kit-react/common'; import { mergeStyles } from '@workday/canvas-kit-react/layout'; import { createStencil, cssVar } from '@workday/canvas-kit-styling'; import { base } from '@workday/canvas-tokens-web'; export const svgStencil = createStencil({ vars: { /** sets width of svg element */ width: '', /** sets height of svg element */ height: '', /** sets width and height of svg element */ size: '', }, base: { name: "d5h410", styles: "box-sizing:border-box;display:inline-block;> svg{display:block;width:var(--width-svg-a30d66, var(--size-svg-a30d66));height:var(--height-svg-a30d66, var(--size-svg-a30d66));}" }, modifiers: { shouldMirror: { true: { name: "d5h411", styles: "transform:scaleX(-1);" } } } }, "svg-a30d66"); /** @deprecated */ export const transformColorNameToToken = (color) => { if (color && color in base) { return cssVar(base[color]); } if (color === null || color === void 0 ? void 0 : color.startsWith('--')) { return cssVar(color); } return color; }; export const Svg = createComponent('span')({ displayName: 'Svg', Component: ({ shouldMirror, src, type, ...elemProps }, ref, Element) => { try { validateIconType(src, type); } catch (e) { console.error(e); return null; } return (React.createElement(Element, { ref: ref, dangerouslySetInnerHTML: { __html: src.svg }, ...mergeStyles(elemProps, svgStencil({ shouldMirror })) })); }, });