@workday/canvas-kit-preview-react 14.0.0-alpha.1123-next.0 → 14.0.0-alpha.1126-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.
Files changed (64) hide show
  1. package/dist/commonjs/divider/lib/Divider.js +1 -1
  2. package/dist/commonjs/information-highlight/lib/InformationHighlight.js +7 -7
  3. package/dist/commonjs/information-highlight/lib/parts/Body.js +1 -1
  4. package/dist/commonjs/information-highlight/lib/parts/Heading.js +1 -1
  5. package/dist/commonjs/information-highlight/lib/parts/Link.js +1 -1
  6. package/dist/commonjs/loading-sparkles/lib/LoadingSparkles.js +2 -2
  7. package/dist/commonjs/multi-select/lib/MultiSelectInput.js +1 -1
  8. package/dist/commonjs/pill/lib/Pill.js +3 -3
  9. package/dist/commonjs/pill/lib/PillAvatar.js +1 -1
  10. package/dist/commonjs/pill/lib/PillCount.js +1 -1
  11. package/dist/commonjs/pill/lib/PillIcon.js +1 -1
  12. package/dist/commonjs/pill/lib/PillIconButton.js +1 -1
  13. package/dist/commonjs/pill/lib/PillLabel.js +1 -1
  14. package/dist/commonjs/radio/lib/RadioGroup.js +3 -3
  15. package/dist/commonjs/radio/lib/RadioLabel.js +1 -1
  16. package/dist/commonjs/radio/lib/RadioText.js +4 -4
  17. package/dist/commonjs/radio/lib/StyledRadioButton.js +5 -5
  18. package/dist/commonjs/segmented-control/index.d.ts +0 -1
  19. package/dist/commonjs/segmented-control/index.d.ts.map +1 -1
  20. package/dist/commonjs/segmented-control/index.js +0 -3
  21. package/dist/commonjs/segmented-control/lib/SegmentedControlItem.d.ts +95 -19
  22. package/dist/commonjs/segmented-control/lib/SegmentedControlItem.d.ts.map +1 -1
  23. package/dist/commonjs/segmented-control/lib/SegmentedControlItem.js +68 -85
  24. package/dist/commonjs/segmented-control/lib/SegmentedControlList.d.ts +17 -135
  25. package/dist/commonjs/segmented-control/lib/SegmentedControlList.d.ts.map +1 -1
  26. package/dist/commonjs/segmented-control/lib/SegmentedControlList.js +24 -12
  27. package/dist/commonjs/side-panel/lib/SidePanel.js +7 -7
  28. package/dist/commonjs/side-panel/lib/SidePanelToggleButton.js +11 -11
  29. package/dist/commonjs/status-indicator/lib/StatusIndicator.js +13 -13
  30. package/dist/commonjs/status-indicator/lib/StatusIndicatorLabel.js +1 -1
  31. package/dist/es6/divider/lib/Divider.js +1 -1
  32. package/dist/es6/information-highlight/lib/InformationHighlight.js +7 -7
  33. package/dist/es6/information-highlight/lib/parts/Body.js +1 -1
  34. package/dist/es6/information-highlight/lib/parts/Heading.js +1 -1
  35. package/dist/es6/information-highlight/lib/parts/Link.js +1 -1
  36. package/dist/es6/loading-sparkles/lib/LoadingSparkles.js +2 -2
  37. package/dist/es6/multi-select/lib/MultiSelectInput.js +1 -1
  38. package/dist/es6/pill/lib/Pill.js +3 -3
  39. package/dist/es6/pill/lib/PillAvatar.js +1 -1
  40. package/dist/es6/pill/lib/PillCount.js +1 -1
  41. package/dist/es6/pill/lib/PillIcon.js +1 -1
  42. package/dist/es6/pill/lib/PillIconButton.js +1 -1
  43. package/dist/es6/pill/lib/PillLabel.js +1 -1
  44. package/dist/es6/radio/lib/RadioGroup.js +3 -3
  45. package/dist/es6/radio/lib/RadioLabel.js +1 -1
  46. package/dist/es6/radio/lib/RadioText.js +4 -4
  47. package/dist/es6/radio/lib/StyledRadioButton.js +5 -5
  48. package/dist/es6/segmented-control/index.d.ts +0 -1
  49. package/dist/es6/segmented-control/index.d.ts.map +1 -1
  50. package/dist/es6/segmented-control/index.js +0 -1
  51. package/dist/es6/segmented-control/lib/SegmentedControlItem.d.ts +95 -19
  52. package/dist/es6/segmented-control/lib/SegmentedControlItem.d.ts.map +1 -1
  53. package/dist/es6/segmented-control/lib/SegmentedControlItem.js +68 -85
  54. package/dist/es6/segmented-control/lib/SegmentedControlList.d.ts +17 -135
  55. package/dist/es6/segmented-control/lib/SegmentedControlList.d.ts.map +1 -1
  56. package/dist/es6/segmented-control/lib/SegmentedControlList.js +24 -12
  57. package/dist/es6/side-panel/lib/SidePanel.js +7 -7
  58. package/dist/es6/side-panel/lib/SidePanelToggleButton.js +11 -11
  59. package/dist/es6/status-indicator/lib/StatusIndicator.js +13 -13
  60. package/dist/es6/status-indicator/lib/StatusIndicatorLabel.js +1 -1
  61. package/package.json +4 -4
  62. package/segmented-control/index.ts +0 -1
  63. package/segmented-control/lib/SegmentedControlItem.tsx +153 -122
  64. package/segmented-control/lib/SegmentedControlList.tsx +42 -27
