@zohodesk/components 1.0.0-temp-219.3 → 1.0.0-temp-229.1

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 (46) hide show
  1. package/.cli/config/variables/variableMapping.json +8 -1
  2. package/.cli/propValidation_report.html +1 -1
  3. package/README.md +13 -0
  4. package/assets/Appearance/dark/mode/Component_v1_DarkMode.module.css +11 -0
  5. package/assets/Appearance/light/mode/Component_v1_LightMode.module.css +11 -0
  6. package/assets/Appearance/pureDark/mode/Component_v1_PureDarkMode.module.css +11 -0
  7. package/es/AppContainer/AppContainer.js +5 -4
  8. package/es/Card/Card.js +39 -10
  9. package/es/Card/props/defaultProps.js +2 -1
  10. package/es/Card/props/propTypes.js +2 -1
  11. package/es/CheckBox/CheckBox.js +2 -9
  12. package/es/Label/Label.js +2 -9
  13. package/es/Provider/LibraryContext.js +7 -3
  14. package/es/deprecated/Switch/Switch.js +94 -0
  15. package/es/deprecated/Switch/props/defaultProps.js +11 -0
  16. package/es/deprecated/Switch/props/propTypes.js +28 -0
  17. package/es/v1/Switch/Switch.js +122 -78
  18. package/es/v1/Switch/__tests__/Switch.spec.js +30 -0
  19. package/es/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
  20. package/es/v1/Switch/contants/index.js +24 -0
  21. package/es/v1/Switch/css/Switch_v1.module.css +134 -0
  22. package/es/v1/Switch/css/cssJSLogic.js +48 -0
  23. package/es/v1/Switch/props/defaultProps.js +8 -8
  24. package/es/v1/Switch/props/propTypes.js +30 -22
  25. package/es/v1/Switch/useSwitch.js +33 -0
  26. package/lib/AppContainer/AppContainer.js +7 -6
  27. package/lib/Card/Card.js +54 -25
  28. package/lib/Card/props/defaultProps.js +2 -1
  29. package/lib/Card/props/propTypes.js +2 -1
  30. package/lib/CheckBox/CheckBox.js +2 -9
  31. package/lib/Label/Label.js +2 -9
  32. package/lib/Provider/LibraryContext.js +7 -3
  33. package/lib/deprecated/Switch/Switch.js +108 -0
  34. package/lib/deprecated/Switch/props/defaultProps.js +18 -0
  35. package/lib/deprecated/Switch/props/propTypes.js +39 -0
  36. package/lib/v1/Switch/Switch.js +130 -79
  37. package/lib/v1/Switch/__tests__/Switch.spec.js +37 -0
  38. package/lib/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
  39. package/lib/v1/Switch/contants/index.js +34 -0
  40. package/lib/v1/Switch/css/Switch_v1.module.css +134 -0
  41. package/lib/v1/Switch/css/cssJSLogic.js +37 -0
  42. package/lib/v1/Switch/props/defaultProps.js +10 -10
  43. package/lib/v1/Switch/props/propTypes.js +32 -24
  44. package/lib/v1/Switch/useSwitch.js +56 -0
  45. package/package.json +10 -8
  46. package/result.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development across projects.
4
4
 
5
+ # 1.4.1
6
+
7
+ - **Switch(v1)** - labelPlacement top | bottom alignment and hover style issue fixed.
8
+
9
+ # 1.4.0
10
+
11
+ - **Switch(v1)** - Existing v1 Switch moved to depreacated folder and all New component Switch created with required accessibility and customization.
12
+ - Theme entry for component_v1 added.
13
+ - **LibraryContext** - `shouldIndicateSwitchState` key added for Switch component.
14
+
15
+ # 1.3.5
16
+
17
+ - **AppContainer** - Memory leak issue resolved.
5
18
 
6
19
  # 1.3.4
7
20
 
@@ -0,0 +1,11 @@
1
+ [data-mode='dark'] {
2
+ /* switch */
3
+ --zdt_v1_switch_track_on_bg: hsla(133, 48.36%, calc(52.16% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
4
+ --zdt_v1_switch_track_off_bg: hsla(223, 21.68%, calc(28.04% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
5
+ --zdt_v1_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_v1_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_v1_switch_thumb_bg: hsla(217, 23.08%, calc(17.84% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
8
+ --zdt_v1_switch_onLabel: hsla(217, 23.08%, calc(17.84% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
9
+ --zdt_v1_switch_offLabel: hsla(217, 13.73%, calc(70.00% + var(--zdc_default_inverse_medium)), calc(1 + var(--zdc_alpha_low)));
10
+ --zdt_v1_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_v1_switch_track_on_bg: hsla(133, 63.29%, calc(40.59% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
4
+ --zdt_v1_switch_track_off_bg: hsla(213, 27.27%, calc(87.06% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
5
+ --zdt_v1_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_v1_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_v1_switch_thumb_bg: hsla(0, 0.00%, calc(100.00% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
8
+ --zdt_v1_switch_onLabel: hsla(0, 0.00%, calc(100.00% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
9
+ --zdt_v1_switch_offLabel: hsla(220, 10.45%, calc(39.41% + var(--zdc_default_inverse_medium)), calc(1 + var(--zdc_alpha_low)));
10
+ --zdt_v1_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_v1_switch_track_on_bg: hsla(133, 48.36%, calc(52.16% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
4
+ --zdt_v1_switch_track_off_bg: hsla(0, 0.00%, calc(20.00% + var(--zdc_default_inverse_low)), calc(1 + var(--zdc_alpha_low)));
5
+ --zdt_v1_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_v1_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_v1_switch_thumb_bg: hsla(0, 0.00%, calc(12.94% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
8
+ --zdt_v1_switch_onLabel: hsla(0, 0.00%, calc(12.94% + var(--zdc_default)), calc(1 + var(--zdc_alpha_high)));
9
+ --zdt_v1_switch_offLabel: hsla(0, 0.00%, calc(60.00% + var(--zdc_default_inverse_medium)), calc(1 + var(--zdc_alpha_low)));
10
+ --zdt_v1_switch_offLabel_hover: hsla(210, 7.41%, calc(89.41% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
11
+ }
@@ -81,12 +81,13 @@ export default class AppContainer extends React.Component {
81
81
 
82
82
  if (this.containerElement && needTooltip) {
83
83
  this.containerElement.removeEventListener('mouseover', this.handleOver, false);
84
- this.containerElement.addEventListener('mouseout', this.removeTimeout, false);
84
+ this.containerElement.removeEventListener('mouseout', this.removeTimeout, false);
85
85
  this.tooltipRef.unObserveElement();
86
- setLibraryConfig({
87
- getTooltipContainer: () => null
88
- });
89
86
  }
87
+
88
+ setLibraryConfig({
89
+ getTooltipContainer: () => null
90
+ });
90
91
  }
91
92
 
92
93
  render() {
package/es/Card/Card.js CHANGED
@@ -96,7 +96,9 @@ export default class Card extends Component {
96
96
  this.to = from + 3 * limit;
97
97
  this.isFetching = false;
98
98
  this.lastScrollTop = 0;
99
- this.onScroll = this.onScroll.bind(this); //this.onSetScroll = debounce(this.setScroll.bind(this, true), 10, true);
99
+ this.onScroll = this.onScroll.bind(this);
100
+ this.setScrollRef = this.setScrollRef.bind(this);
101
+ this.childEleRef = null; //this.onSetScroll = debounce(this.setScroll.bind(this, true), 10, true);
100
102
  //this.onClearScroll = debounce(this.setScroll.bind(this, false), 500);
101
103
  }
102
104
 
@@ -127,8 +129,11 @@ export default class Card extends Component {
127
129
  scrollAt,
128
130
  noNeedUpScroll,
129
131
  // isScrollShadow,
130
- isPercentageScroll
132
+ isPercentageScroll,
133
+ isRecentOnBottom
131
134
  } = this.props;
135
+ const scrollLimitHeight = scrollHeight - scrollAt;
136
+ const currentVisibleBottom = scrollTop + offsetHeight;
132
137
 
133
138
  if (scrollTop > this.lastScrollTop) {
134
139
  this.scrollDirection = 'down';
@@ -139,9 +144,12 @@ export default class Card extends Component {
139
144
  this.lastScrollTop = scrollTop;
140
145
 
141
146
  if (fetchData && !this.isFetching) {
142
- if (this.scrollDirection === 'down' && !noMoreData) {
143
- const scrollingPercentage = (scrollTop + offsetHeight) / (scrollHeight - scrollAt) * 100;
144
- const prefetch = isPercentageScroll ? scrollingPercentage >= getLibraryConfig('scrollFetchLimit') : scrollHeight - scrollAt <= scrollTop + offsetHeight;
147
+ const fetchDirection = isRecentOnBottom ? 'up' : 'down';
148
+
149
+ if (this.scrollDirection === fetchDirection && !noMoreData) {
150
+ const scrollingPercentage = currentVisibleBottom / scrollLimitHeight * 100;
151
+ const scrolledUpPercentage = (scrollHeight - scrollTop) / scrollLimitHeight * 100;
152
+ const prefetch = isRecentOnBottom ? isPercentageScroll ? scrolledUpPercentage >= getLibraryConfig('scrollFetchLimit') : scrollTop <= scrollAt : isPercentageScroll ? scrollingPercentage >= getLibraryConfig('scrollFetchLimit') : scrollLimitHeight <= currentVisibleBottom;
145
153
 
146
154
  if (prefetch) {
147
155
  this.isFetching = true;
@@ -153,7 +161,9 @@ export default class Card extends Component {
153
161
  });
154
162
  }
155
163
  } else {
156
- if (0 >= scrollTop - scrollAt && this.from !== 0 && !noNeedUpScroll) {
164
+ const prefetch = isRecentOnBottom ? scrollLimitHeight <= currentVisibleBottom : 0 >= scrollTop - scrollAt;
165
+
166
+ if (prefetch && this.from !== 0 && !noNeedUpScroll) {
157
167
  this.isFetching = true;
158
168
  fetchData(this.from - this.limit, this.to - this.limit, this.scrollDirection).then(() => {
159
169
  this.to = this.to - this.limit;
@@ -166,9 +176,12 @@ export default class Card extends Component {
166
176
  }
167
177
 
168
178
  if (fetchData && !noNeedUpScroll) {
169
- if (this.from !== 0 && scrollTop === 0 && !noNeedUpScroll) {
170
- scrollContainerObj.scrollTop = scrollTop + offsetHeight / 3;
171
- } else if (scrollHeight === scrollTop + offsetHeight && !noMoreData) {
179
+ const topFetch = isRecentOnBottom ? !noMoreData : !noNeedUpScroll;
180
+ const bottomFetch = isRecentOnBottom ? !noNeedUpScroll : !noMoreData;
181
+
182
+ if (this.from !== 0 && scrollTop === 0 && topFetch) {
183
+ scrollContainerObj.scrollTop = currentVisibleBottom / 3;
184
+ } else if (scrollHeight === currentVisibleBottom && bottomFetch) {
172
185
  scrollContainerObj.scrollTop = scrollTop - offsetHeight / 2;
173
186
  }
174
187
  } // if (isScrollShadow) {
@@ -187,6 +200,21 @@ export default class Card extends Component {
187
200
  // }
188
201
 
189
202
 
203
+ setScrollRef(el) {
204
+ const {
205
+ scrollAt,
206
+ isRecentOnBottom
207
+ } = this.props;
208
+
209
+ if (el && isRecentOnBottom) {
210
+ requestAnimationFrame(() => {
211
+ el.scrollTop = el.scrollHeight + Number(scrollAt);
212
+ });
213
+ }
214
+
215
+ this.childEleRef && this.childEleRef(el);
216
+ }
217
+
190
218
  render() {
191
219
  let {
192
220
  onClick,
@@ -220,6 +248,7 @@ export default class Card extends Component {
220
248
  isScroll
221
249
  });
222
250
  } else if (child.type === CardContent || this.props.childTypes && child.type === this.props.childTypes.cardContent) {
251
+ this.childEleRef = child.props.eleRef;
223
252
  return /*#__PURE__*/React.createElement(Box, {
224
253
  id: htmlId,
225
254
  role: role,
@@ -227,7 +256,7 @@ export default class Card extends Component {
227
256
  scroll: child.props.scroll,
228
257
  preventParentScroll: child.props.preventParentScroll,
229
258
  onScroll: this.onScroll,
230
- eleRef: child.props.eleRef,
259
+ eleRef: this.setScrollRef,
231
260
  isScrollAttribute: child.props.isScrollAttribute,
232
261
  dataId: child.props.dataId,
233
262
  shrink: child.props.shrink,
@@ -4,7 +4,8 @@ export const Card_defaultProps = {
4
4
  onClick: null,
5
5
  scrollAt: '10',
6
6
  a11y: {},
7
- isPercentageScroll: false
7
+ isPercentageScroll: false,
8
+ isRecentOnBottom: false
8
9
  };
9
10
  export const CardHeader_defaultProps = {
10
11
  dataId: 'CardHeader',
@@ -38,7 +38,8 @@ export const Card_propTypes = {
38
38
  role: PropTypes.string
39
39
  }),
40
40
  isPercentageScroll: PropTypes.bool,
41
- eleRef: PropTypes.func
41
+ eleRef: PropTypes.func,
42
+ isRecentOnBottom: PropTypes.bool
42
43
  };
43
44
  export const CardFooter_propTypes = {
44
45
  children: PropTypes.node,
@@ -1,13 +1,11 @@
1
1
  import React from 'react';
2
2
  import { propTypes } from "./props/propTypes";
3
3
  import { defaultProps } from "./props/defaultProps";
4
- import { withComponentRegistrar } from '@zohodesk/dotkit/es/react/ComponentRegistry';
5
4
  import Label from "../Label/Label";
6
5
  import { Container, Box } from "../Layout";
7
6
  import CssProvider from "../Provider/CssProvider";
8
7
  import style from "./CheckBox.module.css";
9
-
10
- class CheckBox extends React.Component {
8
+ export default class CheckBox extends React.Component {
11
9
  constructor(props) {
12
10
  super(props);
13
11
  this.onChange = this.onChange.bind(this);
@@ -165,15 +163,10 @@ class CheckBox extends React.Component {
165
163
  }
166
164
 
167
165
  }
168
-
169
166
  CheckBox.defaultProps = defaultProps;
170
167
  CheckBox.propTypes = propTypes; // if (__DOCS__) {
171
168
  // CheckBox.docs = {
172
169
  // componentGroup: 'Form Elements',
173
170
  // folderName: 'Style Guide'
174
171
  // };
175
- // }
176
-
177
- export default withComponentRegistrar(CheckBox, {
178
- name: 'ZDC_CheckBox'
179
- });
172
+ // }
package/es/Label/Label.js CHANGED
@@ -4,11 +4,9 @@
4
4
  import React from 'react';
5
5
  import { defaultProps } from "./props/defaultProps";
6
6
  import { propTypes } from "./props/propTypes";
7
- import { withComponentRegistrar } from '@zohodesk/dotkit/es/react/ComponentRegistry';
8
7
  import style from "./Label.module.css";
9
8
  import colors from "./LabelColors.module.css";
10
-
11
- class Label extends React.Component {
9
+ export default class Label extends React.Component {
12
10
  render() {
13
11
  let {
14
12
  text,
@@ -44,15 +42,10 @@ class Label extends React.Component {
44
42
  }
45
43
 
46
44
  }
47
-
48
45
  Label.defaultProps = defaultProps;
49
46
  Label.propTypes = propTypes; // if (__DOCS__) {
50
47
  // Label.docs = {
51
48
  // componentGroup: 'Form Elements',
52
49
  // folderName: 'Style Guide'
53
50
  // };
54
- // }
55
-
56
- export default withComponentRegistrar(Label, {
57
- name: 'ZDC_Label'
58
- });
51
+ // }
@@ -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) {
@@ -38,12 +40,14 @@ LibraryContextProvider.propTypes = {
38
40
  isReducedMotion: PropTypes.bool,
39
41
  coloredTagVariant: PropTypes.oneOf(['bold', 'subtle', 'minimal']),
40
42
  hasTagColorInheritedToText: PropTypes.bool,
41
- direction: PropTypes.string
43
+ direction: PropTypes.string,
44
+ shouldIndicateSwitchState: PropTypes.bool
42
45
  };
43
46
  LibraryContextProvider.defaultProps = {
44
47
  isReducedMotion: getLibraryConfig('isReducedMotion'),
45
48
  direction: getLibraryConfig('direction'),
46
49
  coloredTagVariant: 'bold',
47
- hasTagColorInheritedToText: true
50
+ hasTagColorInheritedToText: true,
51
+ shouldIndicateSwitchState: false
48
52
  };
49
53
  export default LibraryContextProvider;
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { defaultProps } from "./props/defaultProps";
3
+ import { propTypes } from "./props/propTypes";
4
+ import { Container, Box } from "../../v1/Layout";
5
+ import Label from "../../v1/Label/Label";
6
+ import style from "../../Switch/Switch.module.css";
7
+
8
+ const Switch = props => {
9
+ let {
10
+ id,
11
+ name,
12
+ value,
13
+ checked,
14
+ disabled,
15
+ isReadOnly,
16
+ size,
17
+ text,
18
+ labelSize,
19
+ labelPalette,
20
+ title,
21
+ disableTitle,
22
+ dataId,
23
+ dataSelectorId,
24
+ customClass,
25
+ customProps
26
+ } = props;
27
+
28
+ function onChange(e) {
29
+ const {
30
+ onChange
31
+ } = props;
32
+ onChange && onChange(!checked, e);
33
+ }
34
+
35
+ let {
36
+ SwitchProps = {},
37
+ LabelProps = {}
38
+ } = customProps;
39
+ let {
40
+ customSwitchWrap = '',
41
+ customSwitch = '',
42
+ customSwitchSize = '',
43
+ customLabel = ''
44
+ } = customClass;
45
+ size !== 'small' ? size = 'switch_medium' : size = 'switch_small';
46
+ return /*#__PURE__*/React.createElement(Container, {
47
+ align: "vertical",
48
+ isCover: false,
49
+ alignBox: "row",
50
+ isInline: true,
51
+ className: `${style.container} ${customSwitchWrap} ${disabled ? style.disabled : isReadOnly ? style.readonly : style.effect}`,
52
+ "data-title": disabled ? disableTitle : title,
53
+ "aria-checked": checked,
54
+ role: "switch",
55
+ dataSelectorId: dataSelectorId,
56
+ ...SwitchProps
57
+ }, /*#__PURE__*/React.createElement(Box, {
58
+ className: `${style[size]} ${customSwitchSize}`
59
+ }, /*#__PURE__*/React.createElement("input", {
60
+ type: "checkbox",
61
+ id: id,
62
+ className: `${style.input} ${checked ? style.checked : ''}`,
63
+ name: name,
64
+ value: value,
65
+ checked: checked,
66
+ disabled: disabled,
67
+ readOnly: isReadOnly,
68
+ onClick: !disabled || !isReadOnly ? onChange : null
69
+ }), /*#__PURE__*/React.createElement("label", {
70
+ htmlFor: id,
71
+ "data-id": dataId,
72
+ "data-test-id": dataId,
73
+ className: `${style.label} ${style[`${size}Label`]} ${customSwitch}`,
74
+ tabIndex: isReadOnly || disabled ? '-1' : '0'
75
+ })), text && /*#__PURE__*/React.createElement(Label, {
76
+ text: text,
77
+ palette: labelPalette,
78
+ id: id,
79
+ size: labelSize,
80
+ type: "subtitle",
81
+ onClick: !disabled || !isReadOnly ? onChange : null,
82
+ customClass: customLabel,
83
+ ...LabelProps
84
+ }));
85
+ };
86
+
87
+ Switch.defaultProps = defaultProps;
88
+ Switch.propTypes = propTypes;
89
+ export default Switch; // if (__DOCS__) {
90
+ // Switch.docs = {
91
+ // componentGroup: 'Form Elements',
92
+ // folderName: 'Style Guide'
93
+ // };
94
+ // }
@@ -0,0 +1,11 @@
1
+ export const defaultProps = {
2
+ checked: false,
3
+ disabled: false,
4
+ labelPalette: 'primary',
5
+ labelSize: 'medium',
6
+ size: 'medium',
7
+ isReadOnly: false,
8
+ customClass: {},
9
+ customProps: {},
10
+ dataSelectorId: 'switch'
11
+ };
@@ -0,0 +1,28 @@
1
+ import PropTypes from 'prop-types';
2
+ export const propTypes = {
3
+ checked: PropTypes.bool,
4
+ dataId: PropTypes.string,
5
+ dataSelectorId: PropTypes.string,
6
+ disableTitle: PropTypes.string,
7
+ disabled: PropTypes.bool,
8
+ id: PropTypes.string.isRequired,
9
+ isReadOnly: PropTypes.bool,
10
+ labelPalette: PropTypes.oneOf(['default', 'primary', 'secondary', 'danger', 'mandatory']),
11
+ labelSize: PropTypes.oneOf(['small', 'medium', 'large']),
12
+ name: PropTypes.string,
13
+ onChange: PropTypes.func,
14
+ size: PropTypes.oneOf(['small', 'medium']),
15
+ text: PropTypes.string,
16
+ title: PropTypes.string,
17
+ value: PropTypes.bool,
18
+ customClass: PropTypes.shape({
19
+ customSwitchWrap: PropTypes.string,
20
+ customSwitch: PropTypes.string,
21
+ customSwitchSize: PropTypes.string,
22
+ customLabel: PropTypes.string
23
+ }),
24
+ customProps: PropTypes.shape({
25
+ SwitchProps: PropTypes.object,
26
+ LabelProps: PropTypes.object
27
+ })
28
+ };
@@ -1,94 +1,138 @@
1
- import React from 'react';
2
- import { defaultProps } from "./props/defaultProps";
3
- import { propTypes } from "./props/propTypes";
4
- import { Container, Box } from "../Layout";
5
- import Label from "../Label/Label";
6
- import style from "../../Switch/Switch.module.css";
1
+ import React 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 { ALIGN_ITEMS, ITEMS_DIRECTION, OFF_LABEL_RADIUS, THUMB_RADIUS } from "./contants"; // components
12
+
13
+ import Flex from '@zohodesk/layout/es/Flex/Flex';
14
+ import Label from "../../Label/Label"; // css
15
+
16
+ import defaultStyle from "./css/Switch_v1.module.css";
7
17
 
8
18
  const Switch = props => {
9
- let {
10
- id,
19
+ const {
11
20
  name,
12
21
  value,
13
- checked,
14
- disabled,
15
- isReadOnly,
22
+ id,
16
23
  size,
17
- text,
24
+ isDisabled,
25
+ isReadOnly,
26
+ hasStateIndication,
27
+ label,
28
+ labelPlacement,
18
29
  labelSize,
19
- labelPalette,
20
30
  title,
21
- disableTitle,
22
- dataId,
23
- dataSelectorId,
24
- customClass,
25
- customProps
31
+ customProps,
32
+ tagAttributes,
33
+ a11yAttributes,
34
+ i18nKeys,
35
+ customId,
36
+ testId,
37
+ customStyle
26
38
  } = props;
27
-
28
- function onChange(e) {
29
- const {
30
- onChange
31
- } = props;
32
- onChange && onChange(!checked, e);
33
- }
34
-
35
- let {
36
- SwitchProps = {},
37
- LabelProps = {}
39
+ const {
40
+ container: customProps_container,
41
+ label: customProps_label
38
42
  } = customProps;
39
- let {
40
- customSwitchWrap = '',
41
- customSwitch = '',
42
- customSwitchSize = '',
43
- customLabel = ''
44
- } = customClass;
45
- size !== 'small' ? size = 'switch_medium' : size = 'switch_small';
46
- return /*#__PURE__*/React.createElement(Container, {
47
- align: "vertical",
48
- isCover: false,
49
- alignBox: "row",
50
- isInline: true,
51
- className: `${style.container} ${customSwitchWrap} ${disabled ? style.disabled : isReadOnly ? style.readonly : style.effect}`,
52
- "data-title": disabled ? disableTitle : title,
53
- "aria-checked": checked,
54
- role: "switch",
55
- dataSelectorId: dataSelectorId,
56
- ...SwitchProps
57
- }, /*#__PURE__*/React.createElement(Box, {
58
- className: `${style[size]} ${customSwitchSize}`
59
- }, /*#__PURE__*/React.createElement("input", {
43
+ const {
44
+ container: tagAttributes_container,
45
+ switch: tagAttributes_switch
46
+ } = tagAttributes;
47
+ const {
48
+ container: a11yAttributes_container,
49
+ switch: a11yAttributes_switch = {},
50
+ label: a11yAttributes_label
51
+ } = a11yAttributes;
52
+ const {
53
+ ariaDisabled = isDisabled,
54
+ ariaLabel,
55
+ ...restA11yAttributes_switch
56
+ } = a11yAttributes_switch;
57
+ const {
58
+ readOnlyAriaLabel: i18n_readOnlyAriaLabel = 'Read Only'
59
+ } = i18nKeys;
60
+ const readOnlyAriaLabel = label ? `${label}, ${i18n_readOnlyAriaLabel}` : i18n_readOnlyAriaLabel;
61
+ const {
62
+ isChecked,
63
+ handleChange
64
+ } = useSwitch(props);
65
+ const style = mergeStyle(defaultStyle, customStyle);
66
+ const {
67
+ containerClass,
68
+ labelClass,
69
+ trackClass,
70
+ trackWrapperClass,
71
+ thumbClass,
72
+ labelIndicationClass
73
+ } = cssJSLogic({
74
+ props: { ...props,
75
+ isChecked
76
+ },
77
+ style
78
+ });
79
+ return /*#__PURE__*/React.createElement(Flex, { ...customProps_container,
80
+ $ui_displayMode: "inline",
81
+ $ui_direction: ITEMS_DIRECTION[labelPlacement],
82
+ $ui_alignItems: ALIGN_ITEMS[labelPlacement],
83
+ $tagAttributes_container: { ...tagAttributes_container,
84
+ 'data-selector-id': customId
85
+ },
86
+ testId: testId,
87
+ customId: customId,
88
+ $ui_className: containerClass,
89
+ $a11yAttributes_container: a11yAttributes_container
90
+ }, label && /*#__PURE__*/React.createElement(Label, { ...customProps_label,
91
+ text: label,
92
+ palette: isDisabled ? 'primary' : 'default',
93
+ size: labelSize,
94
+ htmlFor: id,
95
+ customClass: labelClass,
96
+ a11y: a11yAttributes_label,
97
+ clipped: true,
98
+ title: label
99
+ }), /*#__PURE__*/React.createElement(Flex, {
100
+ $flag_shrink: false,
101
+ $ui_className: trackWrapperClass
102
+ }, /*#__PURE__*/React.createElement("input", { ...tagAttributes_switch,
103
+ ...restA11yAttributes_switch,
60
104
  type: "checkbox",
61
105
  id: id,
62
- className: `${style.input} ${checked ? style.checked : ''}`,
63
106
  name: name,
64
107
  value: value,
65
- checked: checked,
66
- disabled: disabled,
67
- readOnly: isReadOnly,
68
- onClick: !disabled || !isReadOnly ? onChange : null
69
- }), /*#__PURE__*/React.createElement("label", {
70
- htmlFor: id,
71
- "data-id": dataId,
72
- "data-test-id": dataId,
73
- className: `${style.label} ${style[`${size}Label`]} ${customSwitch}`,
74
- tabIndex: isReadOnly || disabled ? '-1' : '0'
75
- })), text && /*#__PURE__*/React.createElement(Label, {
76
- text: text,
77
- palette: labelPalette,
78
- id: id,
79
- size: labelSize,
80
- type: "subtitle",
81
- onClick: !disabled || !isReadOnly ? onChange : null,
82
- customClass: customLabel,
83
- ...LabelProps
84
- }));
108
+ checked: isChecked,
109
+ onChange: handleChange,
110
+ className: trackClass,
111
+ "data-title": title,
112
+ role: "switch",
113
+ "aria-disabled": ariaDisabled,
114
+ "aria-label": isReadOnly ? readOnlyAriaLabel : ariaLabel
115
+ }), /*#__PURE__*/React.createElement("svg", {
116
+ className: thumbClass,
117
+ xmlns: "http://www.w3.org/2000/svg"
118
+ }, /*#__PURE__*/React.createElement("circle", {
119
+ cx: "50%",
120
+ cy: "50%",
121
+ r: THUMB_RADIUS[size]
122
+ })), hasStateIndication ? /*#__PURE__*/React.createElement("svg", {
123
+ className: labelIndicationClass,
124
+ xmlns: "http://www.w3.org/2000/svg"
125
+ }, isChecked ? /*#__PURE__*/React.createElement("rect", {
126
+ width: "100%",
127
+ height: "100%",
128
+ rx: "50%"
129
+ }) : /*#__PURE__*/React.createElement("circle", {
130
+ cx: "50%",
131
+ cy: "50%",
132
+ r: OFF_LABEL_RADIUS[size]
133
+ })) : null));
85
134
  };
86
135
 
136
+ export default Switch;
87
137
  Switch.defaultProps = defaultProps;
88
- Switch.propTypes = propTypes;
89
- export default Switch; // if (__DOCS__) {
90
- // Switch.docs = {
91
- // componentGroup: 'Form Elements',
92
- // folderName: 'Style Guide'
93
- // };
94
- // }
138
+ Switch.propTypes = propTypes;