quirk-ui 0.0.108 → 0.0.109

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,101 +1,112 @@
1
- import { jsx as f, jsxs as T } from "react/jsx-runtime";
2
- import L, { useState as x, useId as A, useRef as m, useMemo as I, useLayoutEffect as d } from "react";
3
- import { TabsContext as h, useTabsContext as p } from "./Context.js";
4
- import '../../assets/index33.css';const R = "_tabs_1wmov_1", C = "_tabsList_1wmov_7", N = "_left_1wmov_13", W = "_center_1wmov_17", k = "_right_1wmov_21", H = "_tabsTrigger_1wmov_25", M = "_active_1wmov_40", j = "_tabsPanelWrapper_1wmov_45", D = "_tabsPanel_1wmov_45", n = {
5
- tabs: R,
1
+ import { jsx as _, jsxs as T } from "react/jsx-runtime";
2
+ import x, { useState as L, useId as A, useRef as m, useMemo as d, useLayoutEffect as I } from "react";
3
+ import { TabsContext as R, useTabsContext as p } from "./Context.js";
4
+ import '../../assets/index33.css';const h = "_tabs_1wmov_1", C = "_tabsList_1wmov_7", N = "_left_1wmov_13", W = "_center_1wmov_17", k = "_right_1wmov_21", M = "_tabsTrigger_1wmov_25", j = "_active_1wmov_40", D = "_tabsPanelWrapper_1wmov_45", E = "_tabsPanel_1wmov_45", o = {
5
+ tabs: h,
6
6
  tabsList: C,
7
7
  left: N,
8
8
  center: W,
9
9
  right: k,
10
- tabsTrigger: H,
11
- active: M,
12
- tabsPanelWrapper: j,
13
- tabsPanel: D
14
- }, E = {
15
- left: n.left,
16
- center: n.center,
17
- right: n.right
10
+ tabsTrigger: M,
11
+ active: j,
12
+ tabsPanelWrapper: D,
13
+ tabsPanel: E
14
+ }, F = {
15
+ left: o.left,
16
+ center: o.center,
17
+ right: o.right
18
18
  };
19
19
  function v({
20
- children: r,
20
+ children: c,
21
21
  defaultIndex: t = 0,
22
22
  align: s = "left"
23
23
  }) {
24
- const [a, c] = x(t), o = A(), b = [], u = [], l = m(null), i = m([]), y = I(
25
- () => ({ activeIndex: a, setActiveIndex: c, idPrefix: o, align: s, panelRefs: i }),
26
- [a, o, s]
24
+ const [a, f] = L(t), n = A(), r = [], i = [], b = m(null), l = m([]), w = () => {
25
+ const e = b.current, u = l.current[a];
26
+ if (e && u) {
27
+ const $ = u.offsetHeight;
28
+ e.style.height = `${$}px`;
29
+ }
30
+ }, y = d(
31
+ () => ({
32
+ activeIndex: a,
33
+ setActiveIndex: f,
34
+ idPrefix: n,
35
+ align: s,
36
+ panelRefs: l,
37
+ setWrapperHeight: w
38
+ }),
39
+ [a, n, s]
27
40
  );
28
- return L.Children.forEach(r, (e) => {
29
- var _;
30
- (e == null ? void 0 : e.type) === P ? b.push(e) : ((e == null ? void 0 : e.type) === w || ((_ = e == null ? void 0 : e.type) == null ? void 0 : _.name) === "Panel") && u.push(e);
31
- }), d(() => {
32
- const e = l.current, _ = requestAnimationFrame(() => {
33
- const g = i.current[a];
34
- if (e && g) {
35
- const $ = g.offsetHeight;
36
- e.offsetHeight, e.style.height = `${$}px`;
37
- }
38
- });
39
- return () => cancelAnimationFrame(_);
40
- }, [a]), /* @__PURE__ */ f(h.Provider, { value: y, children: /* @__PURE__ */ T("div", { className: n.tabs, children: [
41
- b,
42
- /* @__PURE__ */ f("div", { ref: l, className: n.tabsPanelWrapper, children: u })
41
+ return x.Children.forEach(c, (e) => {
42
+ var u;
43
+ (e == null ? void 0 : e.type) === g ? r.push(e) : ((e == null ? void 0 : e.type) === P || ((u = e == null ? void 0 : e.type) == null ? void 0 : u.name) === "Panel") && i.push(e);
44
+ }), /* @__PURE__ */ _(R.Provider, { value: y, children: /* @__PURE__ */ T("div", { className: o.tabs, children: [
45
+ r,
46
+ /* @__PURE__ */ _("div", { ref: b, className: o.tabsPanelWrapper, children: i })
43
47
  ] }) });
44
48
  }
45
- function P({ children: r }) {
49
+ function g({ children: c }) {
46
50
  const { align: t } = p();
47
- return /* @__PURE__ */ f(
51
+ return /* @__PURE__ */ _(
48
52
  "div",
49
53
  {
50
- className: `${n.tabsList} ${E[t]}`,
54
+ className: `${o.tabsList} ${F[t]}`,
51
55
  role: "tablist",
52
56
  "aria-label": "Tabs",
53
- children: r
57
+ children: c
54
58
  }
55
59
  );
56
60
  }
57
- function F({ children: r, index: t }) {
58
- const { activeIndex: s, setActiveIndex: a, idPrefix: c } = p(), o = m(null), b = (l) => {
59
- l.key === "ArrowRight" ? a((i) => i + 1) : l.key === "ArrowLeft" && a((i) => Math.max(0, i - 1));
60
- }, u = s === t;
61
- return /* @__PURE__ */ f(
61
+ function H({ children: c, index: t }) {
62
+ const { activeIndex: s, setActiveIndex: a, idPrefix: f } = p(), n = m(null), r = (b) => {
63
+ b.key === "ArrowRight" ? a((l) => l + 1) : b.key === "ArrowLeft" && a((l) => Math.max(0, l - 1));
64
+ }, i = s === t;
65
+ return /* @__PURE__ */ _(
62
66
  "button",
63
67
  {
64
- className: `${n.tabsTrigger} ${u ? n.active : ""}`,
68
+ className: `${o.tabsTrigger} ${i ? o.active : ""}`,
65
69
  role: "tab",
66
- ref: o,
67
- id: `${c}-tab-${t}`,
70
+ ref: n,
71
+ id: `${f}-tab-${t}`,
68
72
  "aria-selected": s === t,
69
73
  tabIndex: s === t ? 0 : -1,
70
74
  onClick: () => a(t),
71
- onKeyDown: b,
72
- children: r
75
+ onKeyDown: r,
76
+ children: c
73
77
  }
74
78
  );
75
79
  }
76
- function w({ children: r, index: t }) {
77
- const { activeIndex: s, idPrefix: a, panelRefs: c } = p();
78
- return t !== s ? null : /* @__PURE__ */ f(
80
+ function P({ children: c, index: t }) {
81
+ const { activeIndex: s, idPrefix: a, panelRefs: f, setWrapperHeight: n } = p(), r = t === s;
82
+ return I(() => {
83
+ if (r) {
84
+ const i = requestAnimationFrame(() => {
85
+ n == null || n();
86
+ });
87
+ return () => cancelAnimationFrame(i);
88
+ }
89
+ }, [s, n]), r ? /* @__PURE__ */ _(
79
90
  "div",
80
91
  {
81
- ref: (o) => {
82
- c.current[t] = o;
92
+ ref: (i) => {
93
+ f.current[t] = i;
83
94
  },
84
- className: n.tabsPanel,
95
+ className: o.tabsPanel,
85
96
  role: "tabpanel",
86
97
  id: `${a}-panel-${t}`,
87
98
  "aria-labelledby": `${a}-tab-${t}`,
88
- "aria-hidden": s !== t,
89
- hidden: s !== t,
90
- children: r
99
+ "aria-hidden": !r,
100
+ hidden: !r,
101
+ children: c
91
102
  }
92
- );
103
+ ) : null;
93
104
  }
94
- v.List = P;
95
- v.Trigger = F;
96
- v.Panel = w;
105
+ v.List = g;
106
+ v.Trigger = H;
107
+ v.Panel = P;
97
108
  export {
98
109
  v as Tabs,
99
- E as alignClassMap,
110
+ F as alignClassMap,
100
111
  v as default
101
112
  };
@@ -6,6 +6,7 @@ export type TabsContextType = {
6
6
  idPrefix: string;
7
7
  align: Align;
8
8
  panelRefs: React.RefObject<(HTMLDivElement | null)[]>;
9
+ setWrapperHeight?: () => void;
9
10
  };
10
11
  export declare const TabsContext: React.Context<TabsContextType | null>;
11
12
  export declare function useTabsContext(): TabsContextType;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quirk-ui",
3
3
  "private": false,
4
- "version": "0.0.108",
4
+ "version": "0.0.109",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {