wimui 0.62.2 → 0.63.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.
- package/dist/components/_internal/OverlayBase.cjs +1 -1
- package/dist/components/_internal/OverlayBase.js +31 -30
- package/dist/components/_internal/composeEventHandlers.cjs +2 -0
- package/dist/components/_internal/composeEventHandlers.d.ts +25 -0
- package/dist/components/_internal/composeEventHandlers.js +8 -0
- package/dist/components/_internal/observeMove.cjs +2 -0
- package/dist/components/_internal/observeMove.d.ts +16 -0
- package/dist/components/_internal/observeMove.js +44 -0
- package/dist/components/ai/ChatUI/ChatUI.cjs +1 -1
- package/dist/components/ai/ChatUI/ChatUI.js +83 -82
- package/dist/components/data-display/Accordion/Accordion.cjs +1 -1
- package/dist/components/data-display/Accordion/Accordion.js +79 -78
- package/dist/components/data-display/PullToRefresh/PullToRefresh.cjs +1 -1
- package/dist/components/data-display/PullToRefresh/PullToRefresh.js +73 -72
- package/dist/components/data-display/SortableList/SortableList.cjs +1 -1
- package/dist/components/data-display/SortableList/SortableList.js +54 -53
- package/dist/components/data-display/SwipeAction/SwipeAction.cjs +1 -1
- package/dist/components/data-display/SwipeAction/SwipeAction.js +77 -76
- package/dist/components/feedback/Tour/Tour.cjs +1 -1
- package/dist/components/feedback/Tour/Tour.js +91 -88
- package/dist/components/form/Button/Button.cjs +1 -1
- package/dist/components/form/Button/Button.d.ts +2 -2
- package/dist/components/form/Button/Button.js +14 -12
- package/dist/components/form/Cascader/Cascader.cjs +1 -1
- package/dist/components/form/Cascader/Cascader.js +99 -98
- package/dist/components/form/DatePicker/DatePicker.cjs +1 -1
- package/dist/components/form/DatePicker/DatePicker.js +53 -52
- package/dist/components/form/RangeSlider/RangeSlider.cjs +1 -1
- package/dist/components/form/RangeSlider/RangeSlider.js +109 -108
- package/dist/components/form/Rating/Rating.cjs +1 -1
- package/dist/components/form/Rating/Rating.js +75 -74
- package/dist/components/form/Slider/Slider.cjs +1 -1
- package/dist/components/form/Slider/Slider.js +58 -57
- package/dist/components/form/SmartSearchInput/SmartSearchInput.cjs +1 -1
- package/dist/components/form/SmartSearchInput/SmartSearchInput.js +65 -64
- package/dist/components/form/Textarea/Textarea.cjs +1 -1
- package/dist/components/form/Textarea/Textarea.js +4 -4
- package/dist/components/form/TimePicker/TimePicker.cjs +1 -1
- package/dist/components/form/TimePicker/TimePicker.js +31 -30
- package/dist/components/layout/Dashboard/Dashboard.cjs +1 -1
- package/dist/components/layout/Dashboard/Dashboard.js +3 -2
- package/dist/components/layout/InteractiveArea/InteractiveArea.cjs +1 -1
- package/dist/components/layout/InteractiveArea/InteractiveArea.js +1 -1
- package/dist/components/layout/Navbar/Navbar.cjs +1 -1
- package/dist/components/layout/Navbar/Navbar.js +68 -66
- package/dist/components/layout/Splitter/Splitter.cjs +1 -1
- package/dist/components/layout/Splitter/Splitter.js +47 -46
- package/dist/components/layout/Transition/Transition.cjs +1 -1
- package/dist/components/layout/Transition/Transition.js +25 -24
- package/dist/components/media/Audio/Audio.cjs +1 -1
- package/dist/components/media/Audio/Audio.js +39 -38
- package/dist/components/media/Image/Image.cjs +2 -2
- package/dist/components/media/Image/Image.js +96 -95
- package/dist/components/media/ImageCompare/ImageCompare.cjs +1 -1
- package/dist/components/media/ImageCompare/ImageCompare.js +75 -73
- package/dist/components/media/Video/Video.cjs +1 -1
- package/dist/components/media/Video/Video.js +114 -113
- package/dist/components/navigation/Affix/Affix.cjs +1 -1
- package/dist/components/navigation/Affix/Affix.js +39 -36
- package/dist/components/navigation/Menubar/Menubar.cjs +1 -1
- package/dist/components/navigation/Menubar/Menubar.js +67 -61
- package/dist/components/navigation/SpeedDial/SpeedDial.cjs +1 -1
- package/dist/components/navigation/SpeedDial/SpeedDial.js +47 -46
- package/dist/components/navigation/Tabs/Tabs.cjs +1 -1
- package/dist/components/navigation/Tabs/Tabs.js +87 -86
- package/dist/components/overlay/Dropdown/Dropdown.cjs +1 -1
- package/dist/components/overlay/Dropdown/Dropdown.js +42 -36
- package/dist/components/overlay/Popover/Popover.cjs +1 -1
- package/dist/components/overlay/Popover/Popover.js +1 -1
- package/dist/llms-full.txt +3 -3
- package/dist/llms.txt +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +1 -1
|
@@ -2,159 +2,160 @@
|
|
|
2
2
|
import { Root as e, Slottable as t } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
3
|
import { useWimTranslation as n } from "../../../i18n/useWimTranslation.js";
|
|
4
4
|
import { commonNs as r } from "../../../i18n/generated/common.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import o from "
|
|
8
|
-
import
|
|
9
|
-
import u from "
|
|
10
|
-
import
|
|
5
|
+
import { composeEventHandlers as i } from "../../_internal/composeEventHandlers.js";
|
|
6
|
+
import { FieldTemplate as a } from "../FieldTemplate/FieldTemplate.js";
|
|
7
|
+
import { useSliderCommon as o } from "../../../utilities/slider-utils.js";
|
|
8
|
+
import s from "./range-slider.module.js";
|
|
9
|
+
import { useCallback as c, useEffect as l, useId as ee, useRef as u, useState as d } from "react";
|
|
10
|
+
import f from "classnames";
|
|
11
|
+
import { jsx as p, jsxs as te } from "react/jsx-runtime";
|
|
11
12
|
//#region src/components/form/RangeSlider/RangeSlider.tsx
|
|
12
|
-
var
|
|
13
|
-
let { t:
|
|
14
|
-
|
|
15
|
-
let [ge,
|
|
16
|
-
let t =
|
|
17
|
-
|
|
18
|
-
}, [
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
var m = ({ value: m, defaultValue: ne = [20, 80], min: h = 0, max: g = 100, step: _ = 1, allowCross: v = !1, disabled: y = !1, onChange: b, onAfterChange: re, className: ie, name: x, label: S, error: C, required: ae, layout: oe = "vertical", id: se, "aria-label": ce, "aria-labelledby": w, "aria-describedby": le, asChild: ue = !1, children: de, ...T }) => {
|
|
14
|
+
let { t: E } = n(r), D = m !== void 0, fe = ee(), O = se || fe, pe = `wim-range-slider-label-${O}`, me = `wim-range-slider-error-${O}`, he = [le, C ? me : void 0].filter(Boolean).join(" ") || void 0, k = S || ce, A = `wim-range-slider-start-${O}`, j = `wim-range-slider-end-${O}`, M = (e) => !k && w ? `${w} ${e}` : void 0, { clamp: N, calculateValue: P } = o(h, g, _), F = [N(ne[0], h, g), N(ne[1], h, g)];
|
|
15
|
+
F[0] > F[1] && F.sort((e, t) => e - t);
|
|
16
|
+
let [ge, I] = d(F), L = D ? m : ge, R = u(null), z = u(null), B = u(null), V = u(null), H = u(null), U = u(null), [W, G] = d(null), K = u(null), q = u([...L]), J = c((e) => (e - h) / (g - h) * 100, [h, g]), Y = c((e) => {
|
|
17
|
+
let t = J(e[0]), n = J(e[1]);
|
|
18
|
+
z.current && (z.current.style.left = `${t}%`, z.current.setAttribute("aria-valuenow", String(e[0])), z.current.setAttribute("aria-valuemax", String(e[1]))), B.current && (B.current.style.left = `${n}%`, B.current.setAttribute("aria-valuenow", String(e[1])), B.current.setAttribute("aria-valuemin", String(e[0]))), V.current && (V.current.style.left = `${t}%`, V.current.style.width = `${n - t}%`), H.current && (H.current.value = String(e[0])), U.current && (U.current.value = String(e[1]));
|
|
19
|
+
}, [J]);
|
|
20
|
+
l(() => {
|
|
21
|
+
W || Y(L);
|
|
21
22
|
}, [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
L,
|
|
24
|
+
W,
|
|
25
|
+
Y
|
|
25
26
|
]);
|
|
26
|
-
let
|
|
27
|
-
|
|
27
|
+
let X = (e, t) => {
|
|
28
|
+
y || (q.current = [...L], K.current = t, G(t), e.stopPropagation(), e.preventDefault());
|
|
28
29
|
}, _e = (e) => {
|
|
29
|
-
if (
|
|
30
|
-
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n =
|
|
31
|
-
a = r < i ? "min" : i < r ? "max" : n <
|
|
32
|
-
let o = [...
|
|
33
|
-
a === "min" ? o[0] = Math.min(n,
|
|
34
|
-
},
|
|
35
|
-
if (!
|
|
36
|
-
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n =
|
|
37
|
-
|
|
30
|
+
if (y) return;
|
|
31
|
+
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n = P(t, R.current), r = Math.abs(L[0] - n), i = Math.abs(L[1] - n), a;
|
|
32
|
+
a = r < i ? "min" : i < r ? "max" : n < L[0] ? "min" : "max", K.current = a, G(a);
|
|
33
|
+
let o = [...q.current];
|
|
34
|
+
a === "min" ? o[0] = Math.min(n, v ? g : o[1]) : o[1] = Math.max(n, v ? h : o[0]), q.current = o, Y(o), b?.(o);
|
|
35
|
+
}, Z = c((e) => {
|
|
36
|
+
if (!K.current || y) return;
|
|
37
|
+
let t = "touches" in e ? e.touches[0].clientX : e.clientX, n = P(t, R.current), r = [...q.current];
|
|
38
|
+
K.current === "min" ? r[0] = Math.min(n, v ? g : r[1]) : r[1] = Math.max(n, v ? h : r[0]), q.current = r, Y(r), b?.(r);
|
|
38
39
|
}, [
|
|
39
|
-
v,
|
|
40
40
|
y,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
b,
|
|
42
|
+
v,
|
|
43
|
+
P,
|
|
44
44
|
h,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
g,
|
|
46
|
+
Y
|
|
47
|
+
]), Q = c(() => {
|
|
48
|
+
if (K.current) {
|
|
49
|
+
K.current = null, G(null);
|
|
50
|
+
let e = q.current;
|
|
51
|
+
D || I([...e]), re?.(e);
|
|
51
52
|
}
|
|
52
|
-
}, [
|
|
53
|
-
|
|
54
|
-
document.removeEventListener("mousemove",
|
|
55
|
-
}), [
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
58
|
-
let n = [...
|
|
59
|
-
if (e.key === "ArrowLeft" || e.key === "ArrowDown") i = Math.max(
|
|
60
|
-
else if (e.key === "ArrowRight" || e.key === "ArrowUp") i = Math.min(
|
|
61
|
-
else if (e.key === "Home") i =
|
|
62
|
-
else if (e.key === "End") i =
|
|
53
|
+
}, [D, re]);
|
|
54
|
+
l(() => (document.addEventListener("mousemove", Z), document.addEventListener("mouseup", Q), document.addEventListener("touchmove", Z, { passive: !1 }), document.addEventListener("touchend", Q), () => {
|
|
55
|
+
document.removeEventListener("mousemove", Z), document.removeEventListener("mouseup", Q), document.removeEventListener("touchmove", Z), document.removeEventListener("touchend", Q);
|
|
56
|
+
}), [Z, Q]);
|
|
57
|
+
let ve = (e, t) => {
|
|
58
|
+
if (y) return;
|
|
59
|
+
let n = [...L], r = t === "min" ? n[0] : n[1], i;
|
|
60
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowDown") i = Math.max(h, r - _);
|
|
61
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowUp") i = Math.min(g, r + _);
|
|
62
|
+
else if (e.key === "Home") i = h;
|
|
63
|
+
else if (e.key === "End") i = g;
|
|
63
64
|
else return;
|
|
64
65
|
if (t === "min") {
|
|
65
|
-
let e =
|
|
66
|
+
let e = v ? g : n[1];
|
|
66
67
|
n[0] = Math.min(i, e);
|
|
67
68
|
} else {
|
|
68
|
-
let e =
|
|
69
|
+
let e = v ? h : n[0];
|
|
69
70
|
n[1] = Math.max(i, e);
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
}, $ =
|
|
73
|
-
return /* @__PURE__ */
|
|
72
|
+
D || I(n), b?.(n), e.preventDefault();
|
|
73
|
+
}, $ = J(L[0]), ye = J(L[1]);
|
|
74
|
+
return /* @__PURE__ */ p(a, {
|
|
74
75
|
label: S,
|
|
75
76
|
error: C,
|
|
76
|
-
required:
|
|
77
|
-
layout:
|
|
77
|
+
required: ae,
|
|
78
|
+
layout: oe,
|
|
78
79
|
labelId: pe,
|
|
79
80
|
errorId: me,
|
|
80
|
-
className:
|
|
81
|
-
children: /* @__PURE__ */
|
|
81
|
+
className: ie,
|
|
82
|
+
children: /* @__PURE__ */ te(ue ? e : "div", {
|
|
82
83
|
role: "presentation",
|
|
83
84
|
"data-testid": "range-slider-root",
|
|
84
|
-
className:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
className: f("wim-range-slider", s.root, y && s.disabled, C && s.danger),
|
|
86
|
+
...T,
|
|
87
|
+
onMouseDown: (e) => i(T.onMouseDown, _e)(e),
|
|
88
|
+
onTouchStart: (e) => i(T.onTouchStart, _e)(e),
|
|
88
89
|
children: [
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
className:
|
|
91
|
-
ref:
|
|
90
|
+
/* @__PURE__ */ te("div", {
|
|
91
|
+
className: s.trackContainer,
|
|
92
|
+
ref: R,
|
|
92
93
|
children: [
|
|
93
|
-
/* @__PURE__ */
|
|
94
|
-
ref:
|
|
95
|
-
className:
|
|
94
|
+
/* @__PURE__ */ p("div", {
|
|
95
|
+
ref: V,
|
|
96
|
+
className: s.track,
|
|
96
97
|
style: {
|
|
97
98
|
left: `${$}%`,
|
|
98
|
-
width: `${
|
|
99
|
+
width: `${ye - $}%`
|
|
99
100
|
}
|
|
100
101
|
}),
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
-
ref:
|
|
103
|
-
className:
|
|
102
|
+
/* @__PURE__ */ p("div", {
|
|
103
|
+
ref: z,
|
|
104
|
+
className: f(s.thumb, W === "min" && s.active),
|
|
104
105
|
style: { left: `${$}%` },
|
|
105
106
|
role: "slider",
|
|
106
|
-
"aria-valuemin":
|
|
107
|
-
"aria-valuemax":
|
|
108
|
-
"aria-valuenow":
|
|
109
|
-
"aria-disabled":
|
|
110
|
-
id:
|
|
111
|
-
"aria-labelledby":
|
|
112
|
-
"aria-label":
|
|
107
|
+
"aria-valuemin": h,
|
|
108
|
+
"aria-valuemax": L[1],
|
|
109
|
+
"aria-valuenow": L[0],
|
|
110
|
+
"aria-disabled": y,
|
|
111
|
+
id: A,
|
|
112
|
+
"aria-labelledby": M(A),
|
|
113
|
+
"aria-label": k ? E("rangeSlider.start_of", { label: k }) : E("rangeSlider.start"),
|
|
113
114
|
"aria-describedby": he,
|
|
114
115
|
"aria-invalid": C ? !0 : void 0,
|
|
115
|
-
tabIndex:
|
|
116
|
-
onMouseDown: (e) =>
|
|
117
|
-
onTouchStart: (e) =>
|
|
118
|
-
onKeyDown: (e) =>
|
|
116
|
+
tabIndex: y ? -1 : 0,
|
|
117
|
+
onMouseDown: (e) => X(e, "min"),
|
|
118
|
+
onTouchStart: (e) => X(e, "min"),
|
|
119
|
+
onKeyDown: (e) => ve(e, "min")
|
|
119
120
|
}),
|
|
120
|
-
/* @__PURE__ */
|
|
121
|
-
ref:
|
|
122
|
-
className:
|
|
123
|
-
style: { left: `${
|
|
121
|
+
/* @__PURE__ */ p("div", {
|
|
122
|
+
ref: B,
|
|
123
|
+
className: f(s.thumb, W === "max" && s.active),
|
|
124
|
+
style: { left: `${ye}%` },
|
|
124
125
|
role: "slider",
|
|
125
|
-
"aria-valuemin":
|
|
126
|
-
"aria-valuemax":
|
|
127
|
-
"aria-valuenow":
|
|
128
|
-
"aria-disabled":
|
|
129
|
-
id:
|
|
130
|
-
"aria-labelledby": j
|
|
131
|
-
"aria-label":
|
|
126
|
+
"aria-valuemin": L[0],
|
|
127
|
+
"aria-valuemax": g,
|
|
128
|
+
"aria-valuenow": L[1],
|
|
129
|
+
"aria-disabled": y,
|
|
130
|
+
id: j,
|
|
131
|
+
"aria-labelledby": M(j),
|
|
132
|
+
"aria-label": k ? E("rangeSlider.end_of", { label: k }) : E("rangeSlider.end"),
|
|
132
133
|
"aria-describedby": he,
|
|
133
134
|
"aria-invalid": C ? !0 : void 0,
|
|
134
|
-
tabIndex:
|
|
135
|
-
onMouseDown: (e) =>
|
|
136
|
-
onTouchStart: (e) =>
|
|
137
|
-
onKeyDown: (e) =>
|
|
135
|
+
tabIndex: y ? -1 : 0,
|
|
136
|
+
onMouseDown: (e) => X(e, "max"),
|
|
137
|
+
onTouchStart: (e) => X(e, "max"),
|
|
138
|
+
onKeyDown: (e) => ve(e, "max")
|
|
138
139
|
})
|
|
139
140
|
]
|
|
140
141
|
}),
|
|
141
|
-
/* @__PURE__ */
|
|
142
|
-
ref:
|
|
142
|
+
/* @__PURE__ */ p("input", {
|
|
143
|
+
ref: H,
|
|
143
144
|
type: "hidden",
|
|
144
145
|
name: x ? `${x}-min` : "",
|
|
145
|
-
value:
|
|
146
|
+
value: L[0]
|
|
146
147
|
}),
|
|
147
|
-
/* @__PURE__ */
|
|
148
|
-
ref:
|
|
148
|
+
/* @__PURE__ */ p("input", {
|
|
149
|
+
ref: U,
|
|
149
150
|
type: "hidden",
|
|
150
151
|
name: x ? `${x}-max` : "",
|
|
151
|
-
value:
|
|
152
|
+
value: L[1]
|
|
152
153
|
}),
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
+
/* @__PURE__ */ p(t, { children: de })
|
|
154
155
|
]
|
|
155
156
|
})
|
|
156
157
|
});
|
|
157
158
|
};
|
|
158
|
-
|
|
159
|
+
m.displayName = "RangeSlider";
|
|
159
160
|
//#endregion
|
|
160
|
-
export {
|
|
161
|
+
export { m as RangeSlider };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../icon/star.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../_internal/composeEventHandlers.cjs"),r=require("../../../icon/star.cjs"),i=require("../../media/Icon/Icon.cjs"),a=require("../FieldTemplate/FieldTemplate.cjs"),o=require("./rating.module.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("classnames");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=({value:e,defaultValue:u=0,count:d=5,allowHalf:f=!1,disabled:p=!1,readOnly:m=!1,size:h=`md`,onChange:g,className:_,label:v,error:y,required:b,layout:x=`vertical`,labels:S={},asChild:C=!1,children:w,...T})=>{let{star:E=e=>`${e} star${e===1?``:`s`}`,readonly:D=(e,t)=>`Rating: ${e} out of ${t}`}=S,O=e!==void 0,[k,A]=(0,s.useState)(u),[j,M]=(0,s.useState)(null),N=(0,s.useId)(),P=`wim-rating-label-${N}`,F=`wim-rating-error-${N}`,I=(0,s.useRef)([]),L=O?e:k,R=j===null?L:j,z=(e,t)=>{if(p||m)return;let n=e+1;if(f){let e=t.currentTarget.getBoundingClientRect();t.clientX-e.left<=e.width/2&&(n-=.5)}M(n)},B=()=>{p||m||M(null)},V=e=>{p||m||(O||A(e),g?.(e))},H=(()=>{if(L===0)return 0;for(let e=0;e<d;e++){let t=e+1;if(L===t||f&&L===t-.5)return e}return 0})(),U=(e,t)=>{if(p||m)return;let n=f?.5:1;if(t.key===`ArrowRight`||t.key===`ArrowUp`){t.preventDefault();let e=Math.min(d,L+n),r=Math.min(Math.ceil(e)-1,d-1);V(e),I.current[r]?.focus()}else if(t.key===`ArrowLeft`||t.key===`ArrowDown`){t.preventDefault();let e=Math.max(0,L-n),r=e===0?0:Math.ceil(e)-1;V(e),I.current[r]?.focus()}else t.key===`Home`?(t.preventDefault(),V(0),I.current[0]?.focus()):t.key===`End`&&(t.preventDefault(),V(d),I.current[d-1]?.focus())},W=e=>{let t=e+1,n=R>=t,a=!n&&R>=t-.5,s=L===t||f&&L===t-.5;return(0,l.jsxs)(`div`,{ref:t=>{I.current[e]=t},className:(0,c.default)(o.default.star,n&&o.default.full,a&&o.default.half),onMouseMove:t=>z(e,t),onClick:e=>{let n=e.currentTarget.getBoundingClientRect(),r=e.clientX-n.left,i=t;f&&r<=n.width/2&&(i-=.5),V(i)},onKeyDown:n=>{n.key===`Enter`||n.key===` `?(n.preventDefault(),V(t)):U(e,n)},role:m?`presentation`:`radio`,tabIndex:p||m?-1:e===H?0:-1,"aria-checked":m?void 0:s,"aria-label":m?void 0:E(e+1),children:[(0,l.jsx)(`div`,{className:o.default.background,children:(0,l.jsx)(i.Icon,{component:r.default,size:h,className:o.default.icon})}),(0,l.jsx)(`div`,{className:o.default.foreground,children:(0,l.jsx)(i.Icon,{component:r.default,size:h,className:o.default.icon})})]},e)},G=Array.from({length:d},(e,t)=>W(t));return(0,l.jsx)(a.FieldTemplate,{label:v,error:y,required:b,layout:x,labelId:P,errorId:F,className:_,children:(0,l.jsxs)(C?t.Root:`div`,{className:(0,c.default)(`wim-rating`,o.default.root,o.default[h],p&&o.default.disabled),role:m?`img`:`radiogroup`,"aria-label":m?D(L,d):void 0,"aria-labelledby":!m&&v?P:void 0,"aria-disabled":!m&&p?!0:void 0,"aria-required":m?void 0:b,"aria-describedby":!m&&y?F:void 0,"aria-invalid":!m&&y?!0:void 0,...T,onMouseLeave:n.composeEventHandlers(T.onMouseLeave,m?void 0:B),children:[G,(0,l.jsx)(t.Slottable,{children:w})]})})};exports.Rating=u;
|
|
@@ -1,103 +1,104 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Root as e, Slottable as t } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
|
-
import n from "
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import a from "
|
|
7
|
-
import
|
|
8
|
-
import l from "
|
|
9
|
-
import
|
|
3
|
+
import { composeEventHandlers as n } from "../../_internal/composeEventHandlers.js";
|
|
4
|
+
import r from "../../../icon/star.js";
|
|
5
|
+
import { Icon as i } from "../../media/Icon/Icon.js";
|
|
6
|
+
import { FieldTemplate as a } from "../FieldTemplate/FieldTemplate.js";
|
|
7
|
+
import o from "./rating.module.js";
|
|
8
|
+
import { useId as s, useRef as c, useState as l } from "react";
|
|
9
|
+
import u from "classnames";
|
|
10
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
10
11
|
//#region src/components/form/Rating/Rating.tsx
|
|
11
|
-
var
|
|
12
|
-
let { star:
|
|
13
|
-
if (
|
|
12
|
+
var p = ({ value: p, defaultValue: m = 0, count: h = 5, allowHalf: g = !1, disabled: _ = !1, readOnly: v = !1, size: y = "md", onChange: b, className: x, label: S, error: C, required: w, layout: T = "vertical", labels: E = {}, asChild: D = !1, children: O, ...k }) => {
|
|
13
|
+
let { star: A = (e) => `${e} star${e === 1 ? "" : "s"}`, readonly: j = (e, t) => `Rating: ${e} out of ${t}` } = E, M = p !== void 0, [N, P] = l(m), [F, I] = l(null), L = s(), R = `wim-rating-label-${L}`, z = `wim-rating-error-${L}`, B = c([]), V = M ? p : N, H = F === null ? V : F, U = (e, t) => {
|
|
14
|
+
if (_ || v) return;
|
|
14
15
|
let n = e + 1;
|
|
15
|
-
if (
|
|
16
|
+
if (g) {
|
|
16
17
|
let e = t.currentTarget.getBoundingClientRect();
|
|
17
18
|
t.clientX - e.left <= e.width / 2 && (n -= .5);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
if (
|
|
26
|
-
for (let e = 0; e <
|
|
20
|
+
I(n);
|
|
21
|
+
}, W = () => {
|
|
22
|
+
_ || v || I(null);
|
|
23
|
+
}, G = (e) => {
|
|
24
|
+
_ || v || (M || P(e), b?.(e));
|
|
25
|
+
}, K = (() => {
|
|
26
|
+
if (V === 0) return 0;
|
|
27
|
+
for (let e = 0; e < h; e++) {
|
|
27
28
|
let t = e + 1;
|
|
28
|
-
if (
|
|
29
|
+
if (V === t || g && V === t - .5) return e;
|
|
29
30
|
}
|
|
30
31
|
return 0;
|
|
31
|
-
})(),
|
|
32
|
-
if (
|
|
33
|
-
let n =
|
|
32
|
+
})(), q = (e, t) => {
|
|
33
|
+
if (_ || v) return;
|
|
34
|
+
let n = g ? .5 : 1;
|
|
34
35
|
if (t.key === "ArrowRight" || t.key === "ArrowUp") {
|
|
35
36
|
t.preventDefault();
|
|
36
|
-
let e = Math.min(
|
|
37
|
-
|
|
37
|
+
let e = Math.min(h, V + n), r = Math.min(Math.ceil(e) - 1, h - 1);
|
|
38
|
+
G(e), B.current[r]?.focus();
|
|
38
39
|
} else if (t.key === "ArrowLeft" || t.key === "ArrowDown") {
|
|
39
40
|
t.preventDefault();
|
|
40
|
-
let e = Math.max(0,
|
|
41
|
-
|
|
42
|
-
} else t.key === "Home" ? (t.preventDefault(),
|
|
43
|
-
},
|
|
44
|
-
let t = e + 1,
|
|
45
|
-
return /* @__PURE__ */
|
|
41
|
+
let e = Math.max(0, V - n), r = e === 0 ? 0 : Math.ceil(e) - 1;
|
|
42
|
+
G(e), B.current[r]?.focus();
|
|
43
|
+
} else t.key === "Home" ? (t.preventDefault(), G(0), B.current[0]?.focus()) : t.key === "End" && (t.preventDefault(), G(h), B.current[h - 1]?.focus());
|
|
44
|
+
}, J = (e) => {
|
|
45
|
+
let t = e + 1, n = H >= t, a = !n && H >= t - .5, s = V === t || g && V === t - .5;
|
|
46
|
+
return /* @__PURE__ */ f("div", {
|
|
46
47
|
ref: (t) => {
|
|
47
|
-
|
|
48
|
+
B.current[e] = t;
|
|
48
49
|
},
|
|
49
|
-
className:
|
|
50
|
-
onMouseMove: (t) =>
|
|
50
|
+
className: u(o.star, n && o.full, a && o.half),
|
|
51
|
+
onMouseMove: (t) => U(e, t),
|
|
51
52
|
onClick: (e) => {
|
|
52
53
|
let n = e.currentTarget.getBoundingClientRect(), r = e.clientX - n.left, i = t;
|
|
53
|
-
|
|
54
|
+
g && r <= n.width / 2 && (i -= .5), G(i);
|
|
54
55
|
},
|
|
55
56
|
onKeyDown: (n) => {
|
|
56
|
-
n.key === "Enter" || n.key === " " ? (n.preventDefault(),
|
|
57
|
+
n.key === "Enter" || n.key === " " ? (n.preventDefault(), G(t)) : q(e, n);
|
|
57
58
|
},
|
|
58
|
-
role:
|
|
59
|
-
tabIndex:
|
|
60
|
-
"aria-checked":
|
|
61
|
-
"aria-label":
|
|
62
|
-
children: [/* @__PURE__ */
|
|
63
|
-
className:
|
|
64
|
-
children: /* @__PURE__ */
|
|
65
|
-
component:
|
|
66
|
-
size:
|
|
67
|
-
className:
|
|
59
|
+
role: v ? "presentation" : "radio",
|
|
60
|
+
tabIndex: _ || v ? -1 : e === K ? 0 : -1,
|
|
61
|
+
"aria-checked": v ? void 0 : s,
|
|
62
|
+
"aria-label": v ? void 0 : A(e + 1),
|
|
63
|
+
children: [/* @__PURE__ */ d("div", {
|
|
64
|
+
className: o.background,
|
|
65
|
+
children: /* @__PURE__ */ d(i, {
|
|
66
|
+
component: r,
|
|
67
|
+
size: y,
|
|
68
|
+
className: o.icon
|
|
68
69
|
})
|
|
69
|
-
}), /* @__PURE__ */
|
|
70
|
-
className:
|
|
71
|
-
children: /* @__PURE__ */
|
|
72
|
-
component:
|
|
73
|
-
size:
|
|
74
|
-
className:
|
|
70
|
+
}), /* @__PURE__ */ d("div", {
|
|
71
|
+
className: o.foreground,
|
|
72
|
+
children: /* @__PURE__ */ d(i, {
|
|
73
|
+
component: r,
|
|
74
|
+
size: y,
|
|
75
|
+
className: o.icon
|
|
75
76
|
})
|
|
76
77
|
})]
|
|
77
78
|
}, e);
|
|
78
|
-
},
|
|
79
|
-
return /* @__PURE__ */
|
|
80
|
-
label:
|
|
81
|
-
error:
|
|
82
|
-
required:
|
|
83
|
-
layout:
|
|
84
|
-
labelId:
|
|
85
|
-
errorId:
|
|
86
|
-
className:
|
|
87
|
-
children: /* @__PURE__ */
|
|
88
|
-
className:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"aria-
|
|
92
|
-
"aria-
|
|
93
|
-
"aria-
|
|
94
|
-
"aria-
|
|
95
|
-
"aria-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
children: [
|
|
79
|
+
}, Y = Array.from({ length: h }, (e, t) => J(t));
|
|
80
|
+
return /* @__PURE__ */ d(a, {
|
|
81
|
+
label: S,
|
|
82
|
+
error: C,
|
|
83
|
+
required: w,
|
|
84
|
+
layout: T,
|
|
85
|
+
labelId: R,
|
|
86
|
+
errorId: z,
|
|
87
|
+
className: x,
|
|
88
|
+
children: /* @__PURE__ */ f(D ? e : "div", {
|
|
89
|
+
className: u("wim-rating", o.root, o[y], _ && o.disabled),
|
|
90
|
+
role: v ? "img" : "radiogroup",
|
|
91
|
+
"aria-label": v ? j(V, h) : void 0,
|
|
92
|
+
"aria-labelledby": !v && S ? R : void 0,
|
|
93
|
+
"aria-disabled": !v && _ ? !0 : void 0,
|
|
94
|
+
"aria-required": v ? void 0 : w,
|
|
95
|
+
"aria-describedby": !v && C ? z : void 0,
|
|
96
|
+
"aria-invalid": !v && C ? !0 : void 0,
|
|
97
|
+
...k,
|
|
98
|
+
onMouseLeave: n(k.onMouseLeave, v ? void 0 : W),
|
|
99
|
+
children: [Y, /* @__PURE__ */ d(t, { children: O })]
|
|
99
100
|
})
|
|
100
101
|
});
|
|
101
102
|
};
|
|
102
103
|
//#endregion
|
|
103
|
-
export {
|
|
104
|
+
export { p as Rating };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../FieldTemplate/FieldTemplate.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../_internal/composeEventHandlers.cjs"),r=require("../FieldTemplate/FieldTemplate.cjs"),i=require("../../../utilities/slider-utils.cjs"),a=require("./slider.module.cjs");let o=require("react");o=e.__toESM(o,1);let s=require("classnames");s=e.__toESM(s,1);let c=require("react/jsx-runtime");var l=(0,o.forwardRef)(({value:e,defaultValue:l=0,min:u=0,max:d=100,step:f=1,disabled:p=!1,onChange:m,onAfterChange:h,className:g,name:_,label:v,error:y,required:b,layout:x=`vertical`,id:S,"aria-label":C,"aria-labelledby":w,"aria-describedby":T,asChild:E=!1,styles:D,children:O,...k},A)=>{let j=e!==void 0,[M,N]=(0,o.useState)(l),P=j?e:M,F=(0,o.useRef)(null),I=(0,o.useRef)(null),L=(0,o.useRef)(null),R=(0,o.useRef)(null),z=(0,o.useRef)(!1),B=(0,o.useRef)(P),V=(0,o.useId)(),H=S||V,U=`wim-slider-label-${H}`,W=`wim-slider-error-${H}`,{calculateValue:G}=i.useSliderCommon(u,d,f),K=(0,o.useCallback)(e=>(e-u)/(d-u)*100,[u,d]),q=(0,o.useCallback)(e=>{let t=K(e);L.current&&(L.current.style.width=`${t}%`),I.current&&(I.current.style.left=`${t}%`,I.current.setAttribute(`aria-valuenow`,String(e))),R.current&&(R.current.value=String(e))},[K]);(0,o.useEffect)(()=>{z.current||q(P)},[P,q]);let J=e=>{if(p)return;z.current=!0;let t=`touches`in e?e.touches[0].clientX:e.clientX,n=G(t,F.current);B.current=n,q(n),m?.(n),e.preventDefault()},Y=(0,o.useCallback)(e=>{if(!z.current||p)return;let t=`touches`in e?e.touches[0].clientX:e.clientX,n=G(t,F.current);B.current=n,q(n),m?.(n)},[p,G,m,q]),X=(0,o.useCallback)(()=>{if(z.current){z.current=!1;let e=B.current;j||N(e),h?.(e)}},[j,h]);(0,o.useEffect)(()=>(document.addEventListener(`mousemove`,Y),document.addEventListener(`mouseup`,X),document.addEventListener(`touchmove`,Y,{passive:!1}),document.addEventListener(`touchend`,X),()=>{document.removeEventListener(`mousemove`,Y),document.removeEventListener(`mouseup`,X),document.removeEventListener(`touchmove`,Y),document.removeEventListener(`touchend`,X)}),[Y,X]);let Z=e=>{if(p)return;let t;if(e.key===`ArrowLeft`||e.key===`ArrowDown`)t=Math.max(u,P-f);else if(e.key===`ArrowRight`||e.key===`ArrowUp`)t=Math.min(d,P+f);else if(e.key===`Home`)t=u;else if(e.key===`End`)t=d;else return;j||N(t),m?.(t),e.preventDefault()},Q=K(P);return(0,c.jsx)(r.FieldTemplate,{label:v,error:y,required:b,layout:x,labelId:U,errorId:W,className:g,styles:D,children:(0,c.jsxs)(E?t.Root:`div`,{role:`presentation`,className:(0,s.default)(`wim-slider`,a.default.root,p&&a.default.disabled,y&&a.default.danger),ref:A,...k,onMouseDown:n.composeEventHandlers(k.onMouseDown,J),onTouchStart:n.composeEventHandlers(k.onTouchStart,J),children:[(0,c.jsxs)(`div`,{className:a.default.trackContainer,ref:F,children:[(0,c.jsx)(`div`,{ref:L,className:a.default.track,style:{width:`${Q}%`}}),(0,c.jsx)(`div`,{ref:I,className:a.default.thumb,style:{left:`${Q}%`},role:`slider`,"aria-valuemin":u,"aria-valuemax":d,"aria-valuenow":P,"aria-disabled":p,"aria-labelledby":v?U:w,"aria-label":v?void 0:C,"aria-describedby":[T,y?W:void 0].filter(Boolean).join(` `)||void 0,"aria-invalid":y?!0:void 0,tabIndex:p?-1:0,onKeyDown:Z})]}),(0,c.jsx)(`input`,{ref:R,type:`hidden`,name:_,value:P}),E?(0,c.jsx)(t.Slottable,{children:O}):null]})})});l.displayName=`Slider`,exports.Slider=l,exports.default=l;
|