@workday/canvas-kit-react 6.0.0-alpha.0-next.27 → 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.
Files changed (35) hide show
  1. package/button/lib/PrimaryButton.tsx +110 -32
  2. package/button/lib/parts/ButtonContainer.tsx +16 -5
  3. package/button/lib/parts/ButtonLabelIcon.tsx +34 -14
  4. package/button/lib/types.ts +10 -0
  5. package/dist/commonjs/button/lib/PrimaryButton.d.ts +80 -6
  6. package/dist/commonjs/button/lib/PrimaryButton.d.ts.map +1 -1
  7. package/dist/commonjs/button/lib/PrimaryButton.js +80 -26
  8. package/dist/commonjs/button/lib/parts/ButtonContainer.d.ts +5 -3
  9. package/dist/commonjs/button/lib/parts/ButtonContainer.d.ts.map +1 -1
  10. package/dist/commonjs/button/lib/parts/ButtonContainer.js +11 -9
  11. package/dist/commonjs/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
  12. package/dist/commonjs/button/lib/parts/ButtonLabelIcon.d.ts.map +1 -1
  13. package/dist/commonjs/button/lib/parts/ButtonLabelIcon.js +28 -13
  14. package/dist/commonjs/button/lib/types.d.ts +8 -0
  15. package/dist/commonjs/button/lib/types.d.ts.map +1 -1
  16. package/dist/es6/button/lib/PrimaryButton.d.ts +80 -6
  17. package/dist/es6/button/lib/PrimaryButton.d.ts.map +1 -1
  18. package/dist/es6/button/lib/PrimaryButton.js +81 -27
  19. package/dist/es6/button/lib/parts/ButtonContainer.d.ts +5 -3
  20. package/dist/es6/button/lib/parts/ButtonContainer.d.ts.map +1 -1
  21. package/dist/es6/button/lib/parts/ButtonContainer.js +11 -9
  22. package/dist/es6/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
  23. package/dist/es6/button/lib/parts/ButtonLabelIcon.d.ts.map +1 -1
  24. package/dist/es6/button/lib/parts/ButtonLabelIcon.js +28 -13
  25. package/dist/es6/button/lib/types.d.ts +8 -0
  26. package/dist/es6/button/lib/types.d.ts.map +1 -1
  27. package/package.json +5 -5
  28. package/ts3.5/dist/commonjs/button/lib/PrimaryButton.d.ts +80 -6
  29. package/ts3.5/dist/commonjs/button/lib/parts/ButtonContainer.d.ts +5 -3
  30. package/ts3.5/dist/commonjs/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
  31. package/ts3.5/dist/commonjs/button/lib/types.d.ts +8 -0
  32. package/ts3.5/dist/es6/button/lib/PrimaryButton.d.ts +80 -6
  33. package/ts3.5/dist/es6/button/lib/parts/ButtonContainer.d.ts +5 -3
  34. package/ts3.5/dist/es6/button/lib/parts/ButtonLabelIcon.d.ts +7 -4
  35. package/ts3.5/dist/es6/button/lib/types.d.ts +8 -0
