@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
57 lines (56 loc) • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Svg = exports.resolveSize = exports.svgStencil = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const common_1 = require("@workday/canvas-kit-react/common");
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
exports.svgStencil = (0, canvas_kit_styling_1.createStencil)({
vars: {
/** sets width of svg element
* @deprecated use size instead or svg selector
*/
width: '',
/** sets height of svg element
* @deprecated use size instead or svg selector
*/
height: '',
/** sets width and height of svg element */
size: '',
},
base: { name: "2bua3u", styles: "box-sizing:border-box;display:inline-block;> svg{display:block;width:var(--width-svg-bca693, var(--size-svg-bca693));height:var(--height-svg-bca693, var(--size-svg-bca693));}" },
modifiers: {
shouldMirror: {
true: { name: "38ol7h", styles: "transform:scaleX(-1);" }
},
shouldMirrorInRTL: {
true: { name: "2jlqun", styles: "&:dir(rtl){transform:scaleX(-1);}" }
}
}
}, "svg-bca693");
/**
* Resolves the size of the SVG based on the size token or string / numeric (px) value.
* @param size - The size variant or string / numeric (px) value.
* @param tokens - The tokens to use to resolve the size.
* @returns The resolved size.
*/
const resolveSize = (size, tokens) => {
if (size) {
return size in tokens
? tokens[size]
: typeof size === 'number'
? (0, canvas_kit_styling_1.px2rem)(size)
: size;
}
return '';
};
exports.resolveSize = resolveSize;
exports.Svg = (0, common_1.createComponent)('span')({
displayName: 'Svg',
Component: ({ shouldMirror, shouldMirrorInRTL, src, type, ...elemProps }, ref, Element) => {
if ((src === null || src === void 0 ? void 0 : src.type) !== type) {
console.error(`Icon type "${src.type}" does not match expected type "${type}"`);
return null;
}
return ((0, jsx_runtime_1.jsx)(Element, { ref: ref, dangerouslySetInnerHTML: { __html: src.svg }, ...(0, canvas_kit_styling_1.handleCsProp)(elemProps, (0, exports.svgStencil)({ shouldMirror, shouldMirrorInRTL })) }));
},
});