@telia/teddy 0.0.6 → 0.0.7

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.
@@ -1,422 +0,0 @@
1
- import './assets/radio-group.css';
2
- import { jsx as C } from "react/jsx-runtime";
3
- import I, { forwardRef as x, createElement as b, useRef as w, useState as G, useEffect as P, useCallback as T } from "react";
4
- import { c as E } from "./clsx-DB4S2d7J.js";
5
- import { _, b as M } from "./index-DpfSJps6.js";
6
- import { $ as le, a as z, b as H, c as Y, d as $e, e as h, f as pe, g as ve, h as me, i as _e } from "./index-0Eg2mucA.js";
7
- import { $ as S } from "./index-DM5e-Whg.js";
8
- import { Label as ge } from "./components/label/label.js";
9
- import { useComposedRefs as Re } from "./utils/composeRefs.js";
10
- const O = "rovingFocusGroup.onEntryFocus", he = {
11
- bubbles: !1,
12
- cancelable: !0
13
- }, K = "RovingFocusGroup", [L, j, Ie] = le(K), [xe, W] = z(K, [
14
- Ie
15
- ]), [ye, Ce] = xe(K), we = /* @__PURE__ */ x((e, t) => /* @__PURE__ */ b(L.Provider, {
16
- scope: e.__scopeRovingFocusGroup
17
- }, /* @__PURE__ */ b(L.Slot, {
18
- scope: e.__scopeRovingFocusGroup
19
- }, /* @__PURE__ */ b(Fe, _({}, e, {
20
- ref: t
21
- }))))), Fe = /* @__PURE__ */ x((e, t) => {
22
- const { __scopeRovingFocusGroup: o, orientation: r, loop: n = !1, dir: c, currentTabStopId: a, defaultCurrentTabStopId: f, onCurrentTabStopIdChange: d, onEntryFocus: s, ...m } = e, $ = w(null), p = M(t, $), u = H(c), [i = null, l] = Y({
23
- prop: a,
24
- defaultProp: f,
25
- onChange: d
26
- }), [F, g] = G(!1), R = $e(s), se = j(o), N = w(!1), [de, q] = G(0);
27
- return P(() => {
28
- const v = $.current;
29
- if (v)
30
- return v.addEventListener(O, R), () => v.removeEventListener(O, R);
31
- }, [
32
- R
33
- ]), /* @__PURE__ */ b(ye, {
34
- scope: o,
35
- orientation: r,
36
- dir: u,
37
- loop: n,
38
- currentTabStopId: i,
39
- onItemFocus: T(
40
- (v) => l(v),
41
- [
42
- l
43
- ]
44
- ),
45
- onItemShiftTab: T(
46
- () => g(!0),
47
- []
48
- ),
49
- onFocusableItemAdd: T(
50
- () => q(
51
- (v) => v + 1
52
- ),
53
- []
54
- ),
55
- onFocusableItemRemove: T(
56
- () => q(
57
- (v) => v - 1
58
- ),
59
- []
60
- )
61
- }, /* @__PURE__ */ b(S.div, _({
62
- tabIndex: F || de === 0 ? -1 : 0,
63
- "data-orientation": r
64
- }, m, {
65
- ref: p,
66
- style: {
67
- outline: "none",
68
- ...e.style
69
- },
70
- onMouseDown: h(e.onMouseDown, () => {
71
- N.current = !0;
72
- }),
73
- onFocus: h(e.onFocus, (v) => {
74
- const ie = !N.current;
75
- if (v.target === v.currentTarget && ie && !F) {
76
- const V = new CustomEvent(O, he);
77
- if (v.currentTarget.dispatchEvent(V), !V.defaultPrevented) {
78
- const D = se().filter(
79
- (y) => y.focusable
80
- ), ue = D.find(
81
- (y) => y.active
82
- ), fe = D.find(
83
- (y) => y.id === i
84
- ), be = [
85
- ue,
86
- fe,
87
- ...D
88
- ].filter(Boolean).map(
89
- (y) => y.ref.current
90
- );
91
- X(be);
92
- }
93
- }
94
- N.current = !1;
95
- }),
96
- onBlur: h(
97
- e.onBlur,
98
- () => g(!1)
99
- )
100
- })));
101
- }), Ee = "RovingFocusGroupItem", Se = /* @__PURE__ */ x((e, t) => {
102
- const { __scopeRovingFocusGroup: o, focusable: r = !0, active: n = !1, tabStopId: c, ...a } = e, f = pe(), d = c || f, s = Ce(Ee, o), m = s.currentTabStopId === d, $ = j(o), { onFocusableItemAdd: p, onFocusableItemRemove: u } = s;
103
- return P(() => {
104
- if (r)
105
- return p(), () => u();
106
- }, [
107
- r,
108
- p,
109
- u
110
- ]), /* @__PURE__ */ b(L.ItemSlot, {
111
- scope: o,
112
- id: d,
113
- focusable: r,
114
- active: n
115
- }, /* @__PURE__ */ b(S.span, _({
116
- tabIndex: m ? 0 : -1,
117
- "data-orientation": s.orientation
118
- }, a, {
119
- ref: t,
120
- onMouseDown: h(e.onMouseDown, (i) => {
121
- r ? s.onItemFocus(d) : i.preventDefault();
122
- }),
123
- onFocus: h(
124
- e.onFocus,
125
- () => s.onItemFocus(d)
126
- ),
127
- onKeyDown: h(e.onKeyDown, (i) => {
128
- if (i.key === "Tab" && i.shiftKey) {
129
- s.onItemShiftTab();
130
- return;
131
- }
132
- if (i.target !== i.currentTarget)
133
- return;
134
- const l = Te(i, s.orientation, s.dir);
135
- if (l !== void 0) {
136
- i.preventDefault();
137
- let g = $().filter(
138
- (R) => R.focusable
139
- ).map(
140
- (R) => R.ref.current
141
- );
142
- if (l === "last")
143
- g.reverse();
144
- else if (l === "prev" || l === "next") {
145
- l === "prev" && g.reverse();
146
- const R = g.indexOf(i.currentTarget);
147
- g = s.loop ? Ge(g, R + 1) : g.slice(R + 1);
148
- }
149
- setTimeout(
150
- () => X(g)
151
- );
152
- }
153
- })
154
- })));
155
- }), Ae = {
156
- ArrowLeft: "prev",
157
- ArrowUp: "prev",
158
- ArrowRight: "next",
159
- ArrowDown: "next",
160
- PageUp: "first",
161
- Home: "first",
162
- PageDown: "last",
163
- End: "last"
164
- };
165
- function ke(e, t) {
166
- return t !== "rtl" ? e : e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e;
167
- }
168
- function Te(e, t, o) {
169
- const r = ke(e.key, o);
170
- if (!(t === "vertical" && [
171
- "ArrowLeft",
172
- "ArrowRight"
173
- ].includes(r)) && !(t === "horizontal" && [
174
- "ArrowUp",
175
- "ArrowDown"
176
- ].includes(r)))
177
- return Ae[r];
178
- }
179
- function X(e) {
180
- const t = document.activeElement;
181
- for (const o of e)
182
- if (o === t || (o.focus(), document.activeElement !== t))
183
- return;
184
- }
185
- function Ge(e, t) {
186
- return e.map(
187
- (o, r) => e[(t + r) % e.length]
188
- );
189
- }
190
- const Pe = we, Ne = Se;
191
- function De(e) {
192
- const [t, o] = G(void 0);
193
- return ve(() => {
194
- if (e) {
195
- o({
196
- width: e.offsetWidth,
197
- height: e.offsetHeight
198
- });
199
- const r = new ResizeObserver((n) => {
200
- if (!Array.isArray(n) || !n.length)
201
- return;
202
- const c = n[0];
203
- let a, f;
204
- if ("borderBoxSize" in c) {
205
- const d = c.borderBoxSize, s = Array.isArray(d) ? d[0] : d;
206
- a = s.inlineSize, f = s.blockSize;
207
- } else
208
- a = e.offsetWidth, f = e.offsetHeight;
209
- o({
210
- width: a,
211
- height: f
212
- });
213
- });
214
- return r.observe(e, {
215
- box: "border-box"
216
- }), () => r.unobserve(e);
217
- } else
218
- o(void 0);
219
- }, [
220
- e
221
- ]), t;
222
- }
223
- const J = "Radio", [Oe, Q] = z(J), [Le, Me] = Oe(J), ze = /* @__PURE__ */ x((e, t) => {
224
- const { __scopeRadio: o, name: r, checked: n = !1, required: c, disabled: a, value: f = "on", onCheck: d, ...s } = e, [m, $] = G(null), p = M(
225
- t,
226
- (l) => $(l)
227
- ), u = w(!1), i = m ? !!m.closest("form") : !0;
228
- return /* @__PURE__ */ b(Le, {
229
- scope: o,
230
- checked: n,
231
- disabled: a
232
- }, /* @__PURE__ */ b(S.button, _({
233
- type: "button",
234
- role: "radio",
235
- "aria-checked": n,
236
- "data-state": Z(n),
237
- "data-disabled": a ? "" : void 0,
238
- disabled: a,
239
- value: f
240
- }, s, {
241
- ref: p,
242
- onClick: h(e.onClick, (l) => {
243
- n || d == null || d(), i && (u.current = l.isPropagationStopped(), u.current || l.stopPropagation());
244
- })
245
- })), i && /* @__PURE__ */ b(Be, {
246
- control: m,
247
- bubbles: !u.current,
248
- name: r,
249
- value: f,
250
- checked: n,
251
- required: c,
252
- disabled: a,
253
- style: {
254
- transform: "translateX(-100%)"
255
- }
256
- }));
257
- }), Ke = "RadioIndicator", Ue = /* @__PURE__ */ x((e, t) => {
258
- const { __scopeRadio: o, forceMount: r, ...n } = e, c = Me(Ke, o);
259
- return /* @__PURE__ */ b(me, {
260
- present: r || c.checked
261
- }, /* @__PURE__ */ b(S.span, _({
262
- "data-state": Z(c.checked),
263
- "data-disabled": c.disabled ? "" : void 0
264
- }, n, {
265
- ref: t
266
- })));
267
- }), Be = (e) => {
268
- const { control: t, checked: o, bubbles: r = !0, ...n } = e, c = w(null), a = _e(o), f = De(t);
269
- return P(() => {
270
- const d = c.current, s = window.HTMLInputElement.prototype, $ = Object.getOwnPropertyDescriptor(s, "checked").set;
271
- if (a !== o && $) {
272
- const p = new Event("click", {
273
- bubbles: r
274
- });
275
- $.call(d, o), d.dispatchEvent(p);
276
- }
277
- }, [
278
- a,
279
- o,
280
- r
281
- ]), /* @__PURE__ */ b("input", _({
282
- type: "radio",
283
- "aria-hidden": !0,
284
- defaultChecked: o
285
- }, n, {
286
- tabIndex: -1,
287
- ref: c,
288
- style: {
289
- ...e.style,
290
- ...f,
291
- position: "absolute",
292
- pointerEvents: "none",
293
- opacity: 0,
294
- margin: 0
295
- }
296
- }));
297
- };
298
- function Z(e) {
299
- return e ? "checked" : "unchecked";
300
- }
301
- const qe = [
302
- "ArrowUp",
303
- "ArrowDown",
304
- "ArrowLeft",
305
- "ArrowRight"
306
- ], ee = "RadioGroup", [Ve, fo] = z(ee, [
307
- W,
308
- Q
309
- ]), oe = W(), te = Q(), [He, Ye] = Ve(ee), je = /* @__PURE__ */ x((e, t) => {
310
- const { __scopeRadioGroup: o, name: r, defaultValue: n, value: c, required: a = !1, disabled: f = !1, orientation: d, dir: s, loop: m = !0, onValueChange: $, ...p } = e, u = oe(o), i = H(s), [l, F] = Y({
311
- prop: c,
312
- defaultProp: n,
313
- onChange: $
314
- });
315
- return /* @__PURE__ */ b(He, {
316
- scope: o,
317
- name: r,
318
- required: a,
319
- disabled: f,
320
- value: l,
321
- onValueChange: F
322
- }, /* @__PURE__ */ b(Pe, _({
323
- asChild: !0
324
- }, u, {
325
- orientation: d,
326
- dir: i,
327
- loop: m
328
- }), /* @__PURE__ */ b(S.div, _({
329
- role: "radiogroup",
330
- "aria-required": a,
331
- "aria-orientation": d,
332
- "data-disabled": f ? "" : void 0,
333
- dir: i
334
- }, p, {
335
- ref: t
336
- }))));
337
- }), We = "RadioGroupItem", Xe = /* @__PURE__ */ x((e, t) => {
338
- const { __scopeRadioGroup: o, disabled: r, ...n } = e, c = Ye(We, o), a = c.disabled || r, f = oe(o), d = te(o), s = w(null), m = M(t, s), $ = c.value === n.value, p = w(!1);
339
- return P(() => {
340
- const u = (l) => {
341
- qe.includes(l.key) && (p.current = !0);
342
- }, i = () => p.current = !1;
343
- return document.addEventListener("keydown", u), document.addEventListener("keyup", i), () => {
344
- document.removeEventListener("keydown", u), document.removeEventListener("keyup", i);
345
- };
346
- }, []), /* @__PURE__ */ b(Ne, _({
347
- asChild: !0
348
- }, f, {
349
- focusable: !a,
350
- active: $
351
- }), /* @__PURE__ */ b(ze, _({
352
- disabled: a,
353
- required: c.required,
354
- checked: $
355
- }, d, n, {
356
- name: c.name,
357
- ref: m,
358
- onCheck: () => c.onValueChange(n.value),
359
- onKeyDown: h((u) => {
360
- u.key === "Enter" && u.preventDefault();
361
- }),
362
- onFocus: h(n.onFocus, () => {
363
- var u;
364
- p.current && ((u = s.current) === null || u === void 0 || u.click());
365
- })
366
- })));
367
- }), Je = /* @__PURE__ */ x((e, t) => {
368
- const { __scopeRadioGroup: o, ...r } = e, n = te(o);
369
- return /* @__PURE__ */ b(Ue, _({}, n, r, {
370
- ref: t
371
- }));
372
- }), Qe = je, Ze = Xe, eo = Je, A = {
373
- "teddy-radio-group": "_teddy-radio-group_peeuu_1",
374
- "teddy-radio-group__item-label": "_teddy-radio-group__item-label_peeuu_9",
375
- "teddy-radio-group__item": "_teddy-radio-group__item_peeuu_9",
376
- "teddy-radio-group__trigger": "_teddy-radio-group__trigger_peeuu_21",
377
- "teddy-radio-group__indicator": "_teddy-radio-group__indicator_peeuu_46"
378
- }, k = "teddy-radio-group", re = I.forwardRef(
379
- ({ className: e, ...t }, o) => {
380
- const r = E([A[`${k}`]], e);
381
- return /* @__PURE__ */ C(Qe, { ...t, ref: o, className: r });
382
- }
383
- );
384
- re.displayName = "RadioGroup";
385
- const U = I.createContext(
386
- void 0
387
- ), ne = I.forwardRef(({ className: e, ...t }, o) => {
388
- const r = E([A[`${k}__item`]], e), n = w(null), c = `${I.useId()}-trigger`;
389
- return /* @__PURE__ */ C(U.Provider, { value: { triggerRef: n, id: c }, children: /* @__PURE__ */ C("div", { ...t, ref: o, className: r }) });
390
- });
391
- ne.displayName = "RadioGroup.Item";
392
- const ce = I.forwardRef(
393
- ({ className: e, children: t, ...o }, r) => {
394
- const n = E([A[`${k}__trigger`]], e), c = I.useContext(U), a = Re(r, c == null ? void 0 : c.triggerRef), f = o.id || (c == null ? void 0 : c.id);
395
- return /* @__PURE__ */ C(Ze, { ...o, id: f, ref: a, className: n, children: t || /* @__PURE__ */ C(B, {}) });
396
- }
397
- );
398
- ce.displayName = "RadioGroup.Trigger";
399
- const B = I.forwardRef(
400
- ({ className: e, ...t }, o) => {
401
- const r = E([A[`${k}__indicator`]], e);
402
- return /* @__PURE__ */ C(eo, { ...t, ref: o, className: r });
403
- }
404
- );
405
- B.displayName = "RadioGroup.Indicator";
406
- const ae = I.forwardRef(
407
- ({ className: e, ...t }, o) => {
408
- const r = E([A[`${k}__item`]], e), n = I.useContext(U), c = t.htmlFor || (n == null ? void 0 : n.id);
409
- return /* @__PURE__ */ C(ge, { ...t, htmlFor: c, ref: o, className: r });
410
- }
411
- );
412
- ae.displayName = "RadioGroup.Label";
413
- const bo = Object.assign(re, {
414
- Item: ne,
415
- Trigger: ce,
416
- Indicator: B,
417
- Label: ae
418
- });
419
- export {
420
- De as $,
421
- bo as R
422
- };