@workday/canvas-kit-react 6.0.0-alpha.0-next.22 → 6.0.0-alpha.0-next.28
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/button/lib/PrimaryButton.tsx +110 -32
- package/button/lib/parts/ButtonContainer.tsx +16 -5
- package/button/lib/parts/ButtonLabelIcon.tsx +34 -14
- package/button/lib/types.ts +10 -0
- package/common/lib/styles/accessibleHide.ts +2 -2
- 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/PrimaryButton.d.ts +80 -6
- package/dist/commonjs/button/lib/PrimaryButton.d.ts.map +1 -1
- package/dist/commonjs/button/lib/PrimaryButton.js +80 -26
- package/dist/commonjs/button/lib/parts/ButtonContainer.d.ts +5 -3
- package/dist/commonjs/button/lib/parts/ButtonContainer.d.ts.map +1 -1
- package/dist/commonjs/button/lib/parts/ButtonContainer.js +11 -9
- package/dist/commonjs/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/dist/commonjs/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
- package/dist/commonjs/button/lib/parts/ButtonLabelIcon.d.ts.map +1 -1
- package/dist/commonjs/button/lib/parts/ButtonLabelIcon.js +28 -13
- package/dist/commonjs/button/lib/types.d.ts +8 -0
- package/dist/commonjs/button/lib/types.d.ts.map +1 -1
- package/dist/commonjs/common/lib/styles/accessibleHide.d.ts +2 -2
- package/dist/commonjs/common/lib/styles/accessibleHide.d.ts.map +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/commonjs/tokens/index.d.ts +3 -20
- package/dist/commonjs/tokens/index.d.ts.map +1 -1
- package/dist/commonjs/tokens/index.js +3 -6
- package/dist/commonjs/tokens/lib/depth.d.ts +109 -3
- package/dist/commonjs/tokens/lib/depth.d.ts.map +1 -1
- package/dist/commonjs/tokens/lib/depth.js +40 -5
- 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/PrimaryButton.d.ts +80 -6
- package/dist/es6/button/lib/PrimaryButton.d.ts.map +1 -1
- package/dist/es6/button/lib/PrimaryButton.js +81 -27
- package/dist/es6/button/lib/parts/ButtonContainer.d.ts +5 -3
- package/dist/es6/button/lib/parts/ButtonContainer.d.ts.map +1 -1
- package/dist/es6/button/lib/parts/ButtonContainer.js +11 -9
- package/dist/es6/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/dist/es6/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
- package/dist/es6/button/lib/parts/ButtonLabelIcon.d.ts.map +1 -1
- package/dist/es6/button/lib/parts/ButtonLabelIcon.js +28 -13
- package/dist/es6/button/lib/types.d.ts +8 -0
- package/dist/es6/button/lib/types.d.ts.map +1 -1
- package/dist/es6/common/lib/styles/accessibleHide.d.ts +2 -2
- package/dist/es6/common/lib/styles/accessibleHide.d.ts.map +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/dist/es6/tokens/index.d.ts +3 -20
- package/dist/es6/tokens/index.d.ts.map +1 -1
- package/dist/es6/tokens/index.js +1 -1
- package/dist/es6/tokens/lib/depth.d.ts +109 -3
- package/dist/es6/tokens/lib/depth.d.ts.map +1 -1
- package/dist/es6/tokens/lib/depth.js +40 -2
- package/package.json +5 -6
- package/tokens/README.md +5 -12
- package/tokens/index.ts +2 -2
- package/tokens/lib/depth.ts +125 -3
- package/ts3.5/dist/commonjs/button/lib/PrimaryButton.d.ts +80 -6
- package/ts3.5/dist/commonjs/button/lib/parts/ButtonContainer.d.ts +5 -3
- package/ts3.5/dist/commonjs/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/ts3.5/dist/commonjs/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
- package/ts3.5/dist/commonjs/button/lib/types.d.ts +8 -0
- package/ts3.5/dist/commonjs/common/lib/styles/accessibleHide.d.ts +2 -2
- 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/commonjs/tokens/index.d.ts +3 -20
- package/ts3.5/dist/commonjs/tokens/lib/depth.d.ts +109 -3
- package/ts3.5/dist/es6/button/lib/PrimaryButton.d.ts +80 -6
- package/ts3.5/dist/es6/button/lib/parts/ButtonContainer.d.ts +5 -3
- package/ts3.5/dist/es6/button/lib/parts/ButtonLabel.d.ts +1 -1
- package/ts3.5/dist/es6/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
- package/ts3.5/dist/es6/button/lib/types.d.ts +8 -0
- package/ts3.5/dist/es6/common/lib/styles/accessibleHide.d.ts +2 -2
- 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
- package/ts3.5/dist/es6/tokens/index.d.ts +3 -20
- package/ts3.5/dist/es6/tokens/lib/depth.d.ts +109 -3
|
@@ -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() {
|
|
@@ -6,17 +6,27 @@ import {
|
|
|
6
6
|
Themeable,
|
|
7
7
|
EmotionCanvasTheme,
|
|
8
8
|
createComponent,
|
|
9
|
+
focusRing,
|
|
9
10
|
} from '@workday/canvas-kit-react/common';
|
|
11
|
+
import {colors} from '@workday/canvas-kit-react/tokens';
|
|
10
12
|
import {CanvasSystemIcon} from '@workday/design-assets-types';
|
|
11
|
-
|
|
13
|
+
|
|
12
14
|
import {ButtonContainer, ButtonLabel, ButtonLabelData, ButtonLabelIcon} from './parts';
|
|
15
|
+
import {ButtonSizes, IconPositions} from './types';
|
|
13
16
|
|
|
14
17
|
export interface PrimaryButtonProps extends Themeable, GrowthBehavior {
|
|
15
18
|
/**
|
|
16
|
-
* The
|
|
19
|
+
* The variant of the PrimaryButton.
|
|
20
|
+
* @default undefined
|
|
21
|
+
*/
|
|
22
|
+
variant?: 'inverse';
|
|
23
|
+
/**
|
|
24
|
+
* There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
|
|
25
|
+
* If no size is provided, it will default to `medium`.
|
|
26
|
+
*
|
|
17
27
|
* @default 'medium'
|
|
18
28
|
*/
|
|
19
|
-
size?:
|
|
29
|
+
size?: ButtonSizes;
|
|
20
30
|
/**
|
|
21
31
|
* The data label of the Button.
|
|
22
32
|
* Note: not displayed at `small` size
|
|
@@ -28,10 +38,11 @@ export interface PrimaryButtonProps extends Themeable, GrowthBehavior {
|
|
|
28
38
|
*/
|
|
29
39
|
icon?: CanvasSystemIcon;
|
|
30
40
|
/**
|
|
31
|
-
*
|
|
41
|
+
* Button icon positions can either be `left` or `right`.
|
|
42
|
+
* If no value is provided, it defaults to `left`.
|
|
32
43
|
* @default 'left'
|
|
33
44
|
*/
|
|
34
|
-
iconPosition?:
|
|
45
|
+
iconPosition?: IconPositions;
|
|
35
46
|
/**
|
|
36
47
|
* If set to `true`, transform the icon's x-axis to mirror the graphic
|
|
37
48
|
* @default false
|
|
@@ -40,6 +51,16 @@ export interface PrimaryButtonProps extends Themeable, GrowthBehavior {
|
|
|
40
51
|
children?: React.ReactNode;
|
|
41
52
|
}
|
|
42
53
|
|
|
54
|
+
// Button sizes where data labels are enabled
|
|
55
|
+
const dataLabelSizes = ['medium', 'large'];
|
|
56
|
+
// All disabled buttons are set to 40% opacity.
|
|
57
|
+
// This will eventually live in the ButtonContainer styles, but for now we're scoping it to Primary, Secondary, and Tertiary buttons.
|
|
58
|
+
const disabledButtonOpacity = {
|
|
59
|
+
'&:disabled, &:disabled:active': {
|
|
60
|
+
opacity: 0.4,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
43
64
|
export const PrimaryButton = createComponent('button')({
|
|
44
65
|
displayName: 'PrimaryButton',
|
|
45
66
|
Component: (
|
|
@@ -49,6 +70,7 @@ export const PrimaryButton = createComponent('button')({
|
|
|
49
70
|
theme = useTheme(),
|
|
50
71
|
size = 'medium',
|
|
51
72
|
iconPosition = 'left',
|
|
73
|
+
variant,
|
|
52
74
|
dataLabel,
|
|
53
75
|
icon,
|
|
54
76
|
shouldMirrorIcon = false,
|
|
@@ -61,11 +83,12 @@ export const PrimaryButton = createComponent('button')({
|
|
|
61
83
|
<ButtonContainer
|
|
62
84
|
ref={ref}
|
|
63
85
|
as={Element}
|
|
64
|
-
colors={getPrimaryButtonColors(theme)}
|
|
86
|
+
colors={getPrimaryButtonColors(variant, theme)}
|
|
65
87
|
size={size}
|
|
88
|
+
extraStyles={disabledButtonOpacity}
|
|
66
89
|
{...elemProps}
|
|
67
90
|
>
|
|
68
|
-
{icon &&
|
|
91
|
+
{icon && iconPosition === 'left' && (
|
|
69
92
|
<ButtonLabelIcon
|
|
70
93
|
size={size}
|
|
71
94
|
iconPosition={iconPosition}
|
|
@@ -74,8 +97,8 @@ export const PrimaryButton = createComponent('button')({
|
|
|
74
97
|
/>
|
|
75
98
|
)}
|
|
76
99
|
<ButtonLabel>{children}</ButtonLabel>
|
|
77
|
-
{dataLabel && size
|
|
78
|
-
{icon &&
|
|
100
|
+
{dataLabel && dataLabelSizes.includes(size) && <ButtonLabelData>{dataLabel}</ButtonLabelData>}
|
|
101
|
+
{icon && iconPosition === 'right' && (
|
|
79
102
|
<ButtonLabelIcon
|
|
80
103
|
size={size}
|
|
81
104
|
iconPosition={iconPosition}
|
|
@@ -87,26 +110,81 @@ export const PrimaryButton = createComponent('button')({
|
|
|
87
110
|
),
|
|
88
111
|
});
|
|
89
112
|
|
|
90
|
-
export const getPrimaryButtonColors = (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
export const getPrimaryButtonColors = (
|
|
114
|
+
variant: 'inverse' | undefined,
|
|
115
|
+
theme: EmotionCanvasTheme
|
|
116
|
+
) => {
|
|
117
|
+
const {
|
|
118
|
+
canvas: {
|
|
119
|
+
palette: {primary: themePrimary},
|
|
120
|
+
},
|
|
121
|
+
} = theme;
|
|
122
|
+
|
|
123
|
+
switch (variant) {
|
|
124
|
+
case undefined:
|
|
125
|
+
default:
|
|
126
|
+
return {
|
|
127
|
+
default: {
|
|
128
|
+
background: themePrimary.main,
|
|
129
|
+
icon: themePrimary.contrast,
|
|
130
|
+
label: themePrimary.contrast,
|
|
131
|
+
},
|
|
132
|
+
hover: {
|
|
133
|
+
background: themePrimary.dark,
|
|
134
|
+
},
|
|
135
|
+
active: {
|
|
136
|
+
background: themePrimary.darkest,
|
|
137
|
+
},
|
|
138
|
+
focus: {
|
|
139
|
+
background: themePrimary.main,
|
|
140
|
+
},
|
|
141
|
+
disabled: {
|
|
142
|
+
background: themePrimary.main,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
case 'inverse':
|
|
147
|
+
return {
|
|
148
|
+
default: {
|
|
149
|
+
background: colors.frenchVanilla100,
|
|
150
|
+
icon: colors.blackPepper400,
|
|
151
|
+
label: colors.blackPepper400,
|
|
152
|
+
labelData: colors.blackPepper400,
|
|
153
|
+
},
|
|
154
|
+
hover: {
|
|
155
|
+
background: colors.soap300,
|
|
156
|
+
icon: colors.blackPepper500,
|
|
157
|
+
label: colors.blackPepper500,
|
|
158
|
+
labelData: colors.blackPepper500,
|
|
159
|
+
},
|
|
160
|
+
active: {
|
|
161
|
+
background: colors.soap300,
|
|
162
|
+
icon: colors.blackPepper500,
|
|
163
|
+
label: colors.blackPepper500,
|
|
164
|
+
labelData: colors.blackPepper500,
|
|
165
|
+
},
|
|
166
|
+
focus: {
|
|
167
|
+
background: colors.frenchVanilla100,
|
|
168
|
+
border: colors.blackPepper400,
|
|
169
|
+
icon: colors.blackPepper400,
|
|
170
|
+
label: colors.blackPepper400,
|
|
171
|
+
labelData: colors.blackPepper400,
|
|
172
|
+
focusRing: focusRing(
|
|
173
|
+
{
|
|
174
|
+
separation: 1,
|
|
175
|
+
innerColor: colors.blackPepper500,
|
|
176
|
+
outerColor: colors.frenchVanilla100,
|
|
177
|
+
},
|
|
178
|
+
theme
|
|
179
|
+
),
|
|
180
|
+
},
|
|
181
|
+
// Identical to inverse 'default' styles. ButtonContainer will set opacity to 40%
|
|
182
|
+
disabled: {
|
|
183
|
+
background: colors.frenchVanilla100,
|
|
184
|
+
icon: colors.blackPepper400,
|
|
185
|
+
label: colors.blackPepper400,
|
|
186
|
+
labelData: colors.blackPepper400,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
EmotionCanvasTheme,
|
|
11
11
|
StyledType,
|
|
12
12
|
} from '@workday/canvas-kit-react/common';
|
|
13
|
-
import {ButtonColors} from '../types';
|
|
13
|
+
import {ButtonColors, ButtonSizes} from '../types';
|
|
14
14
|
import {buttonLabelDataClassName} from './ButtonLabelData';
|
|
15
15
|
|
|
16
16
|
export interface ButtonContainerProps
|
|
@@ -18,10 +18,12 @@ export interface ButtonContainerProps
|
|
|
18
18
|
GrowthBehavior {
|
|
19
19
|
colors?: ButtonColors;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
|
|
22
|
+
* If no size is provided, it will default to `medium`.
|
|
23
|
+
*
|
|
22
24
|
* @default 'medium'
|
|
23
25
|
*/
|
|
24
|
-
size?:
|
|
26
|
+
size?: ButtonSizes;
|
|
25
27
|
/**
|
|
26
28
|
* The ref to the button that the styled component renders.
|
|
27
29
|
*/
|
|
@@ -110,12 +112,13 @@ export const ButtonContainer = styled('button', {
|
|
|
110
112
|
switch (size) {
|
|
111
113
|
case 'large':
|
|
112
114
|
return {
|
|
113
|
-
|
|
115
|
+
...type.levels.body.small,
|
|
116
|
+
fontWeight: type.properties.fontWeights.bold,
|
|
114
117
|
minWidth: '112px',
|
|
115
118
|
height: '48px',
|
|
116
119
|
padding: `0 ${space.l}`,
|
|
117
120
|
'& > * ': {
|
|
118
|
-
margin: `0 ${spaceNumbers.
|
|
121
|
+
margin: `0 ${spaceNumbers.xxs / 2}px`,
|
|
119
122
|
},
|
|
120
123
|
};
|
|
121
124
|
case 'medium':
|
|
@@ -137,6 +140,14 @@ export const ButtonContainer = styled('button', {
|
|
|
137
140
|
margin: `0 ${spaceNumbers.xxxs / 2}px`,
|
|
138
141
|
},
|
|
139
142
|
};
|
|
143
|
+
case 'extraSmall':
|
|
144
|
+
return {
|
|
145
|
+
height: space.m,
|
|
146
|
+
padding: `0 ${space.xs}`,
|
|
147
|
+
'& > * ': {
|
|
148
|
+
margin: `0 ${spaceNumbers.xxxs / 2}px`,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
140
151
|
}
|
|
141
152
|
},
|
|
142
153
|
({grow}) => grow && {width: '100%', maxWidth: '100%'},
|
|
@@ -5,22 +5,25 @@ import isPropValid from '@emotion/is-prop-valid';
|
|
|
5
5
|
import {SystemIcon} from '@workday/canvas-kit-react/icon';
|
|
6
6
|
import {styled} from '@workday/canvas-kit-react/common';
|
|
7
7
|
|
|
8
|
+
import {ButtonSizes, IconPositions} from '../types';
|
|
8
9
|
export interface ButtonLabelIconProps {
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
|
|
12
|
+
*
|
|
11
13
|
* @default 'medium'
|
|
12
14
|
*/
|
|
13
|
-
size?:
|
|
15
|
+
size?: ButtonSizes;
|
|
14
16
|
/**
|
|
15
17
|
* The icon of the Button.
|
|
16
18
|
* Note: not displayed at `small` size
|
|
17
19
|
*/
|
|
18
20
|
icon?: CanvasSystemIcon;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Button icon positions can either be `left` or `right`.
|
|
23
|
+
* If no value is provided, it defaults to `left`.
|
|
21
24
|
* @default 'left'
|
|
22
25
|
*/
|
|
23
|
-
iconPosition?:
|
|
26
|
+
iconPosition?: IconPositions;
|
|
24
27
|
/**
|
|
25
28
|
* If set to `true`, transform the icon's x-axis to mirror the graphic
|
|
26
29
|
* @default false
|
|
@@ -28,8 +31,29 @@ export interface ButtonLabelIconProps {
|
|
|
28
31
|
shouldMirrorIcon?: boolean;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
const
|
|
32
|
-
|
|
34
|
+
const iconSizes: Record<ButtonSizes, number> = {
|
|
35
|
+
extraSmall: 18,
|
|
36
|
+
small: 20,
|
|
37
|
+
medium: 20,
|
|
38
|
+
large: 24,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getIconPositionStyles = ({iconPosition, size}: ButtonLabelIconProps) => {
|
|
42
|
+
// Adjust margin values for visual balance, large buttons require 8px
|
|
43
|
+
const balancingMargin = size === 'large' ? space.xxs : space.xxxs;
|
|
44
|
+
// iconPosition can only be "right", "left", or undefined (defaults to "left")
|
|
45
|
+
if (iconPosition === 'right') {
|
|
46
|
+
return {
|
|
47
|
+
marginLeft: undefined,
|
|
48
|
+
marginRight: `-${balancingMargin} !important`,
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
return {
|
|
52
|
+
marginLeft: `-${balancingMargin} !important`,
|
|
53
|
+
marginRight: undefined,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
33
57
|
|
|
34
58
|
const ButtonLabelIconStyled = styled('span', {
|
|
35
59
|
shouldForwardProp: prop => isPropValid(prop) && prop !== 'size',
|
|
@@ -38,13 +62,10 @@ const ButtonLabelIconStyled = styled('span', {
|
|
|
38
62
|
display: 'inline-block',
|
|
39
63
|
},
|
|
40
64
|
({size}) => ({
|
|
41
|
-
width: size
|
|
42
|
-
height: size
|
|
65
|
+
width: size ? iconSizes[size] : iconSizes.medium,
|
|
66
|
+
height: size ? iconSizes[size] : iconSizes.medium,
|
|
43
67
|
}),
|
|
44
|
-
|
|
45
|
-
marginLeft: iconPosition === 'right' ? undefined : `-${space.xxxs} !important`,
|
|
46
|
-
marginRight: iconPosition === 'right' ? `-${space.xxxs} !important` : undefined,
|
|
47
|
-
})
|
|
68
|
+
getIconPositionStyles
|
|
48
69
|
);
|
|
49
70
|
|
|
50
71
|
export const ButtonLabelIcon = ({
|
|
@@ -54,12 +75,11 @@ export const ButtonLabelIcon = ({
|
|
|
54
75
|
shouldMirrorIcon = false,
|
|
55
76
|
...elemProps
|
|
56
77
|
}: ButtonLabelIconProps) => {
|
|
57
|
-
/* istanbul ignore next line for coverage */
|
|
58
78
|
if (icon === undefined) {
|
|
59
79
|
return null;
|
|
60
80
|
}
|
|
61
81
|
|
|
62
|
-
const iconSize = size
|
|
82
|
+
const iconSize = size ? iconSizes[size] : undefined;
|
|
63
83
|
|
|
64
84
|
return (
|
|
65
85
|
<ButtonLabelIconStyled iconPosition={iconPosition} size={size} {...elemProps}>
|
package/button/lib/types.ts
CHANGED
|
@@ -20,3 +20,13 @@ export interface ButtonColors {
|
|
|
20
20
|
};
|
|
21
21
|
disabled: ButtonStateColors;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
|
|
26
|
+
* If no size is provided, it will default to `medium`.
|
|
27
|
+
*
|
|
28
|
+
* @default 'medium'
|
|
29
|
+
*/
|
|
30
|
+
export type ButtonSizes = 'extraSmall' | 'small' | 'medium' | 'large';
|
|
31
|
+
|
|
32
|
+
export type IconPositions = 'left' | 'right';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {CSSProperties} from '@workday/canvas-kit-react/tokens';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A utility to hide content normal users while still making accessible to screenreaders
|
|
5
5
|
* See https://a11y-101.com/development/skip-link
|
|
6
6
|
*/
|
|
7
|
-
export const accessibleHide:
|
|
7
|
+
export const accessibleHide: CSSProperties = {
|
|
8
8
|
clip: 'rect(1px, 1px, 1px, 1px)', // Deprecated but still used by most browsers, clip-path will be taking its place soon.
|
|
9
9
|
clipPath: 'polygon(0px 0px, 0px 0px, 0px 0px, 0px 0px)',
|
|
10
10
|
position: 'absolute',
|