@progress/kendo-react-inputs 15.1.1-develop.3 → 15.2.0-develop.2
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/checkbox/Checkbox.js +1 -1
- package/checkbox/Checkbox.mjs +72 -70
- package/colors/ColorContrastLabels.js +1 -1
- package/colors/ColorContrastLabels.mjs +2 -2
- package/colors/ColorGradient.js +1 -1
- package/colors/ColorGradient.mjs +51 -52
- package/colors/ColorPalette.js +1 -1
- package/colors/ColorPalette.mjs +71 -72
- package/colors/ColorPicker.js +1 -1
- package/colors/ColorPicker.mjs +203 -195
- package/colors/FlatColorPicker.d.ts +4 -4
- package/colors/FlatColorPicker.js +1 -1
- package/colors/FlatColorPicker.mjs +30 -26
- package/colors/interfaces/ColorPaletteProps.d.ts +7 -0
- package/colors/interfaces/ColorPickerPaletteSettings.d.ts +5 -0
- package/dist/cdn/js/kendo-react-inputs.js +1 -1
- package/maskedtextbox/MaskedTextBox.d.ts +1 -0
- package/maskedtextbox/MaskedTextBox.js +1 -1
- package/maskedtextbox/MaskedTextBox.mjs +26 -23
- package/maskedtextbox/MaskedTextBoxProps.d.ts +7 -0
- package/numerictextbox/NumericTextBox.js +1 -1
- package/numerictextbox/NumericTextBox.mjs +2 -2
- package/otpinput/OTPInput.js +1 -1
- package/otpinput/OTPInput.mjs +141 -143
- package/package-metadata.js +1 -1
- package/package-metadata.mjs +2 -2
- package/package.json +10 -10
- package/radiobutton/RadioButton.js +1 -1
- package/radiobutton/RadioButton.mjs +32 -30
- package/range-slider/RangeSlider.js +11 -11
- package/range-slider/RangeSlider.mjs +54 -54
- package/rating/Rating.d.ts +12 -0
- package/rating/Rating.js +2 -2
- package/rating/Rating.mjs +91 -92
- package/slider/Slider.d.ts +12 -0
- package/slider/Slider.js +1 -1
- package/slider/Slider.mjs +69 -64
- package/switch/Switch.d.ts +15 -0
- package/switch/Switch.js +1 -1
- package/switch/Switch.mjs +87 -82
- package/textarea/TextArea.js +1 -1
- package/textarea/TextArea.mjs +11 -12
package/slider/Slider.mjs
CHANGED
|
@@ -6,39 +6,41 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
import * as r from "react";
|
|
9
|
-
import { useState as
|
|
9
|
+
import { useState as R, useRef as N, useMemo as z, useEffect as q, useCallback as c, useImperativeHandle as ue } from "react";
|
|
10
10
|
import i from "prop-types";
|
|
11
|
-
import { withPropsContext as
|
|
11
|
+
import { withPropsContext as fe, dispatchEvent as ge, Keys as m, useWebMcpRegister as ve, classNames as he, Draggable as be, getTabIndex as ye, createPropsContext as ke } from "@progress/kendo-react-common";
|
|
12
12
|
import { LocalizationService as xe, registerForLocalization as Se } from "@progress/kendo-react-intl";
|
|
13
|
-
import {
|
|
13
|
+
import { sliderDragTitle as H, messages as B, sliderDecreaseValue as W, sliderIncreaseValue as X } from "../messages/index.mjs";
|
|
14
14
|
import { SLIDER_LABEL_ATTRIBUTE as we } from "./SliderLabel.mjs";
|
|
15
15
|
import { Button as _ } from "@progress/kendo-react-buttons";
|
|
16
16
|
import { chevronUpIcon as j, chevronLeftIcon as G, chevronDownIcon as Y, chevronRightIcon as J } from "@progress/kendo-svg-icons";
|
|
17
|
-
const
|
|
17
|
+
const g = {
|
|
18
18
|
step: 1,
|
|
19
19
|
largeStep: 10,
|
|
20
20
|
buttons: !1,
|
|
21
21
|
vertical: !1,
|
|
22
22
|
disabled: !1,
|
|
23
|
+
readOnly: !1,
|
|
23
24
|
tabIndex: 0
|
|
24
|
-
},
|
|
25
|
-
var K, U
|
|
25
|
+
}, V = r.forwardRef((e, Q) => {
|
|
26
|
+
var O, K, U;
|
|
26
27
|
const {
|
|
27
|
-
step: u =
|
|
28
|
-
largeStep:
|
|
29
|
-
vertical: a =
|
|
30
|
-
disabled: d =
|
|
31
|
-
tabIndex: Z =
|
|
32
|
-
|
|
28
|
+
step: u = g.step,
|
|
29
|
+
largeStep: C = g.largeStep,
|
|
30
|
+
vertical: a = g.vertical,
|
|
31
|
+
disabled: d = g.disabled,
|
|
32
|
+
tabIndex: Z = g.tabIndex,
|
|
33
|
+
readOnly: A = g.readOnly
|
|
34
|
+
} = e, [$, p] = R((O = e.defaultValue) != null ? O : e.min), [ee, F] = R(!1), [I, te] = R(e.dir), E = N(null), v = N(null), T = z(() => new xe(), []), D = N(null), L = e.value !== void 0, k = L && e.value !== void 0 ? e.value : $, l = z(() => k < e.min ? e.min : k > e.max ? e.max : k, [k, e.min, e.max]), h = z(() => {
|
|
33
35
|
const t = e.max - e.min;
|
|
34
36
|
return t === 0 ? 0 : (l - e.min) / t * 100;
|
|
35
|
-
}, [l, e.min, e.max]),
|
|
36
|
-
|
|
37
|
+
}, [l, e.min, e.max]), f = (K = e.dir) != null ? K : I;
|
|
38
|
+
q(() => {
|
|
37
39
|
if (e.dir === void 0 && v.current) {
|
|
38
40
|
const n = window.getComputedStyle(v.current).direction;
|
|
39
|
-
n !==
|
|
41
|
+
n !== I && te(n);
|
|
40
42
|
}
|
|
41
|
-
}, [e.dir,
|
|
43
|
+
}, [e.dir, I]);
|
|
42
44
|
const M = c((t) => {
|
|
43
45
|
let n = t;
|
|
44
46
|
for (; n; ) {
|
|
@@ -50,9 +52,9 @@ const f = {
|
|
|
50
52
|
}, []), s = c(
|
|
51
53
|
(t, n) => {
|
|
52
54
|
const o = Math.min(Math.max(n, e.min), e.max);
|
|
53
|
-
|
|
55
|
+
L || p(o), ge(e.onChange, t, D.current, { value: o });
|
|
54
56
|
},
|
|
55
|
-
[e.min, e.max, e.onChange,
|
|
57
|
+
[e.min, e.max, e.onChange, L]
|
|
56
58
|
), ne = c(() => {
|
|
57
59
|
F(!0);
|
|
58
60
|
}, []), ae = c(() => {
|
|
@@ -62,9 +64,9 @@ const f = {
|
|
|
62
64
|
if (d)
|
|
63
65
|
return;
|
|
64
66
|
let n;
|
|
65
|
-
t.keyCode === m.left || t.keyCode === m.down ? n = l - (u || 0) : t.keyCode === m.right || t.keyCode === m.up ? n = l + (u || 0) : t.keyCode === m.pageDown ? n = l - (
|
|
67
|
+
t.keyCode === m.left || t.keyCode === m.down ? n = l - (u || 0) : t.keyCode === m.right || t.keyCode === m.up ? n = l + (u || 0) : t.keyCode === m.pageDown ? n = l - (C || 0) : t.keyCode === m.pageUp ? n = l + (C || 0) : t.keyCode === m.home ? n = e.min : t.keyCode === m.end && (n = e.max), n !== void 0 && (t.preventDefault(), s(t, n));
|
|
66
68
|
},
|
|
67
|
-
[l, u,
|
|
69
|
+
[l, u, C, e.min, e.max, s, d]
|
|
68
70
|
), re = c(
|
|
69
71
|
(t) => {
|
|
70
72
|
t.preventDefault(), !d && s(t, l - (u || 0));
|
|
@@ -75,38 +77,38 @@ const f = {
|
|
|
75
77
|
t.preventDefault(), !d && s(t, l + (u || 0));
|
|
76
78
|
},
|
|
77
79
|
[l, u, s, d]
|
|
78
|
-
),
|
|
80
|
+
), x = c(
|
|
79
81
|
(t) => {
|
|
80
82
|
const n = t.element.getBoundingClientRect();
|
|
81
83
|
let o;
|
|
82
|
-
a ? o = n.bottom - t.event.clientY : o =
|
|
83
|
-
const
|
|
84
|
-
s(t, e.min +
|
|
84
|
+
a ? o = n.bottom - t.event.clientY : o = f === "rtl" ? n.right - t.event.clientX : t.event.clientX - n.left;
|
|
85
|
+
const b = a ? n.height : n.width, y = o / b;
|
|
86
|
+
s(t, e.min + y * (e.max - e.min));
|
|
85
87
|
},
|
|
86
|
-
[a, e.min, e.max,
|
|
88
|
+
[a, e.min, e.max, f, s]
|
|
87
89
|
), ce = c(
|
|
88
90
|
(t) => {
|
|
89
|
-
M(t.event.originalEvent.target) || (t.event.isTouch && t.event.originalEvent.preventDefault(),
|
|
91
|
+
M(t.event.originalEvent.target) || (t.event.isTouch && t.event.originalEvent.preventDefault(), x(t));
|
|
90
92
|
},
|
|
91
|
-
[M,
|
|
93
|
+
[M, x]
|
|
92
94
|
), oe = c(
|
|
93
95
|
(t) => {
|
|
94
|
-
t.event.originalEvent.preventDefault(),
|
|
96
|
+
t.event.originalEvent.preventDefault(), x(t);
|
|
95
97
|
},
|
|
96
|
-
[
|
|
97
|
-
),
|
|
98
|
+
[x]
|
|
99
|
+
), S = c(() => {
|
|
98
100
|
v.current && v.current.focus();
|
|
99
101
|
}, []), de = c(
|
|
100
102
|
(t) => {
|
|
101
103
|
if (!t.enabled)
|
|
102
104
|
return t.children;
|
|
103
|
-
let n, o,
|
|
104
|
-
return
|
|
105
|
+
let n, o, b, y;
|
|
106
|
+
return f === "rtl" ? (n = a ? j : G, o = a ? Y : J, b = a ? "chevron-up" : "chevron-left", y = a ? "chevron-down" : "chevron-right") : (n = a ? j : J, o = a ? Y : G, b = a ? "chevron-up" : "chevron-right", y = a ? "chevron-down" : "chevron-left"), /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(
|
|
105
107
|
_,
|
|
106
108
|
{
|
|
107
109
|
className: "k-button-decrease",
|
|
108
110
|
rounded: "full",
|
|
109
|
-
icon:
|
|
111
|
+
icon: y,
|
|
110
112
|
svgIcon: o,
|
|
111
113
|
title: t.decrementTitle,
|
|
112
114
|
onClick: t.decrement
|
|
@@ -116,39 +118,39 @@ const f = {
|
|
|
116
118
|
{
|
|
117
119
|
className: "k-button-increase",
|
|
118
120
|
rounded: "full",
|
|
119
|
-
icon:
|
|
121
|
+
icon: b,
|
|
120
122
|
svgIcon: n,
|
|
121
123
|
title: t.incrementTitle,
|
|
122
124
|
onClick: t.increment
|
|
123
125
|
}
|
|
124
126
|
));
|
|
125
127
|
},
|
|
126
|
-
[
|
|
128
|
+
[f, a]
|
|
127
129
|
);
|
|
128
130
|
ue(
|
|
129
131
|
Q,
|
|
130
132
|
() => ({
|
|
131
133
|
props: e,
|
|
132
|
-
sliderTrack:
|
|
133
|
-
focus:
|
|
134
|
+
sliderTrack: E.current,
|
|
135
|
+
focus: S
|
|
134
136
|
}),
|
|
135
|
-
[e,
|
|
136
|
-
), ve("slider",
|
|
137
|
-
|
|
137
|
+
[e, S]
|
|
138
|
+
), ve("slider", D, e, e.webMcp), q(() => {
|
|
139
|
+
D.current = {
|
|
138
140
|
props: e,
|
|
139
|
-
sliderTrack:
|
|
140
|
-
focus:
|
|
141
|
+
sliderTrack: E.current,
|
|
142
|
+
focus: S
|
|
141
143
|
};
|
|
142
|
-
}, [e,
|
|
144
|
+
}, [e, S]);
|
|
143
145
|
const se = a ? { marginTop: "0.5rem", marginBottom: "0.5rem" } : { marginLeft: "0.5rem", marginRight: "0.5rem" }, me = a ? { paddingTop: 0, height: "100%" } : {};
|
|
144
|
-
let
|
|
145
|
-
return a ?
|
|
146
|
+
let w;
|
|
147
|
+
return a ? w = { bottom: "calc(" + h + "%)", zIndex: 1 } : f === "rtl" ? w = { right: "calc(" + h + "%)", zIndex: 1 } : w = { left: "calc(" + h + "%)", zIndex: 1 }, /* @__PURE__ */ r.createElement(
|
|
146
148
|
"div",
|
|
147
149
|
{
|
|
148
150
|
ref: v,
|
|
149
|
-
dir:
|
|
151
|
+
dir: f,
|
|
150
152
|
id: e.id,
|
|
151
|
-
"aria-label": e.ariaLabel
|
|
153
|
+
"aria-label": e.ariaLabel,
|
|
152
154
|
style: { gap: 0, ...e.style },
|
|
153
155
|
onFocus: ne,
|
|
154
156
|
onBlur: ae,
|
|
@@ -158,6 +160,7 @@ const f = {
|
|
|
158
160
|
{
|
|
159
161
|
"k-focus": ee,
|
|
160
162
|
"k-disabled": d,
|
|
163
|
+
"k-readonly": A,
|
|
161
164
|
"k-slider-horizontal": !a,
|
|
162
165
|
"k-slider-vertical": a
|
|
163
166
|
},
|
|
@@ -165,16 +168,16 @@ const f = {
|
|
|
165
168
|
)
|
|
166
169
|
},
|
|
167
170
|
de({
|
|
168
|
-
enabled: (
|
|
171
|
+
enabled: (U = e.buttons) != null ? U : g.buttons,
|
|
169
172
|
decrement: re,
|
|
170
173
|
increment: le,
|
|
171
|
-
incrementTitle:
|
|
174
|
+
incrementTitle: T.toLanguageString(
|
|
172
175
|
X,
|
|
173
|
-
|
|
176
|
+
B[X]
|
|
174
177
|
),
|
|
175
|
-
decrementTitle:
|
|
178
|
+
decrementTitle: T.toLanguageString(
|
|
176
179
|
W,
|
|
177
|
-
|
|
180
|
+
B[W]
|
|
178
181
|
),
|
|
179
182
|
children: /* @__PURE__ */ r.createElement(be, { onDrag: oe, onPress: ce, autoScroll: !1 }, /* @__PURE__ */ r.createElement(
|
|
180
183
|
"div",
|
|
@@ -209,14 +212,14 @@ const f = {
|
|
|
209
212
|
"div",
|
|
210
213
|
{
|
|
211
214
|
className: "k-slider-track",
|
|
212
|
-
style: a ? { bottom: 0, height: "100%" } : { [
|
|
213
|
-
ref:
|
|
215
|
+
style: a ? { bottom: 0, height: "100%" } : { [f === "rtl" ? "right" : "left"]: 0, width: "100%" },
|
|
216
|
+
ref: E
|
|
214
217
|
},
|
|
215
218
|
/* @__PURE__ */ r.createElement(
|
|
216
219
|
"div",
|
|
217
220
|
{
|
|
218
221
|
className: "k-slider-selection",
|
|
219
|
-
style: a ? { height:
|
|
222
|
+
style: a ? { height: h + "%" } : { width: h + "%" }
|
|
220
223
|
}
|
|
221
224
|
),
|
|
222
225
|
/* @__PURE__ */ r.createElement(
|
|
@@ -228,16 +231,17 @@ const f = {
|
|
|
228
231
|
"aria-valuenow": l,
|
|
229
232
|
"aria-orientation": a ? "vertical" : void 0,
|
|
230
233
|
"aria-disabled": d ? "true" : void 0,
|
|
234
|
+
"aria-readonly": A ? "true" : void 0,
|
|
231
235
|
"aria-labelledby": e.ariaLabelledBy,
|
|
232
236
|
"aria-describedby": e.ariaDescribedBy,
|
|
233
|
-
"aria-label": e.ariaLabel
|
|
237
|
+
"aria-label": e.ariaLabel,
|
|
234
238
|
tabIndex: ye(Z, d, void 0),
|
|
235
239
|
className: "k-draghandle k-draghandle-end",
|
|
236
|
-
title:
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
title: T.toLanguageString(
|
|
241
|
+
H,
|
|
242
|
+
B[H]
|
|
239
243
|
),
|
|
240
|
-
style:
|
|
244
|
+
style: w
|
|
241
245
|
}
|
|
242
246
|
)
|
|
243
247
|
)
|
|
@@ -245,8 +249,8 @@ const f = {
|
|
|
245
249
|
})
|
|
246
250
|
);
|
|
247
251
|
});
|
|
248
|
-
|
|
249
|
-
const Ce = ke(), P =
|
|
252
|
+
V.displayName = "Slider";
|
|
253
|
+
const Ce = ke(), P = fe(Ce, V);
|
|
250
254
|
P.displayName = "KendoReactSlider";
|
|
251
255
|
P.propTypes = {
|
|
252
256
|
value: i.number,
|
|
@@ -261,6 +265,7 @@ P.propTypes = {
|
|
|
261
265
|
buttons: i.bool,
|
|
262
266
|
tabIndex: i.number,
|
|
263
267
|
disabled: i.bool,
|
|
268
|
+
readOnly: i.bool,
|
|
264
269
|
vertical: i.bool,
|
|
265
270
|
id: i.string,
|
|
266
271
|
ariaDescribedBy: i.string,
|
|
@@ -269,9 +274,9 @@ P.propTypes = {
|
|
|
269
274
|
dir: i.oneOf(["ltr", "rtl"]),
|
|
270
275
|
children: i.node
|
|
271
276
|
};
|
|
272
|
-
Se(
|
|
277
|
+
Se(V);
|
|
273
278
|
export {
|
|
274
279
|
P as Slider,
|
|
275
280
|
Ce as SliderPropsContext,
|
|
276
|
-
|
|
281
|
+
V as SliderWithoutContext
|
|
277
282
|
};
|
package/switch/Switch.d.ts
CHANGED
|
@@ -75,6 +75,18 @@ export interface SwitchProps extends ToggleBaseProps, FormComponentProps {
|
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
77
|
disabled?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Makes the Switch read-only when set to `true`. The Switch will remain focusable but its value cannot be changed by the user.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This property is related to accessibility.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```jsx
|
|
86
|
+
* <Switch readOnly={true} />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
readOnly?: boolean;
|
|
78
90
|
/**
|
|
79
91
|
* Specifies the `dir` property of the wrapping element of the Switch.
|
|
80
92
|
*
|
|
@@ -147,6 +159,9 @@ export interface SwitchProps extends ToggleBaseProps, FormComponentProps {
|
|
|
147
159
|
* Identifies the element(s) which will describe the component.
|
|
148
160
|
* For example these elements could contain error or hint message.
|
|
149
161
|
*
|
|
162
|
+
* @remarks
|
|
163
|
+
* This property is related to accessibility.
|
|
164
|
+
*
|
|
150
165
|
* @example
|
|
151
166
|
* ```jsx
|
|
152
167
|
* <Switch ariaDescribedBy="description-id" />
|
package/switch/Switch.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),t=require("prop-types"),c=require("@progress/kendo-react-common"),
|
|
8
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),t=require("prop-types"),c=require("@progress/kendo-react-common"),Z=require("@progress/kendo-react-intl"),O=require("../messages/index.js");function p(e){const b=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const l in e)if(l!=="default"){const y=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(b,l,y.get?y:{enumerable:!0,get:()=>e[l]})}}return b.default=e,Object.freeze(b)}const d=p(n),r={disabled:!1,defaultChecked:!1,size:void 0,trackRounded:void 0,thumbRounded:void 0,offLabel:"OFF",onBlur:c.noop,onFocus:c.noop,onLabel:"ON",readOnly:!1,validityStyles:!0},x=d.forwardRef((e,b)=>{var z;const{disabled:l=r.disabled,defaultChecked:y=r.defaultChecked,size:C=r.size,trackRounded:R=r.trackRounded,thumbRounded:S=r.thumbRounded,offLabel:I=r.offLabel,onBlur:M=r.onBlur,onFocus:E=r.onFocus,onLabel:q=r.onLabel,readOnly:B=r.readOnly}=e,[D,V]=n.useState(y||!1),[W,P]=n.useState(!1),u=n.useRef(null),o=n.useRef(null),v=n.useRef(null),k=n.useRef(void 0),N=n.useRef(!1),T=n.useRef(void 0),F=n.useMemo(()=>new Z.LocalizationService,[]),i=n.useMemo(()=>k.current!==void 0?k.current:e.checked!==void 0?e.checked:D,[e.checked,D]),h=n.useMemo(()=>{var w,j;const a=e.validationMessage!==void 0,s=(w=e.valid)!=null?w:e.required?!!i:!0,g=(j=e.valid)!=null?j:s;return{customError:a,valid:g,valueMissing:i===null}},[e.valid,e.validationMessage,e.required,i]),_=(z=e.validityStyles)!=null?z:r.validityStyles;n.useEffect(()=>{var a;(a=v.current)!=null&&a.setCustomValidity&&v.current.setCustomValidity(h.valid?"":e.validationMessage||F.toLanguageString(O.switchValidation,O.messages[O.switchValidation]))},[h,e.validationMessage,F]),n.useEffect(()=>{u.current&&(T.current=e.dir||getComputedStyle(u.current).direction||void 0)},[e.dir]);const f=n.useCallback(()=>({props:e,get element(){return u.current},get actionElement(){return o.current},focus:()=>{var a;(a=o.current)==null||a.focus()},get value(){return i},get name(){return e.name},get validity(){return h}}),[e,i,h]),m=n.useCallback((a,s)=>{V(a),k.current=a,c.dispatchEvent(e.onChange,s,{...f(),value:a},{value:a}),k.current=void 0},[e.onChange,f]);n.useEffect(()=>{const a=e.name||e.id,s=c.subscribeToKendoPaste(o.current,{fieldName:a,onValueChange:g=>{if(g!==i){const w={target:o.current,currentTarget:o.current,nativeEvent:new Event("change",{bubbles:!0})};m(g,w)}}});return()=>{s==null||s.unsubscribe()}},[e.name,e.id,i,m]);const $=n.useCallback(a=>{if(a.target===v.current){if(N.current){N.current=!1;return}}else N.current=!0;m(!i,a)},[i,m]),A=n.useCallback(a=>{if(l)return;const{keyCode:s}=a;(s===c.Keys.space||s===c.Keys.enter)&&(m(!i,a),a.preventDefault())},[l,i,m]),G=n.useCallback(a=>{l||(P(!0),E&&E(a))},[l,E]),J=n.useCallback(a=>{l||(P(!1),M&&M(a))},[l,M]);n.useImperativeHandle(b,f,[f]);const K=n.useRef(null);n.useImperativeHandle(K,f,[f]),c.useWebMcpRegister("switch",K,e,e.webMcp);const Q=T.current||e.dir||u.current&&getComputedStyle(u.current).direction||void 0,U=!_||h.valid,X=c.classNames("k-switch",{[`k-switch-${c.kendoThemeMaps.sizeMap[C]||C}`]:C,"k-switch-on":i,"k-switch-off":!i,"k-focus":W,"k-disabled":l,"k-readonly":B,"k-invalid":!U},e.className),Y=d.createElement("input",{type:"checkbox",checked:e.checked,ref:v,tabIndex:-1,value:i,style:{opacity:0,width:1,border:0,zIndex:-1,position:"absolute",left:"50%"},onChange:c.noop,name:e.name||void 0});return d.createElement("span",{ref:o,role:"switch","aria-checked":i,"aria-disabled":l||void 0,"aria-readonly":B?"true":void 0,"aria-labelledby":e.ariaLabelledBy,"aria-describedby":e.ariaDescribedBy,"aria-label":e.ariaLabel,"aria-required":e.required,className:X,dir:Q,onKeyDown:A,onClick:$,onBlur:J,onFocus:G,tabIndex:c.getTabIndex(e.tabIndex,l,void 0),accessKey:e.accessKey,id:e.id},d.createElement("span",{className:c.classNames("k-switch-track",{[`k-rounded-${c.kendoThemeMaps.roundedMap[R]||R}`]:R}),ref:u},Y,q?d.createElement("span",{className:"k-switch-label-on"},q):"",I?d.createElement("span",{className:"k-switch-label-off"},I):""),d.createElement("span",{className:"k-switch-thumb-wrap"},d.createElement("span",{className:c.classNames("k-switch-thumb",{[`k-rounded-${c.kendoThemeMaps.roundedMap[S]||S}`]:S})})))});x.displayName="Switch";const H=c.createPropsContext(),L=c.withIdHOC(c.withPropsContext(H,x));L.displayName="KendoReactSwitch";L.propTypes={accessKey:t.string,checked:t.bool,className:t.string,defaultChecked:t.bool,defaultValue:t.any,disabled:t.bool,readOnly:t.bool,dir:t.string,id:t.string,size:t.oneOf(["small","medium","large"]),trackRounded:t.oneOf(["small","medium","large","full"]),thumbRounded:t.oneOf(["small","medium","large","full"]),ariaDescribedBy:t.string,ariaLabelledBy:t.string,ariaLabel:t.string,offLabel:t.node,onBlur:t.func,onChange:t.func,onFocus:t.func,onLabel:t.node,tabIndex:t.number,value:t.any,name:t.string,required:t.bool,valid:t.bool,validationMessage:t.string,validityStyles:t.bool};exports.Switch=L;exports.SwitchPropsContext=H;exports.SwitchWithoutContext=x;
|
package/switch/Switch.mjs
CHANGED
|
@@ -5,51 +5,53 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import * as
|
|
9
|
-
import { useState as
|
|
8
|
+
import * as d from "react";
|
|
9
|
+
import { useState as V, useRef as l, useMemo as L, useEffect as M, useCallback as m, useImperativeHandle as W } from "react";
|
|
10
10
|
import t from "prop-types";
|
|
11
|
-
import { withIdHOC as
|
|
12
|
-
import { LocalizationService as
|
|
13
|
-
import { switchValidation as
|
|
14
|
-
const
|
|
11
|
+
import { withIdHOC as re, withPropsContext as ce, noop as O, dispatchEvent as de, subscribeToKendoPaste as le, Keys as $, useWebMcpRegister as se, classNames as N, kendoThemeMaps as x, getTabIndex as oe, createPropsContext as ue } from "@progress/kendo-react-common";
|
|
12
|
+
import { LocalizationService as fe } from "@progress/kendo-react-intl";
|
|
13
|
+
import { switchValidation as j, messages as me } from "../messages/index.mjs";
|
|
14
|
+
const i = {
|
|
15
15
|
disabled: !1,
|
|
16
16
|
defaultChecked: !1,
|
|
17
17
|
size: void 0,
|
|
18
18
|
trackRounded: void 0,
|
|
19
19
|
thumbRounded: void 0,
|
|
20
20
|
offLabel: "OFF",
|
|
21
|
-
onBlur:
|
|
22
|
-
onFocus:
|
|
21
|
+
onBlur: O,
|
|
22
|
+
onFocus: O,
|
|
23
23
|
onLabel: "ON",
|
|
24
|
+
readOnly: !1,
|
|
24
25
|
validityStyles: !0
|
|
25
|
-
},
|
|
26
|
-
var
|
|
26
|
+
}, A = d.forwardRef((e, J) => {
|
|
27
|
+
var q;
|
|
27
28
|
const {
|
|
28
|
-
disabled:
|
|
29
|
-
defaultChecked:
|
|
30
|
-
size: k =
|
|
31
|
-
trackRounded: w =
|
|
32
|
-
thumbRounded: C =
|
|
33
|
-
offLabel:
|
|
34
|
-
onBlur: R =
|
|
35
|
-
onFocus:
|
|
36
|
-
onLabel:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
disabled: c = i.disabled,
|
|
30
|
+
defaultChecked: Q = i.defaultChecked,
|
|
31
|
+
size: k = i.size,
|
|
32
|
+
trackRounded: w = i.trackRounded,
|
|
33
|
+
thumbRounded: C = i.thumbRounded,
|
|
34
|
+
offLabel: B = i.offLabel,
|
|
35
|
+
onBlur: R = i.onBlur,
|
|
36
|
+
onFocus: E = i.onFocus,
|
|
37
|
+
onLabel: I = i.onLabel,
|
|
38
|
+
readOnly: F = i.readOnly
|
|
39
|
+
} = e, [D, U] = V(Q || !1), [X, K] = V(!1), s = l(null), o = l(null), h = l(null), v = l(void 0), S = l(!1), z = l(void 0), P = L(() => new fe(), []), n = L(() => v.current !== void 0 ? v.current : e.checked !== void 0 ? e.checked : D, [e.checked, D]), b = L(() => {
|
|
40
|
+
var g, H;
|
|
41
|
+
const a = e.validationMessage !== void 0, r = (g = e.valid) != null ? g : e.required ? !!n : !0, y = (H = e.valid) != null ? H : r;
|
|
40
42
|
return {
|
|
41
43
|
customError: a,
|
|
42
|
-
valid:
|
|
44
|
+
valid: y,
|
|
43
45
|
valueMissing: n === null
|
|
44
46
|
};
|
|
45
|
-
}, [e.valid, e.validationMessage, e.required, n]),
|
|
47
|
+
}, [e.valid, e.validationMessage, e.required, n]), Y = (q = e.validityStyles) != null ? q : i.validityStyles;
|
|
46
48
|
M(() => {
|
|
47
49
|
var a;
|
|
48
50
|
(a = h.current) != null && a.setCustomValidity && h.current.setCustomValidity(
|
|
49
|
-
b.valid ? "" : e.validationMessage ||
|
|
51
|
+
b.valid ? "" : e.validationMessage || P.toLanguageString(j, me[j])
|
|
50
52
|
);
|
|
51
|
-
}, [b, e.validationMessage,
|
|
52
|
-
s.current && (
|
|
53
|
+
}, [b, e.validationMessage, P]), M(() => {
|
|
54
|
+
s.current && (z.current = e.dir || getComputedStyle(s.current).direction || void 0);
|
|
53
55
|
}, [e.dir]);
|
|
54
56
|
const u = m(() => ({
|
|
55
57
|
props: e,
|
|
@@ -73,10 +75,10 @@ const c = {
|
|
|
73
75
|
return b;
|
|
74
76
|
}
|
|
75
77
|
}), [e, n, b]), f = m(
|
|
76
|
-
(a,
|
|
77
|
-
|
|
78
|
+
(a, r) => {
|
|
79
|
+
U(a), v.current = a, de(
|
|
78
80
|
e.onChange,
|
|
79
|
-
|
|
81
|
+
r,
|
|
80
82
|
{ ...u(), value: a },
|
|
81
83
|
{ value: a }
|
|
82
84
|
), v.current = void 0;
|
|
@@ -84,24 +86,24 @@ const c = {
|
|
|
84
86
|
[e.onChange, u]
|
|
85
87
|
);
|
|
86
88
|
M(() => {
|
|
87
|
-
const a = e.name || e.id,
|
|
89
|
+
const a = e.name || e.id, r = le(o.current, {
|
|
88
90
|
fieldName: a,
|
|
89
|
-
onValueChange: (
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
91
|
+
onValueChange: (y) => {
|
|
92
|
+
if (y !== n) {
|
|
93
|
+
const g = {
|
|
92
94
|
target: o.current,
|
|
93
95
|
currentTarget: o.current,
|
|
94
96
|
nativeEvent: new Event("change", { bubbles: !0 })
|
|
95
97
|
};
|
|
96
|
-
f(
|
|
98
|
+
f(y, g);
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
});
|
|
100
102
|
return () => {
|
|
101
|
-
|
|
103
|
+
r == null || r.unsubscribe();
|
|
102
104
|
};
|
|
103
105
|
}, [e.name, e.id, n, f]);
|
|
104
|
-
const
|
|
106
|
+
const Z = m(
|
|
105
107
|
(a) => {
|
|
106
108
|
if (a.target === h.current) {
|
|
107
109
|
if (S.current) {
|
|
@@ -113,40 +115,41 @@ const c = {
|
|
|
113
115
|
f(!n, a);
|
|
114
116
|
},
|
|
115
117
|
[n, f]
|
|
116
|
-
),
|
|
118
|
+
), _ = m(
|
|
117
119
|
(a) => {
|
|
118
|
-
if (
|
|
120
|
+
if (c)
|
|
119
121
|
return;
|
|
120
|
-
const { keyCode:
|
|
121
|
-
(
|
|
122
|
+
const { keyCode: r } = a;
|
|
123
|
+
(r === $.space || r === $.enter) && (f(!n, a), a.preventDefault());
|
|
122
124
|
},
|
|
123
|
-
[
|
|
124
|
-
),
|
|
125
|
+
[c, n, f]
|
|
126
|
+
), p = m(
|
|
125
127
|
(a) => {
|
|
126
|
-
|
|
128
|
+
c || (K(!0), E && E(a));
|
|
127
129
|
},
|
|
128
|
-
[
|
|
129
|
-
),
|
|
130
|
+
[c, E]
|
|
131
|
+
), ee = m(
|
|
130
132
|
(a) => {
|
|
131
|
-
|
|
133
|
+
c || (K(!1), R && R(a));
|
|
132
134
|
},
|
|
133
|
-
[
|
|
135
|
+
[c, R]
|
|
134
136
|
);
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const
|
|
137
|
+
W(J, u, [u]);
|
|
138
|
+
const T = l(null);
|
|
139
|
+
W(T, u, [u]), se("switch", T, e, e.webMcp);
|
|
140
|
+
const te = z.current || e.dir || s.current && getComputedStyle(s.current).direction || void 0, ae = !Y || b.valid, ne = N(
|
|
139
141
|
"k-switch",
|
|
140
142
|
{
|
|
141
143
|
[`k-switch-${x.sizeMap[k] || k}`]: k,
|
|
142
144
|
"k-switch-on": n,
|
|
143
145
|
"k-switch-off": !n,
|
|
144
|
-
"k-focus":
|
|
145
|
-
"k-disabled":
|
|
146
|
-
"k-
|
|
146
|
+
"k-focus": X,
|
|
147
|
+
"k-disabled": c,
|
|
148
|
+
"k-readonly": F,
|
|
149
|
+
"k-invalid": !ae
|
|
147
150
|
},
|
|
148
151
|
e.className
|
|
149
|
-
),
|
|
152
|
+
), ie = /* @__PURE__ */ d.createElement(
|
|
150
153
|
"input",
|
|
151
154
|
{
|
|
152
155
|
type: "checkbox",
|
|
@@ -155,32 +158,33 @@ const c = {
|
|
|
155
158
|
tabIndex: -1,
|
|
156
159
|
value: n,
|
|
157
160
|
style: { opacity: 0, width: 1, border: 0, zIndex: -1, position: "absolute", left: "50%" },
|
|
158
|
-
onChange:
|
|
161
|
+
onChange: O,
|
|
159
162
|
name: e.name || void 0
|
|
160
163
|
}
|
|
161
164
|
);
|
|
162
|
-
return /* @__PURE__ */
|
|
165
|
+
return /* @__PURE__ */ d.createElement(
|
|
163
166
|
"span",
|
|
164
167
|
{
|
|
165
168
|
ref: o,
|
|
166
169
|
role: "switch",
|
|
167
170
|
"aria-checked": n,
|
|
168
|
-
"aria-disabled":
|
|
171
|
+
"aria-disabled": c || void 0,
|
|
172
|
+
"aria-readonly": F ? "true" : void 0,
|
|
169
173
|
"aria-labelledby": e.ariaLabelledBy,
|
|
170
174
|
"aria-describedby": e.ariaDescribedBy,
|
|
171
|
-
"aria-label": e.ariaLabel
|
|
175
|
+
"aria-label": e.ariaLabel,
|
|
172
176
|
"aria-required": e.required,
|
|
173
|
-
className:
|
|
174
|
-
dir:
|
|
175
|
-
onKeyDown:
|
|
176
|
-
onClick:
|
|
177
|
-
onBlur:
|
|
178
|
-
onFocus:
|
|
179
|
-
tabIndex:
|
|
177
|
+
className: ne,
|
|
178
|
+
dir: te,
|
|
179
|
+
onKeyDown: _,
|
|
180
|
+
onClick: Z,
|
|
181
|
+
onBlur: ee,
|
|
182
|
+
onFocus: p,
|
|
183
|
+
tabIndex: oe(e.tabIndex, c, void 0),
|
|
180
184
|
accessKey: e.accessKey,
|
|
181
185
|
id: e.id
|
|
182
186
|
},
|
|
183
|
-
/* @__PURE__ */
|
|
187
|
+
/* @__PURE__ */ d.createElement(
|
|
184
188
|
"span",
|
|
185
189
|
{
|
|
186
190
|
className: N("k-switch-track", {
|
|
@@ -188,11 +192,11 @@ const c = {
|
|
|
188
192
|
}),
|
|
189
193
|
ref: s
|
|
190
194
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
195
|
+
ie,
|
|
196
|
+
I ? /* @__PURE__ */ d.createElement("span", { className: "k-switch-label-on" }, I) : "",
|
|
197
|
+
B ? /* @__PURE__ */ d.createElement("span", { className: "k-switch-label-off" }, B) : ""
|
|
194
198
|
),
|
|
195
|
-
/* @__PURE__ */
|
|
199
|
+
/* @__PURE__ */ d.createElement("span", { className: "k-switch-thumb-wrap" }, /* @__PURE__ */ d.createElement(
|
|
196
200
|
"span",
|
|
197
201
|
{
|
|
198
202
|
className: N("k-switch-thumb", {
|
|
@@ -202,21 +206,22 @@ const c = {
|
|
|
202
206
|
))
|
|
203
207
|
);
|
|
204
208
|
});
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
209
|
+
A.displayName = "Switch";
|
|
210
|
+
const be = ue(), G = re(
|
|
211
|
+
ce(
|
|
212
|
+
be,
|
|
213
|
+
A
|
|
210
214
|
)
|
|
211
215
|
);
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
G.displayName = "KendoReactSwitch";
|
|
217
|
+
G.propTypes = {
|
|
214
218
|
accessKey: t.string,
|
|
215
219
|
checked: t.bool,
|
|
216
220
|
className: t.string,
|
|
217
221
|
defaultChecked: t.bool,
|
|
218
222
|
defaultValue: t.any,
|
|
219
223
|
disabled: t.bool,
|
|
224
|
+
readOnly: t.bool,
|
|
220
225
|
dir: t.string,
|
|
221
226
|
id: t.string,
|
|
222
227
|
size: t.oneOf(["small", "medium", "large"]),
|
|
@@ -239,7 +244,7 @@ J.propTypes = {
|
|
|
239
244
|
validityStyles: t.bool
|
|
240
245
|
};
|
|
241
246
|
export {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
247
|
+
G as Switch,
|
|
248
|
+
be as SwitchPropsContext,
|
|
249
|
+
A as SwitchWithoutContext
|
|
245
250
|
};
|