@workday/canvas-kit-react 10.1.3 → 10.1.4

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.
@@ -5,6 +5,9 @@ import { defaultCanvasTheme, useTheme } from './theming';
5
5
  import { brand } from '@workday/canvas-tokens-web';
6
6
  // eslint-disable-next-line @emotion/no-vanilla
7
7
  import { cache } from '@emotion/css';
8
+ import { createStyles } from '@workday/canvas-kit-styling';
9
+ // copied from brand/_variables.css
10
+ const defaultBranding = createStyles({ name: "xyx30", styles: "--cnvs-brand-error-darkest{}--cnvs-brand-common-alert-inner{}--cnvs-brand-common-error-inner{}--cnvs-brand-common-focus-outline{}--cnvs-brand-neutral-accent{}--cnvs-brand-neutral-darkest{}--cnvs-brand-neutral-dark{}--cnvs-brand-neutral-base{}--cnvs-brand-neutral-light{}--cnvs-brand-neutral-lightest{}--cnvs-brand-success-accent{}--cnvs-brand-success-darkest{}--cnvs-brand-success-dark{}--cnvs-brand-success-base{}--cnvs-brand-success-light{}--cnvs-brand-success-lightest{}--cnvs-brand-error-accent{}--cnvs-brand-error-dark{}--cnvs-brand-error-base{}--cnvs-brand-error-light{}--cnvs-brand-error-lightest{}--cnvs-brand-alert-accent{}--cnvs-brand-alert-darkest{}--cnvs-brand-alert-dark{}--cnvs-brand-alert-base{}--cnvs-brand-alert-light{}--cnvs-brand-alert-lightest{}--cnvs-brand-primary-accent{}--cnvs-brand-primary-darkest{}--cnvs-brand-primary-dark{}--cnvs-brand-primary-base{}--cnvs-brand-primary-light{}--cnvs-brand-primary-lightest{}--cnvs-brand-gradient-primary{}" });
8
11
  const mappedKeys = {
9
12
  lightest: 'lightest',
10
13
  light: 'light',
@@ -13,21 +16,26 @@ const mappedKeys = {
13
16
  darkest: 'darkest',
14
17
  contrast: 'accent',
15
18
  };
16
- const useCanvasThemeToCssVars = (theme, elemProps) => {
19
+ export const useCanvasThemeToCssVars = (theme, elemProps) => {
17
20
  const filledTheme = useTheme(theme);
21
+ const className = (elemProps.className || '').split(' ').concat(defaultBranding).join(' ');
22
+ const style = elemProps.style || {};
18
23
  const { palette } = filledTheme.canvas;
19
- const style = ['common', 'primary', 'error', 'alert', 'success', 'neutral'].reduce((result, color) => {
24
+ ['common', 'primary', 'error', 'alert', 'success', 'neutral'].forEach(color => {
20
25
  if (color === 'common') {
21
26
  // @ts-ignore
22
- result[brand.common.focusOutline] = palette.common.focusOutline;
27
+ style[brand.common.focusOutline] = palette.common.focusOutline;
23
28
  }
24
29
  ['lightest', 'light', 'main', 'dark', 'darkest', 'contrast'].forEach(key => {
30
+ // We only want to set custom colors if they do not match the default. The `defaultBranding` class will take care of the rest.
25
31
  // @ts-ignore
26
- result[brand[color][mappedKeys[key]]] = palette[color][key];
32
+ if (palette[color][key] !== defaultCanvasTheme.palette[color][key]) {
33
+ // @ts-ignore
34
+ style[brand[color][mappedKeys[key]]] = palette[color][key];
35
+ }
27
36
  });
28
- return result;
29
- }, elemProps.style || {});
30
- return { ...elemProps, style };
37
+ });
38
+ return { ...elemProps, className, style };
31
39
  };
32
40
  export const CanvasProvider = ({ children, theme = { canvas: defaultCanvasTheme }, ...props }) => {
33
41
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"usePopupStack.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/usePopupStack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,aAAa,8HAGvB,MAAM,SAAS,CAAC,WAAW,CA2C7B,CAAC"}
1
+ {"version":3,"file":"usePopupStack.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/usePopupStack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,aAAa,8HAGvB,MAAM,SAAS,CAAC,WAAW,CA0E7B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { PopupStack } from '@workday/canvas-kit-popup-stack';
3
- import { useLocalRef, useIsRTL } from '@workday/canvas-kit-react/common';
3
+ import { useLocalRef, useIsRTL, useCanvasThemeToCssVars } from '@workday/canvas-kit-react/common';
4
+ import { ThemeContext } from '@emotion/react';
4
5
  /**
5
6
  * **Note:** If you're using {@link Popper}, you do not need to use this hook directly.
6
7
  *
@@ -46,6 +47,8 @@ import { useLocalRef, useIsRTL } from '@workday/canvas-kit-react/common';
46
47
  export const usePopupStack = (ref, target) => {
47
48
  const { elementRef, localRef } = useLocalRef(ref);
48
49
  const isRTL = useIsRTL();
50
+ const theme = React.useContext(ThemeContext);
51
+ const { className, style } = useCanvasThemeToCssVars(theme, {});
49
52
  // useState function input ensures we only create a container once.
50
53
  const [popupRef] = React.useState(() => {
51
54
  const container = PopupStack.createContainer();
@@ -81,5 +84,32 @@ export const usePopupStack = (ref, target) => {
81
84
  (_b = localRef.current) === null || _b === void 0 ? void 0 : _b.removeAttribute('dir');
82
85
  }
83
86
  }, [localRef, isRTL]);
87
+ // theming className
88
+ React.useLayoutEffect(() => {
89
+ const element = localRef.current;
90
+ element === null || element === void 0 ? void 0 : element.classList.add(className.trim());
91
+ return () => {
92
+ element === null || element === void 0 ? void 0 : element.classList.remove(className.trim());
93
+ };
94
+ }, [localRef, className]);
95
+ React.useLayoutEffect(() => {
96
+ const element = localRef.current;
97
+ if (element) {
98
+ // eslint-disable-next-line guard-for-in
99
+ for (const key in style) {
100
+ // @ts-ignore
101
+ element.style.setProperty(key, style[key]);
102
+ }
103
+ }
104
+ return () => {
105
+ if (element) {
106
+ // eslint-disable-next-line guard-for-in
107
+ for (const key in style) {
108
+ // @ts-ignore
109
+ element.style.removeProperty(key, style[key]);
110
+ }
111
+ }
112
+ };
113
+ }, [localRef, style]);
84
114
  return localRef;
85
115
  };
@@ -9,7 +9,7 @@ import { useSelectModel } from './hooks/useSelectModel';
9
9
  import { useSelectCard } from './hooks/useSelectCard';
10
10
  import { useSelectInput } from './hooks/useSelectInput';
11
11
  import { createStyles } from '@workday/canvas-kit-styling';
12
- const selectInputStyles = createStyles({ name: "q2du11", styles: "caret-color:transparent;cursor:default;&::selection{background-color:transparent;}" });
12
+ const selectInputStyles = createStyles({ name: "xyx312", styles: "caret-color:transparent;cursor:default;&::selection{background-color:transparent;}" });
13
13
  export const SelectInput = createSubcomponent(TextInput)({
14
14
  modelHook: useSelectModel,
15
15
  elemPropsHook: useSelectInput,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-react",
3
- "version": "10.1.3",
3
+ "version": "10.1.4",
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",
@@ -50,8 +50,8 @@
50
50
  "@emotion/styled": "^11.6.0",
51
51
  "@popperjs/core": "^2.5.4",
52
52
  "@workday/canvas-colors-web": "^2.0.0",
53
- "@workday/canvas-kit-popup-stack": "^10.1.3",
54
- "@workday/canvas-kit-styling": "^10.1.3",
53
+ "@workday/canvas-kit-popup-stack": "^10.1.4",
54
+ "@workday/canvas-kit-styling": "^10.1.4",
55
55
  "@workday/canvas-system-icons-web": "^3.0.0",
56
56
  "@workday/canvas-tokens-web": "^1.0.0",
57
57
  "@workday/design-assets-types": "^0.2.8",
@@ -69,5 +69,5 @@
69
69
  "@workday/canvas-accent-icons-web": "^3.0.0",
70
70
  "@workday/canvas-applet-icons-web": "^2.0.0"
71
71
  },
72
- "gitHead": "2936b4918f4df739c86417d45700bbde98130fe9"
72
+ "gitHead": "6dbd6f678e12887b64fa3c6289bbd026849fc26a"
73
73
  }
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
3
  import {PopupStack} from '@workday/canvas-kit-popup-stack';
4
- import {useLocalRef, useIsRTL} from '@workday/canvas-kit-react/common';
4
+ import {useLocalRef, useIsRTL, useCanvasThemeToCssVars} from '@workday/canvas-kit-react/common';
5
+ import {ThemeContext, Theme} from '@emotion/react';
5
6
 
6
7
  /**
7
8
  * **Note:** If you're using {@link Popper}, you do not need to use this hook directly.
@@ -51,6 +52,8 @@ export const usePopupStack = <E extends HTMLElement>(
51
52
  ): React.RefObject<HTMLElement> => {
52
53
  const {elementRef, localRef} = useLocalRef(ref);
53
54
  const isRTL = useIsRTL();
55
+ const theme = React.useContext(ThemeContext as React.Context<Theme>);
56
+ const {className, style} = useCanvasThemeToCssVars(theme, {});
54
57
 
55
58
  // useState function input ensures we only create a container once.
56
59
  const [popupRef] = React.useState(() => {
@@ -90,5 +93,34 @@ export const usePopupStack = <E extends HTMLElement>(
90
93
  }
91
94
  }, [localRef, isRTL]);
92
95
 
96
+ // theming className
97
+ React.useLayoutEffect(() => {
98
+ const element = localRef.current;
99
+ element?.classList.add(className.trim());
100
+ return () => {
101
+ element?.classList.remove(className.trim());
102
+ };
103
+ }, [localRef, className]);
104
+
105
+ React.useLayoutEffect(() => {
106
+ const element = localRef.current;
107
+ if (element) {
108
+ // eslint-disable-next-line guard-for-in
109
+ for (const key in style) {
110
+ // @ts-ignore
111
+ element.style.setProperty(key, style[key]);
112
+ }
113
+ }
114
+ return () => {
115
+ if (element) {
116
+ // eslint-disable-next-line guard-for-in
117
+ for (const key in style) {
118
+ // @ts-ignore
119
+ element.style.removeProperty(key, style[key]);
120
+ }
121
+ }
122
+ };
123
+ }, [localRef, style]);
124
+
93
125
  return localRef;
94
126
  };