@workday/canvas-kit-preview-react 15.0.0-alpha.0008-next.0 → 15.0.0-alpha.0023-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/avatar/lib/Avatar.js +13 -13
- package/dist/commonjs/avatar/lib/AvatarImage.js +1 -1
- package/dist/commonjs/avatar/lib/AvatarName.js +1 -1
- package/dist/commonjs/avatar/lib/BaseAvatar.js +12 -12
- package/dist/commonjs/color-picker/lib/ColorPicker.js +1 -1
- package/dist/commonjs/color-picker/lib/parts/ColorReset.js +1 -1
- package/dist/commonjs/color-picker/lib/parts/SwatchBook.js +1 -1
- package/dist/commonjs/divider/lib/Divider.js +1 -1
- package/dist/commonjs/index.d.ts +0 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +0 -1
- package/dist/commonjs/information-highlight/lib/InformationHighlight.js +7 -7
- package/dist/commonjs/information-highlight/lib/parts/Body.js +1 -1
- package/dist/commonjs/information-highlight/lib/parts/Heading.js +1 -1
- package/dist/commonjs/information-highlight/lib/parts/Link.js +1 -1
- package/dist/commonjs/loading-sparkles/lib/LoadingSparkles.js +2 -2
- package/dist/commonjs/multi-select/lib/MultiSelectInput.js +3 -3
- package/dist/commonjs/pill/lib/Pill.js +3 -3
- package/dist/commonjs/pill/lib/PillAvatar.js +1 -1
- package/dist/commonjs/pill/lib/PillCount.js +1 -1
- package/dist/commonjs/pill/lib/PillIcon.js +1 -1
- package/dist/commonjs/pill/lib/PillIconButton.js +1 -1
- package/dist/commonjs/pill/lib/PillLabel.js +1 -1
- package/dist/commonjs/radio/lib/RadioGroup.js +3 -3
- package/dist/commonjs/radio/lib/RadioLabel.js +1 -1
- package/dist/commonjs/radio/lib/RadioText.js +4 -4
- package/dist/commonjs/radio/lib/StyledRadioButton.js +5 -5
- package/dist/commonjs/side-panel/lib/SidePanel.js +7 -7
- package/dist/commonjs/side-panel/lib/SidePanelToggleButton.js +11 -11
- package/dist/commonjs/status-indicator/lib/StatusIndicator.js +15 -15
- package/dist/commonjs/status-indicator/lib/StatusIndicatorLabel.js +1 -1
- package/dist/commonjs/version/lib/version.js +1 -1
- package/dist/es6/avatar/lib/Avatar.js +13 -13
- package/dist/es6/avatar/lib/AvatarImage.js +1 -1
- package/dist/es6/avatar/lib/AvatarName.js +1 -1
- package/dist/es6/avatar/lib/BaseAvatar.js +12 -12
- package/dist/es6/color-picker/lib/ColorPicker.js +1 -1
- package/dist/es6/color-picker/lib/parts/ColorReset.js +1 -1
- package/dist/es6/color-picker/lib/parts/SwatchBook.js +1 -1
- package/dist/es6/divider/lib/Divider.js +1 -1
- package/dist/es6/index.d.ts +0 -1
- package/dist/es6/index.d.ts.map +1 -1
- package/dist/es6/index.js +0 -1
- package/dist/es6/information-highlight/lib/InformationHighlight.js +7 -7
- package/dist/es6/information-highlight/lib/parts/Body.js +1 -1
- package/dist/es6/information-highlight/lib/parts/Heading.js +1 -1
- package/dist/es6/information-highlight/lib/parts/Link.js +1 -1
- package/dist/es6/loading-sparkles/lib/LoadingSparkles.js +2 -2
- package/dist/es6/multi-select/lib/MultiSelectInput.js +3 -3
- package/dist/es6/pill/lib/Pill.js +3 -3
- package/dist/es6/pill/lib/PillAvatar.js +1 -1
- package/dist/es6/pill/lib/PillCount.js +1 -1
- package/dist/es6/pill/lib/PillIcon.js +1 -1
- package/dist/es6/pill/lib/PillIconButton.js +1 -1
- package/dist/es6/pill/lib/PillLabel.js +1 -1
- package/dist/es6/radio/lib/RadioGroup.js +3 -3
- package/dist/es6/radio/lib/RadioLabel.js +1 -1
- package/dist/es6/radio/lib/RadioText.js +4 -4
- package/dist/es6/radio/lib/StyledRadioButton.js +5 -5
- package/dist/es6/side-panel/lib/SidePanel.js +7 -7
- package/dist/es6/side-panel/lib/SidePanelToggleButton.js +11 -11
- package/dist/es6/status-indicator/lib/StatusIndicator.js +15 -15
- package/dist/es6/status-indicator/lib/StatusIndicatorLabel.js +1 -1
- package/dist/es6/version/lib/version.js +1 -1
- package/index.ts +0 -1
- package/package.json +4 -4
- package/dist/commonjs/segmented-control/index.d.ts +0 -5
- package/dist/commonjs/segmented-control/index.d.ts.map +0 -1
- package/dist/commonjs/segmented-control/index.js +0 -20
- package/dist/commonjs/segmented-control/lib/SegmentedControl.d.ts +0 -1324
- package/dist/commonjs/segmented-control/lib/SegmentedControl.d.ts.map +0 -1
- package/dist/commonjs/segmented-control/lib/SegmentedControl.js +0 -54
- package/dist/commonjs/segmented-control/lib/SegmentedControlItem.d.ts +0 -256
- package/dist/commonjs/segmented-control/lib/SegmentedControlItem.d.ts.map +0 -1
- package/dist/commonjs/segmented-control/lib/SegmentedControlItem.js +0 -114
- package/dist/commonjs/segmented-control/lib/SegmentedControlList.d.ts +0 -153
- package/dist/commonjs/segmented-control/lib/SegmentedControlList.d.ts.map +0 -1
- package/dist/commonjs/segmented-control/lib/SegmentedControlList.js +0 -34
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlItem.d.ts +0 -140
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlItem.d.ts.map +0 -1
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlItem.js +0 -21
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlModel.d.ts +0 -1336
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlModel.d.ts.map +0 -1
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlModel.js +0 -75
- package/dist/es6/segmented-control/index.d.ts +0 -5
- package/dist/es6/segmented-control/index.d.ts.map +0 -1
- package/dist/es6/segmented-control/index.js +0 -4
- package/dist/es6/segmented-control/lib/SegmentedControl.d.ts +0 -1324
- package/dist/es6/segmented-control/lib/SegmentedControl.d.ts.map +0 -1
- package/dist/es6/segmented-control/lib/SegmentedControl.js +0 -51
- package/dist/es6/segmented-control/lib/SegmentedControlItem.d.ts +0 -256
- package/dist/es6/segmented-control/lib/SegmentedControlItem.d.ts.map +0 -1
- package/dist/es6/segmented-control/lib/SegmentedControlItem.js +0 -88
- package/dist/es6/segmented-control/lib/SegmentedControlList.d.ts +0 -153
- package/dist/es6/segmented-control/lib/SegmentedControlList.d.ts.map +0 -1
- package/dist/es6/segmented-control/lib/SegmentedControlList.js +0 -31
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlItem.d.ts +0 -140
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlItem.d.ts.map +0 -1
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlItem.js +0 -18
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlModel.d.ts +0 -1336
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlModel.d.ts.map +0 -1
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlModel.js +0 -69
- package/segmented-control/index.ts +0 -4
- package/segmented-control/lib/SegmentedControl.tsx +0 -57
- package/segmented-control/lib/SegmentedControlItem.tsx +0 -230
- package/segmented-control/lib/SegmentedControlList.tsx +0 -64
- package/segmented-control/lib/hooks/useSegmentedControlItem.tsx +0 -33
- package/segmented-control/lib/hooks/useSegmentedControlModel.tsx +0 -75
- package/segmented-control/package.json +0 -6
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSegmentedControlModel.d.ts","sourceRoot":"","sources":["../../../../../segmented-control/lib/hooks/useSegmentedControlModel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,eAAO,MAAM,wBAAwB;IAGjC;;;OAGG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAxBH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2CL,CAAC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { createModelHook } from '@workday/canvas-kit-react/common';
|
|
3
|
-
import { defaultGetId, useListModel } from '@workday/canvas-kit-react/collection';
|
|
4
|
-
export const useSegmentedControlModel = createModelHook({
|
|
5
|
-
defaultConfig: {
|
|
6
|
-
...useListModel.defaultConfig,
|
|
7
|
-
/**
|
|
8
|
-
* Optional id for the whole `SegmentedControl` group. If not provided, a unique id will be created.
|
|
9
|
-
* @default useUniqueId()
|
|
10
|
-
*/
|
|
11
|
-
id: '',
|
|
12
|
-
/**
|
|
13
|
-
* An initially selected value. This value must match the `data-id` of the `SegmentedControl.Item` component.
|
|
14
|
-
* If not provided, the first value will be selected.
|
|
15
|
-
*/
|
|
16
|
-
initialValue: '',
|
|
17
|
-
/**
|
|
18
|
-
* Sets disabled state for all segmented control buttons
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
disabled: false,
|
|
22
|
-
/**
|
|
23
|
-
* Sets the size of the segmented control container and its buttons. Can be `small`, `medium` or `large`.
|
|
24
|
-
* @default 'medium'
|
|
25
|
-
*/
|
|
26
|
-
size: 'medium',
|
|
27
|
-
/**
|
|
28
|
-
* The SegmentedControl can rendered in a horizontal or vertical orientation.
|
|
29
|
-
* We suggest to use the `vertical` orientation only for icon only variant.
|
|
30
|
-
* @default 'horizontal'
|
|
31
|
-
*/
|
|
32
|
-
orientation: 'horizontal',
|
|
33
|
-
},
|
|
34
|
-
requiredConfig: useListModel.requiredConfig,
|
|
35
|
-
})(config => {
|
|
36
|
-
var _a;
|
|
37
|
-
const getId = config.getId || defaultGetId;
|
|
38
|
-
const initialSelectedRef = React.useRef(config.initialValue);
|
|
39
|
-
const items = config.items;
|
|
40
|
-
const model = useListModel(useListModel.mergeConfig(config, {
|
|
41
|
-
orientation: config.orientation || 'horizontal',
|
|
42
|
-
items,
|
|
43
|
-
onRegisterItem(data) {
|
|
44
|
-
if (!initialSelectedRef.current) {
|
|
45
|
-
initialSelectedRef.current = data.id;
|
|
46
|
-
events.select({ id: initialSelectedRef.current });
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
initialSelectedIds: config.initialValue
|
|
50
|
-
? [config.initialValue]
|
|
51
|
-
: ((_a = config.items) === null || _a === void 0 ? void 0 : _a.length)
|
|
52
|
-
? [getId(config.items[0])]
|
|
53
|
-
: [],
|
|
54
|
-
shouldVirtualize: false,
|
|
55
|
-
}));
|
|
56
|
-
const state = {
|
|
57
|
-
...model.state,
|
|
58
|
-
disabled: config.disabled,
|
|
59
|
-
size: config.size,
|
|
60
|
-
};
|
|
61
|
-
const events = {
|
|
62
|
-
...model.events,
|
|
63
|
-
};
|
|
64
|
-
return {
|
|
65
|
-
...model,
|
|
66
|
-
state,
|
|
67
|
-
events,
|
|
68
|
-
};
|
|
69
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {createContainer} from '@workday/canvas-kit-react/common';
|
|
3
|
-
|
|
4
|
-
import {useSegmentedControlModel} from './hooks/useSegmentedControlModel';
|
|
5
|
-
import {SegmentedControlList} from './SegmentedControlList';
|
|
6
|
-
import {SegmentedControlItem} from './SegmentedControlItem';
|
|
7
|
-
|
|
8
|
-
export interface SegmentedControlProps {
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* `SegmentedControl` is a container component that is responsible for creating a
|
|
14
|
-
* {@link SegmentedControlModel} and sharing it with its subcomponents using React context. It does
|
|
15
|
-
* not represent a real element.
|
|
16
|
-
*
|
|
17
|
-
* ```tsx
|
|
18
|
-
* <SegmentedControl items={[]}>{Child components}</SegmentedControl>
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* Alternatively, you may pass in a model using the [hoisted model
|
|
22
|
-
* pattern](/getting-started/for-developers/resources/compound-components/#configuring-a-model).
|
|
23
|
-
*
|
|
24
|
-
* ```tsx
|
|
25
|
-
* const model = useSegmentedControlModel({
|
|
26
|
-
* items: [],
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* <SegmentedControl model={model}>{Child components}</SegmentedControl>;
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export const SegmentedControl = createContainer()({
|
|
33
|
-
displayName: 'SegmentedControl',
|
|
34
|
-
modelHook: useSegmentedControlModel,
|
|
35
|
-
subComponents: {
|
|
36
|
-
/**
|
|
37
|
-
* `SegmentedControl.List` renders {@link Grid} under the hood. It is a container for
|
|
38
|
-
* {@link SegmentedControlItem SegmentedControl.Item} subcomponents.
|
|
39
|
-
*
|
|
40
|
-
* ```tsx
|
|
41
|
-
* <SegmentedControl.List>{SegmentedControl.Items}</SegmentedControl.List>
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
List: SegmentedControlList,
|
|
45
|
-
/**
|
|
46
|
-
* `SegmentedControl.Item` is a `button` element built on `BaseButton`. `SegmentedControl.Item`
|
|
47
|
-
* has a `data-id` prop to handle `onSelect` properly.
|
|
48
|
-
*
|
|
49
|
-
* ```tsx
|
|
50
|
-
* <SegmentedControl.Item data-id="table">Table</SegmentedControl.Item>
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
Item: SegmentedControlItem,
|
|
54
|
-
},
|
|
55
|
-
})<SegmentedControlProps>(({children}) => {
|
|
56
|
-
return <>{children}</>;
|
|
57
|
-
});
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import {BaseButton, ButtonContainerProps, buttonStencil} from '@workday/canvas-kit-react/button';
|
|
4
|
-
import {CanvasSystemIcon} from '@workday/design-assets-types';
|
|
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';
|
|
10
|
-
import {Text} from '@workday/canvas-kit-react/text';
|
|
11
|
-
import {useSegmentedControlModel} from './hooks/useSegmentedControlModel';
|
|
12
|
-
import {useSegmentedControlItem} from './hooks/useSegmentedControlItem';
|
|
13
|
-
|
|
14
|
-
export interface ItemProps extends ButtonContainerProps {
|
|
15
|
-
/**
|
|
16
|
-
* Optionally pass index to the item. This should be done if `SegmentedControl.Item` components were created
|
|
17
|
-
* via a `[Array::map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)` function. This index will ensure keyboard navigation works even if items are
|
|
18
|
-
* inserted out of order.
|
|
19
|
-
*/
|
|
20
|
-
index?: number;
|
|
21
|
-
/**
|
|
22
|
-
* The contents of the item. This is text used as the accessible name of the button for screen readers.
|
|
23
|
-
*/
|
|
24
|
-
children?: React.ReactNode;
|
|
25
|
-
/**
|
|
26
|
-
* The identifier of the item. This identifier will be used in change events and for `initialTab`.
|
|
27
|
-
* If this property is not provided, it will default to a string representation
|
|
28
|
-
* of the the zero-based index of the item when it was initialized.
|
|
29
|
-
*/
|
|
30
|
-
'data-id'?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Optional id. If not set, it will inherit the ID passed to the `SegmentedControl` component and append the
|
|
33
|
-
* index at the end. Only set this for advanced cases.
|
|
34
|
-
*/
|
|
35
|
-
id?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Part of the ARIA specification for buttons. Lets screen readers know which button is active. This
|
|
38
|
-
* should either be `true` or `false`. This is automatically set by the
|
|
39
|
-
* component and should only be used in advanced cases.
|
|
40
|
-
*/
|
|
41
|
-
'aria-pressed'?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* The icon of the button.
|
|
44
|
-
*/
|
|
45
|
-
icon?: CanvasSystemIcon;
|
|
46
|
-
/**
|
|
47
|
-
* Tooltip Props
|
|
48
|
-
*/
|
|
49
|
-
tooltipProps?: Omit<TooltipProps, 'children'>;
|
|
50
|
-
}
|
|
51
|
-
|
|
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,
|
|
60
|
-
|
|
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,
|
|
64
|
-
|
|
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
|
-
},
|
|
70
|
-
|
|
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
|
-
},
|
|
76
|
-
|
|
77
|
-
'&:focus-visible, &.focus': {
|
|
78
|
-
[buttonStencil.vars.label]: system.color.fg.muted.strong,
|
|
79
|
-
[systemIconStencil.vars.color]: system.color.fg.muted.strong,
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
'&:disabled, &.disabled': {
|
|
83
|
-
[buttonStencil.vars.background]: system.color.bg.alt.soft,
|
|
84
|
-
},
|
|
85
|
-
|
|
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,
|
|
91
|
-
|
|
92
|
-
'&:hover, &.hover': {
|
|
93
|
-
[systemIconStencil.vars.color]: system.color.fg.strong,
|
|
94
|
-
[buttonStencil.vars.label]: system.color.fg.strong,
|
|
95
|
-
},
|
|
96
|
-
|
|
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
|
-
});
|
|
187
|
-
|
|
188
|
-
type ContainerProps = {
|
|
189
|
-
tooltipProps?: Omit<TooltipProps, 'children'>;
|
|
190
|
-
children: React.ReactElement;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const Container = ({tooltipProps, children}: ContainerProps) => {
|
|
194
|
-
return tooltipProps ? (
|
|
195
|
-
<Tooltip {...tooltipProps}>{children}</Tooltip>
|
|
196
|
-
) : (
|
|
197
|
-
<React.Fragment>{children}</React.Fragment>
|
|
198
|
-
);
|
|
199
|
-
};
|
|
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
|
-
|
|
211
|
-
export const SegmentedControlItem = createSubcomponent('button')({
|
|
212
|
-
displayName: 'SegmentedControl.Item',
|
|
213
|
-
modelHook: useSegmentedControlModel,
|
|
214
|
-
elemPropsHook: useSegmentedControlItem,
|
|
215
|
-
})<ItemProps>(({children, icon, tooltipProps, ...elemProps}, Element, {state: {size}}) => {
|
|
216
|
-
const variant = getVariant(icon, children);
|
|
217
|
-
const iconSize = size === 'small' ? 'extraSmall' : 'small';
|
|
218
|
-
|
|
219
|
-
return (
|
|
220
|
-
<Container tooltipProps={tooltipProps}>
|
|
221
|
-
<BaseButton
|
|
222
|
-
as={Element}
|
|
223
|
-
{...handleCsProp(elemProps, segmentedControlItemStencil({size, variant}))}
|
|
224
|
-
>
|
|
225
|
-
{icon && <BaseButton.Icon icon={icon} size={iconSize} />}
|
|
226
|
-
{children && <Text>{children}</Text>}
|
|
227
|
-
</BaseButton>
|
|
228
|
-
</Container>
|
|
229
|
-
);
|
|
230
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import {createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling';
|
|
4
|
-
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
|
|
5
|
-
import {Grid} from '@workday/canvas-kit-react/layout';
|
|
6
|
-
import {system} from '@workday/canvas-tokens-web';
|
|
7
|
-
import {useSegmentedControlModel} from './hooks/useSegmentedControlModel';
|
|
8
|
-
import {useListRenderItems} from '@workday/canvas-kit-react/collection';
|
|
9
|
-
|
|
10
|
-
export interface SegmentedControlListProps<T = any>
|
|
11
|
-
extends Omit<Partial<ExtractProps<typeof Grid, never>>, 'children'> {
|
|
12
|
-
'aria-label': string;
|
|
13
|
-
children: ((item: T) => React.ReactNode) | React.ReactNode;
|
|
14
|
-
}
|
|
15
|
-
|
|
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
|
-
});
|
|
44
|
-
|
|
45
|
-
export const SegmentedControlList = createSubcomponent('div')({
|
|
46
|
-
displayName: 'SegmentedControl.List',
|
|
47
|
-
modelHook: useSegmentedControlModel,
|
|
48
|
-
})<SegmentedControlListProps>(({children, ...elemProps}, Element, model) => {
|
|
49
|
-
return (
|
|
50
|
-
<Element
|
|
51
|
-
role="group"
|
|
52
|
-
{...handleCsProp(
|
|
53
|
-
elemProps,
|
|
54
|
-
segmentedControlListStencil({
|
|
55
|
-
disabled: model.state.disabled,
|
|
56
|
-
items: `${model.state.items.length}`,
|
|
57
|
-
orientation: model.state.orientation,
|
|
58
|
-
})
|
|
59
|
-
)}
|
|
60
|
-
>
|
|
61
|
-
{useListRenderItems(model, children)}
|
|
62
|
-
</Element>
|
|
63
|
-
);
|
|
64
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import {createElemPropsHook, composeHooks} from '@workday/canvas-kit-react/common';
|
|
4
|
-
import {
|
|
5
|
-
useListItemRegister,
|
|
6
|
-
isSelected,
|
|
7
|
-
useListItemSelect,
|
|
8
|
-
} from '@workday/canvas-kit-react/collection';
|
|
9
|
-
import {useSegmentedControlModel} from './useSegmentedControlModel';
|
|
10
|
-
|
|
11
|
-
export const useSegmentedControlItem = composeHooks(
|
|
12
|
-
useListItemSelect,
|
|
13
|
-
createElemPropsHook(useSegmentedControlModel)(
|
|
14
|
-
(model, _, elemProps: {'data-id'?: string; children?: React.ReactNode} = {}) => {
|
|
15
|
-
const name = elemProps['data-id'] || '';
|
|
16
|
-
const selected = !!name && isSelected(name, model.state);
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
id: `${model.state.id}-${name}`,
|
|
20
|
-
'aria-pressed': selected,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
),
|
|
24
|
-
useListItemRegister,
|
|
25
|
-
createElemPropsHook(useSegmentedControlModel)(({state}) => {
|
|
26
|
-
return {
|
|
27
|
-
// override the default disabled functionality of `useListItemRegister`
|
|
28
|
-
// it shouldn't allow to set disabled state only for one button
|
|
29
|
-
// state prop will disable the whole container
|
|
30
|
-
disabled: state.disabled ? true : undefined,
|
|
31
|
-
};
|
|
32
|
-
})
|
|
33
|
-
);
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {createModelHook} from '@workday/canvas-kit-react/common';
|
|
3
|
-
import {defaultGetId, useListModel} from '@workday/canvas-kit-react/collection';
|
|
4
|
-
|
|
5
|
-
export const useSegmentedControlModel = createModelHook({
|
|
6
|
-
defaultConfig: {
|
|
7
|
-
...useListModel.defaultConfig,
|
|
8
|
-
/**
|
|
9
|
-
* Optional id for the whole `SegmentedControl` group. If not provided, a unique id will be created.
|
|
10
|
-
* @default useUniqueId()
|
|
11
|
-
*/
|
|
12
|
-
id: '',
|
|
13
|
-
/**
|
|
14
|
-
* An initially selected value. This value must match the `data-id` of the `SegmentedControl.Item` component.
|
|
15
|
-
* If not provided, the first value will be selected.
|
|
16
|
-
*/
|
|
17
|
-
initialValue: '',
|
|
18
|
-
/**
|
|
19
|
-
* Sets disabled state for all segmented control buttons
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
disabled: false,
|
|
23
|
-
/**
|
|
24
|
-
* Sets the size of the segmented control container and its buttons. Can be `small`, `medium` or `large`.
|
|
25
|
-
* @default 'medium'
|
|
26
|
-
*/
|
|
27
|
-
size: 'medium' as 'small' | 'medium' | 'large',
|
|
28
|
-
/**
|
|
29
|
-
* The SegmentedControl can rendered in a horizontal or vertical orientation.
|
|
30
|
-
* We suggest to use the `vertical` orientation only for icon only variant.
|
|
31
|
-
* @default 'horizontal'
|
|
32
|
-
*/
|
|
33
|
-
orientation: 'horizontal' as typeof useListModel.defaultConfig.orientation,
|
|
34
|
-
},
|
|
35
|
-
requiredConfig: useListModel.requiredConfig,
|
|
36
|
-
})(config => {
|
|
37
|
-
const getId = config.getId || defaultGetId;
|
|
38
|
-
const initialSelectedRef = React.useRef(config.initialValue);
|
|
39
|
-
const items = config.items;
|
|
40
|
-
|
|
41
|
-
const model = useListModel(
|
|
42
|
-
useListModel.mergeConfig(config, {
|
|
43
|
-
orientation: config.orientation || 'horizontal',
|
|
44
|
-
items,
|
|
45
|
-
onRegisterItem(data) {
|
|
46
|
-
if (!initialSelectedRef.current) {
|
|
47
|
-
initialSelectedRef.current = data.id;
|
|
48
|
-
events.select({id: initialSelectedRef.current});
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
initialSelectedIds: config.initialValue
|
|
52
|
-
? [config.initialValue]
|
|
53
|
-
: config.items?.length
|
|
54
|
-
? [getId(config.items![0])]
|
|
55
|
-
: [],
|
|
56
|
-
shouldVirtualize: false,
|
|
57
|
-
})
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const state = {
|
|
61
|
-
...model.state,
|
|
62
|
-
disabled: config.disabled,
|
|
63
|
-
size: config.size,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const events = {
|
|
67
|
-
...model.events,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
...model,
|
|
72
|
-
state,
|
|
73
|
-
events,
|
|
74
|
-
};
|
|
75
|
-
});
|