@mci-ui/mci-ui 0.0.97 → 0.0.99

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,68 +1,69 @@
1
1
  import { jsxs as m, jsx as l } from "react/jsx-runtime";
2
- import { useState as g, useRef as y, useCallback as _, useEffect as v, useMemo as $ } from "react";
2
+ import { useState as y, useRef as S, useCallback as F, useEffect as v, useMemo as q } from "react";
3
3
  import { cn as n } from "../../lib/utils.js";
4
- import k from "./TabCountBadge.js";
5
- const F = {
4
+ import B from "./TabCountBadge.js";
5
+ const W = {
6
6
  top: "flex-col",
7
7
  bottom: "flex-col-reverse",
8
8
  left: "flex-row",
9
9
  right: "flex-row-reverse"
10
- }, q = {
10
+ }, D = {
11
11
  top: "flex-row",
12
12
  bottom: "flex-row",
13
13
  left: "flex-col",
14
14
  right: "flex-col"
15
- }, B = {
15
+ }, H = {
16
16
  top: "mt-4",
17
17
  bottom: "mb-4",
18
18
  left: "ml-4",
19
19
  right: "mr-4"
20
20
  };
21
- function G({
21
+ function Q({
22
22
  tabs: t,
23
- defaultTab: b,
24
- position: f = "top",
23
+ defaultTab: C,
24
+ activeTab: w,
25
+ position: a = "top",
25
26
  darkMode: u = !1,
26
- className: S,
27
+ className: E,
27
28
  width: r,
28
- tabListClassName: E,
29
+ tabListClassName: T,
29
30
  contentClassName: A,
30
- extra: w,
31
- onChange: C
31
+ extra: h,
32
+ onChange: z
32
33
  }) {
33
- const [s, T] = g(b || t[0]?.id), [z, L] = g({}), d = y([]), p = y(null), o = _(() => {
34
+ const [L, I] = y(C || t[0]?.id), p = w !== void 0, s = p ? w : L, [R, O] = y({}), d = S([]), N = S(null), o = F(() => {
34
35
  requestAnimationFrame(() => {
35
36
  requestAnimationFrame(() => {
36
- const e = t.findIndex((j) => j?.id === s), i = d.current[e];
37
+ const e = t.findIndex((k) => k?.id === s), i = d.current[e];
37
38
  if (!i) return;
38
- const { offsetLeft: a, offsetTop: x, offsetWidth: I, offsetHeight: O } = i;
39
- L({
40
- left: `${a}px`,
39
+ const { offsetLeft: f, offsetTop: x, offsetWidth: _, offsetHeight: $ } = i;
40
+ O({
41
+ left: `${f}px`,
41
42
  top: `${x}px`,
42
- width: `${I}px`,
43
- height: `${O}px`,
43
+ width: `${_}px`,
44
+ height: `${$}px`,
44
45
  transition: "all 0.35s cubic-bezier(0.25, 1, 0.5, 1)"
45
46
  });
46
47
  });
47
48
  });
48
49
  }, [s, t]);
49
- v(() => (o(), window.addEventListener("resize", o), "fonts" in document && document.fonts.ready.then(o), () => window.removeEventListener("resize", o)), [f, o]), v(() => {
50
- const e = p.current;
50
+ v(() => (o(), window.addEventListener("resize", o), "fonts" in document && document.fonts.ready.then(o), () => window.removeEventListener("resize", o)), [a, o]), v(() => {
51
+ const e = N.current;
51
52
  if (!e || typeof ResizeObserver > "u") return;
52
53
  const i = new ResizeObserver(() => {
53
54
  o();
54
55
  });
55
- return i.observe(e), d.current.forEach((a) => {
56
- a && i.observe(a);
56
+ return i.observe(e), d.current.forEach((f) => {
57
+ f && i.observe(f);
57
58
  }), () => i.disconnect();
58
59
  }, [t, o]), v(() => {
59
60
  d.current = d.current.slice(0, t.length);
60
61
  }, [t]);
61
- const c = f === "left" || f === "right", h = typeof r == "string" && r.startsWith("w-") ? r : void 0, N = h ? void 0 : r, R = $(
62
+ const c = a === "left" || a === "right", g = typeof r == "string" && r.startsWith("w-") ? r : void 0, b = g ? void 0 : r, j = q(
62
63
  () => t.find((e) => e.id === s)?.content,
63
64
  [s, t]
64
65
  );
65
- return /* @__PURE__ */ m("div", { className: n("flex w-full", F[f], S), children: [
66
+ return /* @__PURE__ */ m("div", { className: n("flex w-full", W[a], E), children: [
66
67
  /* @__PURE__ */ m(
67
68
  "div",
68
69
  {
@@ -77,20 +78,20 @@ function G({
77
78
  className: n(
78
79
  r ? "flex-none" : "flex-1",
79
80
  c ? "w-full" : !r && "min-w-[520px]",
80
- h
81
+ g
81
82
  ),
82
- style: N !== void 0 ? { width: N } : void 0,
83
+ style: b !== void 0 ? { width: b } : void 0,
83
84
  children: /* @__PURE__ */ m(
84
85
  "div",
85
86
  {
86
- ref: p,
87
+ ref: N,
87
88
  className: n(
88
89
  "relative flex rounded-xl p-1",
89
90
  u ? "bg-neutral-300" : "bg-slate-100",
90
- q[f],
91
+ D[a],
91
92
  !c && [!r && "w-full", "overflow-hidden"],
92
93
  c ? "min-w-48" : "",
93
- E
94
+ T
94
95
  ),
95
96
  children: [
96
97
  /* @__PURE__ */ l(
@@ -101,11 +102,11 @@ function G({
101
102
  u ? "bg-black" : "bg-white",
102
103
  c ? "w-full" : "h-full"
103
104
  ),
104
- style: z
105
+ style: R
105
106
  }
106
107
  ),
107
108
  t?.map((e, i) => {
108
- const a = s === e.id;
109
+ const f = s === e.id;
109
110
  return /* @__PURE__ */ m(
110
111
  "button",
111
112
  {
@@ -113,14 +114,14 @@ function G({
113
114
  d.current[i] = x;
114
115
  },
115
116
  onClick: () => {
116
- e?.disabled || (T(e?.id), C?.(e?.id));
117
+ e?.disabled || (p || I(e?.id), z?.(e?.id));
117
118
  },
118
119
  disabled: e?.disabled,
119
120
  className: n(
120
121
  "relative z-10 flex cursor-pointer items-center justify-center px-3 py-2 text-base font-normal whitespace-nowrap transition-colors duration-300",
121
122
  u ? "text-white" : "text-black",
122
123
  e?.disabled && (u ? "cursor-not-allowed text-neutral-100/50 opacity-60" : "cursor-not-allowed opacity-50"),
123
- c ? "w-full justify-start" : r ? "" : "min-w-0 flex-1"
124
+ c ? "w-full justify-start" : "min-w-0 flex-1"
124
125
  ),
125
126
  children: [
126
127
  e?.icon && /* @__PURE__ */ l(
@@ -128,13 +129,13 @@ function G({
128
129
  {
129
130
  className: n(
130
131
  "shrink-0 transition-transform duration-200",
131
- a && "scale-110"
132
+ f && "scale-110"
132
133
  ),
133
134
  children: e?.icon
134
135
  }
135
136
  ),
136
137
  /* @__PURE__ */ l("span", { className: "relative z-10 truncate", title: e?.label, children: e?.label }),
137
- /* @__PURE__ */ l(k, { count: e?.count })
138
+ /* @__PURE__ */ l(B, { count: e?.count })
138
139
  ]
139
140
  },
140
141
  e?.id
@@ -145,16 +146,16 @@ function G({
145
146
  )
146
147
  }
147
148
  ),
148
- w && /* @__PURE__ */ l("div", { className: n("ml-auto shrink-0", c ? "w-full" : "max-w-full"), children: /* @__PURE__ */ l("div", { className: "flex flex-wrap items-center justify-end gap-2", children: w }) })
149
+ h && /* @__PURE__ */ l("div", { className: n("ml-auto shrink-0", c ? "w-full" : "max-w-full"), children: /* @__PURE__ */ l("div", { className: "flex flex-wrap items-center justify-end gap-2", children: h }) })
149
150
  ]
150
151
  }
151
152
  ),
152
- R && /* @__PURE__ */ l(
153
+ j && /* @__PURE__ */ l(
153
154
  "div",
154
155
  {
155
156
  className: n(
156
157
  "w-full flex-1 overflow-hidden",
157
- B[f],
158
+ H[a],
158
159
  A
159
160
  ),
160
161
  children: /* @__PURE__ */ l(
@@ -171,5 +172,5 @@ function G({
171
172
  ] });
172
173
  }
173
174
  export {
174
- G as default
175
+ Q as default
175
176
  };
@@ -1,49 +1,50 @@
1
1
  import { jsxs as c, jsx as a } from "react/jsx-runtime";
2
- import { useState as f, useRef as m, useEffect as N, useMemo as S } from "react";
2
+ import { useState as b, useRef as T, useEffect as O, useMemo as j } from "react";
3
3
  import { cn as i } from "../../lib/utils.js";
4
4
  import A from "./TabCountBadge.js";
5
- const _ = ({
5
+ const z = ({
6
6
  tabs: e,
7
- className: b,
8
- contentClassName: p,
7
+ className: p,
8
+ contentClassName: w,
9
9
  darkMode: l,
10
- defaultTab: T,
11
- onChange: w,
12
- tabClassName: B,
13
- tabListClassName: v,
10
+ defaultTab: B,
11
+ activeTab: d,
12
+ onChange: v,
13
+ tabClassName: y,
14
+ tabListClassName: C,
14
15
  color: r = "orange"
15
16
  }) => {
16
- const [n, y] = f(T || e[0]?.id), [d, C] = f({ left: 0, width: 0 }), g = m({}), u = m(null);
17
- N(() => {
18
- const t = g.current[n], o = u.current;
17
+ const [R, k] = b(B || e[0]?.id), g = d !== void 0, n = g ? d : R, [u, N] = b({ left: 0, width: 0 }), h = T({}), f = T(null);
18
+ O(() => {
19
+ const t = h.current[n], o = f.current;
19
20
  if (t && o) {
20
- const k = o.getBoundingClientRect().left, x = t.getBoundingClientRect();
21
- C({
22
- left: x.left - k,
23
- width: x.width
21
+ const L = o.getBoundingClientRect().left, m = t.getBoundingClientRect();
22
+ N({
23
+ left: m.left - L,
24
+ width: m.width
24
25
  });
25
26
  }
26
27
  }, [n, e]);
27
- const R = (t) => {
28
- y(t), w?.(t);
29
- }, h = S(
28
+ const S = (t) => {
29
+ g || k(t), v?.(t);
30
+ }, x = j(
30
31
  () => e.find((t) => t.id === n)?.content,
31
32
  [n, e]
32
33
  );
33
- return /* @__PURE__ */ c("div", { className: i("space-y-4", b), children: [
34
- /* @__PURE__ */ c("div", { ref: u, className: i("relative flex", v), children: [
34
+ return /* @__PURE__ */ c("div", { className: i("space-y-4", p), children: [
35
+ /* @__PURE__ */ c("div", { ref: f, className: i("relative flex", C), children: [
35
36
  e.map((t) => /* @__PURE__ */ c(
36
37
  "button",
37
38
  {
38
39
  ref: (o) => {
39
- g.current[t.id] = o;
40
+ h.current[t.id] = o;
40
41
  },
41
- onClick: () => R(t.id),
42
+ onClick: () => S(t.id),
42
43
  className: i(
43
44
  "flex cursor-pointer items-center truncate border-b-2 px-3 py-2 text-sm font-medium transition-colors",
44
45
  l ? "border-slate-200/20" : "border-slate-200",
45
46
  n === t.id ? l ? s[r].darkText : s[r].lightText : l ? "text-slate-200/70 hover:text-slate-100" : "hover:text-primary text-slate-400",
46
- B
47
+ y
47
48
  ),
48
49
  children: [
49
50
  /* @__PURE__ */ a("span", { className: "truncate", children: t.label }),
@@ -59,11 +60,11 @@ const _ = ({
59
60
  "pointer-events-none absolute bottom-0 h-0.5 transition-all duration-300 ease-in-out",
60
61
  l ? s[r].darkBg : s[r].lightBg
61
62
  ),
62
- style: { left: d.left, width: d.width }
63
+ style: { left: u.left, width: u.width }
63
64
  }
64
65
  )
65
66
  ] }),
66
- h && /* @__PURE__ */ a("div", { className: i("mt-4", p), children: h })
67
+ x && /* @__PURE__ */ a("div", { className: i("mt-4", w), children: x })
67
68
  ] });
68
69
  }, s = {
69
70
  orange: {
@@ -86,5 +87,5 @@ const _ = ({
86
87
  }
87
88
  };
88
89
  export {
89
- _ as default
90
+ z as default
90
91
  };
@@ -15,6 +15,7 @@ export type TabsProps = {
15
15
  variant?: TabsVariant;
16
16
  color?: TabsColor;
17
17
  defaultTab?: string;
18
+ activeTab?: string;
18
19
  position?: TabsPosition;
19
20
  darkMode?: boolean;
20
21
  className?: string;
@@ -1,2 +1,2 @@
1
1
  import { TabsProps } from '../../types/ui/tabs.types';
2
- export default function FilledTabs({ tabs, defaultTab, position, darkMode, className, width, tabListClassName, contentClassName, extra, onChange, }: TabsProps): import("react/jsx-runtime").JSX.Element;
2
+ export default function FilledTabs({ tabs, defaultTab, activeTab: activeTabProp, position, darkMode, className, width, tabListClassName, contentClassName, extra, onChange, }: TabsProps): import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,3 @@
1
1
  import { TabsProps } from '../../types/ui';
2
- declare const OutlinedTabs: ({ tabs, className, contentClassName, darkMode, defaultTab, onChange, tabClassName, tabListClassName, color, }: TabsProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const OutlinedTabs: ({ tabs, className, contentClassName, darkMode, defaultTab, activeTab: activeTabProp, onChange, tabClassName, tabListClassName, color, }: TabsProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default OutlinedTabs;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mci-ui/mci-ui",
3
3
  "private": false,
4
- "version": "0.0.97",
4
+ "version": "0.0.99",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",