@workday/canvas-kit-react 10.0.5 → 10.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/button/lib/BaseButton.tsx +11 -15
  2. package/button/lib/DeleteButton.tsx +3 -2
  3. package/button/lib/PrimaryButton.tsx +3 -10
  4. package/button/lib/SecondaryButton.tsx +3 -9
  5. package/button/lib/TertiaryButton.tsx +3 -5
  6. package/common/lib/CanvasProvider.tsx +14 -10
  7. package/dist/commonjs/button/lib/BaseButton.d.ts.map +1 -1
  8. package/dist/commonjs/button/lib/BaseButton.js +31 -34
  9. package/dist/commonjs/button/lib/DeleteButton.d.ts.map +1 -1
  10. package/dist/commonjs/button/lib/DeleteButton.js +4 -3
  11. package/dist/commonjs/button/lib/PrimaryButton.d.ts.map +1 -1
  12. package/dist/commonjs/button/lib/PrimaryButton.js +5 -4
  13. package/dist/commonjs/button/lib/SecondaryButton.d.ts.map +1 -1
  14. package/dist/commonjs/button/lib/SecondaryButton.js +5 -4
  15. package/dist/commonjs/button/lib/TertiaryButton.d.ts +1 -1
  16. package/dist/commonjs/button/lib/TertiaryButton.d.ts.map +1 -1
  17. package/dist/commonjs/button/lib/TertiaryButton.js +25 -25
  18. package/dist/commonjs/common/lib/CanvasProvider.d.ts.map +1 -1
  19. package/dist/commonjs/common/lib/CanvasProvider.js +6 -3
  20. package/dist/commonjs/layout/index.d.ts +2 -1
  21. package/dist/commonjs/layout/index.d.ts.map +1 -1
  22. package/dist/commonjs/layout/index.js +4 -1
  23. package/dist/commonjs/layout/lib/utils/mergeStyles.d.ts +61 -0
  24. package/dist/commonjs/layout/lib/utils/mergeStyles.d.ts.map +1 -0
  25. package/dist/commonjs/layout/lib/utils/mergeStyles.js +160 -0
  26. package/dist/commonjs/menu/lib/MenuItem.d.ts +1 -1
  27. package/dist/commonjs/modal/lib/ModalOverlay.d.ts.map +1 -1
  28. package/dist/commonjs/modal/lib/ModalOverlay.js +9 -2
  29. package/dist/commonjs/tabs/lib/TabsItem.d.ts +1 -1
  30. package/dist/es6/button/lib/BaseButton.d.ts.map +1 -1
  31. package/dist/es6/button/lib/BaseButton.js +31 -34
  32. package/dist/es6/button/lib/DeleteButton.d.ts.map +1 -1
  33. package/dist/es6/button/lib/DeleteButton.js +4 -3
  34. package/dist/es6/button/lib/PrimaryButton.d.ts.map +1 -1
  35. package/dist/es6/button/lib/PrimaryButton.js +5 -4
  36. package/dist/es6/button/lib/SecondaryButton.d.ts.map +1 -1
  37. package/dist/es6/button/lib/SecondaryButton.js +5 -4
  38. package/dist/es6/button/lib/TertiaryButton.d.ts +1 -1
  39. package/dist/es6/button/lib/TertiaryButton.d.ts.map +1 -1
  40. package/dist/es6/button/lib/TertiaryButton.js +25 -25
  41. package/dist/es6/common/lib/CanvasProvider.d.ts.map +1 -1
  42. package/dist/es6/common/lib/CanvasProvider.js +7 -4
  43. package/dist/es6/layout/index.d.ts +2 -1
  44. package/dist/es6/layout/index.d.ts.map +1 -1
  45. package/dist/es6/layout/index.js +2 -0
  46. package/dist/es6/layout/lib/utils/mergeStyles.d.ts +61 -0
  47. package/dist/es6/layout/lib/utils/mergeStyles.d.ts.map +1 -0
  48. package/dist/es6/layout/lib/utils/mergeStyles.js +156 -0
  49. package/dist/es6/menu/lib/MenuItem.d.ts +1 -1
  50. package/dist/es6/modal/lib/ModalOverlay.d.ts.map +1 -1
  51. package/dist/es6/modal/lib/ModalOverlay.js +9 -2
  52. package/dist/es6/tabs/lib/TabsItem.d.ts +1 -1
  53. package/layout/index.ts +4 -3
  54. package/layout/lib/utils/mergeStyles.ts +178 -0
  55. package/modal/lib/ModalOverlay.tsx +25 -15
  56. package/package.json +6 -4
@@ -0,0 +1,178 @@
1
+ import {getRegisteredStyles} from '@emotion/utils';
2
+ // eslint-disable-next-line @emotion/no-vanilla
3
+ import {cache, css} from '@emotion/css';
4
+ import {csToProps, CSToPropsInput, createStylesCache} from '@workday/canvas-kit-styling';
5
+ import {boxStyleFn} from '../Box';
6
+ import {backgroundStyleFnConfigs} from './background';
7
+ import {borderStyleFnConfigs} from './border';
8
+ import {colorStyleFnConfigs} from './color';
9
+ import {depthStyleFnConfigs} from './depth';
10
+ import {flexItemStyleFnConfigs} from './flexItem';
11
+ import {gridItemStyleFnConfigs} from './gridItem';
12
+ import {layoutStyleFnConfigs} from './layout';
13
+ import {otherStyleFnConfigs} from './other';
14
+ import {positionStyleFnConfigs} from './position';
15
+ import {spaceStyleFnConfigs} from './space';
16
+ import {CommonStyleProps} from './styleProps';
17
+ import {textStyleFnConfigs} from './text';
18
+
19
+ // get a hash of all the style props for a faster lookup
20
+ const stylePropHash = [
21
+ ...backgroundStyleFnConfigs,
22
+ ...borderStyleFnConfigs,
23
+ ...colorStyleFnConfigs,
24
+ ...depthStyleFnConfigs,
25
+ ...flexItemStyleFnConfigs,
26
+ ...gridItemStyleFnConfigs,
27
+ ...layoutStyleFnConfigs,
28
+ ...otherStyleFnConfigs,
29
+ ...positionStyleFnConfigs,
30
+ ...spaceStyleFnConfigs,
31
+ ...textStyleFnConfigs,
32
+ ].reduce((result, prop) => {
33
+ //@ts-ignore
34
+ result[prop.name] = true;
35
+ return result;
36
+ }, {} as Record<string, boolean>);
37
+
38
+ function isStyleProps(prop: string): boolean {
39
+ return stylePropHash[prop] || false;
40
+ }
41
+
42
+ /**
43
+ * This is an opinionated function that will force style merging with Emotion's runtime APIs,
44
+ * including [styled components](https://emotion.sh/docs/styled) and the [css
45
+ * prop](https://emotion.sh/docs/css-prop). It will also handle style props for as long as those are
46
+ * supported. `mergeStyles` is exported from the layout package since it supports style props
47
+ * defined in the layout packages.
48
+ *
49
+ * It works by detecting styles added via Emotion's runtime APIs and forcing styling merging if use
50
+ * of runtime APIs have been detected. If only `createStyles` were used to style a component, the
51
+ * faster non-runtime styling will be used.
52
+ *
53
+ * You can use `mergeStyles` if you wish to use {@link createStyles} on your own components and want
54
+ * your components to be compatible with Emotion's runtime styling APIs.
55
+ *
56
+ * ```tsx
57
+ * import {createStyles, CSProps} from '@workday/canvas-kit-styling';
58
+ * import {mergeStyles} from '@workday/canvas-kit-react/layout';
59
+ *
60
+ * interface MyComponentProps extends CSProps {
61
+ * // other props
62
+ * }
63
+ *
64
+ * const myStyles = createStyles({
65
+ * background: 'green',
66
+ * height: 40,
67
+ * width: 40
68
+ * })
69
+ *
70
+ * const MyComponent = ({children, ...elemProps}: MyComponentProps) => {
71
+ * return (
72
+ * <div
73
+ * {...mergeStyles(elemProps, [myStyles])}
74
+ * >
75
+ * {children}
76
+ * </div>
77
+ * )
78
+ * }
79
+ *
80
+ * const StyledMyComponent(MyComponent)({
81
+ * background: 'red'
82
+ * })
83
+ *
84
+ * const myOverridingStyles = createStyles({
85
+ * background: 'blue'
86
+ * })
87
+ *
88
+ * // now everything works. Without `mergeStyles`, the last component would be a red box
89
+ * export default () => (
90
+ * <>
91
+ * <MyComponent>Green box</MyComponent>
92
+ * <StyledMyComponent>Red box</StyledMyComponent>
93
+ * <StyledMyComponent cs={myOverridingStyles}>Blue box</StyledMyComponent>
94
+ * </>
95
+ * )
96
+ * ```
97
+ *
98
+ */
99
+ export function mergeStyles<T extends {}>(
100
+ allProps: T,
101
+ cs: CSToPropsInput
102
+ ): Omit<T, 'cs' | keyof CommonStyleProps> {
103
+ const styleProps = {};
104
+ let shouldRuntimeMergeStyles = false;
105
+ // TypeScript can't handle a type where I declare T extends `{className?: string}` for some
106
+ // reason, so we'll do a `as any` any time we check for possible props on `allProps`
107
+ let className = (allProps as any).className || '';
108
+
109
+ // separate style props from all other props. `cs` is special and should be forwarded to the
110
+ // `handleCsProp` function.
111
+ const elemProps = Object.keys(allProps).reduce((result, prop) => {
112
+ if (isStyleProps(prop)) {
113
+ shouldRuntimeMergeStyles = true;
114
+ // @ts-ignore
115
+ styleProps[prop] = allProps[prop];
116
+ } else {
117
+ if (prop !== 'cs') {
118
+ // @ts-ignore
119
+ result[prop] = allProps[prop];
120
+ }
121
+ }
122
+
123
+ return result;
124
+ }, {});
125
+
126
+ // We need to determine if style props have been used. If they have, we need to merge all the CSS
127
+ // classes into a single class name in the order that the class names are listed. This variable
128
+ // will collect the CSS class name created by Emotion if we detect style props.
129
+ let stylePropsClassName = '';
130
+
131
+ // We have style props. We need to create style and merge with our `csToProps` to get the correct
132
+ // merging order for styles
133
+ if (shouldRuntimeMergeStyles) {
134
+ const styles = boxStyleFn(styleProps);
135
+ stylePropsClassName = css(styles);
136
+ }
137
+
138
+ const returnProps = csToProps([
139
+ cs,
140
+ stylePropsClassName, // if style props are not defined, this will be an empty string, which is fine
141
+ className, // This will come from `styled` components or the `css` prop or if a user manually sets the `className` prop
142
+ (allProps as any).cs, // doesn't matter if `cs` is undefined. csToProps will handle undefined. Thanks anyways, TypeScript
143
+ (allProps as any).style, // doesn't matter if `style` is undefined. csToProps will handle undefined. Thanks anyways, TypeScript
144
+ ]);
145
+
146
+ // see if we need to do style merging based off use of Emotion runtime APIs. We do this by testing
147
+ // the Emotion cache for a match to any class names we find, filtering out those created via
148
+ // `createStyles`. If only `createStyles` is detected, there is no reason to merge styles
149
+ (returnProps.className || '').split(' ').forEach(name => {
150
+ if (!createStylesCache[name] && cache.registered[name]) {
151
+ shouldRuntimeMergeStyles = true;
152
+ }
153
+ });
154
+
155
+ if (shouldRuntimeMergeStyles) {
156
+ const registeredStyles: string[] = [];
157
+
158
+ // We are using the raw `css` instead of `createStyles` because `css` uses style hashing and
159
+ // `createStyles` generates a new ID every time. We could use `createStyles` here, but it
160
+ // would be more wasteful and new styles would be generated each React render cycle. `css` is
161
+ // safe to use inside a render function while `createStyles` should always be used outside the
162
+ // React render cycle.
163
+ className = getRegisteredStyles(
164
+ cache.registered,
165
+ registeredStyles,
166
+ returnProps.className || ''
167
+ );
168
+
169
+ className += css(registeredStyles);
170
+ } else {
171
+ className = returnProps.className;
172
+ }
173
+
174
+ return {...elemProps, ...returnProps, ...{className}} as any as Omit<
175
+ T,
176
+ 'cs' | keyof CommonStyleProps
177
+ >;
178
+ }
@@ -26,20 +26,30 @@ const fadeIn = keyframes`
26
26
  }
27
27
  `;
