@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
35 lines (34 loc) • 1.84 kB
JavaScript
import { default as emotionStyled } from '@emotion/styled';
import { useTheme, ContentDirection } from './index';
import rtlCSSJS from 'rtl-css-js';
const noop = (styles) => styles;
/**
* @deprecated ⚠️ `filterOutProps` is deprecated and will be removed in a future major version. Use our `createComponent` and `handleCsProp` helpers to handle props. For more information, view our [Meriging Styles Docs](https://workday.github.io/canvas-kit/?path=/docs/styling-guides-merging-styles--docs#handlecsprop).
*/
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);
};
}
/**
* @deprecated ⚠️ `styled` is deprecated and will be removed in a future major version. Please use `createStyles` or `createStencil` instead with [CSS logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values). For more information, view our [Styling docs](https://workday.github.io/canvas-kit/?path=/docs/styling-getting-started-overview--docs).
*/
export default styled;