@x-plat/design-system 0.17.0 → 0.19.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/Chart/index.cjs +5 -4
- package/dist/components/Chart/index.d.cts +9 -0
- package/dist/components/Chart/index.d.ts +9 -0
- package/dist/components/Chart/index.js +5 -4
- 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 +164 -112
- package/dist/components/index.css +172 -145
- package/dist/components/index.js +198 -146
- package/dist/index.cjs +169 -117
- package/dist/index.css +172 -145
- package/dist/index.js +208 -156
- package/guidelines/components/chart.md +52 -10
- package/package.json +1 -1
|
@@ -643,9 +643,9 @@ var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, childr
|
|
|
643
643
|
}
|
|
644
644
|
);
|
|
645
645
|
};
|
|
646
|
-
var ChartLegend = ({ data, labels,
|
|
646
|
+
var ChartLegend = ({ data, labels, shape }) => {
|
|
647
647
|
const entries = Object.entries(data);
|
|
648
|
-
if (
|
|
648
|
+
if (shape === "pie" || shape === "doughnut") {
|
|
649
649
|
const values = entries.flatMap(([, v]) => v);
|
|
650
650
|
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
651
651
|
const firstKey = entries[0]?.[0] ?? "";
|
|
@@ -682,8 +682,9 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
682
682
|
}) });
|
|
683
683
|
};
|
|
684
684
|
var Chart = import_react.default.memo((props) => {
|
|
685
|
-
const { variant, type, data, labels, tooltip: showTooltip = true, tooltipType = "light" } = props;
|
|
685
|
+
const { variant, type, data, labels, legend, tooltip: showTooltip = true, tooltipType = "light" } = props;
|
|
686
686
|
const shape = variant ?? type ?? "line";
|
|
687
|
+
const showLegend = legend ?? (shape === "pie" || shape === "doughnut");
|
|
687
688
|
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
688
689
|
const { width, height } = useChartSize(containerRef);
|
|
689
690
|
const stableData = import_react.default.useMemo(() => data, [JSON.stringify(data)]);
|
|
@@ -697,7 +698,7 @@ var Chart = import_react.default.memo((props) => {
|
|
|
697
698
|
ready && shape === "bar" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
698
699
|
ready && shape === "pie" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
699
700
|
ready && shape === "doughnut" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
|
|
700
|
-
ready &&
|
|
701
|
+
ready && showLegend && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartLegend, { data: stableData, labels: stableLabels, shape }),
|
|
701
702
|
tooltip.visible && tooltip.content && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
|
|
702
703
|
] });
|
|
703
704
|
});
|
|
@@ -13,6 +13,15 @@ interface ChartProps {
|
|
|
13
13
|
data: Record<string, number[]>;
|
|
14
14
|
/** x축 라벨. data 의 값 배열과 길이가 같아야 한다 */
|
|
15
15
|
labels: string[];
|
|
16
|
+
/**
|
|
17
|
+
* 계열 이름·색·합계를 차트 아래에 적는다.
|
|
18
|
+
*
|
|
19
|
+
* 안 주면 **원형·도넛만 켜진다** — 조각에는 제 이름을 적을 데가 없어서다.
|
|
20
|
+
* 선·곡선·막대는 축 라벨이 있어 지금까지 범례 없이 지냈고, 켜면 차트가
|
|
21
|
+
* 범례 높이만큼 길어지므로 기본값을 바꾸지 않는다. 필요한 곳에서 `legend`
|
|
22
|
+
* 를 주면 된다.
|
|
23
|
+
*/
|
|
24
|
+
legend?: boolean;
|
|
16
25
|
/** 마우스를 올렸을 때 값 말풍선을 띄운다 */
|
|
17
26
|
tooltip?: boolean;
|
|
18
27
|
/** 말풍선 배색 */
|
|
@@ -13,6 +13,15 @@ interface ChartProps {
|
|
|
13
13
|
data: Record<string, number[]>;
|
|
14
14
|
/** x축 라벨. data 의 값 배열과 길이가 같아야 한다 */
|
|
15
15
|
labels: string[];
|
|
16
|
+
/**
|
|
17
|
+
* 계열 이름·색·합계를 차트 아래에 적는다.
|
|
18
|
+
*
|
|
19
|
+
* 안 주면 **원형·도넛만 켜진다** — 조각에는 제 이름을 적을 데가 없어서다.
|
|
20
|
+
* 선·곡선·막대는 축 라벨이 있어 지금까지 범례 없이 지냈고, 켜면 차트가
|
|
21
|
+
* 범례 높이만큼 길어지므로 기본값을 바꾸지 않는다. 필요한 곳에서 `legend`
|
|
22
|
+
* 를 주면 된다.
|
|
23
|
+
*/
|
|
24
|
+
legend?: boolean;
|
|
16
25
|
/** 마우스를 올렸을 때 값 말풍선을 띄운다 */
|
|
17
26
|
tooltip?: boolean;
|
|
18
27
|
/** 말풍선 배색 */
|
|
@@ -607,9 +607,9 @@ var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, childr
|
|
|
607
607
|
}
|
|
608
608
|
);
|
|
609
609
|
};
|
|
610
|
-
var ChartLegend = ({ data, labels,
|
|
610
|
+
var ChartLegend = ({ data, labels, shape }) => {
|
|
611
611
|
const entries = Object.entries(data);
|
|
612
|
-
if (
|
|
612
|
+
if (shape === "pie" || shape === "doughnut") {
|
|
613
613
|
const values = entries.flatMap(([, v]) => v);
|
|
614
614
|
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
615
615
|
const firstKey = entries[0]?.[0] ?? "";
|
|
@@ -646,8 +646,9 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
646
646
|
}) });
|
|
647
647
|
};
|
|
648
648
|
var Chart = React.memo((props) => {
|
|
649
|
-
const { variant, type, data, labels, tooltip: showTooltip = true, tooltipType = "light" } = props;
|
|
649
|
+
const { variant, type, data, labels, legend, tooltip: showTooltip = true, tooltipType = "light" } = props;
|
|
650
650
|
const shape = variant ?? type ?? "line";
|
|
651
|
+
const showLegend = legend ?? (shape === "pie" || shape === "doughnut");
|
|
651
652
|
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
652
653
|
const { width, height } = useChartSize(containerRef);
|
|
653
654
|
const stableData = React.useMemo(() => data, [JSON.stringify(data)]);
|
|
@@ -661,7 +662,7 @@ var Chart = React.memo((props) => {
|
|
|
661
662
|
ready && shape === "bar" && /* @__PURE__ */ jsx(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
662
663
|
ready && shape === "pie" && /* @__PURE__ */ jsx(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
663
664
|
ready && shape === "doughnut" && /* @__PURE__ */ jsx(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
|
|
664
|
-
ready &&
|
|
665
|
+
ready && showLegend && /* @__PURE__ */ jsx(ChartLegend, { data: stableData, labels: stableLabels, shape }),
|
|
665
666
|
tooltip.visible && tooltip.content && /* @__PURE__ */ jsx(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
|
|
666
667
|
] });
|
|
667
668
|
});
|
|
@@ -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;
|