@bouku/core 0.1.5 → 0.1.7
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/button/upload.d.ts +3 -2
- package/dist/components/button/upload.js +2 -2
- package/dist/components/table/header.js +1 -0
- package/dist/components/table/index.d.ts +3 -2
- package/dist/components/table/index.js +12 -7
- package/dist/components/table/row.d.ts +8 -1
- package/dist/components/table/row.js +11 -2
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
type FileType = "csv";
|
|
1
|
+
type FileType = "csv" | "pdf";
|
|
2
2
|
type Props<T> = {
|
|
3
3
|
type?: FileType | FileType[];
|
|
4
|
+
variant?: "accent" | "surface";
|
|
4
5
|
url: string;
|
|
5
6
|
next?: (data: T) => void;
|
|
6
7
|
oops?: (err: string) => void;
|
|
7
8
|
};
|
|
8
|
-
export default function FileUploader<T>({ type, url, next, oops }: Props<T>): import("react").JSX.Element;
|
|
9
|
+
export default function FileUploader<T>({ type, variant, url, next, oops }: Props<T>): import("react").JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -10,7 +10,7 @@ const react_1 = require("react");
|
|
|
10
10
|
const upload_svg_1 = __importDefault(require("../../assets/icons/upload.svg"));
|
|
11
11
|
const core_1 = require("@bouku/core");
|
|
12
12
|
const snatch_http_1 = require("snatch-http");
|
|
13
|
-
function FileUploader({ type, url, next, oops }) {
|
|
13
|
+
function FileUploader({ type, variant = "accent", url, next, oops }) {
|
|
14
14
|
const inputRef = (0, react_1.useRef)(null);
|
|
15
15
|
const clickButton = () => inputRef.current?.click();
|
|
16
16
|
const [isLoading, setLoading] = (0, react_1.useState)(false);
|
|
@@ -38,5 +38,5 @@ function FileUploader({ type, url, next, oops }) {
|
|
|
38
38
|
if (event.target)
|
|
39
39
|
event.target.value = "";
|
|
40
40
|
};
|
|
41
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(core_1.Button, { variant:
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(core_1.Button, { variant: variant, action: clickButton, disabled: isLoading, children: [(0, jsx_runtime_1.jsx)(upload_svg_1.default, {}), "Upload ", typesArray?.length === 1 ? typesArray[0].toUpperCase() : "File"] }), (0, jsx_runtime_1.jsx)("input", { ref: inputRef, type: "file", className: "hidden", accept: acceptAttribute, onChange: handleUpload })] }));
|
|
42
42
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Row } from "./row";
|
|
1
|
+
import { type Row, type Action } from "./row";
|
|
2
2
|
type ColumnOptions = {
|
|
3
3
|
label?: string;
|
|
4
4
|
pad?: number;
|
|
@@ -9,6 +9,7 @@ type Props<T extends Row> = {
|
|
|
9
9
|
title?: string;
|
|
10
10
|
config: Partial<Record<keyof T, boolean | ColumnOptions>>;
|
|
11
11
|
items: T[];
|
|
12
|
+
actions?: Action<T>[];
|
|
12
13
|
};
|
|
13
|
-
export default function Table<T extends Row>({ style, title, config: initConfig, items }: Props<T>): import("react").JSX.Element;
|
|
14
|
+
export default function Table<T extends Row>({ style, title, config: initConfig, items, actions }: Props<T>): import("react").JSX.Element;
|
|
14
15
|
export {};
|
|
@@ -4,25 +4,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.default = Table;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const sorter_1 = require("./sorter");
|
|
7
|
+
const ts_helper_kit_1 = require("ts-helper-kit");
|
|
8
|
+
const _1 = require("../../utils/functions/_");
|
|
7
9
|
const flex_1 = require("../layout/flex");
|
|
8
10
|
const header_1 = require("./header");
|
|
9
11
|
const row_1 = require("./row");
|
|
10
|
-
|
|
11
|
-
const style_1 = require("../../utils/functions/style");
|
|
12
|
-
function Table({ style, title, config: initConfig, items }) {
|
|
12
|
+
function Table({ style, title, config: initConfig, items, actions }) {
|
|
13
13
|
const { sortedItems, ...sortOptions } = (0, sorter_1.useSort)(items);
|
|
14
|
-
const config = parseConfig(initConfig);
|
|
14
|
+
const config = parseConfig(initConfig, !!actions?.length);
|
|
15
15
|
const columns = Object.keys(config);
|
|
16
16
|
const condensedItems = (0, ts_helper_kit_1.condenseArray)(sortedItems, columns);
|
|
17
|
-
return ((0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { style: (0,
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { style: (0, _1.cn)(s.container, style), children: [title && ((0, jsx_runtime_1.jsx)("span", { className: s.title, children: title })), (0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { style: s.subcontainer, children: [(0, jsx_runtime_1.jsx)(header_1.Header, { ...sortOptions, columnLabels: Object.fromEntries(columns.map(c => [c, config[c].label])) }), (0, jsx_runtime_1.jsx)(flex_1.ColumnBox, { style: s.rows, children: condensedItems.map(({ item, count }, i) => ((0, jsx_runtime_1.jsx)(row_1.TableRow, { config: config, data: item, count: count, actions: actions }, i))) })] })] }));
|
|
18
18
|
}
|
|
19
|
-
function parseConfig(config) {
|
|
20
|
-
|
|
19
|
+
function parseConfig(config, hasActions) {
|
|
20
|
+
const parsed = Object.entries(config).reduce((acc, [key, value]) => {
|
|
21
21
|
const label = String(key).replaceAll("_", " ");
|
|
22
22
|
const isObject = typeof value === "object" && value !== null;
|
|
23
23
|
acc[key] = isObject ? { label, ...value } : { label };
|
|
24
24
|
return acc;
|
|
25
25
|
}, {});
|
|
26
|
+
// Automatically append an actions column if actions exist
|
|
27
|
+
if (hasActions) {
|
|
28
|
+
parsed["actions"] = { label: "Actions" };
|
|
29
|
+
}
|
|
30
|
+
return parsed;
|
|
26
31
|
}
|
|
27
32
|
const s = {
|
|
28
33
|
container: "gap-3 overflow-hidden",
|
|
@@ -4,12 +4,19 @@ type ColumnOptions = {
|
|
|
4
4
|
pad?: number;
|
|
5
5
|
link?: string;
|
|
6
6
|
};
|
|
7
|
+
export type Action<T> = {
|
|
8
|
+
variant?: "accent" | "surface" | "error";
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
style?: string;
|
|
11
|
+
handler: (row: T) => void;
|
|
12
|
+
};
|
|
7
13
|
interface Props<T> {
|
|
8
14
|
config: Record<string, ColumnOptions>;
|
|
9
15
|
data: T;
|
|
10
16
|
count: number;
|
|
17
|
+
actions?: Action<T>[];
|
|
11
18
|
}
|
|
12
19
|
export type Row = Record<string, CellValue>;
|
|
13
20
|
export type CellValue = string | number | boolean | object | null;
|
|
14
|
-
export declare function TableRow<T extends Row>({ config, data, count }: Props<T>): import("react").JSX.Element;
|
|
21
|
+
export declare function TableRow<T extends Row>({ config, data, actions, count }: Props<T>): import("react").JSX.Element;
|
|
15
22
|
export {};
|
|
@@ -7,13 +7,22 @@ exports.isDateLike = void 0;
|
|
|
7
7
|
exports.TableRow = TableRow;
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const flex_1 = require("../layout/flex");
|
|
10
|
-
const
|
|
10
|
+
const _1 = require("../button/_");
|
|
11
11
|
const check_circle_svg_1 = __importDefault(require("../../assets/icons/check-circle.svg"));
|
|
12
12
|
const x_circle_svg_1 = __importDefault(require("../../assets/icons/x-circle.svg"));
|
|
13
|
+
const ts_helper_kit_1 = require("ts-helper-kit");
|
|
13
14
|
const isDateLike = (val) => !isNaN(Date.parse(val)) && isNaN(Number(val));
|
|
14
15
|
exports.isDateLike = isDateLike;
|
|
15
|
-
function TableRow({ config, data, count }) {
|
|
16
|
+
function TableRow({ config, data, actions, count }) {
|
|
16
17
|
return ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: s.container, children: [Object.keys(config).map((key, i) => {
|
|
18
|
+
if (key === "actions" && actions) {
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: s.cell, children: (0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: "gap-2 items-center", children: actions.map((action, actionIdx) => {
|
|
20
|
+
const variantStyles = action.variant === "error" ? "bg-error/10 text-error hover:bg-error/20" :
|
|
21
|
+
action.variant === "accent" ? "bg-accent/10 text-accent hover:bg-accent/20" :
|
|
22
|
+
"bg-surface-light text-primary hover:bg-surface-light/80";
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(_1.Button, { size: "xs", variant: "surface", style: action.style, icon: action.icon, action: () => action.handler(data) }, actionIdx));
|
|
24
|
+
}) }) }, i));
|
|
25
|
+
}
|
|
17
26
|
const rawValue = data[key];
|
|
18
27
|
const value = rawValue === 0 ? 0 : (data[key] ?? "N/A");
|
|
19
28
|
const options = config[key];
|