@@ -1,17 +1,14 @@
1
1
  import * as React from 'react';
2
2
 
3
- import {colors, type, space} from '@workday/canvas-kit-react/tokens';
4
- import {createSubcomponent, useIsRTL} from '@workday/canvas-kit-react/common';
5
- import {Tooltip, TooltipProps} from '@workday/canvas-kit-react/tooltip';
6
- import {
7
- BaseButton,
8
- ButtonContainerProps,
9
- ButtonColors,
10
- ButtonSizes,
11
- } from '@workday/canvas-kit-react/button';
3
+ import {BaseButton, ButtonContainerProps, buttonStencil} from '@workday/canvas-kit-react/button';
12
4
  import {CanvasSystemIcon} from '@workday/design-assets-types';
13
- import {useSegmentedControlModel} from './hooks/useSegmentedControlModel';
5
+ import {createSubcomponent} from '@workday/canvas-kit-react/common';
6
+ import {createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling';
7
+ import {system} from '@workday/canvas-tokens-web';
8
+ import {systemIconStencil} from '@workday/canvas-kit-react/icon';
9
+ import {Tooltip, TooltipProps} from '@workday/canvas-kit-react/tooltip';
14
10
  import {Text} from '@workday/canvas-kit-react/text';
11
+ import {useSegmentedControlModel} from './hooks/useSegmentedControlModel';
15
12
  import {useSegmentedControlItem} from './hooks/useSegmentedControlItem';
16
13
 
17
14
  export interface ItemProps extends ButtonContainerProps {
@@ -52,112 +49,148 @@ export interface ItemProps extends ButtonContainerProps {
52
49
  tooltipProps?: Omit<TooltipProps, 'children'>;
53
50
  }
54
51
 
55
- const getMinWidthStyles = (children: React.ReactNode, size: ButtonSizes) => {
56
- switch (size) {
57
- case 'large':
58
- return children ? '112px' : '48px';
59
- case 'medium':
60
- return children ? '96px' : space.xl;
61
- case 'small':
62
- return children ? space.xxxl : space.l;
63
- case 'extraSmall':
64
- return children ? 'auto' : space.m;
65
- default:
66
- return children ? '96px' : space.xl;
67
- }
68
- };
69
-
70
- const getButtonSize = (size: ButtonContainerProps['size']) => {
71
- switch (size) {
72
- case 'large':
73
- return 'medium';
74
- case 'medium':
75
- return 'small';
76
- case 'small':
77
- return 'extraSmall';
78
- default:
79
- return 'medium';
80
- }
81
- };
52
+ export const segmentedControlItemStencil = createStencil({
53
+ extends: buttonStencil,
54
+ base: {
55
+ ...system.type.subtext.large,
56
+ fontWeight: system.fontWeight.bold,
57
+ textAlign: 'start',
58
+ paddingInline: system.space.zero,
59
+ gap: system.space.x1,
82
60
 
83
- const getIconButtonColors = (toggled?: boolean): ButtonColors => {
84
- return {
85
- default: {
86
- background: toggled ? colors.frenchVanilla100 : colors.soap200,
87
- border: toggled ? colors.licorice200 : 'transparent',
88
- icon: toggled ? colors.blackPepper400 : colors.licorice400,
89
- label: toggled ? colors.blackPepper400 : colors.licorice400,
90
- },
91
- hover: {
92
- background: toggled ? colors.frenchVanilla100 : colors.soap400,
93
- border: toggled ? colors.licorice200 : 'transparent',
94
- icon: colors.licorice400,
95
- label: colors.licorice400,
96
- },
97
- active: {
98
- background: toggled ? colors.frenchVanilla100 : colors.soap400,
99
- border: toggled ? colors.licorice200 : 'transparent',
100
- icon: colors.licorice400,
101
- label: colors.licorice400,
102
- },
103
- focus: {
104
- background: toggled ? colors.frenchVanilla100 : colors.soap200,
105
- border: toggled ? colors.licorice200 : 'transparent',
106
- icon: toggled ? colors.blackPepper400 : colors.licorice400,
107
- label: toggled ? colors.blackPepper400 : colors.licorice400,
108
- },
109
- disabled: {
110
- background: colors.soap200,
111
- opacity: '1',
112
- icon: colors.licorice400,
113
- border: toggled ? colors.licorice200 : 'transparent',
114
- label: colors.blackPepper400,
115
- },
116
- };
117
- };
61
+ [buttonStencil.vars.borderRadius]: system.shape.x1,
62
+ [buttonStencil.vars.label]: system.color.fg.muted.strong,
63
+ [systemIconStencil.vars.color]: system.color.fg.muted.strong,
118
64
 
119
- const getPaddingStyles = (
120
- children: React.ReactNode,
121
- size: ButtonContainerProps['size'],
122
- icon: CanvasSystemIcon | undefined
123
- ) => {
124
- if (!children) {
125
- return 0;
126
- }
65
+ '&:hover, &.hover': {
66
+ [buttonStencil.vars.background]: system.color.bg.alt.strong,
67
+ [buttonStencil.vars.label]: system.color.fg.muted.strong,
68
+ [systemIconStencil.vars.color]: system.color.fg.muted.strong,
69
+ },
127
70
 
128
- switch (size) {
129
- case 'large':
130
- return icon ? `0 ${space.m} 0 20px` : `0 ${space.m}`;
71
+ '&:active, &.active': {
72
+ [buttonStencil.vars.background]: system.color.bg.alt.strong,
73
+ [buttonStencil.vars.label]: system.color.fg.muted.strong,
74
+ [systemIconStencil.vars.color]: system.color.fg.muted.strong,
75
+ },
131
76
 
132
- case 'medium':
133
- return icon ? `0 20px 0 ${space.s}` : `0 ${space.s}`;
77
+ '&:focus-visible, &.focus': {
78
+ [buttonStencil.vars.label]: system.color.fg.muted.strong,
79
+ [systemIconStencil.vars.color]: system.color.fg.muted.strong,
80
+ },
134
81
 
135
- case 'small':
136
- return icon ? `0 ${space.xs} 0 ${space.xxs}` : `0 ${space.xs}`;
82
+ '&:disabled, &.disabled': {
83
+ [buttonStencil.vars.background]: system.color.bg.alt.soft,
84
+ },
137
85
 
138
- default:
139
- return icon ? `0 20px 0 ${space.s}` : `0 ${space.s}`;
140
- }
141
- };
86
+ "&[aria-pressed='true']": {
87
+ [buttonStencil.vars.background]: system.color.bg.default,
88
+ [buttonStencil.vars.border]: system.color.border.input.default,
89
+ [systemIconStencil.vars.color]: system.color.fg.strong,
90
+ [buttonStencil.vars.label]: system.color.fg.strong,
142
91
 
143
- const geButtonStyles = (size: ButtonSizes, children: React.ReactNode, icon?: CanvasSystemIcon) => {
144
- const buttonSize = getButtonSize(size);
145
- const minWidthValue = getMinWidthStyles(children, children ? size : buttonSize);
92
+ '&:hover, &.hover': {
93
+ [systemIconStencil.vars.color]: system.color.fg.strong,
94
+ [buttonStencil.vars.label]: system.color.fg.strong,
95
+ },
146
96
 
147
- return {
148
- height: getMinWidthStyles(false, buttonSize),
149
- minWidth: minWidthValue,
150
- padding: getPaddingStyles(children, size, icon),
151
- };
152
- };
97
+ '&:disabled, &.disabled': {
98
+ [buttonStencil.vars.border]: system.color.border.input.default,
99
+ [buttonStencil.vars.label]: system.color.fg.strong,
100
+ [systemIconStencil.vars.color]: system.color.fg.strong,
101
+ },
102
+ },
103
+ ':dir(rtl)': {
104
+ svg: {
105
+ transform: 'scaleX(-1)',
106
+ },
107
+ },
108
+ },
109
+ modifiers: {
110
+ size: {
111
+ large: {
112
+ height: system.space.x10,
113
+ gap: system.space.x2,
114
+ },
115
+ medium: {
116
+ height: system.space.x8,
117
+ },
118
+ small: {
119
+ ...system.type.subtext.medium,
120
+ fontWeight: system.fontWeight.bold,
121
+ height: system.space.x6,
122
+ },
123
+ },
124
+ variant: {
125
+ iconOnly: {},
126
+ textOnly: {},
127
+ iconWithText: {},
128
+ },
129
+ },
130
+ compound: [
131
+ {
132
+ modifiers: {size: 'large', variant: 'iconOnly'},
133
+ styles: {
134
+ minWidth: system.space.x10,
135
+ },
136
+ },
137
+ {
138
+ modifiers: {size: 'large', variant: 'iconWithText'},
139
+ styles: {
140
+ paddingInline: `${px2rem(20)} ${system.space.x6}`,
141
+ },
142
+ },
143
+ {
144
+ modifiers: {size: 'large', variant: 'textOnly'},
145
+ styles: {
146
+ paddingInline: system.space.x6,
147
+ },
148
+ },
149
+ {
150
+ modifiers: {size: 'medium', variant: 'iconOnly'},
151
+ styles: {
152
+ minWidth: system.space.x8,
153
+ },
154
+ },
155
+ {
156
+ modifiers: {size: 'medium', variant: 'iconWithText'},
157
+ styles: {
158
+ paddingInline: `${system.space.x4} ${px2rem(20)}`,
159
+ },
160
+ },
161
+ {
162
+ modifiers: {size: 'medium', variant: 'textOnly'},
163
+ styles: {
164
+ paddingInline: px2rem(20),
165
+ },
166
+ },
167
+ {
168
+ modifiers: {size: 'small', variant: 'iconOnly'},
169
+ styles: {
170
+ minWidth: system.space.x6,
171
+ },
172
+ },
173
+ {
174
+ modifiers: {size: 'small', variant: 'iconWithText'},
175
+ styles: {
176
+ paddingInline: `${system.space.x2} ${system.space.x3}`,
177
+ },
178
+ },
179
+ {
180
+ modifiers: {size: 'small', variant: 'textOnly'},
181
+ styles: {
182
+ paddingInline: system.space.x3,
183
+ },
184
+ },
185
+ ],
186
+ });
153
187
 
154
- const Container = ({
155
- tooltipProps,
156
- children,
157
- }: {
188
+ type ContainerProps = {
158
189
  tooltipProps?: Omit<TooltipProps, 'children'>;
159
190
  children: React.ReactElement;
160
- }) => {
191
+ };
192
+
193
+ const Container = ({tooltipProps, children}: ContainerProps) => {
161
194
  return tooltipProps ? (
162
195
  <Tooltip {...tooltipProps}>{children}</Tooltip>
163
196
  ) : (
@@ -165,34 +198,32 @@ const Container = ({
165
198
  );
166
199
  };
167
200
 
201
+ const getVariant = (icon: CanvasSystemIcon | undefined, children: React.ReactNode) => {
202
+ if (icon && children) {
203
+ return 'iconWithText';
204
+ } else if (!icon && children) {
205
+ return 'textOnly';
206
+ } else {
207
+ return 'iconOnly';
208
+ }
209
+ };
210
+
168
211
  export const SegmentedControlItem = createSubcomponent('button')({
169
212
  displayName: 'SegmentedControl.Item',
170
213
  modelHook: useSegmentedControlModel,
171
214
  elemPropsHook: useSegmentedControlItem,
172
215
  })<ItemProps>(({children, icon, tooltipProps, ...elemProps}, Element, {state: {size}}) => {
173
- const {color, ...textStyles} = type.levels.subtext[size === 'small' ? 'medium' : 'large'];
216
+ const variant = getVariant(icon, children);
217
+ const iconSize = size === 'small' ? 'extraSmall' : 'small';
174
218
 
175
219
  return (
176
220
  <Container tooltipProps={tooltipProps}>
177
221
  <BaseButton
178
222
  as={Element}
179
- borderRadius="m"
180
- colors={getIconButtonColors(elemProps['aria-pressed'])}
181
- {...geButtonStyles(size, children, icon)}
182
- {...elemProps}
223
+ {...handleCsProp(elemProps, segmentedControlItemStencil({size, variant}))}
183
224
  >
184
- {icon && (
185
- <BaseButton.Icon
186
- size={size === 'small' ? 'extraSmall' : 'medium'}
187
- icon={icon}
188
- shouldMirrorIcon={useIsRTL()}
189
- />
190
- )}
191
- {children && (
192
- <Text {...textStyles} fontWeight="bold" textAlign="left">
193
- {children}
194
- </Text>
195
- )}
225
+ {icon && <BaseButton.Icon icon={icon} size={iconSize} />}
226
+ {children && <Text>{children}</Text>}
196
227
  </BaseButton>
197
228
  </Container>
198
229
  );
@@ -1,13 +1,11 @@
1
1
  import * as React from 'react';
2
2
 
3
- import {
4
- createSubcomponent,
5
- ExtractProps,
6
- createElemPropsHook,
7
- } from '@workday/canvas-kit-react/common';
3
+ import {createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling';
4
+ import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
8
5
  import {Grid} from '@workday/canvas-kit-react/layout';
9
- import {useListRenderItems} from '@workday/canvas-kit-react/collection';
6
+ import {system} from '@workday/canvas-tokens-web';
10
7
  import {useSegmentedControlModel} from './hooks/useSegmentedControlModel';
8
+ import {useListRenderItems} from '@workday/canvas-kit-react/collection';
11
9
 
12
10
  export interface SegmentedControlListProps<T = any>
13
11
  extends Omit<Partial<ExtractProps<typeof Grid, never>>, 'children'> {
@@ -15,35 +13,52 @@ export interface SegmentedControlListProps<T = any>
15
13
  children: ((item: T) => React.ReactNode) | React.ReactNode;
16
14
  }
17
15
 
18
- export const useSegmentedControlList = createElemPropsHook(useSegmentedControlModel)(
19
- ({state: {orientation, disabled, items}}) => {
20
- const directionName = orientation === 'vertical' ? 'Row' : 'Column';
21
- return {
22
- [`gridTemplate${directionName}s`]: `repeat(${items.length}, 1fr)`,
23
- opacity: disabled ? 0.4 : undefined,
24
- };
25
- }
26
- );
16
+ export const segmentedControlListStencil = createStencil({
17
+ vars: {
18
+ items: '',
19
+ },
20
+ base: {
21
+ display: 'inline-grid',
22
+ backgroundColor: system.color.bg.alt.soft,
23
+ border: `${px2rem(1)} solid ${system.color.border.input.default}`,
24
+ borderRadius: system.shape.x2,
25
+ padding: px2rem(3),
26
+ gridGap: system.space.x2,
27
+ },
28
+ modifiers: {
29
+ disabled: {
30
+ true: {
31
+ opacity: system.opacity.disabled,
32
+ },
33
+ },
34
+ orientation: {
35
+ vertical: ({items}) => ({
36
+ gridTemplateRows: `repeat(${items}, 1fr)`,
37
+ }),
38
+ horizontal: ({items}) => ({
39
+ gridTemplateColumns: `repeat(${items}, 1fr)`,
40
+ }),
41
+ },
42
+ },
43
+ });
27
44
 
28
45
  export const SegmentedControlList = createSubcomponent('div')({
29
46
  displayName: 'SegmentedControl.List',
30
47
  modelHook: useSegmentedControlModel,
31
- elemPropsHook: useSegmentedControlList,
32
48
  })<SegmentedControlListProps>(({children, ...elemProps}, Element, model) => {
33
49
  return (
34
- <Grid
35
- as={Element}
36
- display="inline-grid"
50
+ <Element
37
51
  role="group"
38
- backgroundColor="soap200"
39
- border="1px solid transparent"
40
- borderColor="licorice200"
41
- borderRadius="l"
42
- padding="3px"
43
- gridGap="xxs"
44
- {...elemProps}
52
+ {...handleCsProp(
53
+ elemProps,
54
+ segmentedControlListStencil({
55
+ disabled: model.state.disabled,
56
+ items: `${model.state.items.length}`,
57
+ orientation: model.state.orientation,
58
+ })
59
+ )}
45
60
  >
46
61
  {useListRenderItems(model, children)}
47
- </Grid>
62
+ </Element>
48
63
  );
49
64
  });