@zohodesk/components 1.0.0-temp-219.3 → 1.0.0-temp-229
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/.cli/config/variables/variableMapping.json +8 -1
- package/.cli/propValidation_report.html +1 -1
- package/README.md +13 -0
- package/assets/Appearance/dark/mode/Component_v1_DarkMode.module.css +11 -0
- package/assets/Appearance/light/mode/Component_v1_LightMode.module.css +11 -0
- package/assets/Appearance/pureDark/mode/Component_v1_PureDarkMode.module.css +11 -0
- package/es/AppContainer/AppContainer.js +5 -4
- package/es/Card/Card.js +35 -8
- package/es/Card/props/defaultProps.js +2 -1
- package/es/Card/props/propTypes.js +2 -1
- package/es/CheckBox/CheckBox.js +2 -9
- package/es/Label/Label.js +2 -9
- package/es/Provider/LibraryContext.js +7 -3
- package/es/deprecated/Switch/Switch.js +94 -0
- package/es/deprecated/Switch/props/defaultProps.js +11 -0
- package/es/deprecated/Switch/props/propTypes.js +28 -0
- package/es/v1/Switch/Switch.js +122 -78
- package/es/v1/Switch/__tests__/Switch.spec.js +30 -0
- package/es/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
- package/es/v1/Switch/contants/index.js +24 -0
- package/es/v1/Switch/css/Switch_v1.module.css +134 -0
- package/es/v1/Switch/css/cssJSLogic.js +48 -0
- package/es/v1/Switch/props/defaultProps.js +8 -8
- package/es/v1/Switch/props/propTypes.js +30 -22
- package/es/v1/Switch/useSwitch.js +33 -0
- package/lib/AppContainer/AppContainer.js +7 -6
- package/lib/Card/Card.js +50 -23
- package/lib/Card/props/defaultProps.js +2 -1
- package/lib/Card/props/propTypes.js +2 -1
- package/lib/CheckBox/CheckBox.js +2 -9
- package/lib/Label/Label.js +2 -9
- package/lib/Provider/LibraryContext.js +7 -3
- package/lib/deprecated/Switch/Switch.js +108 -0
- package/lib/deprecated/Switch/props/defaultProps.js +18 -0
- package/lib/deprecated/Switch/props/propTypes.js +39 -0
- package/lib/v1/Switch/Switch.js +130 -79
- package/lib/v1/Switch/__tests__/Switch.spec.js +37 -0
- package/lib/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
- package/lib/v1/Switch/contants/index.js +34 -0
- package/lib/v1/Switch/css/Switch_v1.module.css +134 -0
- package/lib/v1/Switch/css/cssJSLogic.js +37 -0
- package/lib/v1/Switch/props/defaultProps.js +10 -10
- package/lib/v1/Switch/props/propTypes.js +32 -24
- package/lib/v1/Switch/useSwitch.js +56 -0
- package/package.json +10 -8
- package/result.json +0 -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.
|
|
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);
|
|
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,7 +129,8 @@ export default class Card extends Component {
|
|
|
127
129
|
scrollAt,
|
|
128
130
|
noNeedUpScroll,
|
|
129
131
|
// isScrollShadow,
|
|
130
|
-
isPercentageScroll
|
|
132
|
+
isPercentageScroll,
|
|
133
|
+
isRecentOnTop
|
|
131
134
|
} = this.props;
|
|
132
135
|
|
|
133
136
|
if (scrollTop > this.lastScrollTop) {
|
|
@@ -139,9 +142,12 @@ export default class Card extends Component {
|
|
|
139
142
|
this.lastScrollTop = scrollTop;
|
|
140
143
|
|
|
141
144
|
if (fetchData && !this.isFetching) {
|
|
142
|
-
|
|
145
|
+
const nextFetchDirection = isRecentOnTop ? 'down' : 'up';
|
|
146
|
+
|
|
147
|
+
if (this.scrollDirection === nextFetchDirection && !noMoreData) {
|
|
143
148
|
const scrollingPercentage = (scrollTop + offsetHeight) / (scrollHeight - scrollAt) * 100;
|
|
144
|
-
const
|
|
149
|
+
const scrolledUpPercentage = (scrollHeight - scrollTop) / (scrollHeight - scrollAt) * 100;
|
|
150
|
+
const prefetch = isRecentOnTop ? isPercentageScroll ? scrollingPercentage >= getLibraryConfig('scrollFetchLimit') : scrollHeight - scrollAt <= scrollTop + offsetHeight : isPercentageScroll ? scrolledUpPercentage >= getLibraryConfig('scrollFetchLimit') : scrollTop <= scrollAt;
|
|
145
151
|
|
|
146
152
|
if (prefetch) {
|
|
147
153
|
this.isFetching = true;
|
|
@@ -153,7 +159,9 @@ export default class Card extends Component {
|
|
|
153
159
|
});
|
|
154
160
|
}
|
|
155
161
|
} else {
|
|
156
|
-
|
|
162
|
+
const prefetch = isRecentOnTop ? 0 >= scrollTop - scrollAt : scrollHeight - scrollAt <= scrollTop + offsetHeight;
|
|
163
|
+
|
|
164
|
+
if (prefetch && this.from !== 0 && !noNeedUpScroll) {
|
|
157
165
|
this.isFetching = true;
|
|
158
166
|
fetchData(this.from - this.limit, this.to - this.limit, this.scrollDirection).then(() => {
|
|
159
167
|
this.to = this.to - this.limit;
|
|
@@ -166,9 +174,12 @@ export default class Card extends Component {
|
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
if (fetchData && !noNeedUpScroll) {
|
|
169
|
-
|
|
177
|
+
const topFetch = isRecentOnTop ? !noNeedUpScroll : !noMoreData;
|
|
178
|
+
const bottomFetch = isRecentOnTop ? !noMoreData : !noNeedUpScroll;
|
|
179
|
+
|
|
180
|
+
if (this.from !== 0 && scrollTop === 0 && topFetch) {
|
|
170
181
|
scrollContainerObj.scrollTop = scrollTop + offsetHeight / 3;
|
|
171
|
-
} else if (scrollHeight === scrollTop + offsetHeight &&
|
|
182
|
+
} else if (scrollHeight === scrollTop + offsetHeight && bottomFetch) {
|
|
172
183
|
scrollContainerObj.scrollTop = scrollTop - offsetHeight / 2;
|
|
173
184
|
}
|
|
174
185
|
} // if (isScrollShadow) {
|
|
@@ -187,6 +198,21 @@ export default class Card extends Component {
|
|
|
187
198
|
// }
|
|
188
199
|
|
|
189
200
|
|
|
201
|
+
setScrollRef(el) {
|
|
202
|
+
const {
|
|
203
|
+
scrollAt,
|
|
204
|
+
isRecentOnTop
|
|
205
|
+
} = this.props;
|
|
206
|
+
|
|
207
|
+
if (el && !isRecentOnTop) {
|
|
208
|
+
requestAnimationFrame(() => {
|
|
209
|
+
el.scrollTop = el.scrollHeight + Number(scrollAt);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
this.childEleRef && this.childEleRef(el);
|
|
214
|
+
}
|
|
215
|
+
|
|
190
216
|
render() {
|
|
191
217
|
let {
|
|
192
218
|
onClick,
|
|
@@ -220,6 +246,7 @@ export default class Card extends Component {
|
|
|
220
246
|
isScroll
|
|
221
247
|
});
|
|
222
248
|
} else if (child.type === CardContent || this.props.childTypes && child.type === this.props.childTypes.cardContent) {
|
|
249
|
+
this.childEleRef = child.props.eleRef;
|
|
223
250
|
return /*#__PURE__*/React.createElement(Box, {
|
|
224
251
|
id: htmlId,
|
|
225
252
|
role: role,
|
|
@@ -227,7 +254,7 @@ export default class Card extends Component {
|
|
|
227
254
|
scroll: child.props.scroll,
|
|
228
255
|
preventParentScroll: child.props.preventParentScroll,
|
|
229
256
|
onScroll: this.onScroll,
|
|
230
|
-
eleRef:
|
|
257
|
+
eleRef: this.setScrollRef,
|
|
231
258
|
isScrollAttribute: child.props.isScrollAttribute,
|
|
232
259
|
dataId: child.props.dataId,
|
|
233
260
|
shrink: child.props.shrink,
|
|
@@ -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
|
+
isRecentOnTop: PropTypes.bool
|
|
42
43
|
};
|
|
43
44
|
export const CardFooter_propTypes = {
|
|
44
45
|
children: PropTypes.node,
|
package/es/CheckBox/CheckBox.js
CHANGED
|
@@ -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,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
|
+
};
|
package/es/v1/Switch/Switch.js
CHANGED
|
@@ -1,94 +1,138 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
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
|
-
|
|
10
|
-
id,
|
|
19
|
+
const {
|
|
11
20
|
name,
|
|
12
21
|
value,
|
|
13
|
-
|
|
14
|
-
disabled,
|
|
15
|
-
isReadOnly,
|
|
22
|
+
id,
|
|
16
23
|
size,
|
|
17
|
-
|
|
24
|
+
isDisabled,
|
|
25
|
+
isReadOnly,
|
|
26
|
+
hasStateIndication,
|
|
27
|
+
label,
|
|
28
|
+
labelPlacement,
|
|
18
29
|
labelSize,
|
|
19
|
-
labelPalette,
|
|
20
30
|
title,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
customProps,
|
|
32
|
+
tagAttributes,
|
|
33
|
+
a11yAttributes,
|
|
34
|
+
i18nKeys,
|
|
35
|
+
customId,
|
|
36
|
+
testId,
|
|
37
|
+
customStyle
|
|
26
38
|
} = props;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
className:
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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;
|