@workday/canvas-kit-react 14.1.19 → 14.2.0-0009-next.0
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.
- package/banner/lib/hooks/useThemedPalette.ts +6 -0
- package/common/lib/CanvasProvider.tsx +6 -0
- package/common/lib/theming/README.md +104 -444
- package/common/lib/theming/getObjectProxy.ts +1 -0
- package/common/lib/theming/index.ts +28 -0
- package/common/lib/theming/types.ts +19 -1
- package/common/lib/utils/colorUtils.ts +2 -1
- package/dist/commonjs/banner/lib/hooks/useThemedPalette.d.ts +6 -0
- package/dist/commonjs/banner/lib/hooks/useThemedPalette.d.ts.map +1 -1
- package/dist/commonjs/banner/lib/hooks/useThemedPalette.js +6 -0
- package/dist/commonjs/common/lib/CanvasProvider.d.ts +3 -0
- package/dist/commonjs/common/lib/CanvasProvider.d.ts.map +1 -1
- package/dist/commonjs/common/lib/CanvasProvider.js +6 -2
- package/dist/commonjs/common/lib/theming/getObjectProxy.d.ts +1 -0
- package/dist/commonjs/common/lib/theming/getObjectProxy.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/getObjectProxy.js +1 -0
- package/dist/commonjs/common/lib/theming/index.d.ts +28 -0
- package/dist/commonjs/common/lib/theming/index.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/index.js +28 -0
- package/dist/commonjs/common/lib/theming/types.d.ts +15 -0
- package/dist/commonjs/common/lib/theming/types.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/types.js +1 -0
- package/dist/commonjs/common/lib/utils/colorUtils.d.ts +1 -0
- package/dist/commonjs/common/lib/utils/colorUtils.d.ts.map +1 -1
- package/dist/commonjs/common/lib/utils/colorUtils.js +1 -0
- package/dist/commonjs/pagination/lib/Pagination/Controls.d.ts.map +1 -1
- package/dist/commonjs/pagination/lib/Pagination/Controls.js +9 -15
- package/dist/commonjs/testing/lib/ComponentStatesTable.js +5 -5
- package/dist/es6/banner/lib/hooks/useThemedPalette.d.ts +6 -0
- package/dist/es6/banner/lib/hooks/useThemedPalette.d.ts.map +1 -1
- package/dist/es6/banner/lib/hooks/useThemedPalette.js +6 -0
- package/dist/es6/common/lib/CanvasProvider.d.ts +3 -0
- package/dist/es6/common/lib/CanvasProvider.d.ts.map +1 -1
- package/dist/es6/common/lib/CanvasProvider.js +6 -2
- package/dist/es6/common/lib/theming/getObjectProxy.d.ts +1 -0
- package/dist/es6/common/lib/theming/getObjectProxy.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/getObjectProxy.js +1 -0
- package/dist/es6/common/lib/theming/index.d.ts +28 -0
- package/dist/es6/common/lib/theming/index.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/index.js +28 -0
- package/dist/es6/common/lib/theming/types.d.ts +15 -0
- package/dist/es6/common/lib/theming/types.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/types.js +1 -0
- package/dist/es6/common/lib/utils/colorUtils.d.ts +1 -0
- package/dist/es6/common/lib/utils/colorUtils.d.ts.map +1 -1
- package/dist/es6/common/lib/utils/colorUtils.js +1 -0
- package/dist/es6/pagination/lib/Pagination/Controls.d.ts.map +1 -1
- package/dist/es6/pagination/lib/Pagination/Controls.js +9 -15
- package/dist/es6/testing/lib/ComponentStatesTable.js +5 -5
- package/package.json +5 -5
- package/pagination/lib/Pagination/Controls.tsx +21 -17
- package/testing/lib/ComponentStatesTable.tsx +5 -5
|
@@ -27,6 +27,9 @@ const getPaletteColorsFromTheme = (
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated ⚠️ `getPaletteColors` is deprecated. Use CSS variables from `@workday/canvas-tokens-web` instead. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
32
|
+
*/
|
|
30
33
|
export const getPaletteColors = (
|
|
31
34
|
type: paletteSelection,
|
|
32
35
|
theme: EmotionCanvasTheme
|
|
@@ -46,6 +49,9 @@ export const getPaletteColors = (
|
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated ⚠️ `useThemedPalette` is deprecated. In previous versions of Canvas Kit, we allowed teams to pass a theme object, this supported [Emotion's theming](https://emotion.sh/docs/theming). Now that we're shifting to a global theming approach based on CSS variables, we advise to no longer using the theme prop. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
54
|
+
*/
|
|
49
55
|
export const useThemedPalette = (type: paletteSelection) => {
|
|
50
56
|
const theme = useTheme();
|
|
51
57
|
|
|
@@ -5,6 +5,9 @@ import {brand, base} from '@workday/canvas-tokens-web';
|
|
|
5
5
|
import {getCache, maybeWrapCSSVariables, createStyles} from '@workday/canvas-kit-styling';
|
|
6
6
|
|
|
7
7
|
export interface CanvasProviderProps {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated ⚠️ `theme` is deprecated. In previous versions of Canvas Kit, we allowed teams to pass a theme object, this supported [Emotion's theming](https://emotion.sh/docs/theming). Now that we're shifting to a global theming approach based on CSS variables, we advise to no longer using the theme prop. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
10
|
+
*/
|
|
8
11
|
theme?: PartialEmotionCanvasTheme;
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -66,6 +69,9 @@ export const defaultBranding = createStyles({
|
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
export const useCanvasThemeToCssVars = (
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated ⚠️ `theme` is deprecated. In previous versions of Canvas Kit, we allowed teams to pass a theme object, this supported [Emotion's theming](https://emotion.sh/docs/theming). Now that we're shifting to a global theming approach based on CSS variables, we advise to no longer using the theme prop. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
74
|
+
*/
|
|
69
75
|
theme: PartialEmotionCanvasTheme | undefined,
|
|
70
76
|
elemProps: React.HTMLAttributes<HTMLElement>
|
|
71
77
|
) => {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# Canvas Kit Theming
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
> **Deprecation Notice:** The `theme` prop on `CanvasProvider` and all associated theming utilities
|
|
4
|
+
> (`useTheme`, `getTheme`, `styled`, `defaultCanvasTheme`, `ContentDirection`, etc.) are deprecated.
|
|
5
|
+
> Please use CSS variables from `@workday/canvas-tokens-web` for theming. For the full theming
|
|
6
|
+
> guide, see our
|
|
7
|
+
> [Theming Documentation](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs).
|
|
5
8
|
|
|
6
9
|
## Installation
|
|
7
10
|
|
|
@@ -9,330 +12,102 @@ utilities that are used across components.
|
|
|
9
12
|
yarn add @workday/canvas-kit-react/common
|
|
10
13
|
```
|
|
11
14
|
|
|
12
|
-
##
|
|
15
|
+
## Recommended Approach: CSS Variables
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[`InputProvider`](../../README.md#input-provider) and includes all global configuration needed for
|
|
17
|
-
our Canvas Components.
|
|
17
|
+
Canvas Kit v14+ promotes using CSS variables for theming. Import CSS variable files and override
|
|
18
|
+
values in your root CSS:
|
|
18
19
|
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Component Props
|
|
27
|
-
|
|
28
|
-
### Required
|
|
29
|
-
|
|
30
|
-
> None
|
|
31
|
-
|
|
32
|
-
### Optional
|
|
20
|
+
```css
|
|
21
|
+
/* index.css */
|
|
22
|
+
@import '@workday/canvas-tokens-web/css/base/_variables.css';
|
|
23
|
+
@import '@workday/canvas-tokens-web/css/system/_variables.css';
|
|
24
|
+
@import '@workday/canvas-tokens-web/css/brand/_variables.css';
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
## Theme Object
|
|
41
|
-
|
|
42
|
-
The Canvas theme is based on the following object:
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
export const defaultCanvasTheme: CanvasTheme = {
|
|
46
|
-
palette: {
|
|
47
|
-
primary: {
|
|
48
|
-
lightest: colors.blueberry100,
|
|
49
|
-
light: colors.blueberry200,
|
|
50
|
-
main: colors.blueberry400,
|
|
51
|
-
dark: colors.blueberry500,
|
|
52
|
-
darkest: colors.blueberry600,
|
|
53
|
-
contrast: colors.frenchVanilla100,
|
|
54
|
-
},
|
|
55
|
-
caution: {
|
|
56
|
-
lightest: colors.cantaloupe100,
|
|
57
|
-
light: colors.cantaloupe300,
|
|
58
|
-
main: colors.cantaloupe400,
|
|
59
|
-
dark: colors.cantaloupe500,
|
|
60
|
-
darkest: colors.cantaloupe600,
|
|
61
|
-
contrast: colors.frenchVanilla100,
|
|
62
|
-
},
|
|
63
|
-
error: {
|
|
64
|
-
lightest: colors.cinnamon100,
|
|
65
|
-
light: colors.cinnamon300,
|
|
66
|
-
main: colors.cinnamon500,
|
|
67
|
-
dark: colors.cinnamon600,
|
|
68
|
-
darkest: '#80160E',
|
|
69
|
-
contrast: colors.frenchVanilla100,
|
|
70
|
-
},
|
|
71
|
-
success: {
|
|
72
|
-
lightest: colors.greenApple100,
|
|
73
|
-
light: colors.greenApple300,
|
|
74
|
-
main: colors.greenApple600,
|
|
75
|
-
dark: '',
|
|
76
|
-
darkest: '',
|
|
77
|
-
contrast: colors.frenchVanilla100,
|
|
78
|
-
},
|
|
79
|
-
neutral: {
|
|
80
|
-
lightest: colors.soap200,
|
|
81
|
-
light: colors.soap300,
|
|
82
|
-
main: colors.soap600,
|
|
83
|
-
dark: colors.licorice300,
|
|
84
|
-
darkest: colors.licorice400,
|
|
85
|
-
contrast: colors.frenchVanilla100,
|
|
86
|
-
},
|
|
87
|
-
common: {
|
|
88
|
-
focusOutline: colors.blueberry400,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
breakpoints: {
|
|
92
|
-
values: {
|
|
93
|
-
zero: 0,
|
|
94
|
-
s: 320,
|
|
95
|
-
m: 768,
|
|
96
|
-
l: 1024,
|
|
97
|
-
xl: 1440,
|
|
98
|
-
},
|
|
99
|
-
up,
|
|
100
|
-
down,
|
|
101
|
-
between,
|
|
102
|
-
only,
|
|
103
|
-
},
|
|
104
|
-
direction: ContentDirection.LTR,
|
|
105
|
-
};
|
|
26
|
+
:root {
|
|
27
|
+
/* Override brand primary colors */
|
|
28
|
+
--cnvs-brand-primary-base: var(--cnvs-base-palette-magenta-600);
|
|
29
|
+
--cnvs-brand-primary-light: var(--cnvs-base-palette-magenta-200);
|
|
30
|
+
--cnvs-brand-primary-dark: var(--cnvs-base-palette-magenta-700);
|
|
31
|
+
}
|
|
106
32
|
```
|
|
107
33
|
|
|
108
|
-
|
|
109
|
-
own use cases.
|
|
110
|
-
|
|
111
|
-
## Custom Theme
|
|
112
|
-
|
|
113
|
-
The `CanvasProvider` accepts a full or partial theme object to give a branded look or a different
|
|
114
|
-
direction to the component library.
|
|
115
|
-
|
|
116
|
-
> Note: Our theme is namespaced under the `canvas` key within the Emotion `ThemeContext`.
|
|
117
|
-
|
|
118
|
-
For a consistent theming experience, provide a value for each property in the theme object. Use our
|
|
119
|
-
CSS variables.
|
|
120
|
-
|
|
121
|
-
Example:
|
|
34
|
+
Or use `createStyles` to generate themed class names:
|
|
122
35
|
|
|
123
36
|
```tsx
|
|
124
|
-
import {
|
|
125
|
-
import {brand} from '@workday/canvas-tokens-web';
|
|
126
|
-
|
|
127
|
-
const theme: EmotionCanvasTheme = {
|
|
128
|
-
canvas: {
|
|
129
|
-
palette: {
|
|
130
|
-
primary: {
|
|
131
|
-
lightest: base.magenta25,
|
|
132
|
-
lighter: base.magenta50,
|
|
133
|
-
light: base.magenta200,
|
|
134
|
-
main: base.magenta600,
|
|
135
|
-
dark: base.magenta700,
|
|
136
|
-
darkest: base.magenta800,
|
|
137
|
-
contrast: base.neutral0,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
<CanvasProvider theme={theme}>{/* Your app with Canvas components */}</CanvasProvider>;
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Bidirectionality
|
|
147
|
-
|
|
148
|
-
We strongly encourage the use of
|
|
149
|
-
[CSS logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties)
|
|
150
|
-
for styling. All previous bidirectionality in the Canvas theme have been deprecated.
|
|
151
|
-
|
|
152
|
-
### Nesting CanvasProvider components
|
|
153
|
-
|
|
154
|
-
It is possible to set a theme for a specific component or set of components within your React tree.
|
|
155
|
-
This is generally discouraged for consistency reasons, but may be required in some contexts (a green
|
|
156
|
-
`Switch` component for example, or changing the direction of a set of components). To do this, you
|
|
157
|
-
can nest CanvasProvider components with a different theme.
|
|
37
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
38
|
+
import {brand, base} from '@workday/canvas-tokens-web';
|
|
39
|
+
import {CanvasProvider} from '@workday/canvas-kit-react/common';
|
|
158
40
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
EmotionCanvasTheme,
|
|
164
|
-
PartialEmotionCanvasTheme,
|
|
165
|
-
ContentDirection,
|
|
166
|
-
} from '@workday/canvas-kit-react/common';
|
|
167
|
-
import {Switch} from '@workday/canvas-kit-react/switch';
|
|
168
|
-
|
|
169
|
-
const rtlTheme: EmotionCanvasTheme = {
|
|
170
|
-
canvas: {
|
|
171
|
-
direction: ContentDirection.RTL,
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const theme: PartialEmotionCanvasTheme = {
|
|
176
|
-
canvas: {
|
|
177
|
-
palette: {
|
|
178
|
-
primary: {
|
|
179
|
-
main: colors.greenApple400,
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
direction: ContentDirection.LTR,
|
|
183
|
-
},
|
|
184
|
-
};
|
|
41
|
+
const themedBrand = createStyles({
|
|
42
|
+
[brand.primary.base]: base.magenta600,
|
|
43
|
+
[brand.primary.dark]: base.magenta700,
|
|
44
|
+
});
|
|
185
45
|
|
|
186
|
-
<CanvasProvider
|
|
187
|
-
<
|
|
188
|
-
<Switch checked={true} />
|
|
189
|
-
{/* Content that should be LTR */}
|
|
190
|
-
</CanvasProvider>
|
|
46
|
+
<CanvasProvider className={themedBrand}>
|
|
47
|
+
<App />
|
|
191
48
|
</CanvasProvider>;
|
|
192
49
|
```
|
|
193
50
|
|
|
194
|
-
|
|
51
|
+
## Bidirectionality (RTL Support)
|
|
195
52
|
|
|
196
|
-
|
|
197
|
-
example of this is an app with many small React trees.
|
|
53
|
+
### Setting RTL Direction
|
|
198
54
|
|
|
199
|
-
|
|
55
|
+
Use the native HTML `dir` attribute to set the text direction. The `CanvasProvider` accepts a `dir`
|
|
56
|
+
prop:
|
|
200
57
|
|
|
201
58
|
```tsx
|
|
202
|
-
|
|
203
|
-
canvas: {
|
|
204
|
-
palette: {
|
|
205
|
-
primary: {
|
|
206
|
-
main: colors.greenApple400,
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
window.workday.canvas.theme = theme;
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
Note if any of the window object hasn't been defined, you will need to change your assignment. For
|
|
216
|
-
example:
|
|
59
|
+
import {CanvasProvider} from '@workday/canvas-kit-react/common';
|
|
217
60
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
theme: theme;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
61
|
+
<CanvasProvider dir="rtl">
|
|
62
|
+
<App />
|
|
63
|
+
</CanvasProvider>;
|
|
224
64
|
```
|
|
225
65
|
|
|
226
|
-
|
|
227
|
-
variable before falling back to the default theme.
|
|
66
|
+
### CSS Logical Properties
|
|
228
67
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
need to access the theme within a function component, use the hook, `useTheme`. If you need to
|
|
233
|
-
access the theme within a `styled` component, a class component, or outside a component, use
|
|
234
|
-
`getTheme`. The main difference is `useTheme` is intended to work within the `CanvasProvider` and
|
|
235
|
-
will check the `ThemeContext` for the theme first. Both functions check the window for the theme and
|
|
236
|
-
fall back to the default theme is nothing is found. Both functions will return a full theme object
|
|
237
|
-
in this shape:
|
|
238
|
-
|
|
239
|
-
**Return value**
|
|
68
|
+
Use
|
|
69
|
+
[CSS logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties)
|
|
70
|
+
for styling. These automatically adapt to the text direction:
|
|
240
71
|
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
},
|
|
247
|
-
breakpoints: {
|
|
248
|
-
// ...
|
|
249
|
-
},
|
|
250
|
-
direction: ContentDirection.LTR,
|
|
251
|
-
},
|
|
252
|
-
// other themes can be placed here
|
|
72
|
+
```css
|
|
73
|
+
/* Use CSS logical properties */
|
|
74
|
+
.my-component {
|
|
75
|
+
margin-inline-start: 1rem; /* Instead of margin-left */
|
|
76
|
+
padding-inline-end: 1rem; /* Instead of padding-right */
|
|
253
77
|
}
|
|
254
78
|
```
|
|
255
79
|
|
|
256
|
-
###
|
|
257
|
-
|
|
258
|
-
`getTheme` is a function that returns the full theme object with the Canvas Kit theme under the
|
|
259
|
-
`canvas` key. It should be used with `styled` components, class components, or outside components.
|
|
260
|
-
|
|
261
|
-
Below is an example of how to use `getTheme` to build responsive media query styles with the
|
|
262
|
-
breakpoint functions provided in the theme.
|
|
263
|
-
|
|
264
|
-
```tsx
|
|
265
|
-
import {getTheme} from '@workday/canvas-kit-react/common';
|
|
266
|
-
|
|
267
|
-
const theme = getTheme();
|
|
268
|
-
const {up, down} = theme.canvas.breakpoints;
|
|
269
|
-
const small = down('m'); // Returns '@media (max-width: 768px)'
|
|
270
|
-
const medium = up('m'); // Returns '@media (min-width: 768px)'
|
|
271
|
-
const styles = {
|
|
272
|
-
[small]: {
|
|
273
|
-
margin: space.m,
|
|
274
|
-
},
|
|
275
|
-
[medium]: {
|
|
276
|
-
margin: space.l,
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
### useTheme
|
|
282
|
-
|
|
283
|
-
`useTheme` is hook to get the full theme object. It should be used only with functional compoents
|
|
284
|
-
wrapped in ContextProvider. Function returns a theme object with the Canvas Kit theme under the
|
|
285
|
-
canvas key.
|
|
286
|
-
|
|
287
|
-
`useTheme` should be used only inside functional component otherwise it will show a warning if the
|
|
288
|
-
theme context value has not been found. In that case you will need to use `getTheme`.
|
|
80
|
+
### Conditional RTL Styles
|
|
289
81
|
|
|
290
|
-
|
|
291
|
-
|
|
82
|
+
For styles that need to change based on direction, use the
|
|
83
|
+
[`:dir()` pseudo-class selector](https://developer.mozilla.org/en-US/docs/Web/CSS/:dir):
|
|
292
84
|
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
<Subtext size="large" color={theme.canvas.palette.error.main}>
|
|
298
|
-
)
|
|
85
|
+
```css
|
|
86
|
+
/* Use :dir() for RTL-specific styles */
|
|
87
|
+
.my-component:dir(rtl) {
|
|
88
|
+
/* RTL-specific styles */
|
|
299
89
|
}
|
|
300
90
|
```
|
|
301
91
|
|
|
302
|
-
### Overwriting the theme
|
|
303
|
-
|
|
304
|
-
You can also use both functions to overwrite the theme object by providing a partial or full theme
|
|
305
|
-
object to overwrite the current theme. In the example below, we're setting a custom content
|
|
306
|
-
direction, which can be passed to either `useTheme` or `getTheme`. These functions will properly
|
|
307
|
-
merge your the partial theme with the default Canvas theme and return a complete theme object.
|
|
308
|
-
|
|
309
92
|
```tsx
|
|
310
|
-
import {
|
|
93
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
311
94
|
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
95
|
+
const styles = createStyles({
|
|
96
|
+
':dir(rtl)': {
|
|
97
|
+
svg: {
|
|
98
|
+
transform: 'rotate(180deg)',
|
|
99
|
+
},
|
|
316
100
|
},
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
// Overwriting the theme with useTheme
|
|
320
|
-
const customTheme = useTheme(customTheme);
|
|
321
|
-
|
|
322
|
-
// Overwriting the theme with getTheme
|
|
323
|
-
const customTheme = getTheme(customTheme);
|
|
101
|
+
});
|
|
324
102
|
```
|
|
325
103
|
|
|
326
104
|
## Breakpoints
|
|
327
105
|
|
|
328
|
-
Breakpoints are used by media queries to conditionally apply or modify styles based on
|
|
329
|
-
width.
|
|
106
|
+
Breakpoints are used by media queries to conditionally apply or modify styles based on viewport
|
|
107
|
+
width.
|
|
330
108
|
|
|
331
109
|
### Values
|
|
332
110
|
|
|
333
|
-
The canvas theme object provides five breakpoint values that correspond to the min-widths of our
|
|
334
|
-
standard screen sizes.
|
|
335
|
-
|
|
336
111
|
| Name | Size (px) |
|
|
337
112
|
| ------ | --------- |
|
|
338
113
|
| `zero` | 0 |
|
|
@@ -341,186 +116,71 @@ standard screen sizes.
|
|
|
341
116
|
| `l` | 1024 |
|
|
342
117
|
| `xl` | 1440 |
|
|
343
118
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
- `small` (320px - 767px) Used for mobile-sized screens
|
|
347
|
-
- `medium` (768px - 1023px) Used for tablet-sized screens
|
|
348
|
-
- `large` - (1024px - 1439px) Used for laptop and small desktop screens
|
|
349
|
-
- `extra-large` (≥1440px) Used for very large screens
|
|
119
|
+
Standard screen size ranges:
|
|
350
120
|
|
|
351
|
-
|
|
121
|
+
- `small` (320px - 767px) - Mobile screens
|
|
122
|
+
- `medium` (768px - 1023px) - Tablet screens
|
|
123
|
+
- `large` (1024px - 1439px) - Laptop/small desktop screens
|
|
124
|
+
- `extra-large` (≥1440px) - Large screens
|
|
352
125
|
|
|
353
|
-
|
|
126
|
+
### Using Breakpoints
|
|
354
127
|
|
|
355
|
-
|
|
356
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
357
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
128
|
+
You can use standard CSS media queries:
|
|
358
129
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
};
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
### Functions
|
|
369
|
-
|
|
370
|
-
There are also several functions to help with generating media queries:
|
|
371
|
-
|
|
372
|
-
- [Up](#Up)
|
|
373
|
-
- [Down](#Down)
|
|
374
|
-
- [Between](#Between)
|
|
375
|
-
- [Only](#Only)
|
|
376
|
-
|
|
377
|
-
#### Up
|
|
378
|
-
|
|
379
|
-
_Returns a media query above the `min-width` for the range of a given breakpoint_
|
|
380
|
-
|
|
381
|
-
Given a `start` breakpoint key ("zero", "s", "m", "l", "xl"), this function returns a media query
|
|
382
|
-
(string) using a `min-width`.
|
|
383
|
-
|
|
384
|
-
```ts
|
|
385
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
386
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
387
|
-
|
|
388
|
-
const theme = useTheme();
|
|
389
|
-
const {up} = theme.canvas.breakpoints;
|
|
390
|
-
const mediaQuery = up('l'); // Returns '@media (min-width: 1024px)'
|
|
391
|
-
const styles = {
|
|
392
|
-
[mediaQuery]: {
|
|
393
|
-
padding: space.m,
|
|
394
|
-
},
|
|
395
|
-
};
|
|
130
|
+
```css
|
|
131
|
+
@media (min-width: 768px) {
|
|
132
|
+
.my-component {
|
|
133
|
+
padding: 1rem;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
396
136
|
```
|
|
397
137
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
_Returns a media query below the `max-width` for the range of a given breakpoint_
|
|
401
|
-
|
|
402
|
-
Given an `end` breakpoint key ("zero", "s", "m", "l", "xl"), this function returns a media query
|
|
403
|
-
(string) using a `max-width`.
|
|
138
|
+
---
|
|
404
139
|
|
|
405
|
-
|
|
406
|
-
> example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
140
|
+
## Deprecated API Reference
|
|
407
141
|
|
|
408
|
-
|
|
409
|
-
`0`, as seen in the second example below.
|
|
142
|
+
The following APIs are deprecated and should not be used in new code.
|
|
410
143
|
|
|
411
|
-
|
|
412
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
413
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
144
|
+
### ~~CanvasProvider theme prop~~ (Deprecated)
|
|
414
145
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
padding: space.m,
|
|
421
|
-
},
|
|
422
|
-
};
|
|
146
|
+
```tsx
|
|
147
|
+
// DEPRECATED - Do not use
|
|
148
|
+
<CanvasProvider theme={{canvas: {palette: {primary: {main: 'purple'}}}}}>
|
|
149
|
+
<App />
|
|
150
|
+
</CanvasProvider>
|
|
423
151
|
```
|
|
424
152
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
```ts
|
|
428
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
429
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
153
|
+
### ~~useTheme / getTheme~~ (Deprecated)
|
|
430
154
|
|
|
155
|
+
```tsx
|
|
156
|
+
// DEPRECATED - Use CSS variables instead
|
|
431
157
|
const theme = useTheme();
|
|
432
|
-
const
|
|
433
|
-
const mediaQuery = down('xl'); // Returns '@media (min-width: 0)'
|
|
434
|
-
const styles = {
|
|
435
|
-
[mediaQuery]: {
|
|
436
|
-
padding: space.m,
|
|
437
|
-
},
|
|
438
|
-
};
|
|
158
|
+
const theme = getTheme();
|
|
439
159
|
```
|
|
440
160
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
_Returns a media query between two given breakpoints_
|
|
161
|
+
### ~~styled~~ (Deprecated)
|
|
444
162
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
> Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions. For
|
|
449
|
-
> example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
450
|
-
|
|
451
|
-
If the `xl` breakpoint is provided, this function returns a media query with only a `min-width`, as
|
|
452
|
-
seen in the second example below.
|
|
453
|
-
|
|
454
|
-
```ts
|
|
455
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
456
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
457
|
-
|
|
458
|
-
const theme = useTheme();
|
|
459
|
-
const {between} = theme.canvas.breakpoints;
|
|
460
|
-
// Returns '@media (min-width: 320px) and (max-width: 1023.5px)'
|
|
461
|
-
const mediaQuery = between('s', 'm');
|
|
462
|
-
const styles = {
|
|
463
|
-
[mediaQuery]: {
|
|
464
|
-
padding: space.s,
|
|
465
|
-
},
|
|
466
|
-
};
|
|
163
|
+
```tsx
|
|
164
|
+
// DEPRECATED - Use createStyles or createStencil instead
|
|
165
|
+
import {styled} from '@workday/canvas-kit-react/common';
|
|
467
166
|
```
|
|
468
167
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
```ts
|
|
472
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
473
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
168
|
+
### ~~ContentDirection~~ (Deprecated)
|
|
474
169
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
const styles = {
|
|
479
|
-
[mediaQuery]: {
|
|
480
|
-
padding: space.s,
|
|
481
|
-
},
|
|
482
|
-
};
|
|
170
|
+
```tsx
|
|
171
|
+
// DEPRECATED - Use :dir() pseudo-class and CSS logical properties instead
|
|
172
|
+
import {ContentDirection} from '@workday/canvas-kit-react/common';
|
|
483
173
|
```
|
|
484
174
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
_Returns a media query with a `min-width` and `max-width` for a given breakpoint_
|
|
175
|
+
### ~~defaultCanvasTheme~~ (Deprecated)
|
|
488
176
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
> Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions.For
|
|
493
|
-
> example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
494
|
-
|
|
495
|
-
If the `xl` breakpoint is provided, this function returns a media query with only a `min-width` of
|
|
496
|
-
`1440px`, as seen in the second example below.
|
|
497
|
-
|
|
498
|
-
```ts
|
|
499
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
500
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
177
|
+
```tsx
|
|
178
|
+
// DEPRECATED - Use defaultBranding instead
|
|
179
|
+
import {defaultCanvasTheme} from '@workday/canvas-kit-react/common';
|
|
501
180
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const mediaQuery = only('s'); // Returns '@media (min-width: 320px) and (max-width: 767.5px)'
|
|
505
|
-
const styles = {
|
|
506
|
-
[mediaQuery]: {
|
|
507
|
-
padding: space.s,
|
|
508
|
-
},
|
|
509
|
-
};
|
|
181
|
+
// NEW - Use defaultBranding
|
|
182
|
+
import {defaultBranding} from '@workday/canvas-kit-react/common';
|
|
510
183
|
```
|
|
511
184
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
```ts
|
|
515
|
-
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
516
|
-
import {space} from '@workday/canvas-kit-react/tokens';
|
|
517
|
-
|
|
518
|
-
const theme = useTheme();
|
|
519
|
-
const {only} = theme.canvas.breakpoints;
|
|
520
|
-
const mediaQuery = only('m', 'xl'); // Returns '@media (min-width: 1440px)'
|
|
521
|
-
const styles = {
|
|
522
|
-
[mediaQuery]: {
|
|
523
|
-
padding: space.s,
|
|
524
|
-
},
|
|
525
|
-
};
|
|
526
|
-
```
|
|
185
|
+
For detailed migration guidance, see our
|
|
186
|
+
[Theming Documentation](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs).
|
|
@@ -11,6 +11,7 @@ export type RecursivePartial<T> = {
|
|
|
11
11
|
* This function will also handle nested properties.
|
|
12
12
|
* @param target A partial object with up to the same shape as the `fallback` object
|
|
13
13
|
* @param fallback A fallback object. If a property to be accessed from the proxy is not available on the target object, the fallback object will be used
|
|
14
|
+
* @deprecated ⚠️ `getObjectProxy` is deprecated. This utility was used for theme object fallbacks. Now that we're shifting to a global theming approach based on CSS variables, this is no longer needed. For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
14
15
|
*/
|
|
15
16
|
export function getObjectProxy<T extends {}>(
|
|
16
17
|
target: RecursivePartial<T> | undefined,
|