UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

84 lines (83 loc) 5.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemIcon = exports.systemIconStencil = exports.systemIconStyles = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const tokens_1 = require("@workday/canvas-kit-react/tokens"); const design_assets_types_1 = require("@workday/design-assets-types"); const common_1 = require("@workday/canvas-kit-react/common"); const canvas_kit_styling_1 = require("@workday/canvas-kit-styling"); const canvas_tokens_web_1 = require("@workday/canvas-tokens-web"); const Svg_1 = require("./Svg"); /** * @deprecated This style utility function is deprecated and will be removed in a future version. We'll track usage over time to prevent unnecessary burden on upgrading. Most of the time, this function is used in conjunction with styling `SystemIcon`. There are a few ways to override the colors used in `SystemIcon`. * - Pass props directly to the `SystemIcon` component: `<SystemIcon color={color} {...etc} /> * - Style overrides using the `systemIconStencil`: * ```tsx * // styling container * * ``` */ const systemIconStyles = ({ accent, accentHover, background = 'transparent', backgroundHover = 'transparent', color = tokens_1.iconColors.standard, colorHover = tokens_1.iconColors.hover, fill, fillHover, }) => ({ '& .wd-icon-fill': { fill: (0, common_1.getColor)(fill) || (0, common_1.getColor)(color), }, ':hover .wd-icon-fill': { fill: (0, common_1.getColor)(fillHover) || (0, common_1.getColor)(colorHover), }, '& .wd-icon-accent, & .wd-icon-accent2': { fill: (0, common_1.getColor)(accent) || (0, common_1.getColor)(color), }, ':hover .wd-icon-accent, :hover .wd-icon-accent2': { fill: (0, common_1.getColor)(accentHover) || (0, common_1.getColor)(colorHover), }, '& .wd-icon-background': { fill: (0, common_1.getColor)(background), }, ':hover .wd-icon-background': { fill: (0, common_1.getColor)(backgroundHover), }, }); exports.systemIconStyles = systemIconStyles; /** * @deprecated These variables are being used for backward compatibility with existing hover props. Please use the following instead: * ```tsx * '&:hover': { * [systemIconStencil.vars.color]: desiredHoverColor * } * ``` */ const deprecatedSystemIconVars = (0, canvas_kit_styling_1.createVars)({ id: "02493f", args: ["colorHover", "fillHover", "accentHover", "backgroundHover"] }); exports.systemIconStencil = (0, canvas_kit_styling_1.createStencil)({ extends: Svg_1.svgStencil, vars: { /** * This will set the icon's color (both `.wd-icon-fill` and `.wd-icon-accent` SVG layers). Most * of the time, this is the only color you need to change. Icons also have an accent layer. If you * wish to change the accent layer independently, also set the `accentColor` variable */ color: '', accentColor: '', backgroundColor: '', }, base: { name: "3oqcpb", styles: "box-sizing:border-box;& svg{width:var(--width-svg-8fcab8, var(--size-svg-8fcab8, var(--cnvs-sys-space-x6)));height:var(--height-svg-8fcab8, var(--size-svg-8fcab8, var(--cnvs-sys-space-x6)));}& .wd-icon-fill{fill:var(--color-system-icon-3a4847, var(--cnvs-sys-color-icon-default));}& .wd-icon-accent, & .wd-icon-accent2{fill:var(--accentColor-system-icon-3a4847, var(--color-system-icon-3a4847, var(--cnvs-sys-color-fg-default)));}& .wd-icon-background{fill:var(--backgroundColor-system-icon-3a4847, transparent);}&:where(:hover, .hover) .wd-icon-fill{fill:var(--fillHover-02493f, var(--colorHover-02493f, var(--color-system-icon-3a4847, var(--cnvs-sys-color-fg-default))));}&:where(:hover, .hover) .wd-icon-accent, & .wd-icon-accent2{fill:var(--accentHover-02493f, var(--colorHover-02493f, var(--accentColor-system-icon-3a4847, var(--color-system-icon-3a4847, var(--cnvs-sys-color-fg-default)))));}&:where(:hover, .hover) .wd-icon-background{fill:var(--backgroundHover-02493f, var(--backgroundColor-system-icon-3a4847, transparent));}@media (prefers-contrast: more){.wd-icon-fill, .wd-icon-accent{color:currentColor;fill:currentColor;}}" }, modifiers: {} }, "system-icon-3a4847"); exports.SystemIcon = (0, common_1.createComponent)('span')({ displayName: 'SystemIcon', Component: ({ size, background, backgroundHover, color, colorHover, icon, accent, accentHover, fill, fillHover, ...elemProps }, ref, Element) => { return ((0, jsx_runtime_1.jsx)(Svg_1.Svg, { as: Element, src: icon, type: design_assets_types_1.CanvasIconTypes.System, ref: ref, ...(0, canvas_kit_styling_1.handleCsProp)(elemProps, [ (0, exports.systemIconStencil)({ size: typeof size === 'number' ? (0, canvas_kit_styling_1.px2rem)(size) : size, color: (0, Svg_1.transformColorNameToToken)(fill || color), accentColor: (0, Svg_1.transformColorNameToToken)(accent || color), backgroundColor: (0, Svg_1.transformColorNameToToken)(background), }), { [deprecatedSystemIconVars.colorHover]: colorHover && (0, Svg_1.transformColorNameToToken)(colorHover), [deprecatedSystemIconVars.fillHover]: fillHover && (0, Svg_1.transformColorNameToToken)(fillHover), [deprecatedSystemIconVars.accentHover]: accentHover && (0, Svg_1.transformColorNameToToken)(accentHover), [deprecatedSystemIconVars.backgroundHover]: backgroundHover && (0, Svg_1.transformColorNameToToken)(backgroundHover), }, ]) })); }, });