UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

31 lines (30 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StaticStates = exports.convertToStaticStates = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const common_1 = require("@workday/canvas-kit-react/common"); const convertToStaticStates = obj => { if (!obj) { return obj; } return Object.keys(obj).reduce((result, key) => { const newKey = key .replace(/^:/, '&:') // handle shorthand like ":focus" .replace(/,(\s+):/g, ',$1&:') // handle selectors like ":focus, :hover" .replace(/:(focus|hover|active)/g, '.$1'); // Remove any selectors that use data-whatinput. Leaving them in would cause focus rings to disappear when the user clicks with a mouse. if (/data-whatinput/.test(key)) { return result; } const value = typeof obj[key] === 'object' ? (0, exports.convertToStaticStates)(obj[key]) : obj[key]; const newObj = { ...result, [newKey]: value }; return newObj; }, {}); }; exports.convertToStaticStates = convertToStaticStates; const StaticStates = ({ children, theme, ...elemProps }) => { const localTheme = (0, common_1.useTheme)(theme); localTheme._styleRewriteFn = exports.convertToStaticStates; return ((0, jsx_runtime_1.jsx)(common_1.CanvasProvider, { theme: localTheme, ...elemProps, children: children })); }; exports.StaticStates = StaticStates;