@x-plat/design-system 0.17.0 → 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.
- package/dist/components/Table/index.cjs +81 -30
- package/dist/components/Table/index.css +172 -145
- package/dist/components/Table/index.js +88 -37
- package/dist/components/index.cjs +159 -108
- package/dist/components/index.css +172 -145
- package/dist/components/index.js +193 -142
- package/dist/index.cjs +164 -113
- package/dist/index.css +172 -145
- package/dist/index.js +203 -152
- package/package.json +1 -1
|
@@ -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,
|
|
@@ -20,27 +52,46 @@ var Table = (props) => {
|
|
|
20
52
|
stickyShadow = true,
|
|
21
53
|
minWidth
|
|
22
54
|
} = props;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
)
|
|
44
95
|
);
|
|
45
96
|
};
|
|
46
97
|
Table.displayName = "Table";
|
|
@@ -56,7 +107,7 @@ TableBody.displayName = "TableBody";
|
|
|
56
107
|
var TableBody_default = TableBody;
|
|
57
108
|
|
|
58
109
|
// src/components/Table/TableCell.tsx
|
|
59
|
-
import
|
|
110
|
+
import React5 from "react";
|
|
60
111
|
|
|
61
112
|
// ../../node_modules/clsx/dist/clsx.mjs
|
|
62
113
|
function r(e) {
|
|
@@ -75,21 +126,21 @@ function clsx() {
|
|
|
75
126
|
var clsx_default = clsx;
|
|
76
127
|
|
|
77
128
|
// src/components/Table/TableHeadContext.tsx
|
|
78
|
-
import
|
|
79
|
-
var TableHeadContext =
|
|
129
|
+
import React3 from "react";
|
|
130
|
+
var TableHeadContext = React3.createContext(
|
|
80
131
|
null
|
|
81
132
|
);
|
|
82
133
|
var useTableHeadContext = () => {
|
|
83
|
-
const ctx =
|
|
134
|
+
const ctx = React3.useContext(TableHeadContext);
|
|
84
135
|
return ctx;
|
|
85
136
|
};
|
|
86
137
|
var TableHeadContext_default = TableHeadContext;
|
|
87
138
|
|
|
88
139
|
// src/components/Table/TableRowContext.tsx
|
|
89
|
-
import
|
|
90
|
-
var TableRowContext =
|
|
140
|
+
import React4 from "react";
|
|
141
|
+
var TableRowContext = React4.createContext(null);
|
|
91
142
|
var useTableRowContext = () => {
|
|
92
|
-
const ctx =
|
|
143
|
+
const ctx = React4.useContext(TableRowContext);
|
|
93
144
|
if (!ctx) throw new Error("Table components must be used inside <Table>");
|
|
94
145
|
return ctx;
|
|
95
146
|
};
|
|
@@ -97,7 +148,7 @@ var TableRowContext_default = TableRowContext;
|
|
|
97
148
|
|
|
98
149
|
// src/components/Table/TableCell.tsx
|
|
99
150
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
100
|
-
var TableCell =
|
|
151
|
+
var TableCell = React5.memo((props) => {
|
|
101
152
|
const {
|
|
102
153
|
children,
|
|
103
154
|
align = "center",
|
|
@@ -111,9 +162,9 @@ var TableCell = React4.memo((props) => {
|
|
|
111
162
|
const { registerStickyCell, stickyCells } = useTableRowContext();
|
|
112
163
|
const { stickyShadow } = useTableContext();
|
|
113
164
|
const headContext = useTableHeadContext();
|
|
114
|
-
const [left, setLeft] =
|
|
115
|
-
const cellRef =
|
|
116
|
-
const calculateLeft =
|
|
165
|
+
const [left, setLeft] = React5.useState(0);
|
|
166
|
+
const cellRef = React5.useRef(null);
|
|
167
|
+
const calculateLeft = React5.useCallback(() => {
|
|
117
168
|
if (!cellRef.current) return 0;
|
|
118
169
|
let totalLeft = 0;
|
|
119
170
|
for (const ref of stickyCells) {
|
|
@@ -122,7 +173,7 @@ var TableCell = React4.memo((props) => {
|
|
|
122
173
|
}
|
|
123
174
|
return totalLeft;
|
|
124
175
|
}, [stickyCells]);
|
|
125
|
-
|
|
176
|
+
React5.useEffect(() => {
|
|
126
177
|
if (!isSticky || !cellRef.current) return;
|
|
127
178
|
registerStickyCell(cellRef);
|
|
128
179
|
setLeft(calculateLeft());
|
|
@@ -180,9 +231,9 @@ TableHead.displayName = "TableHead";
|
|
|
180
231
|
var TableHead_default = TableHead;
|
|
181
232
|
|
|
182
233
|
// src/components/Table/TableRow.tsx
|
|
183
|
-
import
|
|
234
|
+
import React6 from "react";
|
|
184
235
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
185
|
-
var TableRow =
|
|
236
|
+
var TableRow = React6.memo((props) => {
|
|
186
237
|
const {
|
|
187
238
|
children,
|
|
188
239
|
type = "secondary",
|
|
@@ -191,7 +242,7 @@ var TableRow = React5.memo((props) => {
|
|
|
191
242
|
onClick
|
|
192
243
|
} = props;
|
|
193
244
|
const { rowBorderUse } = useTableContext();
|
|
194
|
-
const [stickyCells, setStickyCells] =
|
|
245
|
+
const [stickyCells, setStickyCells] = React6.useState([]);
|
|
195
246
|
const registerStickyCell = (ref) => {
|
|
196
247
|
setStickyCells((prev) => {
|
|
197
248
|
if (prev.includes(ref)) return prev;
|