UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

29 lines (28 loc) 1.1 kB
import { default as emotionStyled } from '@emotion/styled'; import { useTheme, ContentDirection } from './index'; import rtlCSSJS from 'rtl-css-js'; const noop = (styles) => styles; export const filterOutProps = (omittedProps) => { return (prop) => !omittedProps.includes(prop); }; function styled(node, options) { return (...args) => { const newArgs = args.map(interpolation => (props) => { props.theme = useTheme(props.theme); const direction = props.theme.canvas.direction; const maybeFlip = direction === ContentDirection.RTL ? rtlCSSJS : noop; const maybeConvert = props.theme._styleRewriteFn || noop; try { if (typeof interpolation === 'function') { return maybeFlip(maybeConvert(interpolation(props))); } return maybeFlip(maybeConvert(interpolation)); } catch (e) { return maybeConvert(interpolation); } }); return emotionStyled(node, options)(newArgs); }; } export default styled;