28
28
 
29
- const Container = styled(Box)<StyledType>({
30
- position: 'fixed',
31
- top: 0,
32
- left: 0,
33
- width: '100vw',
34
- height: '100vh',
35
- background: 'rgba(0,0,0,0.65)',
36
- animationName: `${fadeIn}`,
37
- animationDuration: '0.3s',
38
- // Allow overriding of animation in special cases
39
- '.wd-no-animation &': {
40
- animation: 'none',
29
+ const Container = styled(Box)<StyledType>(
30
+ {
31
+ position: 'fixed',
32
+ top: 0,
33
+ left: 0,
34
+ width: '100vw',
35
+ height: '100vh',
36
+ background: 'rgba(0,0,0,0.65)',
37
+ animationName: `${fadeIn}`,
38
+ animationDuration: '0.3s',
39
+ // Allow overriding of animation in special cases
40
+ '.wd-no-animation &': {
41
+ animation: 'none',
42
+ },
41
43
  },
42
- });
44
+ ({theme}) => {
45
+ const {canvas: canvasTheme} = getTheme(theme);
46
+ return {
47
+ [canvasTheme.breakpoints.down('s')]: {
48
+ height: '100%',
49
+ },
50
+ };
51
+ }
52
+ );
43
53
 
44
54
  // This centering container helps fix an issue with Chrome. Chrome doesn't normally do subpixel
45
55
  // positioning, but seems to when using flexbox centering. This messes up Popper calculations inside
@@ -48,14 +58,14 @@ const Container = styled(Box)<StyledType>({
48
58
  const ResponsiveContainer = styled('div')(({theme}) => {
49
59
  const {canvas: canvasTheme} = getTheme(theme);
50
60
  return {
51
- maxHeight: '100vh',
61
+ maxHeight: '100%',
52
62
  display: 'flex',
53
63
  position: 'absolute',
54
64
  left: 0,
55
65
  top: 0,
56
66
  justifyContent: 'center',
57
67
  alignItems: 'center',
58
- height: '100vh',
68
+ height: '100%',
59
69
  [canvasTheme.breakpoints.down('s')]: {
60
70
  alignItems: 'end',
61
71
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-react",
3
- "version": "10.0.5",
3
+ "version": "10.0.7",
4
4
  "description": "The parent module that contains all Workday Canvas Kit React components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -44,13 +44,15 @@
44
44
  "react": ">=16.14"
45
45
  },
46
46
  "dependencies": {
47
+ "@emotion/css": "^11.7.1",
47
48
  "@emotion/is-prop-valid": "^1.1.1",
48
49
  "@emotion/react": "^11.7.1",
49
50
  "@emotion/styled": "^11.6.0",
51
+ "@emotion/utils": "^1.0.0",
50
52
  "@popperjs/core": "^2.5.4",
51
53
  "@workday/canvas-colors-web": "^2.0.0",
52
- "@workday/canvas-kit-popup-stack": "^10.0.5",
53
- "@workday/canvas-kit-styling": "^10.0.5",
54
+ "@workday/canvas-kit-popup-stack": "^10.0.7",
55
+ "@workday/canvas-kit-styling": "^10.0.7",
54
56
  "@workday/canvas-system-icons-web": "^3.0.0",
55
57
  "@workday/canvas-tokens-web": "^1.0.0",
56
58
  "@workday/design-assets-types": "^0.2.8",
@@ -68,5 +70,5 @@
68
70
  "@workday/canvas-accent-icons-web": "^3.0.0",
69
71
  "@workday/canvas-applet-icons-web": "^2.0.0"
70
72
  },
71
- "gitHead": "b62560cec000216312915cdc4e0acec1173d0acf"
73
+ "gitHead": "3068ffec35c5735a6f7d91e076a71e95e65e8c79"
72
74
  }