UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

48 lines (47 loc) 2.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useThemedPalette = exports.getPaletteColors = void 0; const common_1 = require("@workday/canvas-kit-react/common"); const tokens_1 = require("@workday/canvas-kit-react/tokens"); const chroma_js_1 = __importDefault(require("chroma-js")); const isAccessible = (foreground, background) => { return chroma_js_1.default.contrast(foreground, background) >= 3; }; const getPaletteColorsFromTheme = (palette, fallbackColors) => { return { hover: palette.dark, normal: palette.main, contrast: isAccessible(palette.contrast, palette.main) ? palette.contrast : fallbackColors === null || fallbackColors === void 0 ? void 0 : fallbackColors.contrast, }; }; /** * @deprecated ⚠️ `getPaletteColors` is deprecated. Use CSS variables from `@workday/canvas-tokens-web` instead. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14). */ const getPaletteColors = (type, theme) => { const palette = theme.canvas.palette[type]; switch (type) { case 'error': { return getPaletteColorsFromTheme(palette, { contrast: tokens_1.colors.frenchVanilla100 }); } case 'alert': { return getPaletteColorsFromTheme(palette, { contrast: tokens_1.colors.blackPepper400 }); } default: { return getPaletteColorsFromTheme(palette); } } }; exports.getPaletteColors = getPaletteColors; /** * @deprecated ⚠️ `useThemedPalette` is deprecated. In previous versions of Canvas Kit, we allowed teams to pass a theme object, this supported [Emotion's theming](https://emotion.sh/docs/theming). Now that we're shifting to a global theming approach based on CSS variables, we advise to no longer using the theme prop. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14). */ const useThemedPalette = (type) => { const theme = (0, common_1.useTheme)(); return (0, exports.getPaletteColors)(type, theme); }; exports.useThemedPalette = useThemedPalette;