@x-plat/design-system 0.16.3 → 0.18.0

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,3 +1,6 @@
1
+ // src/components/Table/Table.tsx
2
+ import React2 from "react";
3
+
1
4
  // src/components/Table/TableContext.tsx
2
5
  import React from "react";
3
6
  var TableContext = React.createContext(null);
@@ -9,7 +12,36 @@ var useTableContext = () => {
9
12
  var TableContext_default = TableContext;
10
13
 
11
14
  // src/components/Table/Table.tsx
12
- import { jsx } from "react/jsx-runtime";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var useScrollExtent = (scrollerRef, thumbRef) => {
17
+ const [scrollable, setScrollable] = React2.useState(false);
18
+ React2.useEffect(() => {
19
+ const el = scrollerRef.current;
20
+ if (!el) return;
21
+ const update = () => {
22
+ const max = el.scrollWidth - el.clientWidth;
23
+ const can = max > 1;
24
+ setScrollable(can);
25
+ const thumb = thumbRef.current;
26
+ if (!thumb) return;
27
+ const ratio = can ? el.clientWidth / el.scrollWidth : 1;
28
+ const w = Math.max(ratio * 100, 8);
29
+ thumb.style.width = `${w.toFixed(2)}%`;
30
+ thumb.style.left = can ? `${(el.scrollLeft / max * (100 - w)).toFixed(2)}%` : "0%";
31
+ };
32
+ update();
33
+ el.addEventListener("scroll", update, { passive: true });
34
+ const ro = new ResizeObserver(update);
35
+ ro.observe(el);
36
+ const table = el.firstElementChild;
37
+ if (table) ro.observe(table);
38
+ return () => {
39
+ el.removeEventListener("scroll", update);
40
+ ro.disconnect();
41
+ };
42
+ }, [scrollerRef, thumbRef]);
43
+ return scrollable;
44
+ };
13
45
  var Table = (props) => {
14
46
  const {
15
47
  children,
@@ -17,26 +49,49 @@ var Table = (props) => {
17
49
  rowBorderUse = true,
18
50
  colBorderUse = true,
19
51
  headerSticky = false,
20
- stickyShadow = true
52
+ stickyShadow = true,
53
+ minWidth
21
54
  } = props;
22
- return /* @__PURE__ */ jsx(
23
- "div",
24
- {
25
- className: `lib-xplat-table-wrapper ${size}`,
26
- "data-xplat-overlay-escape": "",
27
- children: /* @__PURE__ */ jsx(
28
- TableContext_default.Provider,
29
- {
30
- value: {
31
- rowBorderUse,
32
- colBorderUse,
33
- headerSticky,
34
- stickyShadow
35
- },
36
- children: /* @__PURE__ */ jsx("table", { className: "lib-xplat-table", children })
37
- }
38
- )
39
- }
55
+ const scrollerRef = React2.useRef(null);
56
+ const thumbRef = React2.useRef(null);
57
+ const scrollable = useScrollExtent(scrollerRef, thumbRef);
58
+ return (
59
+ /**
60
+ * 바깥 이름(`lib-xplat-table-wrapper`)을 그대로 둔다 — 소비처가 이 클래스를
61
+ * 자리 잡는 데 쓰고 있을 수 있어서다. 스크롤은 안쪽 `-scroller` 가 맡는다.
62
+ */
63
+ /* @__PURE__ */ jsxs(
64
+ "div",
65
+ {
66
+ className: `lib-xplat-table-wrapper ${size}`,
67
+ style: minWidth === void 0 ? void 0 : {
68
+ "--table-min-width": typeof minWidth === "number" ? `${minWidth}px` : minWidth
69
+ },
70
+ children: [
71
+ /* @__PURE__ */ jsx(
72
+ "div",
73
+ {
74
+ ref: scrollerRef,
75
+ className: "lib-xplat-table-scroller",
76
+ "data-xplat-overlay-escape": "",
77
+ children: /* @__PURE__ */ jsx(
78
+ TableContext_default.Provider,
79
+ {
80
+ value: {
81
+ rowBorderUse,
82
+ colBorderUse,
83
+ headerSticky,
84
+ stickyShadow
85
+ },
86
+ children: /* @__PURE__ */ jsx("table", { className: "lib-xplat-table", children })
87
+ }
88
+ )
89
+ }
90
+ ),
91
+ /* @__PURE__ */ jsx("div", { className: `lib-xplat-table-scrollbar${scrollable ? " scrollable" : ""}`, "aria-hidden": true, children: /* @__PURE__ */ jsx("div", { ref: thumbRef, className: "table-scrollbar-thumb" }) })
92
+ ]
93
+ }
94
+ )
40
95
  );
41
96
  };
42
97
  Table.displayName = "Table";
@@ -52,7 +107,7 @@ TableBody.displayName = "TableBody";
52
107
  var TableBody_default = TableBody;
53
108
 
54
109
  // src/components/Table/TableCell.tsx
55
- import React4 from "react";
110
+ import React5 from "react";
56
111
 
57
112
  // ../../node_modules/clsx/dist/clsx.mjs
58
113
  function r(e) {
@@ -71,21 +126,21 @@ function clsx() {
71
126
  var clsx_default = clsx;
72
127
 
73
128
  // src/components/Table/TableHeadContext.tsx
74
- import React2 from "react";
75
- var TableHeadContext = React2.createContext(
129
+ import React3 from "react";
130
+ var TableHeadContext = React3.createContext(
76
131
  null
77
132
  );
78
133
  var useTableHeadContext = () => {
79
- const ctx = React2.useContext(TableHeadContext);
134
+ const ctx = React3.useContext(TableHeadContext);
80
135
  return ctx;
81
136
  };
82
137
  var TableHeadContext_default = TableHeadContext;
83
138
 
84
139
  // src/components/Table/TableRowContext.tsx
85
- import React3 from "react";
86
- var TableRowContext = React3.createContext(null);
140
+ import React4 from "react";
141
+ var TableRowContext = React4.createContext(null);
87
142
  var useTableRowContext = () => {
88
- const ctx = React3.useContext(TableRowContext);
143
+ const ctx = React4.useContext(TableRowContext);
89
144
  if (!ctx) throw new Error("Table components must be used inside <Table>");
90
145
  return ctx;
91
146
  };
@@ -93,7 +148,7 @@ var TableRowContext_default = TableRowContext;
93
148
 
94
149
  // src/components/Table/TableCell.tsx
95
150
  import { jsx as jsx3 } from "react/jsx-runtime";
96
- var TableCell = React4.memo((props) => {
151
+ var TableCell = React5.memo((props) => {
97
152
  const {
98
153
  children,
99
154
  align = "center",
@@ -107,9 +162,9 @@ var TableCell = React4.memo((props) => {
107
162
  const { registerStickyCell, stickyCells } = useTableRowContext();
108
163
  const { stickyShadow } = useTableContext();
109
164
  const headContext = useTableHeadContext();
110
- const [left, setLeft] = React4.useState(0);
111
- const cellRef = React4.useRef(null);
112
- const calculateLeft = React4.useCallback(() => {
165
+ const [left, setLeft] = React5.useState(0);
166
+ const cellRef = React5.useRef(null);
167
+ const calculateLeft = React5.useCallback(() => {
113
168
  if (!cellRef.current) return 0;
114
169
  let totalLeft = 0;
115
170
  for (const ref of stickyCells) {
@@ -118,7 +173,7 @@ var TableCell = React4.memo((props) => {
118
173
  }
119
174
  return totalLeft;
120
175
  }, [stickyCells]);
121
- React4.useEffect(() => {
176
+ React5.useEffect(() => {
122
177
  if (!isSticky || !cellRef.current) return;
123
178
  registerStickyCell(cellRef);
124
179
  setLeft(calculateLeft());
@@ -176,9 +231,9 @@ TableHead.displayName = "TableHead";
176
231
  var TableHead_default = TableHead;
177
232
 
178
233
  // src/components/Table/TableRow.tsx
179
- import React5 from "react";
234
+ import React6 from "react";
180
235
  import { jsx as jsx5 } from "react/jsx-runtime";
181
- var TableRow = React5.memo((props) => {
236
+ var TableRow = React6.memo((props) => {
182
237
  const {
183
238
  children,
184
239
  type = "secondary",
@@ -187,7 +242,7 @@ var TableRow = React5.memo((props) => {
187
242
  onClick
188
243
  } = props;
189
244
  const { rowBorderUse } = useTableContext();
190
- const [stickyCells, setStickyCells] = React5.useState([]);
245
+ const [stickyCells, setStickyCells] = React6.useState([]);
191
246
  const registerStickyCell = (ref) => {
192
247
  setStickyCells((prev) => {
193
248
  if (prev.includes(ref)) return prev;