@bouku/core 0.4.4 → 0.4.6
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.
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
1
2
|
type FileType = "csv" | "pdf" | "xlsx";
|
|
2
3
|
type Props = {
|
|
3
4
|
size?: "xs" | "sm" | "md" | "lg";
|
|
4
5
|
variant?: "surface" | "accent" | "outline" | "ghost" | "error";
|
|
5
|
-
icon?:
|
|
6
|
+
icon?: ReactNode;
|
|
6
7
|
accept?: FileType | FileType[];
|
|
7
8
|
action: (file: File) => Promise<void>;
|
|
8
9
|
disabled?: boolean;
|
|
10
|
+
children?: ReactNode;
|
|
9
11
|
};
|
|
10
|
-
export default function FileUploader({ accept, action, disabled, ...props }: Props): import("react").JSX.Element;
|
|
12
|
+
export default function FileUploader({ accept, action, disabled, children, ...props }: Props): import("react").JSX.Element;
|
|
11
13
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useRef, useState, Fragment } from "react";
|
|
4
4
|
import Button from "./normal.js";
|
|
5
5
|
import UploadIcon from "../../assets/icons/upload.svg";
|
|
6
|
-
export default function FileUploader({ accept, action, disabled, ...props }) {
|
|
6
|
+
export default function FileUploader({ accept, action, disabled, children, ...props }) {
|
|
7
7
|
const ref = useRef(null);
|
|
8
8
|
const [isLoading, setLoading] = useState(false);
|
|
9
9
|
const fileTypes = accept ? (Array.isArray(accept) ? accept : [accept]) : undefined;
|
|
@@ -25,5 +25,5 @@ export default function FileUploader({ accept, action, disabled, ...props }) {
|
|
|
25
25
|
if (event.target)
|
|
26
26
|
event.target.value = "";
|
|
27
27
|
};
|
|
28
|
-
return (_jsxs(Fragment, { children: [
|
|
28
|
+
return (_jsxs(Fragment, { children: [_jsx(Button, { ...props, icon: _jsx(UploadIcon, {}), action: () => ref.current?.click(), disabled: disabled || isLoading, children: children ? children : (_jsxs(_Fragment, { children: ["Upload ", " ", fileTypes?.length === 1 ? fileTypes[0].toUpperCase() : "File"] })) }), _jsx("input", { type: "file", className: "hidden", accept: acceptAttribute, onChange: handleUpload, ref: ref })] }));
|
|
29
29
|
}
|
|
@@ -13,7 +13,7 @@ export function CheckBox({ size, label, value: isChecked, update, disabled = fal
|
|
|
13
13
|
const getStyle = tv({
|
|
14
14
|
slots: {
|
|
15
15
|
container: "items-center",
|
|
16
|
-
box: "flex justify-center items-center hover:bg-
|
|
16
|
+
box: "flex justify-center items-center bg-input hover:bg-input-light border rounded border-outline duration-200 cursor-pointer",
|
|
17
17
|
check: "text-background",
|
|
18
18
|
label: "text-primary-dark"
|
|
19
19
|
},
|
|
@@ -34,7 +34,7 @@ const getStyle = tv({
|
|
|
34
34
|
},
|
|
35
35
|
active: {
|
|
36
36
|
true: {
|
|
37
|
-
box: "bg-accent"
|
|
37
|
+
box: "bg-accent!"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
},
|
|
@@ -4,6 +4,7 @@ import { CheckBox } from "../miscellaneous/checkbox/index.js";
|
|
|
4
4
|
import { Actions } from "./actions.js";
|
|
5
5
|
import CheckCircle from "../../assets/icons/check-circle.svg";
|
|
6
6
|
import XCircle from "../../assets/icons/x-circle.svg";
|
|
7
|
+
import { parseDate } from "./utils/date.js";
|
|
7
8
|
export const isDateLike = (val) => !isNaN(Date.parse(val)) && isNaN(Number(val));
|
|
8
9
|
export const TableRow = ({ columns, data, actions, count, selected, toggleSelected }) => (_jsxs(RowBox, { style: s.container, children: [toggleSelected && (_jsx(RowBox, { style: s.selection, children: _jsx(CheckBox, { size: "sm", value: selected ?? false, update: toggleSelected }) })), columns.map(({ key, format }, i) => {
|
|
9
10
|
const rawValue = data[key];
|
|
@@ -11,10 +12,8 @@ export const TableRow = ({ columns, data, actions, count, selected, toggleSelect
|
|
|
11
12
|
? 0
|
|
12
13
|
: (data[key] ?? "-");
|
|
13
14
|
let cellValue = value;
|
|
14
|
-
if (format === "date" &&
|
|
15
|
-
|
|
16
|
-
cellValue = new Date(cellValue.toString()).toLocaleDateString();
|
|
17
|
-
}
|
|
15
|
+
if (format === "date" && isDateLike(value.toString()))
|
|
16
|
+
cellValue = parseDate(value).toLocaleDateString();
|
|
18
17
|
return (_jsx(RowBox, { style: cn(s.cell, i === 0 && "justify-start"), children: _jsx("span", { className: "truncate", children: value === true
|
|
19
18
|
? _jsx(CheckCircle, { className: "text-success" })
|
|
20
19
|
: value === false
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { parseDate } from "./date.js";
|
|
1
2
|
export function formatCellValue(value, format) {
|
|
2
3
|
if (value == null) {
|
|
3
4
|
return "";
|
|
4
5
|
}
|
|
5
6
|
if (format === "date") {
|
|
6
|
-
return
|
|
7
|
+
return parseDate(String(value)).toLocaleDateString();
|
|
7
8
|
}
|
|
8
9
|
return String(value);
|
|
9
10
|
}
|