UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

79 lines (78 loc) 5.1 kB
import * as React from 'react'; import { iconColors } from '@workday/canvas-kit-react/tokens'; import { CanvasIconTypes } from '@workday/design-assets-types'; import { createComponent, getColor } from '@workday/canvas-kit-react/common'; import { cssVar, createStencil, handleCsProp, px2rem, createVars } from '@workday/canvas-kit-styling'; import { base, system } from '@workday/canvas-tokens-web'; import { Svg, svgStencil, transformColorNameToToken } from './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 * * ``` */ export const systemIconStyles = ({ accent, accentHover, background = 'transparent', backgroundHover = 'transparent', color = iconColors.standard, colorHover = iconColors.hover, fill, fillHover, }) => ({ '& .wd-icon-fill': { fill: getColor(fill) || getColor(color), }, ':hover .wd-icon-fill': { fill: getColor(fillHover) || getColor(colorHover), }, '& .wd-icon-accent, & .wd-icon-accent2': { fill: getColor(accent) || getColor(color), }, ':hover .wd-icon-accent, :hover .wd-icon-accent2': { fill: getColor(accentHover) || getColor(colorHover), }, '& .wd-icon-background': { fill: getColor(background), }, ':hover .wd-icon-background': { fill: getColor(backgroundHover), }, }); /** * @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 = createVars({ id: "a571ba", args: ["colorHover", "fillHover", "accentHover", "backgroundHover"] }); export const systemIconStencil = createStencil({ extends: 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: "d5h415", styles: "box-sizing:border-box;& svg{width:var(--width-svg-a30d66, var(--size-svg-a30d66, var(--cnvs-sys-space-x6)));height:var(--height-svg-a30d66, var(--size-svg-a30d66, var(--cnvs-sys-space-x6)));}& .wd-icon-fill{fill:var(--color-system-icon-212f69, var(--cnvs-base-palette-licorice-200));}& .wd-icon-accent, & .wd-icon-accent2{fill:var(--accentColor-system-icon-212f69, var(--color-system-icon-212f69, var(--cnvs-base-palette-licorice-200)));}& .wd-icon-background{fill:var(--backgroundColor-system-icon-212f69, transparent);}&:where(:hover, .hover) .wd-icon-fill{fill:var(--fillHover-a571ba, var(--colorHover-a571ba, var(--color-system-icon-212f69, var(--cnvs-base-palette-licorice-200))));}&:where(:hover, .hover) .wd-icon-accent, & .wd-icon-accent2{fill:var(--accentHover-a571ba, var(--colorHover-a571ba, var(--accentColor-system-icon-212f69, var(--color-system-icon-212f69, var(--cnvs-base-palette-licorice-200)))));}&:where(:hover, .hover) .wd-icon-background{fill:var(--backgroundHover-a571ba, var(--backgroundColor-system-icon-212f69, transparent));}@media (prefers-contrast: more){.wd-icon-fill, .wd-icon-accent{color:currentColor;fill:currentColor;}}" } }, "system-icon-212f69"); export const SystemIcon = createComponent('span')({ displayName: 'SystemIcon', Component: ({ size, background, backgroundHover, color, colorHover, icon, accent, accentHover, fill, fillHover, ...elemProps }, ref, Element) => { return (React.createElement(Svg, { as: Element, src: icon, type: CanvasIconTypes.System, ref: ref, ...handleCsProp(elemProps, [ systemIconStencil({ size: typeof size === 'number' ? px2rem(size) : size, color: transformColorNameToToken(fill || color), accentColor: transformColorNameToToken(accent || color), backgroundColor: transformColorNameToToken(background), }), { [deprecatedSystemIconVars.colorHover]: colorHover && transformColorNameToToken(colorHover), [deprecatedSystemIconVars.fillHover]: fillHover && transformColorNameToToken(fillHover), [deprecatedSystemIconVars.accentHover]: accentHover && transformColorNameToToken(accentHover), [deprecatedSystemIconVars.backgroundHover]: backgroundHover && transformColorNameToToken(backgroundHover), }, ]) })); }, });