@zohodesk/components 1.0.0-temp-225-1 → 1.0.0-temp-228

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 (29) hide show
  1. package/.cli/propValidation_report.html +1 -1
  2. package/README.md +16 -21
  3. package/assets/Appearance/dark/mode/Component_v2_DarkMode.module.css +11 -0
  4. package/assets/Appearance/light/mode/Component_v2_LightMode.module.css +11 -0
  5. package/assets/Appearance/pureDark/mode/Component_v2_PureDarkMode.module.css +11 -0
  6. package/es/ListItem/ListItem.js +3 -12
  7. package/es/ListItem/ListItem.module.css +0 -9
  8. package/es/ListItem/props/propTypes.js +1 -2
  9. package/es/Provider/LibraryContext.js +3 -1
  10. package/es/components-v2/Switch/Switch.js +151 -0
  11. package/es/components-v2/Switch/contants/index.js +12 -0
  12. package/es/components-v2/Switch/css/Switch_v2.module.css +140 -0
  13. package/es/components-v2/Switch/css/cssJSLogic.js +48 -0
  14. package/es/components-v2/Switch/props/defaultProps.js +12 -0
  15. package/es/components-v2/Switch/props/propTypes.js +32 -0
  16. package/es/components-v2/Switch/useSwitch.js +29 -0
  17. package/lib/ListItem/ListItem.js +3 -12
  18. package/lib/ListItem/ListItem.module.css +0 -9
  19. package/lib/ListItem/props/propTypes.js +1 -2
  20. package/lib/Provider/LibraryContext.js +3 -1
  21. package/lib/components-v2/Switch/Switch.js +169 -0
  22. package/lib/components-v2/Switch/contants/index.js +20 -0
  23. package/lib/components-v2/Switch/css/Switch_v2.module.css +140 -0
  24. package/lib/components-v2/Switch/css/cssJSLogic.js +37 -0
  25. package/lib/components-v2/Switch/props/defaultProps.js +19 -0
  26. package/lib/components-v2/Switch/props/propTypes.js +43 -0
  27. package/lib/components-v2/Switch/useSwitch.js +52 -0
  28. package/package.json +4 -3
  29. package/result.json +1 -1
package/README.md CHANGED
@@ -32,16 +32,11 @@ In this Package, we Provide Some Basic Components to Build Web App
32
32
  - TextBoxIcon
33
33
  - Tooltip
34
34
 
35
- # 1.3.3
36
-
37
- - **ListItem**
38
- - Added `SecondaryValue` prop to supported.
39
-
40
35
  # 1.3.2
41
36
 
42
37
  - **Popup**
43
38
  - Added `scrollDebounceTime` prop to support debounce control for fixed popup scroll behavior.
44
-
39
+
45
40
  # 1.3.1
46
41
 
47
42
  - **dropDownUtils** - The isObjectContainsSearchString function logic has been updated to use some instead of filter, and additional conditions have been added to prevent potential runtime issues.
@@ -49,7 +44,7 @@ In this Package, we Provide Some Basic Components to Build Web App
49
44
  # 1.3.0
50
45
 
51
46
  - **AdvancedMultiSelect, MultiSelect, MultiSelectWithAvatar** - searchFields prop supported
52
- - **AdvancedMultiSelect, MultiSelectWithAvatar** - secondaryField prop supported
47
+ - **AdvancedMultiSelect, MultiSelectWithAvatar** - secondaryField prop supported
53
48
  - **ListContainer** - align prop supported
54
49
  - **ListItemWithAvatar** - secondaryValue, lhsAlignContent prop supported
55
50
  - **ListItemWithCheckBox, ListItemWithIcon, ListItemWithRadio** - secondaryValue, lhsAlignContent, lhsJustifyContent prop supported
@@ -67,11 +62,11 @@ In this Package, we Provide Some Basic Components to Build Web App
67
62
 
68
63
  # 1.2.61
69
64
 
70
- - **Textarea** - Handled the default height and width appropriately based on the rows and cols props.
65
+ - **Textarea** - Handled the default height and width appropriately based on the rows and cols props.
71
66
 
