wimui 0.63.5 → 0.64.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/dist/components/data-display/Carousel/Carousel.cjs +1 -1
- package/dist/components/data-display/Carousel/Carousel.d.ts +2 -0
- package/dist/components/data-display/Carousel/Carousel.js +119 -98
- package/dist/components/feedback/Snackbar/Snackbar.cjs +1 -1
- package/dist/components/feedback/Snackbar/Snackbar.d.ts +1 -1
- package/dist/components/feedback/Snackbar/Snackbar.js +81 -79
- package/dist/components/feedback/Toast/Toast.cjs +1 -1
- package/dist/components/feedback/Toast/Toast.js +85 -66
- package/dist/components/feedback/Toast/toast.module.cjs +1 -1
- package/dist/components/feedback/Toast/toast.module.js +27 -26
- package/dist/components/form/RichTextEditor/RichTextEditor.cjs +1 -1
- package/dist/components/form/RichTextEditor/RichTextEditor.js +5 -1
- package/dist/components/media/Lightbox/Lightbox.cjs +1 -1
- package/dist/components/media/Lightbox/Lightbox.js +134 -116
- package/dist/components/navigation/CommandPalette/command-palette.module.cjs +1 -1
- package/dist/components/navigation/CommandPalette/command-palette.module.js +1 -1
- package/dist/i18n/generated/components.cjs +1 -1
- package/dist/i18n/generated/components.d.ts +1 -1
- package/dist/i18n/generated/components.js +9 -3
- package/dist/llms-full.txt +2 -2
- package/dist/llms.txt +1 -1
- package/dist/locales/en/components.json +3 -1
- package/dist/locales/ja/components.json +3 -1
- package/dist/locales/pt/components.json +3 -1
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +1 -1
|
@@ -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("../../../i18n/useWimTranslation.cjs"),r=require("../../../i18n/generated/components.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../i18n/useWimTranslation.cjs"),r=require("../../../hooks/useMergedRef.cjs"),i=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),ee=require("../../../i18n/generated/components.cjs"),a=require("../../../icon/chevron-left.cjs"),te=require("../../../icon/chevron-right.cjs"),o=require("../../media/Icon/Icon.cjs"),s=require("./carousel.module.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("classnames");l=e.__toESM(l,1);let u=require("react/jsx-runtime");var d=(e,t)=>typeof e==`number`?e:e?t>=1280&&e.xl?e.xl:t>=1024&&e.lg?e.lg:t>=768&&e.md?e.md:t>=640&&e.sm?e.sm:e.base||1:1,f=(0,c.forwardRef)(({children:e,autoPlay:f=!1,interval:p=5e3,showIndicators:m=!0,showControls:ne=!0,controlsPlacement:re=`overlay`,loop:h=!0,slidesToShow:g=1,aspectRatio:_,objectFit:v=`cover`,labels:y,className:b,asChild:x,...ie},ae)=>{let oe=x?t.Root:`div`,{t:S}=n.useWimTranslation(ee.componentsNs),C={slideLabel:e=>S(`carousel.slide`,{number:e}),prevSlide:S(`carousel.prev_slide`),nextSlide:S(`carousel.next_slide`),goToSlide:e=>S(`carousel.go_to_slide`,{number:e}),slideStatus:(e,t)=>S(`carousel.slide_status`,{current:e,total:t}),...y},w=x&&c.default.isValidElement(e)?e.props.children:e,T=(0,c.useMemo)(()=>c.default.Children.toArray(w),[w]),E=T.length,[D,O]=(0,c.useState)(typeof window<`u`?window.innerWidth:0),[k,A]=(0,c.useState)(h?E:0),[j,M]=(0,c.useState)(!1),[N,P]=(0,c.useState)(!1),F=d(g,D),I=(0,c.useRef)(null),L=(0,c.useRef)(null),R=(0,c.useRef)(null),z=(0,c.useRef)(null),B=(0,c.useRef)(null),V=(0,c.useRef)(null),H=(0,c.useRef)(null),U=r.useMergedRef(ae,H);(0,c.useEffect)(()=>{let e=()=>O(window.innerWidth);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let W=(0,c.useMemo)(()=>!h||E===0?T:[...T,...T,...T],[T,h,E]),G=(0,c.useCallback)(()=>{if(!j){if(!h){A(e=>Math.min(e+1,E-F));return}M(!0),A(e=>e+1)}},[j,h,E,F]),K=(0,c.useCallback)(()=>{if(!j){if(!h){A(e=>Math.max(e-1,0));return}M(!0),A(e=>e-1)}},[j,h]),se=e=>{j||(h?(M(!0),A(e+E)):A(e))},ce=()=>{h&&(M(!1),k>=E*2?A(k-E):k<E&&A(k+E))};(0,c.useEffect)(()=>(f&&!N&&E>F&&(I.current=window.setInterval(G,p)),()=>{I.current&&window.clearInterval(I.current)}),[f,p,G,E,F,N]);let[le,ue]=(0,c.useState)(``),q=h?k%E:k,J=h?E-1:Math.max(E-F,0),Y=e=>{j||e===q||ue(C.slideStatus(e+1,E))},de=e=>{Y(e),se(e)},X=()=>{let e=h?(q-1+E)%E:Math.max(q-1,0);Y(e),!h&&e===0&&document.activeElement===B.current&&H.current?.focus(),K()},Z=()=>{let e=h?(q+1)%E:Math.min(q+1,J);Y(e),!h&&e===J&&document.activeElement===V.current&&H.current?.focus(),G()},fe=e=>{e.key===`ArrowLeft`?X():e.key===`ArrowRight`&&Z()},pe=e=>{R.current=e.targetTouches[0].clientX},me=e=>{z.current=e.targetTouches[0].clientX},he=()=>{if(!R.current||!z.current)return;let e=R.current-z.current;e>50?G():e<-50&&K(),R.current=null,z.current=null};if(E===0)return null;let Q=100/F,ge=-k*Q,$=(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(i.VisuallyHidden,{role:`status`,"aria-atomic":`true`,children:le}),(0,u.jsx)(`div`,{className:s.default.viewport,children:(0,u.jsx)(`div`,{ref:L,className:(0,l.default)(s.default.track,j&&s.default.transition),style:{transform:`translateX(${ge}%)`},onTransitionEnd:ce,onTouchStart:pe,onTouchMove:me,onTouchEnd:he,children:W.map((e,t)=>(0,u.jsx)(`div`,{className:(0,l.default)(s.default.item,_&&s.default.hasAspectRatio),style:{flex:`0 0 ${Q}%`,width:`${Q}%`,..._?{aspectRatio:_,"--wim-carousel-object-fit":v}:{}},role:`group`,"aria-roledescription":S(`carousel.slide_roledescription`),"aria-label":C.slideLabel(t%E+1),children:e},t))})}),ne&&E>F&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`button`,{ref:B,className:(0,l.default)(s.default.control,s.default.prev),onClick:X,"aria-label":C.prevSlide,disabled:!h&&k===0,children:(0,u.jsx)(o.Icon,{component:a.default,size:`md`})}),(0,u.jsx)(`button`,{ref:V,className:(0,l.default)(s.default.control,s.default.next),onClick:Z,"aria-label":C.nextSlide,disabled:!h&&k>=E-F,children:(0,u.jsx)(o.Icon,{component:te.default,size:`md`})})]}),m&&E>1&&(0,u.jsx)(`div`,{className:s.default.indicators,children:T.map((e,t)=>{let n=h?k%E===t:k===t;return(0,u.jsx)(`button`,{className:(0,l.default)(s.default.indicator,n&&s.default.active),onClick:()=>de(t),"aria-label":C.goToSlide(t+1),"aria-current":n?`true`:`false`},t)})})]});return(0,u.jsx)(oe,{ref:U,className:(0,l.default)(`wim-carousel`,s.default.root,re===`outside`&&s.default.controlsOutside,b),onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1),onFocus:()=>P(!0),onBlur:()=>P(!1),onKeyDown:fe,tabIndex:0,role:`region`,"aria-roledescription":S(`carousel.roledescription`),...ie,children:x?(0,u.jsx)(t.Slottable,{child:e,children:()=>$}):$})});f.displayName=`Carousel`,exports.Carousel=f;
|
|
@@ -11,6 +11,8 @@ export type CarouselLabels = {
|
|
|
11
11
|
prevSlide?: string;
|
|
12
12
|
nextSlide?: string;
|
|
13
13
|
goToSlide?: (number: number) => string;
|
|
14
|
+
/** Announced to screen readers when the user changes the slide. Receives the slide number and the slide count. */
|
|
15
|
+
slideStatus?: (current: number, total: number) => string;
|
|
14
16
|
};
|
|
15
17
|
export type CarouselProps = {
|
|
16
18
|
/** Content of the carousel */
|
|
@@ -1,163 +1,184 @@
|
|
|
1
1
|
"use client";
|
|
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
|
-
import {
|
|
5
|
-
import te from "
|
|
6
|
-
import r from "../../../
|
|
4
|
+
import { useMergedRef as ee } from "../../../hooks/useMergedRef.js";
|
|
5
|
+
import { VisuallyHidden as te } from "../../layout/VisuallyHidden/VisuallyHidden.js";
|
|
6
|
+
import { componentsNs as r } from "../../../i18n/generated/components.js";
|
|
7
|
+
import ne from "../../../icon/chevron-left.js";
|
|
8
|
+
import re from "../../../icon/chevron-right.js";
|
|
7
9
|
import { Icon as i } from "../../media/Icon/Icon.js";
|
|
8
10
|
import a from "./carousel.module.js";
|
|
9
11
|
import o, { forwardRef as s, useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
10
12
|
import p from "classnames";
|
|
11
13
|
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
12
14
|
//#region src/components/data-display/Carousel/Carousel.tsx
|
|
13
|
-
var
|
|
14
|
-
let
|
|
15
|
-
slideLabel: (e) =>
|
|
16
|
-
prevSlide:
|
|
17
|
-
nextSlide:
|
|
18
|
-
goToSlide: (e) =>
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
var ie = (e, t) => typeof e == "number" ? e : e ? t >= 1280 && e.xl ? e.xl : t >= 1024 && e.lg ? e.lg : t >= 768 && e.md ? e.md : t >= 640 && e.sm ? e.sm : e.base || 1 : 1, _ = s(({ children: s, autoPlay: _ = !1, interval: v = 5e3, showIndicators: ae = !0, showControls: oe = !0, controlsPlacement: se = "overlay", loop: y = !0, slidesToShow: ce = 1, aspectRatio: b, objectFit: le = "cover", labels: ue, className: x, asChild: S, ...C }, w) => {
|
|
16
|
+
let de = S ? e : "div", { t: T } = n(r), E = {
|
|
17
|
+
slideLabel: (e) => T("carousel.slide", { number: e }),
|
|
18
|
+
prevSlide: T("carousel.prev_slide"),
|
|
19
|
+
nextSlide: T("carousel.next_slide"),
|
|
20
|
+
goToSlide: (e) => T("carousel.go_to_slide", { number: e }),
|
|
21
|
+
slideStatus: (e, t) => T("carousel.slide_status", {
|
|
22
|
+
current: e,
|
|
23
|
+
total: t
|
|
24
|
+
}),
|
|
25
|
+
...ue
|
|
26
|
+
}, D = S && o.isValidElement(s) ? s.props.children : s, O = u(() => o.Children.toArray(D), [D]), k = O.length, [fe, A] = f(typeof window < "u" ? window.innerWidth : 0), [j, M] = f(y ? k : 0), [N, P] = f(!1), [F, I] = f(!1), L = ie(ce, fe), R = d(null), z = d(null), B = d(null), V = d(null), H = d(null), U = d(null), W = d(null), pe = ee(w, W);
|
|
21
27
|
l(() => {
|
|
22
|
-
let e = () =>
|
|
28
|
+
let e = () => A(window.innerWidth);
|
|
23
29
|
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
24
30
|
}, []);
|
|
25
|
-
let
|
|
26
|
-
...
|
|
27
|
-
...
|
|
28
|
-
...
|
|
31
|
+
let me = u(() => !y || k === 0 ? O : [
|
|
32
|
+
...O,
|
|
33
|
+
...O,
|
|
34
|
+
...O
|
|
29
35
|
], [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
]),
|
|
34
|
-
if (!
|
|
35
|
-
if (!
|
|
36
|
-
|
|
36
|
+
O,
|
|
37
|
+
y,
|
|
38
|
+
k
|
|
39
|
+
]), G = c(() => {
|
|
40
|
+
if (!N) {
|
|
41
|
+
if (!y) {
|
|
42
|
+
M((e) => Math.min(e + 1, k - L));
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
P(!0), M((e) => e + 1);
|
|
40
46
|
}
|
|
41
47
|
}, [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
]),
|
|
47
|
-
if (!
|
|
48
|
-
if (!
|
|
49
|
-
|
|
48
|
+
N,
|
|
49
|
+
y,
|
|
50
|
+
k,
|
|
51
|
+
L
|
|
52
|
+
]), K = c(() => {
|
|
53
|
+
if (!N) {
|
|
54
|
+
if (!y) {
|
|
55
|
+
M((e) => Math.max(e - 1, 0));
|
|
50
56
|
return;
|
|
51
57
|
}
|
|
52
|
-
|
|
58
|
+
P(!0), M((e) => e - 1);
|
|
53
59
|
}
|
|
54
|
-
}, [
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
60
|
+
}, [N, y]), he = (e) => {
|
|
61
|
+
N || (y ? (P(!0), M(e + k)) : M(e));
|
|
62
|
+
}, ge = () => {
|
|
63
|
+
y && (P(!1), j >= k * 2 ? M(j - k) : j < k && M(j + k));
|
|
58
64
|
};
|
|
59
|
-
l(() => (
|
|
60
|
-
|
|
65
|
+
l(() => (_ && !F && k > L && (R.current = window.setInterval(G, v)), () => {
|
|
66
|
+
R.current && window.clearInterval(R.current);
|
|
61
67
|
}), [
|
|
68
|
+
_,
|
|
62
69
|
v,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
V
|
|
70
|
+
G,
|
|
71
|
+
k,
|
|
72
|
+
L,
|
|
73
|
+
F
|
|
68
74
|
]);
|
|
69
|
-
let
|
|
70
|
-
e
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
q.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let e =
|
|
78
|
-
|
|
75
|
+
let [_e, ve] = f(""), q = y ? j % k : j, J = y ? k - 1 : Math.max(k - L, 0), Y = (e) => {
|
|
76
|
+
N || e === q || ve(E.slideStatus(e + 1, k));
|
|
77
|
+
}, ye = (e) => {
|
|
78
|
+
Y(e), he(e);
|
|
79
|
+
}, X = () => {
|
|
80
|
+
let e = y ? (q - 1 + k) % k : Math.max(q - 1, 0);
|
|
81
|
+
Y(e), !y && e === 0 && document.activeElement === H.current && W.current?.focus(), K();
|
|
82
|
+
}, Z = () => {
|
|
83
|
+
let e = y ? (q + 1) % k : Math.min(q + 1, J);
|
|
84
|
+
Y(e), !y && e === J && document.activeElement === U.current && W.current?.focus(), G();
|
|
85
|
+
}, be = (e) => {
|
|
86
|
+
e.key === "ArrowLeft" ? X() : e.key === "ArrowRight" && Z();
|
|
87
|
+
}, xe = (e) => {
|
|
88
|
+
B.current = e.targetTouches[0].clientX;
|
|
89
|
+
}, Se = (e) => {
|
|
90
|
+
V.current = e.targetTouches[0].clientX;
|
|
91
|
+
}, Ce = () => {
|
|
92
|
+
if (!B.current || !V.current) return;
|
|
93
|
+
let e = B.current - V.current;
|
|
94
|
+
e > 50 ? G() : e < -50 && K(), B.current = null, V.current = null;
|
|
79
95
|
};
|
|
80
|
-
if (
|
|
81
|
-
let Q = 100 /
|
|
96
|
+
if (k === 0) return null;
|
|
97
|
+
let Q = 100 / L, we = -j * Q, $ = /* @__PURE__ */ g(m, { children: [
|
|
98
|
+
/* @__PURE__ */ h(te, {
|
|
99
|
+
role: "status",
|
|
100
|
+
"aria-atomic": "true",
|
|
101
|
+
children: _e
|
|
102
|
+
}),
|
|
82
103
|
/* @__PURE__ */ h("div", {
|
|
83
104
|
className: a.viewport,
|
|
84
105
|
children: /* @__PURE__ */ h("div", {
|
|
85
|
-
ref:
|
|
86
|
-
className: p(a.track,
|
|
87
|
-
style: { transform: `translateX(${
|
|
88
|
-
onTransitionEnd:
|
|
89
|
-
onTouchStart:
|
|
90
|
-
onTouchMove:
|
|
91
|
-
onTouchEnd:
|
|
92
|
-
children:
|
|
93
|
-
className: p(a.item,
|
|
106
|
+
ref: z,
|
|
107
|
+
className: p(a.track, N && a.transition),
|
|
108
|
+
style: { transform: `translateX(${we}%)` },
|
|
109
|
+
onTransitionEnd: ge,
|
|
110
|
+
onTouchStart: xe,
|
|
111
|
+
onTouchMove: Se,
|
|
112
|
+
onTouchEnd: Ce,
|
|
113
|
+
children: me.map((e, t) => /* @__PURE__ */ h("div", {
|
|
114
|
+
className: p(a.item, b && a.hasAspectRatio),
|
|
94
115
|
style: {
|
|
95
116
|
flex: `0 0 ${Q}%`,
|
|
96
117
|
width: `${Q}%`,
|
|
97
|
-
...
|
|
98
|
-
aspectRatio:
|
|
99
|
-
"--wim-carousel-object-fit":
|
|
118
|
+
...b ? {
|
|
119
|
+
aspectRatio: b,
|
|
120
|
+
"--wim-carousel-object-fit": le
|
|
100
121
|
} : {}
|
|
101
122
|
},
|
|
102
123
|
role: "group",
|
|
103
|
-
"aria-roledescription":
|
|
104
|
-
"aria-label":
|
|
124
|
+
"aria-roledescription": T("carousel.slide_roledescription"),
|
|
125
|
+
"aria-label": E.slideLabel(t % k + 1),
|
|
105
126
|
children: e
|
|
106
127
|
}, t))
|
|
107
128
|
})
|
|
108
129
|
}),
|
|
109
|
-
|
|
130
|
+
oe && k > L && /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("button", {
|
|
131
|
+
ref: H,
|
|
110
132
|
className: p(a.control, a.prev),
|
|
111
133
|
onClick: X,
|
|
112
|
-
"aria-label":
|
|
113
|
-
disabled: !
|
|
114
|
-
tabIndex: -1,
|
|
134
|
+
"aria-label": E.prevSlide,
|
|
135
|
+
disabled: !y && j === 0,
|
|
115
136
|
children: /* @__PURE__ */ h(i, {
|
|
116
|
-
component:
|
|
137
|
+
component: ne,
|
|
117
138
|
size: "md"
|
|
118
139
|
})
|
|
119
140
|
}), /* @__PURE__ */ h("button", {
|
|
141
|
+
ref: U,
|
|
120
142
|
className: p(a.control, a.next),
|
|
121
|
-
onClick:
|
|
122
|
-
"aria-label":
|
|
123
|
-
disabled: !
|
|
124
|
-
tabIndex: -1,
|
|
143
|
+
onClick: Z,
|
|
144
|
+
"aria-label": E.nextSlide,
|
|
145
|
+
disabled: !y && j >= k - L,
|
|
125
146
|
children: /* @__PURE__ */ h(i, {
|
|
126
|
-
component:
|
|
147
|
+
component: re,
|
|
127
148
|
size: "md"
|
|
128
149
|
})
|
|
129
150
|
})] }),
|
|
130
|
-
|
|
151
|
+
ae && k > 1 && /* @__PURE__ */ h("div", {
|
|
131
152
|
className: a.indicators,
|
|
132
|
-
children:
|
|
133
|
-
let n =
|
|
153
|
+
children: O.map((e, t) => {
|
|
154
|
+
let n = y ? j % k === t : j === t;
|
|
134
155
|
return /* @__PURE__ */ h("button", {
|
|
135
156
|
className: p(a.indicator, n && a.active),
|
|
136
|
-
onClick: () =>
|
|
137
|
-
"aria-label":
|
|
157
|
+
onClick: () => ye(t),
|
|
158
|
+
"aria-label": E.goToSlide(t + 1),
|
|
138
159
|
"aria-current": n ? "true" : "false"
|
|
139
160
|
}, t);
|
|
140
161
|
})
|
|
141
162
|
})
|
|
142
163
|
] });
|
|
143
|
-
return /* @__PURE__ */ h(
|
|
144
|
-
ref:
|
|
145
|
-
className: p("wim-carousel", a.root,
|
|
146
|
-
onMouseEnter: () =>
|
|
147
|
-
onMouseLeave: () =>
|
|
148
|
-
onFocus: () =>
|
|
149
|
-
onBlur: () =>
|
|
150
|
-
onKeyDown:
|
|
164
|
+
return /* @__PURE__ */ h(de, {
|
|
165
|
+
ref: pe,
|
|
166
|
+
className: p("wim-carousel", a.root, se === "outside" && a.controlsOutside, x),
|
|
167
|
+
onMouseEnter: () => I(!0),
|
|
168
|
+
onMouseLeave: () => I(!1),
|
|
169
|
+
onFocus: () => I(!0),
|
|
170
|
+
onBlur: () => I(!1),
|
|
171
|
+
onKeyDown: be,
|
|
151
172
|
tabIndex: 0,
|
|
152
173
|
role: "region",
|
|
153
|
-
"aria-roledescription":
|
|
154
|
-
...
|
|
155
|
-
children:
|
|
174
|
+
"aria-roledescription": T("carousel.roledescription"),
|
|
175
|
+
...C,
|
|
176
|
+
children: S ? /* @__PURE__ */ h(t, {
|
|
156
177
|
child: s,
|
|
157
178
|
children: () => $
|
|
158
179
|
}) : $
|
|
159
180
|
});
|
|
160
181
|
});
|
|
161
|
-
|
|
182
|
+
_.displayName = "Carousel";
|
|
162
183
|
//#endregion
|
|
163
|
-
export {
|
|
184
|
+
export { _ as Carousel };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../form/Button/Button.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),n=require("../../form/Button/Button.cjs"),r=require("../../_internal/FeedbackIcon.cjs"),i=require("../../_internal/FeedbackCloseButton.cjs"),a=require("./snackbar.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=({message:e,open:l=!1,intent:u=`default`,position:d=`bottom-center`,autoHideDuration:f=5e3,showCloseButton:p=!1,actionLabel:m,onAction:h,onClose:g,className:_})=>{let[v,y]=(0,o.useState)(!1),[b,x]=(0,o.useState)(!1),[S,C]=(0,o.useState)(l);l!==S&&(C(l),l?x(!0):y(!1)),(0,o.useEffect)(()=>{if(l){let e=setTimeout(()=>y(!0),10);return()=>clearTimeout(e)}{let e=setTimeout(()=>x(!1),300);return()=>clearTimeout(e)}},[l]);let w=(0,o.useCallback)(()=>{y(!1),setTimeout(()=>{g&&g()},300)},[g]),[T,E]=(0,o.useState)(f),[D,O]=(0,o.useState)(()=>Date.now()),[k,A]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(l&&f>0&&!k){let e=setTimeout(()=>{w()},T);return O(Date.now()),()=>clearTimeout(e)}},[l,f,w,k,T]);let j=()=>{if(f>0){A(!0);let e=Date.now()-D;E(t=>Math.max(0,t-e))}},M=()=>{f>0&&(O(Date.now()),A(!1))},N=()=>{h&&h()},P=u===`danger`||u===`warning`?`alert`:`status`;return(0,c.jsxs)(`div`,{className:(0,s.default)(a.default.wrapper,a.default[d]),children:[(0,c.jsx)(t.VisuallyHidden,{role:P,"aria-atomic":`true`,children:l?e:``}),(b||l)&&(0,c.jsxs)(`div`,{className:(0,s.default)(`wim-snackbar`,a.default.root,u&&a.default[u],v&&a.default.visible,p&&a.default.hasCloseButton,_),onMouseEnter:j,onMouseLeave:M,onFocus:j,onBlur:M,children:[(0,c.jsxs)(`div`,{className:a.default.content,children:[(u===`success`||u===`warning`||u===`danger`)&&(0,c.jsx)(`div`,{className:a.default.icon,children:(0,c.jsx)(r.FeedbackIcon,{intent:u,size:`sm`})}),(0,c.jsx)(`span`,{className:a.default.message,children:e})]}),(0,c.jsxs)(`div`,{className:a.default.actions,children:[m&&(0,c.jsx)(n.Button,{variant:`ghost`,size:`sm`,onClick:N,className:a.default.actionButton,children:m}),(0,c.jsx)(i.FeedbackCloseButton,{onClose:p?w:void 0,className:a.default.closeButton,size:`sm`})]})]})]})},u=(0,o.createContext)(void 0),d=({children:e})=>{let[t,n]=(0,o.useState)(null),[r,i]=(0,o.useState)(!1),a=(0,o.useCallback)(e=>{let r=Math.random().toString(36).substr(2,9),a=typeof e==`string`?{message:e}:e;i(!1),setTimeout(()=>{n({...a,id:r}),i(!0)},t?300:0)},[t]),s=(0,o.useCallback)(()=>{i(!1)},[]);return(0,c.jsxs)(u.Provider,{value:{showMessage:a,hideMessage:s},children:[e,(0,c.jsx)(l,{message:``,...t,open:r&&t!==null,onClose:()=>{i(!1),t?.onClose&&t.onClose()}})]})},f=()=>{let e=(0,o.useContext)(u);if(!e)throw Error(`useSnackbar must be used within a SnackbarProvider`);return e};exports.Snackbar=l,exports.SnackbarProvider=d,exports.useSnackbar=f;
|
|
@@ -41,7 +41,7 @@ export interface SnackbarProps {
|
|
|
41
41
|
/**
|
|
42
42
|
* Snackbar for notifying the user with a short message.
|
|
43
43
|
*/
|
|
44
|
-
export declare const Snackbar: ({ message, open, intent, position, autoHideDuration, showCloseButton, actionLabel, onAction, onClose, className, }: SnackbarProps) => React.JSX.Element
|
|
44
|
+
export declare const Snackbar: ({ message, open, intent, position, autoHideDuration, showCloseButton, actionLabel, onAction, onClose, className, }: SnackbarProps) => React.JSX.Element;
|
|
45
45
|
type SnackbarContextType = {
|
|
46
46
|
showMessage: (props: string | Omit<SnackbarProps, "open" | "onClose">) => void;
|
|
47
47
|
hideMessage: () => void;
|
|
@@ -1,96 +1,97 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import r from "
|
|
6
|
-
import
|
|
7
|
-
import l from "
|
|
8
|
-
import
|
|
2
|
+
import { VisuallyHidden as e } from "../../layout/VisuallyHidden/VisuallyHidden.js";
|
|
3
|
+
import { Button as t } from "../../form/Button/Button.js";
|
|
4
|
+
import { FeedbackIcon as n } from "../../_internal/FeedbackIcon.js";
|
|
5
|
+
import { FeedbackCloseButton as r } from "../../_internal/FeedbackCloseButton.js";
|
|
6
|
+
import i from "./snackbar.module.js";
|
|
7
|
+
import { createContext as a, useCallback as o, useContext as s, useEffect as c, useState as l } from "react";
|
|
8
|
+
import u from "classnames";
|
|
9
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
9
10
|
//#region src/components/feedback/Snackbar/Snackbar.tsx
|
|
10
|
-
var
|
|
11
|
-
let [
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
let e = setTimeout(() =>
|
|
11
|
+
var p = ({ message: a, open: s = !1, intent: p = "default", position: m = "bottom-center", autoHideDuration: h = 5e3, showCloseButton: g = !1, actionLabel: _, onAction: v, onClose: y, className: b }) => {
|
|
12
|
+
let [x, S] = l(!1), [C, w] = l(!1), [T, E] = l(s);
|
|
13
|
+
s !== T && (E(s), s ? w(!0) : S(!1)), c(() => {
|
|
14
|
+
if (s) {
|
|
15
|
+
let e = setTimeout(() => S(!0), 10);
|
|
15
16
|
return () => clearTimeout(e);
|
|
16
17
|
}
|
|
17
18
|
{
|
|
18
|
-
let e = setTimeout(() =>
|
|
19
|
+
let e = setTimeout(() => w(!1), 300);
|
|
19
20
|
return () => clearTimeout(e);
|
|
20
21
|
}
|
|
21
|
-
}, [
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
}, [s]);
|
|
23
|
+
let D = o(() => {
|
|
24
|
+
S(!1), setTimeout(() => {
|
|
25
|
+
y && y();
|
|
25
26
|
}, 300);
|
|
26
|
-
}, [
|
|
27
|
-
|
|
28
|
-
if (
|
|
27
|
+
}, [y]), [O, k] = l(h), [A, j] = l(() => Date.now()), [M, N] = l(!1);
|
|
28
|
+
c(() => {
|
|
29
|
+
if (s && h > 0 && !M) {
|
|
29
30
|
let e = setTimeout(() => {
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
return
|
|
31
|
+
D();
|
|
32
|
+
}, O);
|
|
33
|
+
return j(Date.now()), () => clearTimeout(e);
|
|
33
34
|
}
|
|
34
35
|
}, [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
s,
|
|
37
|
+
h,
|
|
38
|
+
D,
|
|
39
|
+
M,
|
|
40
|
+
O
|
|
40
41
|
]);
|
|
41
|
-
let
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
let e = Date.now() -
|
|
45
|
-
|
|
42
|
+
let P = () => {
|
|
43
|
+
if (h > 0) {
|
|
44
|
+
N(!0);
|
|
45
|
+
let e = Date.now() - A;
|
|
46
|
+
k((t) => Math.max(0, t - e));
|
|
46
47
|
}
|
|
47
|
-
}, P = () => {
|
|
48
|
-
m > 0 && (A(Date.now()), M(!1));
|
|
49
48
|
}, F = () => {
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return /* @__PURE__ */
|
|
55
|
-
className:
|
|
56
|
-
children: /* @__PURE__ */ d(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
h > 0 && (j(Date.now()), N(!1));
|
|
50
|
+
}, I = () => {
|
|
51
|
+
v && v();
|
|
52
|
+
}, L = p === "danger" || p === "warning" ? "alert" : "status";
|
|
53
|
+
return /* @__PURE__ */ f("div", {
|
|
54
|
+
className: u(i.wrapper, i[m]),
|
|
55
|
+
children: [/* @__PURE__ */ d(e, {
|
|
56
|
+
role: L,
|
|
57
|
+
"aria-atomic": "true",
|
|
58
|
+
children: s ? a : ""
|
|
59
|
+
}), (C || s) && /* @__PURE__ */ f("div", {
|
|
60
|
+
className: u("wim-snackbar", i.root, p && i[p], x && i.visible, g && i.hasCloseButton, b),
|
|
61
|
+
onMouseEnter: P,
|
|
62
|
+
onMouseLeave: F,
|
|
63
|
+
onFocus: P,
|
|
64
|
+
onBlur: F,
|
|
65
|
+
children: [/* @__PURE__ */ f("div", {
|
|
66
|
+
className: i.content,
|
|
67
|
+
children: [(p === "success" || p === "warning" || p === "danger") && /* @__PURE__ */ d("div", {
|
|
68
|
+
className: i.icon,
|
|
69
|
+
children: /* @__PURE__ */ d(n, {
|
|
70
|
+
intent: p,
|
|
70
71
|
size: "sm"
|
|
71
72
|
})
|
|
72
|
-
}), /* @__PURE__ */
|
|
73
|
-
className:
|
|
74
|
-
children:
|
|
73
|
+
}), /* @__PURE__ */ d("span", {
|
|
74
|
+
className: i.message,
|
|
75
|
+
children: a
|
|
75
76
|
})]
|
|
76
|
-
}), /* @__PURE__ */
|
|
77
|
-
className:
|
|
78
|
-
children: [
|
|
77
|
+
}), /* @__PURE__ */ f("div", {
|
|
78
|
+
className: i.actions,
|
|
79
|
+
children: [_ && /* @__PURE__ */ d(t, {
|
|
79
80
|
variant: "ghost",
|
|
80
81
|
size: "sm",
|
|
81
|
-
onClick:
|
|
82
|
-
className:
|
|
83
|
-
children:
|
|
84
|
-
}), /* @__PURE__ */
|
|
85
|
-
onClose:
|
|
86
|
-
className:
|
|
82
|
+
onClick: I,
|
|
83
|
+
className: i.actionButton,
|
|
84
|
+
children: _
|
|
85
|
+
}), /* @__PURE__ */ d(r, {
|
|
86
|
+
onClose: g ? D : void 0,
|
|
87
|
+
className: i.closeButton,
|
|
87
88
|
size: "sm"
|
|
88
89
|
})]
|
|
89
90
|
})]
|
|
90
|
-
})
|
|
91
|
+
})]
|
|
91
92
|
});
|
|
92
|
-
},
|
|
93
|
-
let [t, n] =
|
|
93
|
+
}, m = a(void 0), h = ({ children: e }) => {
|
|
94
|
+
let [t, n] = l(null), [r, i] = l(!1), a = o((e) => {
|
|
94
95
|
let r = Math.random().toString(36).substr(2, 9), a = typeof e == "string" ? { message: e } : e;
|
|
95
96
|
i(!1), setTimeout(() => {
|
|
96
97
|
n({
|
|
@@ -98,26 +99,27 @@ var f = ({ message: i, open: o = !1, intent: f = "default", position: p = "botto
|
|
|
98
99
|
id: r
|
|
99
100
|
}), i(!0);
|
|
100
101
|
}, t ? 300 : 0);
|
|
101
|
-
}, [t]), s =
|
|
102
|
+
}, [t]), s = o(() => {
|
|
102
103
|
i(!1);
|
|
103
104
|
}, []);
|
|
104
|
-
return /* @__PURE__ */
|
|
105
|
+
return /* @__PURE__ */ f(m.Provider, {
|
|
105
106
|
value: {
|
|
106
|
-
showMessage:
|
|
107
|
+
showMessage: a,
|
|
107
108
|
hideMessage: s
|
|
108
109
|
},
|
|
109
|
-
children: [e,
|
|
110
|
+
children: [e, /* @__PURE__ */ d(p, {
|
|
111
|
+
message: "",
|
|
110
112
|
...t,
|
|
111
|
-
open: r,
|
|
113
|
+
open: r && t !== null,
|
|
112
114
|
onClose: () => {
|
|
113
|
-
i(!1), t
|
|
115
|
+
i(!1), t?.onClose && t.onClose();
|
|
114
116
|
}
|
|
115
117
|
})]
|
|
116
118
|
});
|
|
117
|
-
},
|
|
118
|
-
let e =
|
|
119
|
+
}, g = () => {
|
|
120
|
+
let e = s(m);
|
|
119
121
|
if (!e) throw Error("useSnackbar must be used within a SnackbarProvider");
|
|
120
122
|
return e;
|
|
121
123
|
};
|
|
122
124
|
//#endregion
|
|
123
|
-
export {
|
|
125
|
+
export { p as Snackbar, h as SnackbarProvider, g as useSnackbar };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../layout/Transition/Transition.cjs"),n=require("../../_internal/FeedbackIcon.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../layout/Transition/Transition.cjs"),n=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),r=require("../../_internal/FeedbackIcon.cjs"),i=require("../../_internal/FeedbackCloseButton.cjs"),a=require("./toast.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=({id:e,title:l,description:d,intent:p=`default`,duration:m=3e3,open:h=!0,onClose:g,className:_,"aria-label":v,"aria-labelledby":y})=>{let[b,x]=(0,o.useState)(!0),S=(0,o.useCallback)(()=>{x(!1),g&&g(e)},[g,e]);(0,o.useEffect)(()=>{if(h&&m>0&&b){let e=setTimeout(()=>{S()},m+300);return()=>clearTimeout(e)}},[h,m,e,g,b,S]);let C=(0,o.useContext)(f),w=(0,c.jsxs)(t.Transition,{show:h&&b,enter:a.default.enter,enterFrom:a.default.enterFrom,enterTo:a.default.enterTo,leave:a.default.leave,leaveFrom:a.default.leaveFrom,leaveTo:a.default.leaveTo,className:(0,s.default)(`wim-toast`,a.default.root,a.default[p],_),role:v||y?`group`:void 0,"aria-label":y?void 0:v,"aria-labelledby":y,children:[(p===`success`||p===`warning`||p===`danger`||p===`info`)&&(0,c.jsx)(`div`,{className:a.default.icon,children:(0,c.jsx)(r.FeedbackIcon,{intent:p,size:`sm`})}),(0,c.jsxs)(`div`,{className:a.default.content,children:[l&&(0,c.jsx)(`div`,{className:a.default.title,children:l}),d&&(0,c.jsx)(`p`,{className:a.default.description,children:d})]}),(0,c.jsx)(i.FeedbackCloseButton,{onClose:g?S:void 0,id:e,className:a.default.closeButton,size:`md`})]});return C?w:(0,c.jsxs)(`div`,{className:a.default.live,children:[(0,c.jsx)(n.VisuallyHidden,{role:`status`,"aria-atomic":`true`,children:h&&b?u(l,d):``}),w]})},u=(e,t)=>[e,t].filter(Boolean).join(`: `),d=(0,o.createContext)(void 0),f=(0,o.createContext)(!1),p=({children:e,position:t=`top-right`})=>{let[r,i]=(0,o.useState)([]),[p,m]=(0,o.useState)(null),h=(0,o.useCallback)(e=>{let t=Math.random().toString(36).substr(2,9);i(n=>[...n,{...e,id:t}]),m({...e,id:t})},[]),g=(0,o.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e)),m(t=>t?.id===e?null:t)},[]);return(0,c.jsxs)(d.Provider,{value:{show:h,remove:g},children:[e,(0,c.jsxs)(`div`,{className:(0,s.default)(a.default.container,a.default[t]),children:[(0,c.jsx)(n.VisuallyHidden,{role:`status`,"aria-atomic":`true`,children:p?u(p.title,p.description):``}),(0,c.jsx)(f.Provider,{value:!0,children:r.map(e=>(0,c.jsx)(l,{...e,onClose:()=>g(e.id)},e.id))})]})]})},m=()=>{let e=(0,o.useContext)(d);if(!e)throw Error(`useToast must be used within a ToastProvider`);return e};exports.Toast=l,exports.ToastProvider=p,exports.useToast=m;
|