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