@workday/canvas-kit-docs 7.0.14 → 7.0.15

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.
@@ -0,0 +1,12 @@
1
+ import Basic from './examples/SegmentControlWithText';
2
+
3
+
4
+ # Canvas Kit Examples
5
+
6
+ ## SegmentControl With Text
7
+
8
+ As of `v7`, IconButton was removed, so SegmentControl was changed to support new buttons with
9
+ icon only. This example shows how you use SegmentControl with text until CK
10
+ starts supporting text in SegmentControl buttons. If you'd like to follow along, we have an [open issue](https://github.com/Workday/canvas-kit/issues/207) to enhance the SegmentedControl
11
+
12
+ <ExampleCodeBlock code={Basic} />
@@ -0,0 +1,119 @@
1
+ import * as React from 'react';
2
+
3
+ import {SegmentedControl} from '@workday/canvas-kit-react/segmented-control';
4
+ import {
5
+ styled,
6
+ StyledType,
7
+ ExtractProps,
8
+ mouseFocusBehavior,
9
+ } from '@workday/canvas-kit-react/common';
10
+ import {colors, borderRadius, space} from '@workday/canvas-kit-react/tokens';
11
+ import {BaseButton, ButtonColors} from '@workday/canvas-kit-react/button';
12
+ import {CanvasIconTypes, CanvasSystemIcon} from '@workday/design-assets-types';
13
+ const placeholderIcon: CanvasSystemIcon = {
14
+ name: '',
15
+ svg: '',
16
+ filename: '',
17
+ type: CanvasIconTypes.System,
18
+ };
19
+
20
+ const getIconButtonColors = (toggled?: boolean): ButtonColors => {
21
+ return {
22
+ default: {
23
+ background: toggled ? colors.blueberry400 : colors.soap200,
24
+ icon: toggled ? colors.frenchVanilla100 : colors.licorice200,
25
+ label: toggled ? colors.frenchVanilla100 : colors.licorice200,
26
+ },
27
+ hover: {
28
+ background: toggled ? colors.blueberry400 : colors.soap300,
29
+ icon: toggled ? colors.frenchVanilla100 : colors.licorice500,
30
+ label: toggled ? colors.frenchVanilla100 : colors.licorice500,
31
+ },
32
+ active: {
33
+ background: toggled ? colors.blueberry400 : colors.soap500,
34
+ icon: toggled ? colors.frenchVanilla100 : colors.licorice500,
35
+ label: toggled ? colors.frenchVanilla100 : colors.licorice500,
36
+ },
37
+ focus: {
38
+ background: toggled ? colors.blueberry400 : undefined,
39
+ icon: toggled ? colors.frenchVanilla100 : colors.licorice500,
40
+ label: toggled ? colors.frenchVanilla100 : colors.licorice500,
41
+ },
42
+ disabled: {
43
+ background: toggled ? colors.soap100 : colors.soap100,
44
+ icon: colors.soap600,
45
+ label: colors.soap600,
46
+ opacity: '1',
47
+ },
48
+ };
49
+ };
50
+
51
+ const StyledBaseButton = styled(BaseButton)<
52
+ ExtractProps<typeof SegmentedControl.Button> & StyledType
53
+ >({
54
+ borderRadius: borderRadius.zero,
55
+ border: `1px solid ${colors.soap500}`,
56
+ borderLeft: 'none',
57
+ minWidth: space.xxxl,
58
+ '&:first-of-type': {
59
+ borderRadius: `${borderRadius.m} 0 0 ${borderRadius.m}`,
60
+ borderLeft: `1px solid ${colors.soap500}`,
61
+ },
62
+ '&:last-of-type': {
63
+ borderRadius: `0 ${borderRadius.m} ${borderRadius.m} 0`,
64
+ },
65
+ '&[aria-pressed="true"]': {
66
+ borderColor: `${colors.blueberry400} !important`,
67
+ '&:hover, &:focus:hover': {
68
+ background: colors.blueberry400,
69
+ },
70
+ },
71
+ '&:focus': {
72
+ borderRadius: borderRadius.m,
73
+ zIndex: 1,
74
+ animation: 'none', // reset focusRing animation
75
+ transition: 'all 120ms, border-radius 1ms',
76
+ ...mouseFocusBehavior({
77
+ '&': {
78
+ borderRadius: borderRadius.zero,
79
+ '&:first-of-type': {
80
+ borderRadius: `${borderRadius.m} 0 0 ${borderRadius.m}`,
81
+ },
82
+ '&:last-of-type': {
83
+ borderRadius: `0 ${borderRadius.m} ${borderRadius.m} 0`,
84
+ },
85
+ },
86
+ }),
87
+ },
88
+ });
89
+
90
+ export default () => {
91
+ const [value, setValue] = React.useState<string | number>('day');
92
+ const handleToggle = (selectedValue: string | number) => {
93
+ setValue(selectedValue);
94
+ };
95
+
96
+ const isDayToggled = value === 'day';
97
+ const isWeekToggled = value === 'week';
98
+
99
+ return (
100
+ <SegmentedControl value={value} onChange={handleToggle}>
101
+ <StyledBaseButton
102
+ icon={{...placeholderIcon}}
103
+ colors={getIconButtonColors(isDayToggled)}
104
+ value="day"
105
+ onClick={() => setValue('day')}
106
+ >
107
+ Day
108
+ </StyledBaseButton>
109
+ <StyledBaseButton
110
+ icon={placeholderIcon}
111
+ colors={getIconButtonColors(isWeekToggled)}
112
+ value="week"
113
+ onClick={() => setValue('week')}
114
+ >
115
+ Week
116
+ </StyledBaseButton>
117
+ </SegmentedControl>
118
+ );
119
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "7.0.14",
3
+ "version": "7.0.15",
4
4
  "description": "Documentation components of Canvas Kit components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -42,7 +42,7 @@
42
42
  ],
43
43
  "dependencies": {
44
44
  "@storybook/csf": "0.0.1",
45
- "@workday/canvas-kit-react": "^7.0.14"
45
+ "@workday/canvas-kit-react": "^7.0.15"
46
46
  },
47
47
  "devDependencies": {
48
48
  "fs-extra": "^10.0.0",
@@ -50,5 +50,5 @@
50
50
  "mkdirp": "^1.0.3",
51
51
  "typescript": "4.1"
52
52
  },
53
- "gitHead": "2b90a264804b74bafd284ac6aab74e50c304ad1e"
53
+ "gitHead": "a3d89e1625d00adac2123f572030a082b6fd8ef8"
54
54
  }