72
67
  # 1.2.60
73
68
 
74
- - **Textarea** - Handled the default height and width appropriately based on the rows and cols props.
69
+ - **Textarea** - Handled the default height and width appropriately based on the rows and cols props.
75
70
 
76
71
  # 1.2.59
77
72
 
@@ -84,25 +79,23 @@ In this Package, we Provide Some Basic Components to Build Web App
84
79
  # 1.2.57
85
80
 
86
81
  - **Popup**
87
-
88
82
  - Fixed popup scroll behavior is now supported using the `isOutsideScrollBlocked` flag. When set to `false` (default).
89
83
 
90
84
  - **DropBoxElement**
91
85
  - **Attributes Added**: The `data-box-direction` and `data-arrow-position` attributes have been added to facilitate the use of component-level CSS selectors.
92
86
  - **CSS Selectors**: Added support for `arrow`, `paddingSpace`, `shadow`, and `boxdirection` to facilitate the behavior of the dropbox using CSS selectors.
93
-
87
+
94
88
  # 1.2.56
95
89
 
96
- - **CheckBox**
90
+ - **CheckBox**
97
91
  - `data-selector-id` passing to Container component changed to `dataSelectorId`
98
92
 
99
93
  # 1.2.55
100
94
 
101
- - **ListItemWithAvatar**
102
-
95
+ - **ListItemWithAvatar**
103
96
  - `AvatarTeamProps` and `AvatarProps` props has been added under the `customProps` group.
104
97
 
105
- - **Tag**
98
+ - **Tag**
106
99
  - `avatarProps` and `iconProps` prop has been added under the `customProps` group.
107
100
 
108
101
  # 1.2.54
@@ -110,6 +103,7 @@ In this Package, we Provide Some Basic Components to Build Web App
110
103
  - **Reverted 1.2.45 MultiSelect Fix**
111
104
  - The issue with the non-scrollable API call trigger in multiselect, introduced in version `1.2.45`, has been `reverted` in this version.
112
105
 
106
+
113
107
  # 1.2.53
114
108
 
115
109
  - **CheckBox** - Disabled State CheckBox Color Fixed
@@ -135,7 +129,7 @@ In this Package, we Provide Some Basic Components to Build Web App
135
129
  - **DateTime (v0&v1), CalendarView (v0&v1)**
136
130
 
137
131
  - Week starting day customization support added with `weekStartDay` props and week holiday customization support with `holidays` prop
138
-
132
+
139
133
  - **DateWidget (v0&v1)**
140
134
 
141
135
  - Support has been added for `weekStartDay`, `holidays` props
@@ -144,7 +138,7 @@ In this Package, we Provide Some Basic Components to Build Web App
144
138
 
145
139
  - `holidays` prop added for holiday column indication
146
140
 
147
- # 1.2.49
141
+ # 1.2.49
148
142
 
149
143
  - **Popup**
150
144
  - `isOutsideScrollBlocked` prop supported - Scroll blocking behaviours supported
@@ -157,6 +151,7 @@ In this Package, we Provide Some Basic Components to Build Web App
157
151
  - **ResizeObserver**
158
152
 
159
153
  - The ResizeObserver PolyFill code has been removed, and a separate copy with the PolyFill included is saved under the filename ResizeObserverWithPolyfill.js
154
+
160
155
 
161
156
  # 1.2.47
162
157
 
@@ -253,10 +248,10 @@ In this Package, we Provide Some Basic Components to Build Web App
253
248
 
254
249
  - **MultiSelect**
255
250
  - `dataId` support has been added for the ResponsiveDropBox Component.
256
- - The `dataId` will be reflected as `dataId` with the suffix "\_dropbox".
251
+ - The `dataId` will be reflected as `dataId` with the suffix "_dropbox".
257
252
  - **DateWidget**
258
253
  - `dataId` support has been added for the datePicker icon.
259
- - The `dataId` will be reflected as `dataId` with the suffix "\_datePicker".
254
+ - The `dataId` will be reflected as `dataId` with the suffix "_datePicker".
260
255
 
261
256
  # 1.2.34
262
257
 
@@ -421,7 +416,7 @@ In this Package, we Provide Some Basic Components to Build Web App
421
416
 
422
417
  # 1.1.1
423
418
 
424
- - ComponentTheme file --zdt\_ prefix missing changes
419
+ - ComponentTheme file --zdt_ prefix missing changes
425
420
 
426
421
  # 1.1.0
427
422
 
@@ -449,7 +444,7 @@ In this Package, we Provide Some Basic Components to Build Web App
449
444
 
450
445
  # 1.0.0-alpha-275
451
446
 
452
- - **DateTime** - millisecond and second should work only when customDateFormat is given issue fixed. this fix related to _1.0.0-alpha-272_
447
+ - **DateTime** - millisecond and second should work only when customDateFormat is given issue fixed. this fix related to *1.0.0-alpha-272*
453
448
 
454
449
  # 1.0.0-alpha-274
455
450
 
@@ -0,0 +1,11 @@
1
+ [data-mode='dark'] {
2
+ /* switch */
3
+ --zdt_v2_switch_track_on_bg: hsla(133, 48.36%, calc(52.16% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
4
+ --zdt_v2_switch_track_off_bg: hsla(223, 21.68%, calc(28.04% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
5
+ --zdt_v2_switch_track_on_hover_bg: hsla(134, 67.66%, calc(32.75% + var(--zdc_default_inverse_lower)), calc(1 + var(--zdc_alpha_low)));
6
+ --zdt_v2_switch_track_off_hover_bg: hsla(216, 22.98%, calc(31.57% + var(--zdc_default_inverse_lower)), calc(1 + var(--zdc_alpha_low)));
7
+ --zdt_v2_switch_thumb_bg: hsla(217, 23.08%, calc(17.84% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
8
+ --zdt_v2_switch_onLabel: hsla(217, 23.08%, calc(17.84% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
9
+ --zdt_v2_switch_offLabel: hsla(217, 13.73%, calc(70.00% + var(--zdc_default_inverse_medium)), calc(1 + var(--zdc_alpha_low)));
10
+ --zdt_v2_switch_offLabel_hover: hsla(210, 7.41%, calc(89.41% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
11
+ }
@@ -0,0 +1,11 @@
1
+ [data-mode='light'] {
2
+ /* switch */
3
+ --zdt_v2_switch_track_on_bg: hsla(133, 63.29%, calc(40.59% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
4
+ --zdt_v2_switch_track_off_bg: hsla(213, 27.27%, calc(87.06% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
5
+ --zdt_v2_switch_track_on_hover_bg: hsla(134, 78.63%, calc(25.69% + var(--zdc_default_inverse_lower)), calc(1 + var(--zdc_alpha_low)));
6
+ --zdt_v2_switch_track_off_hover_bg: hsla(231, 22.22%, calc(82.35% + var(--zdc_default_inverse_lower)), calc(1 + var(--zdc_alpha_low)));
7
+ --zdt_v2_switch_thumb_bg: hsla(0, 0.00%, calc(100.00% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
8
+ --zdt_v2_switch_onLabel: hsla(0, 0.00%, calc(100.00% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
9
+ --zdt_v2_switch_offLabel: hsla(220, 10.45%, calc(39.41% + var(--zdc_default_inverse_medium)), calc(1 + var(--zdc_alpha_low)));
10
+ --zdt_v2_switch_offLabel_hover: hsla(0, 0.00%, calc(0.00% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
11
+ }
@@ -0,0 +1,11 @@
1
+ [data-mode='pureDark'] {
2
+ /* switch */
3
+ --zdt_v2_switch_track_on_bg: hsla(133, 48.36%, calc(52.16% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
4
+ --zdt_v2_switch_track_off_bg: hsla(0, 0.00%, calc(20.00% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
5
+ --zdt_v2_switch_track_on_hover_bg: hsla(134, 67.66%, calc(32.75% + var(--zdc_default_inverse_lower)), calc(1 + var(--zdc_alpha_low)));
6
+ --zdt_v2_switch_track_off_hover_bg: hsla(0, 0.00%, calc(34.51% + var(--zdc_default_inverse_lower)), calc(1 + var(--zdc_alpha_low)));
7
+ --zdt_v2_switch_thumb_bg: hsla(0, 0.00%, calc(12.94% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
8
+ --zdt_v2_switch_onLabel: hsla(0, 0.00%, calc(12.94% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
9
+ --zdt_v2_switch_offLabel: hsla(0, 0.00%, calc(60.00% + var(--zdc_default_inverse_medium)), calc(1 + var(--zdc_alpha_low)));
10
+ --zdt_v2_switch_offLabel_hover: hsla(210, 7.41%, calc(89.41% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
11
+ }
@@ -1,6 +1,6 @@
1
1
  /**** Libraries ****/
2
2
  import React from 'react';
3
- import { Container, Box } from '../Layout';
3
+ import { Box } from '../Layout';
4
4
  import ListContainer from './ListContainer';
5
5
  import { ListItemDefaultProps } from './props/defaultProps';
6
6
  import { ListItem_Props } from './props/propTypes';
@@ -70,8 +70,7 @@ export default class ListItem extends React.Component {
70
70
  a11y,
71
71
  customClass,
72
72
  customProps,
73
- needMultiLineText,
74
- secondaryValue
73
+ needMultiLineText
75
74
  } = this.props;
76
75
  let {
77
76
  ListItemProps = {},
@@ -114,11 +113,6 @@ export default class ListItem extends React.Component {
114
113
  eleRef: this.getRef,
115
114
  customProps: ListItemProps,
116
115
  ...ContainerProps
117
- }, /*#__PURE__*/React.createElement(Box, {
118
- flexible: true,
119
- className: style.leftBox
120
- }, /*#__PURE__*/React.createElement(Box, {
121
- className: style.titleBox
122
116
  }, value ? /*#__PURE__*/React.createElement(Box, {
123
117
  shrink: true,
124
118
  adjust: true,
@@ -127,10 +121,7 @@ export default class ListItem extends React.Component {
127
121
  shrink: true,
128
122
  adjust: true,
129
123
  className: style.children
130
- }, children) : null), secondaryValue ? /*#__PURE__*/React.createElement(Box, {
131
- "data-title": isDisabled ? null : secondaryValue,
132
- className: `${style.secondaryField} ${needMultiLineText ? style.multiLine : style.secondaryValue}`
133
- }, secondaryValue) : null), needTick && active ? /*#__PURE__*/React.createElement(Box, {
124
+ }, children) : null, needTick && active ? /*#__PURE__*/React.createElement(Box, {
134
125
  className: `${style.tickIcon} ${tickIconPalette} ${customTickIcon}`,
135
126
  "aria-hidden": ariaHidden,
136
127
  dataId: `${dataIdString}_tickIcon`,
@@ -250,12 +250,3 @@
250
250
  padding-top: var(--zd_size10) ;
251
251
  padding-bottom: var(--zd_size10) ;
252
252
  }
253
-
254
-
255
- .leftBox {
256
- composes: dflex flexcolumn from '../common/common.module.css';
257
- }
258
-
259
- .titleBox {
260
- composes: dflex alignVertical from '../common/common.module.css';
261
- }
@@ -64,8 +64,7 @@ export const ListItem_Props = {
64
64
  }),
65
65
  customProps: PropTypes.shape({
66
66
  ListItemProps: PropTypes.object
67
- }),
68
- secondaryValue: PropTypes.string
67
+ })
69
68
  };
70
69
  export const ListItemWithAvatar_Props = {
71
70
  active: PropTypes.bool,
@@ -9,13 +9,15 @@ const LibraryContextProvider = _ref => {
9
9
  direction,
10
10
  coloredTagVariant,
11
11
  hasTagColorInheritedToText,
12
+ shouldIndicateSwitchState,
12
13
  children
13
14
  } = _ref;
14
15
  const [value, setValue] = useState({
15
16
  isReducedMotion,
16
17
  direction,
17
18
  coloredTagVariant,
18
- hasTagColorInheritedToText
19
+ hasTagColorInheritedToText,
20
+ shouldIndicateSwitchState
19
21
  });
20
22
 
21
23
  function setGlobalContext(key, data) {
@@ -0,0 +1,151 @@
1
+ import React, { useContext } from 'react'; // props
2
+
3
+ import defaultProps from "./props/defaultProps";
4
+ import { propTypes } from "./props/propTypes"; // methods
5
+
6
+ import cssJSLogic from './css/cssJSLogic';
7
+ import { mergeStyle } from '@zohodesk/utils'; // hooks
8
+
9
+ import useSwitch from './useSwitch'; // constants
10
+
11
+ import { OFF_LABEL_RADIUS, THUMB_RADIUS } from './contants'; // components
12
+
13
+ import Flex from '@zohodesk/layout/es/Flex/Flex';
14
+ import Label from '../../Label/Label'; // context
15
+
16
+ import LibraryContext from '../../Provider/LibraryContextInit'; // css
17
+
18
+ import defaultStyle from './css/Switch_v2.module.css';
19
+
20
+ const Switch = props => {
21
+ const {
22
+ name,
23
+ value,
24
+ id,
25
+ size,
26
+ isChecked: isCheckedProp,
27
+ isDefaultChecked,
28
+ isDisabled,
29
+ isReadOnly,
30
+ onChange,
31
+ hasStateIndication,
32
+ label,
33
+ labelPlacement,
34
+ labelSize,
35
+ title,
36
+ customProps,
37
+ tagAttributes,
38
+ a11yAttributes,
39
+ customId,
40
+ testId,
41
+ customStyle
42
+ } = props;
43
+ const {
44
+ shouldIndicateSwitchState
45
+ } = useContext(LibraryContext);
46
+ const {
47
+ container: customProps_container,
48
+ label: customProps_label
49
+ } = customProps;
50
+ const {
51
+ container: tagAttributes_container,
52
+ switch: tagAttributes_switch
53
+ } = tagAttributes;
54
+ const {
55
+ container: a11yAttributes_container,
56
+ switch: a11yAttributes_switch = {},
57
+ label: a11yAttributes_label
58
+ } = a11yAttributes;
59
+ const {
60
+ role = 'switch',
61
+ ariaDisabled = isDisabled,
62
+ restA11yAttributes_switch
63
+ } = a11yAttributes_switch;
64
+ const {
65
+ isChecked,
66
+ handleChange
67
+ } = useSwitch({
68
+ isCheckedProp,
69
+ isDefaultChecked,
70
+ onChange
71
+ });
72
+ const style = mergeStyle(defaultStyle, customStyle);
73
+ const {
74
+ containerClass,
75
+ labelClass,
76
+ trackClass,
77
+ trackWrapperClass,
78
+ thumbClass,
79
+ labelIndicationClass
80
+ } = cssJSLogic({
81
+ props: { ...props,
82
+ isChecked
83
+ },
84
+ style
85
+ });
86
+ return /*#__PURE__*/React.createElement(Flex, {
87
+ $ui_displayMode: "inline",
88
+ $ui_direction: labelPlacement === 'left' ? 'row' : 'rowReverse',
89
+ $ui_alignItems: "center",
90
+ $tagAttributes_container: {
91
+ 'data-selector-id': customId,
92
+ ...tagAttributes_container
93
+ },
94
+ testId: testId,
95
+ customId: customId,
96
+ customStyle: {
97
+ inlineFlex: containerClass
98
+ },
99
+ $a11yAttributes_container: a11yAttributes_container,
100
+ ...customProps_container
101
+ }, label && /*#__PURE__*/React.createElement(Label, {
102
+ text: label,
103
+ palette: isDisabled || isReadOnly ? 'primary' : 'default',
104
+ size: labelSize,
105
+ htmlFor: id,
106
+ customClass: labelClass,
107
+ a11y: a11yAttributes_label,
108
+ ...customProps_label
109
+ }), /*#__PURE__*/React.createElement(Flex, {
110
+ $flag_shrink: false,
111
+ customStyle: {
112
+ noShrink: trackWrapperClass
113
+ }
114
+ }, /*#__PURE__*/React.createElement("input", {
115
+ type: "checkbox",
116
+ id: id,
117
+ name: name,
118
+ value: value,
119
+ checked: isChecked,
120
+ readOnly: isReadOnly,
121
+ onChange: !isDisabled && !isReadOnly ? handleChange : null,
122
+ className: trackClass,
123
+ "data-title": title,
124
+ role: role,
125
+ "aria-disabled": ariaDisabled,
126
+ ...tagAttributes_switch,
127
+ ...restA11yAttributes_switch
128
+ }), /*#__PURE__*/React.createElement("svg", {
129
+ className: thumbClass,
130
+ xmlns: "http://www.w3.org/2000/svg"
131
+ }, /*#__PURE__*/React.createElement("circle", {
132
+ cx: "50%",
133
+ cy: "50%",
134
+ r: THUMB_RADIUS[size]
135
+ })), hasStateIndication || shouldIndicateSwitchState ? /*#__PURE__*/React.createElement("svg", {
136
+ className: labelIndicationClass,
137
+ xmlns: "http://www.w3.org/2000/svg"
138
+ }, isChecked ? /*#__PURE__*/React.createElement("rect", {
139
+ width: "100%",
140
+ height: "100%",
141
+ rx: "50%"
142
+ }) : /*#__PURE__*/React.createElement("circle", {
143
+ cx: "50%",
144
+ cy: "50%",
145
+ r: OFF_LABEL_RADIUS[size]
146
+ })) : null));
147
+ };
148
+
149
+ export default Switch;
150
+ Switch.defaultProps = defaultProps;
151
+ Switch.propTypes = propTypes;
@@ -0,0 +1,12 @@
1
+ export const OFF_LABEL_RADIUS = {
2
+ small: '35.7%',
3
+ medium: '37.5%',
4
+ large: '38.9%',
5
+ xlarge: '40%'
6
+ };
7
+ export const THUMB_RADIUS = {
8
+ small: '40%',
9
+ medium: '42.85%',
10
+ large: '44.45%',
11
+ xlarge: '45.45%'
12
+ };
@@ -0,0 +1,140 @@
1
+ .container {
2
+ --switch-cursor: pointer;
3
+ --switch-offLabel-stroke: var(--zdt_v2_switch_offLabel);
4
+ gap: var(--zd_size6) ;
5
+ }
6
+ .small {
7
+ --switch-track-width: var(--zd_size22);
8
+ --switch-track-height: var(--zd_size12);
9
+ --switch-track-border-radius: 8px;
10
+ --switch-thumb-size: 10px;
11
+ --switch-onLabel-height: var(--zd_size6);
12
+ --switch-onLabel-left: var(--zd_size5);
13
+ --switch-offLabel-size: var(--zd_size7);
14
+ --switch-offLabel-right: var(--zd_size2);
15
+ }
16
+ .medium {
17
+ --switch-track-width: var(--zd_size28);
18
+ --switch-track-height: var(--zd_size16);
19
+ --switch-track-border-radius: 16px;
20
+ --switch-thumb-size: 14px;
21
+ --switch-onLabel-height: var(--zd_size8);
22
+ --switch-onLabel-left: var(--zd_size6);
23
+ --switch-offLabel-size: var(--zd_size8);
24
+ --switch-offLabel-right: var(--zd_size3);
25
+ }
26
+ .large {
27
+ --switch-track-width: var(--zd_size34);
28
+ --switch-track-height: var(--zd_size20);
29
+ --switch-track-border-radius: 10px;
30
+ --switch-thumb-size: 18px;
31
+ --switch-onLabel-height: var(--zd_size10);
32
+ --switch-onLabel-left: var(--zd_size7);
33
+ --switch-offLabel-size: var(--zd_size9);
34
+ --switch-offLabel-right: var(--zd_size4);
35
+ }
36
+ .xlarge {
37
+ --switch-track-width: var(--zd_size40);
38
+ --switch-track-height: var(--zd_size24);
39
+ --switch-track-border-radius: 12px;
40
+ --switch-thumb-size: 22px;
41
+ --switch-onLabel-height: var(--zd_size12);
42
+ --switch-onLabel-left: var(--zd_size8);
43
+ --switch-offLabel-size: var(--zd_size10);
44
+ --switch-offLabel-right: var(--zd_size5);
45
+ }
46
+ .checked {
47
+ --switch-track-background-color: var(--zdt_v2_switch_track_on_bg);
48
+ --switch-thumb-translateX-value: calc(var(--switch-track-width) - var(--switch-thumb-size) - 2px)
49
+ }
50
+ .unChecked {
51
+ --switch-track-background-color: var(--zdt_v2_switch_track_off_bg);
52
+ --switch-thumb-translateX-value: 0;
53
+ }
54
+ .disabled, .readonly {
55
+ --switch-cursor: not-allowed;
56
+ }
57
+ .checked.enabled:hover {
58
+ --switch-track-background-color: var(--zdt_v2_switch_track_on_hover_bg);
59
+ }
60
+ .unChecked.enabled:hover {
61
+ --switch-track-background-color: var(--zdt_v2_switch_track_off_hover_bg);
62
+ }
63
+ .enabled:hover {
64
+ --switch-offLabel-stroke: var(--zdt_v2_switch_offLabel_hover);
65
+ }
66
+ .trackWrapper {
67
+ position: relative;
68
+ }
69
+ .disabled .trackWrapper {
70
+ opacity: 0.4;
71
+ }
72
+ .track {
73
+ appearance: none;
74
+ display: block;
75
+ position: relative;
76
+ height: var(--switch-track-height);
77
+ width: var(--switch-track-width);
78
+ margin: 0 ;
79
+ border-radius: var(--switch-track-border-radius);
80
+ background-color: var(--switch-track-background-color);
81
+ cursor: var(--switch-cursor);
82
+ }
83
+ .commonSvg {
84
+ display: block;
85
+ position: absolute;
86
+ pointer-events: none;
87
+ top: 50% ;
88
+ }
89
+ .thumb {
90
+ transition: transform var(--zd_transition2) cubic-bezier(0.4, 0, 0.2, 1);
91
+ fill: var(--zdt_v2_switch_thumb_bg);
92
+ height: var(--switch-thumb-size);
93
+ width: var(--switch-thumb-size);
94
+ transform: translateX(var(--switch-thumb-translateX-value)) translateY(-50%);
95
+ }
96
+ [dir=ltr] .thumb {
97
+ left: var(--zd_size1) ;
98
+ }
99
+ [dir=rtl] .thumb {
100
+ right: var(--zd_size1) ;
101
+ }
102
+ .label {
103
+ cursor: var(--switch-cursor);
104
+ }
105
+ .onLabel {
106
+ height: var(--switch-onLabel-height);
107
+ fill: var(--zdt_v2_switch_onLabel);
108
+ transform: translateY(-50%);
109
+ }
110
+ [dir=ltr] .onLabel {
111
+ left: var(--switch-onLabel-left);
112
+ }
113
+ [dir=rtl] .onLabel {
114
+ right: var(--switch-onLabel-left);
115
+ }
116
+ .offLabel {
117
+ height: var(--switch-offLabel-size);
118
+ width: var(--switch-offLabel-size);
119
+ fill: transparent;
120
+ stroke: var(--switch-offLabel-stroke);
121
+ transform: translateY(-50%);
122
+ }
123
+ [dir=ltr] .offLabel {
124
+ right: var(--switch-offLabel-right);
125
+ }
126
+ [dir=rtl] .offLabel {
127
+ left: var(--switch-offLabel-right);
128
+ }
129
+ .small .onLabel {
130
+ width: 1.2px;
131
+ }
132
+ .medium .onLabel {
133
+ width: 1.4px;
134
+ }
135
+ .large .onLabel {
136
+ width: 1.6px;
137
+ }
138
+ .xlarge .onLabel {
139
+ width: 1.8px;
140
+ }
@@ -0,0 +1,48 @@
1
+ import compileClassNames from '@zohodesk/utils/es/compileClassNames';
2
+ export default function cssJSLogic(_ref) {
3
+ let {
4
+ props,
5
+ style
6
+ } = _ref;
7
+ const {
8
+ size,
9
+ isChecked,
10
+ isDisabled,
11
+ isReadOnly
12
+ } = props;
13
+ let containerClass = compileClassNames({
14
+ [style.container]: true,
15
+ [style[size]]: true,
16
+ [style.checked]: isChecked,
17
+ [style.unChecked]: !isChecked,
18
+ [style.disabled]: isDisabled,
19
+ [style.enabled]: !isDisabled,
20
+ [style.readonly]: isReadOnly
21
+ });
22
+ let trackClass = compileClassNames({
23
+ [style.track]: true
24
+ });
25
+ let labelClass = compileClassNames({
26
+ [style.label]: true
27
+ });
28
+ let trackWrapperClass = compileClassNames({
29
+ [style.trackWrapper]: true
30
+ });
31
+ let thumbClass = compileClassNames({
32
+ [style.thumb]: true,
33
+ [style.commonSvg]: true
34
+ });
35
+ let labelIndicationClass = compileClassNames({
36
+ [style.onLabel]: isChecked,
37
+ [style.offLabel]: !isChecked,
38
+ [style.commonSvg]: true
39
+ });
40
+ return {
41
+ containerClass,
42
+ trackClass,
43
+ labelClass,
44
+ trackWrapperClass,
45
+ thumbClass,
46
+ labelIndicationClass
47
+ };
48
+ }
@@ -0,0 +1,12 @@
1
+ export default {
2
+ size: 'medium',
3
+ isDisabled: false,
4
+ isReadOnly: false,
5
+ // hasStateIndication: true,
6
+ labelPlacement: 'left',
7
+ labelSize: 'medium',
8
+ customProps: {},
9
+ tagAttributes: {},
10
+ a11yAttributes: {},
11
+ customStyle: {}
12
+ };
@@ -0,0 +1,32 @@
1
+ import PropTypes from 'prop-types';
2
+ export default {
3
+ name: PropTypes.string,
4
+ value: PropTypes.string,
5
+ id: PropTypes.string,
6
+ size: PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']),
7
+ isChecked: PropTypes.bool,
8
+ isDisabled: PropTypes.bool,
9
+ isReadOnly: PropTypes.bool,
10
+ onChange: PropTypes.func,
11
+ hasStateIndication: PropTypes.bool,
12
+ label: PropTypes.string,
13
+ labelPlacement: PropTypes.oneOf(['left', 'right']),
14
+ labelSize: PropTypes.oneOf(['xsmall', 'small', 'medium', 'large']),
15
+ title: PropTypes.string,
16
+ customProps: PropTypes.shape({
17
+ container: PropTypes.object,
18
+ label: PropTypes.object
19
+ }),
20
+ tagAttributes: PropTypes.shape({
21
+ container: PropTypes.object,
22
+ switch: PropTypes.object
23
+ }),
24
+ a11yAttributes: PropTypes.shape({
25
+ container: PropTypes.object,
26
+ switch: PropTypes.object,
27
+ label: PropTypes.object
28
+ }),
29
+ customId: PropTypes.string,
30
+ testId: PropTypes.string,
31
+ customStyle: PropTypes.object
32
+ };
@@ -0,0 +1,29 @@
1
+ import { useState } from "react";
2
+
3
+ const useSwitch = props => {
4
+ const {
5
+ isCheckedProp,
6
+ isDefaultChecked,
7
+ onChange
8
+ } = props;
9
+ const isControlled = isCheckedProp !== undefined;
10
+ const [internalChecked, setInternalChecked] = useState(isDefaultChecked);
11
+ const isChecked = isControlled ? isCheckedProp : internalChecked;
12
+
13
+ const handleChange = e => {
14
+ if (!isControlled) {
15
+ setInternalChecked(!isChecked);
16
+ }
17
+
18
+ if (onChange) {
19
+ onChange(!isChecked, e);
20
+ }
21
+ };
22
+
23
+ return {
24
+ isChecked,
25
+ handleChange
26
+ };
27
+ };
28
+
29
+ export default useSwitch;