@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
|
@@ -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,
|
|
@@ -60,26 +98,39 @@ var Table = (props) => {
|
|
|
60
98
|
stickyShadow = true,
|
|
61
99
|
minWidth
|
|
62
100
|
} = props;
|
|
63
|
-
|
|
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)(
|
|
64
105
|
"div",
|
|
65
106
|
{
|
|
66
107
|
className: `lib-xplat-table-wrapper ${size}`,
|
|
67
|
-
"data-xplat-overlay-escape": "",
|
|
68
108
|
style: minWidth === void 0 ? void 0 : {
|
|
69
109
|
"--table-min-width": typeof minWidth === "number" ? `${minWidth}px` : minWidth
|
|
70
110
|
},
|
|
71
|
-
children:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
]
|
|
83
134
|
}
|
|
84
135
|
);
|
|
85
136
|
};
|
|
@@ -96,7 +147,7 @@ TableBody.displayName = "TableBody";
|
|
|
96
147
|
var TableBody_default = TableBody;
|
|
97
148
|
|
|
98
149
|
// src/components/Table/TableCell.tsx
|
|
99
|
-
var
|
|
150
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
100
151
|
|
|
101
152
|
// ../../node_modules/clsx/dist/clsx.mjs
|
|
102
153
|
function r(e) {
|
|
@@ -115,21 +166,21 @@ function clsx() {
|
|
|
115
166
|
var clsx_default = clsx;
|
|
116
167
|
|
|
117
168
|
// src/components/Table/TableHeadContext.tsx
|
|
118
|
-
var
|
|
119
|
-
var TableHeadContext =
|
|
169
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
170
|
+
var TableHeadContext = import_react3.default.createContext(
|
|
120
171
|
null
|
|
121
172
|
);
|
|
122
173
|
var useTableHeadContext = () => {
|
|
123
|
-
const ctx =
|
|
174
|
+
const ctx = import_react3.default.useContext(TableHeadContext);
|
|
124
175
|
return ctx;
|
|
125
176
|
};
|
|
126
177
|
var TableHeadContext_default = TableHeadContext;
|
|
127
178
|
|
|
128
179
|
// src/components/Table/TableRowContext.tsx
|
|
129
|
-
var
|
|
130
|
-
var TableRowContext =
|
|
180
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
181
|
+
var TableRowContext = import_react4.default.createContext(null);
|
|
131
182
|
var useTableRowContext = () => {
|
|
132
|
-
const ctx =
|
|
183
|
+
const ctx = import_react4.default.useContext(TableRowContext);
|
|
133
184
|
if (!ctx) throw new Error("Table components must be used inside <Table>");
|
|
134
185
|
return ctx;
|
|
135
186
|
};
|
|
@@ -137,7 +188,7 @@ var TableRowContext_default = TableRowContext;
|
|
|
137
188
|
|
|
138
189
|
// src/components/Table/TableCell.tsx
|
|
139
190
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
140
|
-
var TableCell =
|
|
191
|
+
var TableCell = import_react5.default.memo((props) => {
|
|
141
192
|
const {
|
|
142
193
|
children,
|
|
143
194
|
align = "center",
|
|
@@ -151,9 +202,9 @@ var TableCell = import_react4.default.memo((props) => {
|
|
|
151
202
|
const { registerStickyCell, stickyCells } = useTableRowContext();
|
|
152
203
|
const { stickyShadow } = useTableContext();
|
|
153
204
|
const headContext = useTableHeadContext();
|
|
154
|
-
const [left, setLeft] =
|
|
155
|
-
const cellRef =
|
|
156
|
-
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(() => {
|
|
157
208
|
if (!cellRef.current) return 0;
|
|
158
209
|
let totalLeft = 0;
|
|
159
210
|
for (const ref of stickyCells) {
|
|
@@ -162,7 +213,7 @@ var TableCell = import_react4.default.memo((props) => {
|
|
|
162
213
|
}
|
|
163
214
|
return totalLeft;
|
|
164
215
|
}, [stickyCells]);
|
|
165
|
-
|
|
216
|
+
import_react5.default.useEffect(() => {
|
|
166
217
|
if (!isSticky || !cellRef.current) return;
|
|
167
218
|
registerStickyCell(cellRef);
|
|
168
219
|
setLeft(calculateLeft());
|
|
@@ -220,9 +271,9 @@ TableHead.displayName = "TableHead";
|
|
|
220
271
|
var TableHead_default = TableHead;
|
|
221
272
|
|
|
222
273
|
// src/components/Table/TableRow.tsx
|
|
223
|
-
var
|
|
274
|
+
var import_react6 = __toESM(require("react"), 1);
|
|
224
275
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
225
|
-
var TableRow =
|
|
276
|
+
var TableRow = import_react6.default.memo((props) => {
|
|
226
277
|
const {
|
|
227
278
|
children,
|
|
228
279
|
type = "secondary",
|
|
@@ -231,7 +282,7 @@ var TableRow = import_react5.default.memo((props) => {
|
|
|
231
282
|
onClick
|
|
232
283
|
} = props;
|
|
233
284
|
const { rowBorderUse } = useTableContext();
|
|
234
|
-
const [stickyCells, setStickyCells] =
|
|
285
|
+
const [stickyCells, setStickyCells] = import_react6.default.useState([]);
|
|
235
286
|
const registerStickyCell = (ref) => {
|
|
236
287
|
setStickyCells((prev) => {
|
|
237
288
|
if (prev.includes(ref)) return prev;
|