@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.
- package/dist/components/Table/index.cjs +86 -31
- package/dist/components/Table/index.css +173 -146
- package/dist/components/Table/index.d.cts +10 -0
- package/dist/components/Table/index.d.ts +10 -0
- package/dist/components/Table/index.js +90 -35
- package/dist/components/index.cjs +164 -109
- package/dist/components/index.css +173 -146
- package/dist/components/index.js +195 -140
- package/dist/index.cjs +169 -114
- package/dist/index.css +173 -146
- package/dist/index.js +205 -150
- package/guidelines/components/table.md +1 -0
- package/package.json +1 -1
|
@@ -38,6 +38,9 @@ __export(Table_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(Table_exports);
|
|
40
40
|
|
|
41
|
+
// src/components/Table/Table.tsx
|
|
42
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
43
|
+
|
|
41
44
|
// src/components/Table/TableContext.tsx
|
|
42
45
|
var import_react = __toESM(require("react"), 1);
|
|
43
46
|
var TableContext = import_react.default.createContext(null);
|
|
@@ -49,7 +52,42 @@ var useTableContext = () => {
|
|
|
49
52
|
var TableContext_default = TableContext;
|
|
50
53
|
|
|
51
54
|
// src/components/Table/Table.tsx
|
|
52
|
-
var import_jsx_runtime =
|
|
55
|
+
var import_jsx_runtime = (
|
|
56
|
+
/**
|
|
57
|
+
* 바깥 이름(`lib-xplat-table-wrapper`)을 그대로 둔다 — 소비처가 이 클래스를
|
|
58
|
+
* 자리 잡는 데 쓰고 있을 수 있어서다. 스크롤은 안쪽 `-scroller` 가 맡는다.
|
|
59
|
+
*/
|
|
60
|
+
require("react/jsx-runtime")
|
|
61
|
+
);
|
|
62
|
+
var useScrollExtent = (scrollerRef, thumbRef) => {
|
|
63
|
+
const [scrollable, setScrollable] = import_react2.default.useState(false);
|
|
64
|
+
import_react2.default.useEffect(() => {
|
|
65
|
+
const el = scrollerRef.current;
|
|
66
|
+
if (!el) return;
|
|
67
|
+
const update = () => {
|
|
68
|
+
const max = el.scrollWidth - el.clientWidth;
|
|
69
|
+
const can = max > 1;
|
|
70
|
+
setScrollable(can);
|
|
71
|
+
const thumb = thumbRef.current;
|
|
72
|
+
if (!thumb) return;
|
|
73
|
+
const ratio = can ? el.clientWidth / el.scrollWidth : 1;
|
|
74
|
+
const w = Math.max(ratio * 100, 8);
|
|
75
|
+
thumb.style.width = `${w.toFixed(2)}%`;
|
|
76
|
+
thumb.style.left = can ? `${(el.scrollLeft / max * (100 - w)).toFixed(2)}%` : "0%";
|
|
77
|
+
};
|
|
78
|
+
update();
|
|
79
|
+
el.addEventListener("scroll", update, { passive: true });
|
|
80
|
+
const ro = new ResizeObserver(update);
|
|
81
|
+
ro.observe(el);
|
|
82
|
+
const table = el.firstElementChild;
|
|
83
|
+
if (table) ro.observe(table);
|
|
84
|
+
return () => {
|
|
85
|
+
el.removeEventListener("scroll", update);
|
|
86
|
+
ro.disconnect();
|
|
87
|
+
};
|
|
88
|
+
}, [scrollerRef, thumbRef]);
|
|
89
|
+
return scrollable;
|
|
90
|
+
};
|
|
53
91
|
var Table = (props) => {
|
|
54
92
|
const {
|
|
55
93
|
children,
|
|
@@ -57,25 +95,42 @@ var Table = (props) => {
|
|
|
57
95
|
rowBorderUse = true,
|
|
58
96
|
colBorderUse = true,
|
|
59
97
|
headerSticky = false,
|
|
60
|
-
stickyShadow = true
|
|
98
|
+
stickyShadow = true,
|
|
99
|
+
minWidth
|
|
61
100
|
} = props;
|
|
62
|
-
|
|
101
|
+
const scrollerRef = import_react2.default.useRef(null);
|
|
102
|
+
const thumbRef = import_react2.default.useRef(null);
|
|
103
|
+
const scrollable = useScrollExtent(scrollerRef, thumbRef);
|
|
104
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
63
105
|
"div",
|
|
64
106
|
{
|
|
65
107
|
className: `lib-xplat-table-wrapper ${size}`,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
108
|
+
style: minWidth === void 0 ? void 0 : {
|
|
109
|
+
"--table-min-width": typeof minWidth === "number" ? `${minWidth}px` : minWidth
|
|
110
|
+
},
|
|
111
|
+
children: [
|
|
112
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
113
|
+
"div",
|
|
114
|
+
{
|
|
115
|
+
ref: scrollerRef,
|
|
116
|
+
className: "lib-xplat-table-scroller",
|
|
117
|
+
"data-xplat-overlay-escape": "",
|
|
118
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
119
|
+
TableContext_default.Provider,
|
|
120
|
+
{
|
|
121
|
+
value: {
|
|
122
|
+
rowBorderUse,
|
|
123
|
+
colBorderUse,
|
|
124
|
+
headerSticky,
|
|
125
|
+
stickyShadow
|
|
126
|
+
},
|
|
127
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("table", { className: "lib-xplat-table", children })
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `lib-xplat-table-scrollbar${scrollable ? " scrollable" : ""}`, "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: thumbRef, className: "table-scrollbar-thumb" }) })
|
|
133
|
+
]
|
|
79
134
|
}
|
|
80
135
|
);
|
|
81
136
|
};
|
|
@@ -92,7 +147,7 @@ TableBody.displayName = "TableBody";
|
|
|
92
147
|
var TableBody_default = TableBody;
|
|
93
148
|
|
|
94
149
|
// src/components/Table/TableCell.tsx
|
|
95
|
-
var
|
|
150
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
96
151
|
|
|
97
152
|
// ../../node_modules/clsx/dist/clsx.mjs
|
|
98
153
|
function r(e) {
|
|
@@ -111,21 +166,21 @@ function clsx() {
|
|
|
111
166
|
var clsx_default = clsx;
|
|
112
167
|
|
|
113
168
|
// src/components/Table/TableHeadContext.tsx
|
|
114
|
-
var
|
|
115
|
-
var TableHeadContext =
|
|
169
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
170
|
+
var TableHeadContext = import_react3.default.createContext(
|
|
116
171
|
null
|
|
117
172
|
);
|
|
118
173
|
var useTableHeadContext = () => {
|
|
119
|
-
const ctx =
|
|
174
|
+
const ctx = import_react3.default.useContext(TableHeadContext);
|
|
120
175
|
return ctx;
|
|
121
176
|
};
|
|
122
177
|
var TableHeadContext_default = TableHeadContext;
|
|
123
178
|
|
|
124
179
|
// src/components/Table/TableRowContext.tsx
|
|
125
|
-
var
|
|
126
|
-
var TableRowContext =
|
|
180
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
181
|
+
var TableRowContext = import_react4.default.createContext(null);
|
|
127
182
|
var useTableRowContext = () => {
|
|
128
|
-
const ctx =
|
|
183
|
+
const ctx = import_react4.default.useContext(TableRowContext);
|
|
129
184
|
if (!ctx) throw new Error("Table components must be used inside <Table>");
|
|
130
185
|
return ctx;
|
|
131
186
|
};
|
|
@@ -133,7 +188,7 @@ var TableRowContext_default = TableRowContext;
|
|
|
133
188
|
|
|
134
189
|
// src/components/Table/TableCell.tsx
|
|
135
190
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
136
|
-
var TableCell =
|
|
191
|
+
var TableCell = import_react5.default.memo((props) => {
|
|
137
192
|
const {
|
|
138
193
|
children,
|
|
139
194
|
align = "center",
|
|
@@ -147,9 +202,9 @@ var TableCell = import_react4.default.memo((props) => {
|
|
|
147
202
|
const { registerStickyCell, stickyCells } = useTableRowContext();
|
|
148
203
|
const { stickyShadow } = useTableContext();
|
|
149
204
|
const headContext = useTableHeadContext();
|
|
150
|
-
const [left, setLeft] =
|
|
151
|
-
const cellRef =
|
|
152
|
-
const calculateLeft =
|
|
205
|
+
const [left, setLeft] = import_react5.default.useState(0);
|
|
206
|
+
const cellRef = import_react5.default.useRef(null);
|
|
207
|
+
const calculateLeft = import_react5.default.useCallback(() => {
|
|
153
208
|
if (!cellRef.current) return 0;
|
|
154
209
|
let totalLeft = 0;
|
|
155
210
|
for (const ref of stickyCells) {
|
|
@@ -158,7 +213,7 @@ var TableCell = import_react4.default.memo((props) => {
|
|
|
158
213
|
}
|
|
159
214
|
return totalLeft;
|
|
160
215
|
}, [stickyCells]);
|
|
161
|
-
|
|
216
|
+
import_react5.default.useEffect(() => {
|
|
162
217
|
if (!isSticky || !cellRef.current) return;
|
|
163
218
|
registerStickyCell(cellRef);
|
|
164
219
|
setLeft(calculateLeft());
|
|
@@ -216,9 +271,9 @@ TableHead.displayName = "TableHead";
|
|
|
216
271
|
var TableHead_default = TableHead;
|
|
217
272
|
|
|
218
273
|
// src/components/Table/TableRow.tsx
|
|
219
|
-
var
|
|
274
|
+
var import_react6 = __toESM(require("react"), 1);
|
|
220
275
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
221
|
-
var TableRow =
|
|
276
|
+
var TableRow = import_react6.default.memo((props) => {
|
|
222
277
|
const {
|
|
223
278
|
children,
|
|
224
279
|
type = "secondary",
|
|
@@ -227,7 +282,7 @@ var TableRow = import_react5.default.memo((props) => {
|
|
|
227
282
|
onClick
|
|
228
283
|
} = props;
|
|
229
284
|
const { rowBorderUse } = useTableContext();
|
|
230
|
-
const [stickyCells, setStickyCells] =
|
|
285
|
+
const [stickyCells, setStickyCells] = import_react6.default.useState([]);
|
|
231
286
|
const registerStickyCell = (ref) => {
|
|
232
287
|
setStickyCells((prev) => {
|
|
233
288
|
if (prev.includes(ref)) return prev;
|