@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
27 lines (26 loc) • 1.25 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useTheme, CanvasProvider, } from '@workday/canvas-kit-react/common';
export 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' ? convertToStaticStates(obj[key]) : obj[key];
const newObj = { ...result, [newKey]: value };
return newObj;
}, {});
};
export const StaticStates = ({ children, theme, className, ...elemProps }) => {
const localTheme = useTheme(theme);
localTheme._styleRewriteFn = convertToStaticStates;
console.log('className', className);
return (_jsx(CanvasProvider, { theme: localTheme, className: className, ...elemProps, children: children }));
};