@workday/canvas-kit-react 6.0.0-alpha.0-next.26 → 6.0.0-alpha.0-next.27
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/action-bar/lib/ActionBar.tsx +43 -30
- package/common/lib/theming/README.md +189 -25
- package/common/lib/theming/breakpoints.ts +296 -16
- package/common/lib/theming/types.ts +191 -1
- package/dist/commonjs/action-bar/lib/ActionBar.d.ts.map +1 -1
- package/dist/commonjs/action-bar/lib/ActionBar.js +35 -27
- package/dist/commonjs/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/dist/commonjs/common/lib/theming/breakpoints.d.ts +287 -6
- package/dist/commonjs/common/lib/theming/breakpoints.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/breakpoints.js +192 -10
- package/dist/commonjs/common/lib/theming/types.d.ts +191 -1
- package/dist/commonjs/common/lib/theming/types.d.ts.map +1 -1
- package/dist/commonjs/common/lib/utils/components.d.ts +1 -1
- package/dist/commonjs/pagination/lib/Pagination/PageList.d.ts +1 -1
- package/dist/commonjs/pagination/lib/Pagination/Pagination.d.ts +5 -5
- package/dist/commonjs/pagination/lib/Pagination/common/List.d.ts +1 -1
- package/dist/commonjs/pagination/lib/Pagination/common/utils/space.d.ts +28 -28
- package/dist/es6/action-bar/lib/ActionBar.d.ts.map +1 -1
- package/dist/es6/action-bar/lib/ActionBar.js +33 -22
- package/dist/es6/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/dist/es6/common/lib/theming/breakpoints.d.ts +287 -6
- package/dist/es6/common/lib/theming/breakpoints.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/breakpoints.js +192 -10
- package/dist/es6/common/lib/theming/types.d.ts +191 -1
- package/dist/es6/common/lib/theming/types.d.ts.map +1 -1
- package/dist/es6/pagination/lib/Pagination/PageList.d.ts +1 -1
- package/dist/es6/pagination/lib/Pagination/Pagination.d.ts +5 -5
- package/dist/es6/pagination/lib/Pagination/common/List.d.ts +1 -1
- package/dist/es6/pagination/lib/Pagination/common/utils/space.d.ts +28 -28
- package/package.json +5 -5
- package/ts3.5/dist/commonjs/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/ts3.5/dist/commonjs/common/lib/theming/breakpoints.d.ts +287 -6
- package/ts3.5/dist/commonjs/common/lib/theming/types.d.ts +191 -1
- package/ts3.5/dist/commonjs/common/lib/utils/components.d.ts +1 -1
- package/ts3.5/dist/commonjs/pagination/lib/Pagination/PageList.d.ts +1 -1
- package/ts3.5/dist/commonjs/pagination/lib/Pagination/Pagination.d.ts +5 -5
- package/ts3.5/dist/commonjs/pagination/lib/Pagination/common/List.d.ts +1 -1
- package/ts3.5/dist/commonjs/pagination/lib/Pagination/common/utils/space.d.ts +28 -28
- package/ts3.5/dist/es6/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/ts3.5/dist/es6/common/lib/theming/breakpoints.d.ts +287 -6
- package/ts3.5/dist/es6/common/lib/theming/types.d.ts +191 -1
- package/ts3.5/dist/es6/pagination/lib/Pagination/PageList.d.ts +1 -1
- package/ts3.5/dist/es6/pagination/lib/Pagination/Pagination.d.ts +5 -5
- package/ts3.5/dist/es6/pagination/lib/Pagination/common/List.d.ts +1 -1
- package/ts3.5/dist/es6/pagination/lib/Pagination/common/utils/space.d.ts +28 -28
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import styled from '@
|
|
3
|
-
import {colors, commonColors, space} from '@workday/canvas-kit-react/tokens';
|
|
2
|
+
import {styled} from '@workday/canvas-kit-react/common';
|
|
3
|
+
import {colors, commonColors, space, CSSProperties} from '@workday/canvas-kit-react/tokens';
|
|
4
4
|
|
|
5
5
|
export interface ActionBarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
6
|
/**
|
|
@@ -10,45 +10,58 @@ export interface ActionBarProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
10
10
|
fixed?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
function getFixedStyles(fixed = false): CSSProperties {
|
|
14
|
+
return fixed
|
|
15
|
+
? {
|
|
16
|
+
position: 'fixed',
|
|
17
|
+
left: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
right: 0,
|
|
20
|
+
}
|
|
21
|
+
: {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const ActionBarContainer = styled('div')<ActionBarProps>(
|
|
14
25
|
{
|
|
15
26
|
borderTop: `solid 1px ${colors.soap400}`,
|
|
16
27
|
background: commonColors.background,
|
|
17
28
|
padding: space.s,
|
|
18
29
|
boxShadow: '0 -2px 4px rgba(0, 0, 0, 0.08)',
|
|
19
|
-
'@media (max-width: 575px)': {
|
|
20
|
-
padding: space.xxs,
|
|
21
|
-
},
|
|
22
30
|
},
|
|
23
|
-
({fixed}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
31
|
+
({fixed, theme}) => {
|
|
32
|
+
return {
|
|
33
|
+
...getFixedStyles(fixed),
|
|
34
|
+
[theme.canvas.breakpoints.down('s')]: {
|
|
35
|
+
padding: space.xxs,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
30
39
|
);
|
|
31
40
|
|
|
32
|
-
const ChildrenContainer = styled('div')(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
const ChildrenContainer = styled('div')(
|
|
42
|
+
{
|
|
43
|
+
display: 'inline-block',
|
|
44
|
+
padding: `0 ${space.m}`,
|
|
45
|
+
'*:not(:first-of-type)': {
|
|
46
|
+
marginLeft: space.s,
|
|
47
|
+
},
|
|
37
48
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
({theme}) => ({
|
|
50
|
+
[theme.canvas.breakpoints.down('s')]: {
|
|
51
|
+
display: 'flex',
|
|
52
|
+
padding: space.xxs,
|
|
53
|
+
justifyContent: 'center',
|
|
54
|
+
flexDirection: 'row-reverse',
|
|
55
|
+
'> *': {
|
|
56
|
+
flex: 1,
|
|
57
|
+
'&:not(:first-of-type)': {
|
|
58
|
+
marginRight: space.s,
|
|
59
|
+
marginLeft: 0,
|
|
60
|
+
},
|
|
48
61
|
},
|
|
49
62
|
},
|
|
50
|
-
}
|
|
51
|
-
|
|
63
|
+
})
|
|
64
|
+
);
|
|
52
65
|
|
|
53
66
|
export default class ActionBar extends React.Component<ActionBarProps> {
|
|
54
67
|
public render() {
|
|
@@ -90,10 +90,10 @@ export const defaultCanvasTheme: CanvasTheme = {
|
|
|
90
90
|
breakpoints: {
|
|
91
91
|
values: {
|
|
92
92
|
zero: 0,
|
|
93
|
-
s:
|
|
94
|
-
m:
|
|
95
|
-
l:
|
|
96
|
-
xl:
|
|
93
|
+
s: 320,
|
|
94
|
+
m: 768,
|
|
95
|
+
l: 1024,
|
|
96
|
+
xl: 1440,
|
|
97
97
|
},
|
|
98
98
|
up,
|
|
99
99
|
down,
|
|
@@ -243,41 +243,205 @@ variable before falling back to the default theme.
|
|
|
243
243
|
|
|
244
244
|
## Breakpoints
|
|
245
245
|
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
Breakpoints are used by media queries to conditionally apply or modify styles based on the viewport
|
|
247
|
+
width. This allows the UI to be responsive to various screen sizes.
|
|
248
|
+
|
|
249
|
+
### Values
|
|
250
|
+
|
|
251
|
+
The canvas theme object provides five breakpoint values that correspond to the min-widths of our
|
|
252
|
+
standard screen sizes.
|
|
248
253
|
|
|
249
254
|
| Name | Size (px) |
|
|
250
255
|
| ------ | --------- |
|
|
251
256
|
| `zero` | 0 |
|
|
252
|
-
| `s` |
|
|
253
|
-
| `m` |
|
|
254
|
-
| `l` |
|
|
255
|
-
| `xl` |
|
|
257
|
+
| `s` | 320 |
|
|
258
|
+
| `m` | 768 |
|
|
259
|
+
| `l` | 1024 |
|
|
260
|
+
| `xl` | 1440 |
|
|
261
|
+
|
|
262
|
+
And these are our standard screen size ranges:
|
|
263
|
+
|
|
264
|
+
- `small` (320px - 767px) Used for mobile-sized screens
|
|
265
|
+
- `medium` (768px - 1023px) Used for tablet-sized screens
|
|
266
|
+
- `large` - (1024px - 1439px) Used for laptop and small desktop screens
|
|
267
|
+
- `extra-large` (≥1440px) Used for very large screens
|
|
268
|
+
|
|
269
|
+
> Note: Some applications may only require a subset of screen sizes and not use all breakpoints.
|
|
270
|
+
|
|
271
|
+
Our breakpoint system is customized within the theme object. `theme.canvas.breakpoints.values`.
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
275
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
276
|
+
|
|
277
|
+
const {theme} = useTheme();
|
|
278
|
+
const {values} = theme.canvas.breakpoints;
|
|
279
|
+
const styles = {
|
|
280
|
+
[`@media (min-width: ${values.m}px)`]: {
|
|
281
|
+
padding: space.s,
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Functions
|
|
256
287
|
|
|
257
288
|
There are also several functions to help with generating media queries:
|
|
258
289
|
|
|
259
|
-
|
|
290
|
+
- [Up](#Up)
|
|
291
|
+
- [Down](#Down)
|
|
292
|
+
- [Between](#Between)
|
|
293
|
+
- [Only](#Only)
|
|
260
294
|
|
|
261
|
-
|
|
262
|
-
> BreakpointKey.m) or the string (e.g. 'm'). Example: theme.breakpoints.up(BreakpointKey.m) =>
|
|
263
|
-
> '@media (min-width:960px)'
|
|
295
|
+
#### Up
|
|
264
296
|
|
|
265
|
-
|
|
297
|
+
_Returns a media query above the `min-width` for the range of a given breakpoint_
|
|
266
298
|
|
|
267
|
-
|
|
268
|
-
|
|
299
|
+
Given a `start` breakpoint key ("zero", "s", "m", "l", "xl"), this function returns a media query
|
|
300
|
+
(string) using a `min-width`.
|
|
269
301
|
|
|
270
|
-
|
|
302
|
+
```ts
|
|
303
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
304
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
305
|
+
|
|
306
|
+
const theme = useTheme();
|
|
307
|
+
const {up} = theme.canvas.breakpoints;
|
|
308
|
+
const mediaQuery = up('l'); // Returns '@media (min-width: 1024px)'
|
|
309
|
+
const styles = {
|
|
310
|
+
[mediaQuery]: {
|
|
311
|
+
padding: space.m,
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
```
|
|
271
315
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
316
|
+
#### Down
|
|
317
|
+
|
|
318
|
+
_Returns a media query below the `max-width` for the range of a given breakpoint_
|
|
319
|
+
|
|
320
|
+
Given an `end` breakpoint key ("zero", "s", "m", "l", "xl"), this function returns a media query
|
|
321
|
+
(string) using a `max-width`.
|
|
322
|
+
|
|
323
|
+
> Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions. For
|
|
324
|
+
> example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
325
|
+
|
|
326
|
+
If the `xl` breakpoint is provided, this function returns a media query with only a `min-width` of
|
|
327
|
+
`0`, as seen in the second example below.
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
331
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
332
|
+
|
|
333
|
+
const theme = useTheme();
|
|
334
|
+
const {down} = theme.canvas.breakpoints;
|
|
335
|
+
const mediaQuery = down('m'); // Returns '@media (max-width: 1023.5px)'
|
|
336
|
+
const styles = {
|
|
337
|
+
[mediaQuery]: {
|
|
338
|
+
padding: space.m,
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
This example uses the `xl` breakpoint and only adds a `min-width` of `0` to the media query.
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
347
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
348
|
+
|
|
349
|
+
const theme = useTheme();
|
|
350
|
+
const {down} = theme.canvas.breakpoints;
|
|
351
|
+
const mediaQuery = down('xl'); // Returns '@media (min-width: 0)'
|
|
352
|
+
const styles = {
|
|
353
|
+
[mediaQuery]: {
|
|
354
|
+
padding: space.m,
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
```
|
|
275
358
|
|
|
276
|
-
####
|
|
359
|
+
#### Between
|
|
277
360
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
361
|
+
_Returns a media query between two given breakpoints_
|
|
362
|
+
|
|
363
|
+
Given `start` and `end` breakpoint keys ("zero", "s", "m", "l", "xl"), this function returns a media
|
|
364
|
+
query (string) using a min-width and max-width.
|
|
365
|
+
|
|
366
|
+
> Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions. For
|
|
367
|
+
> example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
368
|
+
|
|
369
|
+
If the `xl` breakpoint is provided, this function returns a media query with only a `min-width`, as
|
|
370
|
+
seen in the second example below.
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
374
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
375
|
+
|
|
376
|
+
const theme = useTheme();
|
|
377
|
+
const {between} = theme.canvas.breakpoints;
|
|
378
|
+
// Returns '@media (min-width: 320px) and (max-width: 1023.5px)'
|
|
379
|
+
const mediaQuery = between('s', 'm');
|
|
380
|
+
const styles = {
|
|
381
|
+
[mediaQuery]: {
|
|
382
|
+
padding: space.s,
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
This example uses `xl` as the `end` breakpoint and only adds a min-width to the media query.
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
391
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
392
|
+
|
|
393
|
+
const theme = useTheme();
|
|
394
|
+
const {between} = theme.canvas.breakpoints;
|
|
395
|
+
const mediaQuery = between('m', 'xl'); // Returns '@media (min-width: 768px)'
|
|
396
|
+
const styles = {
|
|
397
|
+
[mediaQuery]: {
|
|
398
|
+
padding: space.s,
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
#### Only
|
|
404
|
+
|
|
405
|
+
_Returns a media query with a `min-width` and `max-width` for a given breakpoint_
|
|
406
|
+
|
|
407
|
+
Given a breakpoint key ("zero", "s", "m", "l", "xl"), this function returns a media query (string)
|
|
408
|
+
using a `min-width` and `max-width`.
|
|
409
|
+
|
|
410
|
+
> Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions.For
|
|
411
|
+
> example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
412
|
+
|
|
413
|
+
If the `xl` breakpoint is provided, this function returns a media query with only a `min-width` of
|
|
414
|
+
`1440px`, as seen in the second example below.
|
|
415
|
+
|
|
416
|
+
```ts
|
|
417
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
418
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
419
|
+
|
|
420
|
+
const theme = useTheme();
|
|
421
|
+
const {only} = theme.canvas.breakpoints;
|
|
422
|
+
const mediaQuery = only('s'); // Returns '@media (min-width: 320px) and (max-width: 767.5px)'
|
|
423
|
+
const styles = {
|
|
424
|
+
[mediaQuery]: {
|
|
425
|
+
padding: space.s,
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
This example uses the `xl` breakpoint and only adds a `min-width` of `1440px` to the media query.
|
|
431
|
+
|
|
432
|
+
```ts
|
|
433
|
+
import {useTheme} from '@workday/canvas-kit-react/common';
|
|
434
|
+
import {space} from '@workday/canvas-kit-react/tokens';
|
|
435
|
+
|
|
436
|
+
const theme = useTheme();
|
|
437
|
+
const {only} = theme.canvas.breakpoints;
|
|
438
|
+
const mediaQuery = only('m', 'xl'); // Returns '@media (min-width: 1440px)'
|
|
439
|
+
const styles = {
|
|
440
|
+
[mediaQuery]: {
|
|
441
|
+
padding: space.s,
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
```
|
|
281
445
|
|
|
282
446
|
## useIsRTL Hook
|
|
283
447
|
|
|
@@ -9,43 +9,278 @@ export enum BreakpointKey {
|
|
|
9
9
|
export type BreakpointFnParam = BreakpointKey | keyof typeof BreakpointKey;
|
|
10
10
|
|
|
11
11
|
export type CanvasBreakpoints = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/**
|
|
13
|
+
* ### Zero Breakpoint
|
|
14
|
+
*
|
|
15
|
+
* This breakpoint is useful when you need to set a media query `min-width` below small.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
20
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
21
|
+
*
|
|
22
|
+
* const theme = useTheme();
|
|
23
|
+
* const { values } = theme.canvas.breakpoints;
|
|
24
|
+
* const styles = {
|
|
25
|
+
* [`@media (min-width: ${values.zero}px)`]: {
|
|
26
|
+
* padding: space.xxs,
|
|
27
|
+
* },
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
zero: 0;
|
|
32
|
+
/**
|
|
33
|
+
* ### Small Breakpoint
|
|
34
|
+
*
|
|
35
|
+
* The small breakpoint provides the `min-width` for mobile devices, such as phones and tablets.
|
|
36
|
+
* This size ranges from a min-width of 320px to a max-width of 767px.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
41
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
42
|
+
*
|
|
43
|
+
* const theme = useTheme();
|
|
44
|
+
* const { values } = theme.canvas.breakpoints;
|
|
45
|
+
* const styles = {
|
|
46
|
+
* [`@media (min-width: ${values.s}px)`]: {
|
|
47
|
+
* padding: space.xs,
|
|
48
|
+
* },
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
s: 320;
|
|
53
|
+
/**
|
|
54
|
+
* ### Medium Breakpoint
|
|
55
|
+
*
|
|
56
|
+
* The medium breakpoint is the min-width for intended for medium screens, such as laptops.
|
|
57
|
+
* This size ranges from a min-width of 768px to a max-width of 1023px.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
62
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
63
|
+
*
|
|
64
|
+
* const theme = useTheme();
|
|
65
|
+
* const { values } = theme.canvas.breakpoints;
|
|
66
|
+
* const styles = {
|
|
67
|
+
* [`@media (min-width: ${values.m}px)`]: {
|
|
68
|
+
* padding: space.s,
|
|
69
|
+
* },
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
m: 768;
|
|
74
|
+
/**
|
|
75
|
+
* ### Large Breakpoint
|
|
76
|
+
*
|
|
77
|
+
* The large breakpoint is the min-width for intended for large screens, such as desktops.
|
|
78
|
+
* This size ranges from a min-width of 1024px to a max-width of 1439px.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
83
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
84
|
+
*
|
|
85
|
+
* const theme = useTheme();
|
|
86
|
+
* const { values } = theme.canvas.breakpoints;
|
|
87
|
+
* const styles = {
|
|
88
|
+
* [`@media (min-width: ${values.m}px)`]: {
|
|
89
|
+
* padding: space.s,
|
|
90
|
+
* },
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
l: 1024;
|
|
95
|
+
/**
|
|
96
|
+
* ### Extra-Large Breakpoint
|
|
97
|
+
*
|
|
98
|
+
* The large breakpoint is the min-width for intended for extra-large screens, such as wide monitors and TVs.
|
|
99
|
+
* This size has a min-width of 1440px and no max-width.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
104
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
105
|
+
*
|
|
106
|
+
* const theme = useTheme();
|
|
107
|
+
* const { values } = theme.canvas.breakpoints;
|
|
108
|
+
* const styles = {
|
|
109
|
+
* [`@media (min-width: ${values.m}px)`]: {
|
|
110
|
+
* padding: space.s
|
|
111
|
+
* },
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
xl: 1440;
|
|
17
116
|
};
|
|
18
117
|
|
|
19
118
|
export const breakpointKeys = ['zero', 's', 'm', 'l', 'xl'] as const;
|
|
20
119
|
|
|
120
|
+
/**
|
|
121
|
+
* ### Theme Breakpoint Values
|
|
122
|
+
*
|
|
123
|
+
* Breakpoints are used by media queries to conditionally apply or modify styles based on the viewport width.
|
|
124
|
+
* This allows the UI to be responsive to various screen sizes. This object provides five breakpoint values
|
|
125
|
+
* that correspond to the min-widths of our standard screen sizes.
|
|
126
|
+
*
|
|
127
|
+
* - `zero`: 0
|
|
128
|
+
* - `s`: 320
|
|
129
|
+
* - `m`: 768
|
|
130
|
+
* - `l`: 1024
|
|
131
|
+
* - `xl`: 1440
|
|
132
|
+
*
|
|
133
|
+
* And these are our standard screen size ranges:
|
|
134
|
+
*
|
|
135
|
+
* - `small` (320px - 767px) Used for mobile-sized screens
|
|
136
|
+
* - `medium` (768px - 1023px) Used for tablet-sized screens
|
|
137
|
+
* - `large` - (1024px - 1439px) Used for laptop and small desktop screens
|
|
138
|
+
* - `extra-large` (≥1440px) Used for very large screens
|
|
139
|
+
*
|
|
140
|
+
* Note: Some applications may only require a subset of screen sizes and not use all breakpoints.
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
21
143
|
export const breakpoints: CanvasBreakpoints = {
|
|
22
144
|
zero: 0,
|
|
23
|
-
s:
|
|
24
|
-
m:
|
|
25
|
-
l:
|
|
26
|
-
xl:
|
|
145
|
+
s: 320,
|
|
146
|
+
m: 768,
|
|
147
|
+
l: 1024,
|
|
148
|
+
xl: 1440,
|
|
27
149
|
};
|
|
28
150
|
|
|
29
151
|
const step = 0.5;
|
|
30
152
|
|
|
153
|
+
/**
|
|
154
|
+
* ### Up
|
|
155
|
+
*
|
|
156
|
+
* _Returns a media query above the `min-width` for the range of a given breakpoint_
|
|
157
|
+
*
|
|
158
|
+
* Given a `start` breakpoint key ("zero", "s", "m", "l", "xl"),
|
|
159
|
+
* this function returns a media query (string) using a `min-width`.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
164
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
165
|
+
*
|
|
166
|
+
* const theme = useTheme();
|
|
167
|
+
* const { up } = theme.canvas.breakpoints;
|
|
168
|
+
* const mediaQuery = up('l'); // Returns '@media (min-width: 1024px)'
|
|
169
|
+
* const styles = {
|
|
170
|
+
* [mediaQuery]: {
|
|
171
|
+
* padding: space.m,
|
|
172
|
+
* }
|
|
173
|
+
* };
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
31
176
|
export function up(key: BreakpointFnParam) {
|
|
32
177
|
const value = typeof breakpoints[key as BreakpointKey] === 'number' ? breakpoints[key] : key;
|
|
33
|
-
return `@media (min-width
|
|
178
|
+
return `@media (min-width: ${value}px)`;
|
|
34
179
|
}
|
|
35
180
|
|
|
36
|
-
|
|
37
|
-
|
|
181
|
+
/**
|
|
182
|
+
* ### Down
|
|
183
|
+
*
|
|
184
|
+
* _Returns a media query below the `max-width` for the range of a given breakpoint_
|
|
185
|
+
*
|
|
186
|
+
* Given an `end` breakpoint key ("zero", "s", "m", "l", "xl"),
|
|
187
|
+
* this function returns a media query (string) using a `max-width`.
|
|
188
|
+
*
|
|
189
|
+
* Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions.
|
|
190
|
+
* For example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
191
|
+
*
|
|
192
|
+
* If the `xl` breakpoint is provided, this function returns a media query with only a `min-width` of `0`,
|
|
193
|
+
* as seen in the second example below.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
198
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
199
|
+
*
|
|
200
|
+
* const theme = useTheme();
|
|
201
|
+
* const { down } = theme.canvas.breakpoints;
|
|
202
|
+
* const mediaQuery = down('m'); // Returns '@media (max-width: 1023.5px)'
|
|
203
|
+
* const styles = {
|
|
204
|
+
* [mediaQuery]: {
|
|
205
|
+
* padding: space.m,
|
|
206
|
+
* }
|
|
207
|
+
* };
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* This example uses the `xl` breakpoint and only adds a `min-width` of `0` to the media query.
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
214
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
215
|
+
*
|
|
216
|
+
* const theme = useTheme();
|
|
217
|
+
* const { down } = theme.canvas.breakpoints;
|
|
218
|
+
* const mediaQuery = down('xl'); // Returns '@media (min-width: 0)'
|
|
219
|
+
* const styles = {
|
|
220
|
+
* [mediaQuery]: {
|
|
221
|
+
* padding: space.m,
|
|
222
|
+
* }
|
|
223
|
+
* };
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export function down(endKey: BreakpointFnParam) {
|
|
227
|
+
const endIndex = breakpointKeys.indexOf(endKey as BreakpointKey) + 1;
|
|
38
228
|
const upperbound = breakpoints[breakpointKeys[endIndex]];
|
|
39
|
-
|
|
40
229
|
if (endIndex === breakpointKeys.length) {
|
|
41
230
|
// xl down applies to all sizes
|
|
42
231
|
return up(BreakpointKey.zero);
|
|
43
232
|
}
|
|
44
233
|
|
|
45
234
|
const value = typeof upperbound === 'number' && endIndex > 0 ? upperbound : 0;
|
|
46
|
-
return `@media (max-width
|
|
235
|
+
return `@media (max-width: ${value - step}px)`;
|
|
47
236
|
}
|
|
48
237
|
|
|
238
|
+
/**
|
|
239
|
+
* ### Between
|
|
240
|
+
*
|
|
241
|
+
* _Returns a media query between two given breakpoints_
|
|
242
|
+
*
|
|
243
|
+
* Given `start` and `end` breakpoint keys ("zero", "s", "m", "l", "xl"),
|
|
244
|
+
* this function returns a media query (string) using a min-width and max-width.
|
|
245
|
+
*
|
|
246
|
+
* Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions.
|
|
247
|
+
* For example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
248
|
+
*
|
|
249
|
+
* If the `xl` breakpoint is provided, this function returns a media query with only a `min-width`,
|
|
250
|
+
* as seen in the second example below.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
255
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
256
|
+
*
|
|
257
|
+
* const theme = useTheme();
|
|
258
|
+
* const { between } = theme.canvas.breakpoints;
|
|
259
|
+
* // Returns '@media (min-width: 320px) and (max-width: 1023.5px)'
|
|
260
|
+
* const mediaQuery = between('s', 'm');
|
|
261
|
+
* const styles = {
|
|
262
|
+
* [mediaQuery]: {
|
|
263
|
+
* padding: space.s,
|
|
264
|
+
* }
|
|
265
|
+
* };
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* This example uses `xl` as the `end` breakpoint and only adds a min-width to the media query.
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
272
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
273
|
+
*
|
|
274
|
+
* const theme = useTheme();
|
|
275
|
+
* const { between } = theme.canvas.breakpoints;
|
|
276
|
+
* const mediaQuery = between('m', 'xl'); // Returns '@media (min-width: 768px)'
|
|
277
|
+
* const styles = {
|
|
278
|
+
* [mediaQuery]: {
|
|
279
|
+
* padding: space.s,
|
|
280
|
+
* }
|
|
281
|
+
* };
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
49
284
|
export function between(start: BreakpointFnParam, end: BreakpointFnParam) {
|
|
50
285
|
const endIndex = breakpointKeys.indexOf(end) + 1;
|
|
51
286
|
|
|
@@ -54,11 +289,56 @@ export function between(start: BreakpointFnParam, end: BreakpointFnParam) {
|
|
|
54
289
|
}
|
|
55
290
|
|
|
56
291
|
return (
|
|
57
|
-
`@media (min-width
|
|
58
|
-
`(max-width
|
|
292
|
+
`@media (min-width: ${breakpoints[start]}px) and ` +
|
|
293
|
+
`(max-width: ${breakpoints[breakpointKeys[endIndex]] - step}px)`
|
|
59
294
|
);
|
|
60
295
|
}
|
|
61
296
|
|
|
297
|
+
/**
|
|
298
|
+
* ### Only
|
|
299
|
+
*
|
|
300
|
+
* _Returns a media query with a `min-width` and `max-width` for a given breakpoint_
|
|
301
|
+
*
|
|
302
|
+
* Given a breakpoint key ("zero", "s", "m", "l", "xl"),
|
|
303
|
+
* this function returns a media query (string) using a `min-width` and `max-width`.
|
|
304
|
+
*
|
|
305
|
+
* Note: This function subtracts `0.5px` from the next breakpoint value to prevent collisions.
|
|
306
|
+
* For example, `breakpoints.values.s`, has a `min-width` of `320px`, and the `max-width` is `767.5px`).
|
|
307
|
+
*
|
|
308
|
+
* If the `xl` breakpoint is provided, this function returns a media query with only a `min-width` of `1440px`,
|
|
309
|
+
* as seen in the second example below.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
314
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
315
|
+
*
|
|
316
|
+
* const theme = useTheme();
|
|
317
|
+
* const { only } = theme.canvas.breakpoints;
|
|
318
|
+
* const mediaQuery = only('s'); // Returns '@media (min-width: 320px) and (max-width: 767.5px)'
|
|
319
|
+
* const styles = {
|
|
320
|
+
* [mediaQuery]: {
|
|
321
|
+
* padding: space.s,
|
|
322
|
+
* }
|
|
323
|
+
* };
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* This example uses the `xl` breakpoint and only adds a `min-width` of `1440px` to the media query.
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* import { useTheme } from '@workday/canvas-kit-react/common';
|
|
330
|
+
* import { space } from '@workday/canvas-kit-react/tokens';
|
|
331
|
+
*
|
|
332
|
+
* const theme = useTheme();
|
|
333
|
+
* const { only } = theme.canvas.breakpoints;
|
|
334
|
+
* const mediaQuery = only('xl'); // Returns '@media (min-width: 1440px)'
|
|
335
|
+
* const styles = {
|
|
336
|
+
* [mediaQuery]: {
|
|
337
|
+
* padding: space.s,
|
|
338
|
+
* }
|
|
339
|
+
* };
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
62
342
|
export function only(key: BreakpointFnParam) {
|
|
63
343
|
return between(key, key);
|
|
64
344
|
}
|