@@ -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
- import {ButtonColors} from './types';
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 size of the Button.
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?: 'small' | 'medium' | 'large';
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
- * The position of the TertiaryButton icon.
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?: 'left' | 'right';
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 && size !== 'small' && iconPosition === 'left' && (
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 !== 'small' && <ButtonLabelData>{dataLabel}</ButtonLabelData>}
78
- {icon && size !== 'small' && iconPosition === 'right' && (
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
- canvas: {
92
- palette: {primary: themePrimary},
93
- },
94
- }: EmotionCanvasTheme): ButtonColors => ({
95
- default: {
96
- background: themePrimary.main,
97
- icon: themePrimary.contrast,
98
- label: themePrimary.contrast,
99
- },
100
- hover: {
101
- background: themePrimary.dark,
102
- },
103
- active: {
104
- background: themePrimary.darkest,
105
- },
106
- focus: {
107
- background: themePrimary.main,
108
- },
109
- disabled: {
110
- background: themePrimary.light,
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
- * The size of the Button.
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?: 'small' | 'medium' | 'large';
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
- fontSize: type.properties.fontSizes[16],
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.xs / 2}px`,
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
- * The size of the Button.
11
+ * There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
12
+ *
11
13
  * @default 'medium'
12
14
  */
13
- size?: 'small' | 'medium' | 'large';
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
- * The position of the TertiaryButton icon.
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?: 'left' | 'right';
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 ICON_SIZE = 24;
32
- const SMALL_ICON_SIZE = 20;
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 === 'small' ? SMALL_ICON_SIZE : ICON_SIZE,
42
- height: size === 'small' ? SMALL_ICON_SIZE : ICON_SIZE,
65
+ width: size ? iconSizes[size] : iconSizes.medium,
66
+ height: size ? iconSizes[size] : iconSizes.medium,
43
67
  }),
44
- ({iconPosition}) => ({
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 === 'small' ? SMALL_ICON_SIZE : undefined;
82
+ const iconSize = size ? iconSizes[size] : undefined;
63
83
 
64
84
  return (
65
85
  <ButtonLabelIconStyled iconPosition={iconPosition} size={size} {...elemProps}>
@@ -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,13 +1,20 @@
1
1
  import * as React from 'react';
2
2
  import { GrowthBehavior, Themeable, EmotionCanvasTheme } from '@workday/canvas-kit-react/common';
3
3
  import { CanvasSystemIcon } from '@workday/design-assets-types';
4
- import { ButtonColors } from './types';
4
+ import { ButtonSizes, IconPositions } from './types';
5
5
  export interface PrimaryButtonProps extends Themeable, GrowthBehavior {
6
6
  /**
7
- * The size of the Button.
7
+ * The variant of the PrimaryButton.
8
+ * @default undefined
9
+ */
10
+ variant?: 'inverse';
11
+ /**
12
+ * There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
13
+ * If no size is provided, it will default to `medium`.
14
+ *
8
15
  * @default 'medium'
9
16
  */
10
- size?: 'small' | 'medium' | 'large';
17
+ size?: ButtonSizes;
11
18
  /**
12
19
  * The data label of the Button.
13
20
  * Note: not displayed at `small` size
@@ -19,10 +26,11 @@ export interface PrimaryButtonProps extends Themeable, GrowthBehavior {
19
26
  */
20
27
  icon?: CanvasSystemIcon;
21
28
  /**
22
- * The position of the TertiaryButton icon.
29
+ * Button icon positions can either be `left` or `right`.
30
+ * If no value is provided, it defaults to `left`.
23
31
  * @default 'left'
24
32
  */
25
- iconPosition?: 'left' | 'right';
33
+ iconPosition?: IconPositions;
26
34
  /**
27
35
  * If set to `true`, transform the icon's x-axis to mirror the graphic
28
36
  * @default false
@@ -31,5 +39,71 @@ export interface PrimaryButtonProps extends Themeable, GrowthBehavior {
31
39
  children?: React.ReactNode;
32
40
  }
33
41
  export declare const PrimaryButton: import("../../common").ElementComponent<"button", PrimaryButtonProps>;
34
- export declare const getPrimaryButtonColors: ({ canvas: { palette: { primary: themePrimary }, }, }: EmotionCanvasTheme) => ButtonColors;
42
+ export declare const getPrimaryButtonColors: (variant: "inverse" | undefined, theme: EmotionCanvasTheme) => {
43
+ default: {
44
+ background: string;
45
+ icon: string;
46
+ label: string;
47
+ labelData?: undefined;
48
+ };
49
+ hover: {
50
+ background: string;
51
+ icon?: undefined;
52
+ label?: undefined;
53
+ labelData?: undefined;
54
+ };
55
+ active: {
56
+ background: string;
57
+ icon?: undefined;
58
+ label?: undefined;
59
+ labelData?: undefined;
60
+ };
61
+ focus: {
62
+ background: string;
63
+ border?: undefined;
64
+ icon?: undefined;
65
+ label?: undefined;
66
+ labelData?: undefined;
67
+ focusRing?: undefined;
68
+ };
69
+ disabled: {
70
+ background: string;
71
+ icon?: undefined;
72
+ label?: undefined;
73
+ labelData?: undefined;
74
+ };
75
+ } | {
76
+ default: {
77
+ background: string;
78
+ icon: string;
79
+ label: string;
80
+ labelData: string;
81
+ };
82
+ hover: {
83
+ background: string;
84
+ icon: string;
85
+ label: string;
86
+ labelData: string;
87
+ };
88
+ active: {
89
+ background: string;
90
+ icon: string;
91
+ label: string;
92
+ labelData: string;
93
+ };
94
+ focus: {
95
+ background: string;
96
+ border: string;
97
+ icon: string;
98
+ label: string;
99
+ labelData: string;
100
+ focusRing: import("@emotion/serialize").CSSObject;
101
+ };
102
+ disabled: {
103
+ background: string;
104
+ icon: string;
105
+ label: string;
106
+ labelData: string;
107
+ };
108
+ };
35
109
  //# sourceMappingURL=PrimaryButton.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrimaryButton.d.ts","sourceRoot":"","sources":["../../../../button/lib/PrimaryButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,cAAc,EAEd,SAAS,EACT,kBAAkB,EAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAGrC,MAAM,WAAW,kBAAmB,SAAQ,SAAS,EAAE,cAAc;IACnE;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,eAAO,MAAM,aAAa,uEA6CxB,CAAC;AAEH,eAAO,MAAM,sBAAsB,4FAsBjC,CAAC"}
1
+ {"version":3,"file":"PrimaryButton.d.ts","sourceRoot":"","sources":["../../../../button/lib/PrimaryButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,cAAc,EAEd,SAAS,EACT,kBAAkB,EAGnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAG9D,OAAO,EAAC,WAAW,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAEnD,MAAM,WAAW,kBAAmB,SAAQ,SAAS,EAAE,cAAc;IACnE;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;;OAIG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAYD,eAAO,MAAM,aAAa,uEA+CxB,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6ElC,CAAC"}
@@ -31,7 +31,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  var React = __importStar(require("react"));
33
33
  var common_1 = require("@workday/canvas-kit-react/common");
34
+ var tokens_1 = require("@workday/canvas-kit-react/tokens");
34
35
  var parts_1 = require("./parts");
36
+ // Button sizes where data labels are enabled
37
+ var dataLabelSizes = ['medium', 'large'];
38
+ // All disabled buttons are set to 40% opacity.
39
+ // This will eventually live in the ButtonContainer styles, but for now we're scoping it to Primary, Secondary, and Tertiary buttons.
40
+ var disabledButtonOpacity = {
41
+ '&:disabled, &:disabled:active': {
42
+ opacity: 0.4,
43
+ },
44
+ };
35
45
  exports.PrimaryButton = common_1.createComponent('button')({
36
46
  displayName: 'PrimaryButton',
37
47
  Component: function (_a, ref, Element) {
@@ -41,33 +51,77 @@ exports.PrimaryButton = common_1.createComponent('button')({
41
51
  _b = _a.theme,
42
52
  // TODO: Fix useTheme and make it a real hook
43
53
  // eslint-disable-next-line react-hooks/rules-of-hooks
44
- theme = _b === void 0 ? common_1.useTheme() : _b, _c = _a.size, size = _c === void 0 ? 'medium' : _c, _d = _a.iconPosition, iconPosition = _d === void 0 ? 'left' : _d, dataLabel = _a.dataLabel, icon = _a.icon, _e = _a.shouldMirrorIcon, shouldMirrorIcon = _e === void 0 ? false : _e, children = _a.children, elemProps = __rest(_a, ["theme", "size", "iconPosition", "dataLabel", "icon", "shouldMirrorIcon", "children"]);
45
- return (React.createElement(parts_1.ButtonContainer, __assign({ ref: ref, as: Element, colors: exports.getPrimaryButtonColors(theme), size: size }, elemProps),
46
- icon && size !== 'small' && iconPosition === 'left' && (React.createElement(parts_1.ButtonLabelIcon, { size: size, iconPosition: iconPosition, icon: icon, shouldMirrorIcon: shouldMirrorIcon })),
54
+ theme = _b === void 0 ? common_1.useTheme() : _b, _c = _a.size, size = _c === void 0 ? 'medium' : _c, _d = _a.iconPosition, iconPosition = _d === void 0 ? 'left' : _d, variant = _a.variant, dataLabel = _a.dataLabel, icon = _a.icon, _e = _a.shouldMirrorIcon, shouldMirrorIcon = _e === void 0 ? false : _e, children = _a.children, elemProps = __rest(_a, ["theme", "size", "iconPosition", "variant", "dataLabel", "icon", "shouldMirrorIcon", "children"]);
55
+ return (React.createElement(parts_1.ButtonContainer, __assign({ ref: ref, as: Element, colors: exports.getPrimaryButtonColors(variant, theme), size: size, extraStyles: disabledButtonOpacity }, elemProps),
56
+ icon && iconPosition === 'left' && (React.createElement(parts_1.ButtonLabelIcon, { size: size, iconPosition: iconPosition, icon: icon, shouldMirrorIcon: shouldMirrorIcon })),
47
57
  React.createElement(parts_1.ButtonLabel, null, children),
48
- dataLabel && size !== 'small' && React.createElement(parts_1.ButtonLabelData, null, dataLabel),
49
- icon && size !== 'small' && iconPosition === 'right' && (React.createElement(parts_1.ButtonLabelIcon, { size: size, iconPosition: iconPosition, icon: icon, shouldMirrorIcon: shouldMirrorIcon }))));
58
+ dataLabel && dataLabelSizes.includes(size) && React.createElement(parts_1.ButtonLabelData, null, dataLabel),
59
+ icon && iconPosition === 'right' && (React.createElement(parts_1.ButtonLabelIcon, { size: size, iconPosition: iconPosition, icon: icon, shouldMirrorIcon: shouldMirrorIcon }))));
50
60
  },
51
61
  });
52
- exports.getPrimaryButtonColors = function (_a) {
53
- var themePrimary = _a.canvas.palette.primary;
54
- return ({
55
- default: {
56
- background: themePrimary.main,
57
- icon: themePrimary.contrast,
58
- label: themePrimary.contrast,
59
- },
60
- hover: {
61
- background: themePrimary.dark,
62
- },
63
- active: {
64
- background: themePrimary.darkest,
65
- },
66
- focus: {
67
- background: themePrimary.main,
68
- },
69
- disabled: {
70
- background: themePrimary.light,
71
- },
72
- });
62
+ exports.getPrimaryButtonColors = function (variant, theme) {
63
+ var themePrimary = theme.canvas.palette.primary;
64
+ switch (variant) {
65
+ case undefined:
66
+ default:
67
+ return {
68
+ default: {
69
+ background: themePrimary.main,
70
+ icon: themePrimary.contrast,
71
+ label: themePrimary.contrast,
72
+ },
73
+ hover: {
74
+ background: themePrimary.dark,
75
+ },
76
+ active: {
77
+ background: themePrimary.darkest,
78
+ },
79
+ focus: {
80
+ background: themePrimary.main,
81
+ },
82
+ disabled: {
83
+ background: themePrimary.main,
84
+ },
85
+ };
86
+ case 'inverse':
87
+ return {
88
+ default: {
89
+ background: tokens_1.colors.frenchVanilla100,
90
+ icon: tokens_1.colors.blackPepper400,
91
+ label: tokens_1.colors.blackPepper400,
92
+ labelData: tokens_1.colors.blackPepper400,
93
+ },
94
+ hover: {
95
+ background: tokens_1.colors.soap300,
96
+ icon: tokens_1.colors.blackPepper500,
97
+ label: tokens_1.colors.blackPepper500,
98
+ labelData: tokens_1.colors.blackPepper500,
99
+ },
100
+ active: {
101
+ background: tokens_1.colors.soap300,
102
+ icon: tokens_1.colors.blackPepper500,
103
+ label: tokens_1.colors.blackPepper500,
104
+ labelData: tokens_1.colors.blackPepper500,
105
+ },
106
+ focus: {
107
+ background: tokens_1.colors.frenchVanilla100,
108
+ border: tokens_1.colors.blackPepper400,
109
+ icon: tokens_1.colors.blackPepper400,
110
+ label: tokens_1.colors.blackPepper400,
111
+ labelData: tokens_1.colors.blackPepper400,
112
+ focusRing: common_1.focusRing({
113
+ separation: 1,
114
+ innerColor: tokens_1.colors.blackPepper500,
115
+ outerColor: tokens_1.colors.frenchVanilla100,
116
+ }, theme),
117
+ },
118
+ // Identical to inverse 'default' styles. ButtonContainer will set opacity to 40%
119
+ disabled: {
120
+ background: tokens_1.colors.frenchVanilla100,
121
+ icon: tokens_1.colors.blackPepper400,
122
+ label: tokens_1.colors.blackPepper400,
123
+ labelData: tokens_1.colors.blackPepper400,
124
+ },
125
+ };
126
+ }
73
127
  };
@@ -1,14 +1,16 @@
1
1
  import * as React from 'react';
2
2
  import { CSSObject } from '@emotion/core';
3
3
  import { GrowthBehavior, EmotionCanvasTheme, StyledType } from '@workday/canvas-kit-react/common';
4
- import { ButtonColors } from '../types';
4
+ import { ButtonColors, ButtonSizes } from '../types';
5
5
  export interface ButtonContainerProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, GrowthBehavior {
6
6
  colors?: ButtonColors;
7
7
  /**
8
- * The size of the Button.
8
+ * There are four button sizes: `extraSmall`, `small`, `medium`, and `large`.
9
+ * If no size is provided, it will default to `medium`.
10
+ *
9
11
  * @default 'medium'
10
12
  */
11
- size?: 'small' | 'medium' | 'large';
13
+ size?: ButtonSizes;
12
14
  /**
13
15
  * The ref to the button that the styled component renders.
14
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ButtonContainer.d.ts","sourceRoot":"","sources":["../../../../../button/lib/parts/ButtonContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,cAAc,EAId,kBAAkB,EAClB,UAAU,EACX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAGtC,MAAM,WAAW,oBACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EACnD,cAAc;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB;AA8BD,eAAO,MAAM,eAAe,kMAqK3B,CAAC"}
1
+ {"version":3,"file":"ButtonContainer.d.ts","sourceRoot":"","sources":["../../../../../button/lib/parts/ButtonContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,cAAc,EAId,kBAAkB,EAClB,UAAU,EACX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAE,WAAW,EAAC,MAAM,UAAU,CAAC;AAGnD,MAAM,WAAW,oBACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EACnD,cAAc;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB;AA8BD,eAAO,MAAM,eAAe,kMA8K3B,CAAC"}
@@ -50,15 +50,9 @@ exports.ButtonContainer = common_1.styled('button', {
50
50
  var size = _a.size;
51
51
  switch (size) {
52
52
  case 'large':
53
- return {
54
- fontSize: tokens_1.type.properties.fontSizes[16],
55
- minWidth: '112px',
56
- height: '48px',
57
- padding: "0 " + tokens_1.space.l,
58
- '& > * ': {
59
- margin: "0 " + tokens_1.spaceNumbers.xs / 2 + "px",
60
- },
61
- };
53
+ return __assign(__assign({}, tokens_1.type.levels.body.small), { fontWeight: tokens_1.type.properties.fontWeights.bold, minWidth: '112px', height: '48px', padding: "0 " + tokens_1.space.l, '& > * ': {
54
+ margin: "0 " + tokens_1.spaceNumbers.xxs / 2 + "px",
55
+ } });
62
56
  case 'medium':
63
57
  default:
64
58
  return {
@@ -78,6 +72,14 @@ exports.ButtonContainer = common_1.styled('button', {
78
72
  margin: "0 " + tokens_1.spaceNumbers.xxxs / 2 + "px",
79
73
  },
80
74
  };
75
+ case 'extraSmall':
76
+ return {
77
+ height: tokens_1.space.m,
78
+ padding: "0 " + tokens_1.space.xs,
79
+ '& > * ': {
80
+ margin: "0 " + tokens_1.spaceNumbers.xxxs / 2 + "px",
81
+ },
82
+ };
81
83
  }
82
84
  }, function (_a) {
83
85
  var grow = _a.grow;