@bouku/core 0.4.1 → 0.4.2
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/miscellaneous/checkbox/index.d.ts +1 -1
- package/dist/components/miscellaneous/checkbox/index.js +16 -10
- package/dist/components/table/state/sort.js +4 -12
- package/dist/components/table/utils/date.d.ts +1 -0
- package/dist/components/table/utils/date.js +3 -0
- package/package.json +1 -1
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { RowBox } from "
|
|
2
|
+
import { RowBox } from "@bouku/core";
|
|
3
3
|
import Check from "../../../assets/icons/check.svg";
|
|
4
|
-
import { cn } from "../../../utils/functions/
|
|
4
|
+
import { cn } from "../../../utils/functions/style.js";
|
|
5
5
|
import { tv } from "tailwind-variants";
|
|
6
6
|
export const CheckBox = ({ size, label, value: isChecked, update, disabled = false }) => {
|
|
7
|
-
const s =
|
|
7
|
+
const s = baseStyles({
|
|
8
8
|
size,
|
|
9
9
|
active: isChecked
|
|
10
10
|
});
|
|
11
11
|
return (_jsxs(RowBox, { style: s.container(), children: [_jsx("div", { className: cn(s.box(), disabled && "pointer-events-none"), onClick: () => !disabled ? update(!isChecked) : null, children: isChecked && _jsx(Check, { className: s.check() }) }), _jsx("span", { className: s.label(), children: label })] }));
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const baseStyles = 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-dark border rounded border-outline duration-200 cursor-pointer",
|
|
17
17
|
check: "text-background",
|
|
18
|
-
label: "text-primary
|
|
18
|
+
label: "text-primary"
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
size: "md"
|
|
19
22
|
},
|
|
20
23
|
variants: {
|
|
21
24
|
size: {
|
|
@@ -26,6 +29,12 @@ const getStyle = tv({
|
|
|
26
29
|
label: "text-xs"
|
|
27
30
|
},
|
|
28
31
|
md: {
|
|
32
|
+
container: "gap-3",
|
|
33
|
+
box: "size-5 min-w-5",
|
|
34
|
+
check: "size-3",
|
|
35
|
+
label: "text-sm"
|
|
36
|
+
},
|
|
37
|
+
lg: {
|
|
29
38
|
container: "gap-3",
|
|
30
39
|
box: "size-5 min-w-5",
|
|
31
40
|
check: "size-3",
|
|
@@ -34,12 +43,9 @@ const getStyle = tv({
|
|
|
34
43
|
},
|
|
35
44
|
active: {
|
|
36
45
|
true: {
|
|
37
|
-
box: "bg-accent"
|
|
46
|
+
box: "!bg-accent border-accent-darker"
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
|
-
},
|
|
41
|
-
defaultVariants: {
|
|
42
|
-
size: "md"
|
|
43
49
|
}
|
|
44
50
|
});
|
|
45
51
|
export default CheckBox;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
|
-
import { parseDate } from "../utils/date.js";
|
|
2
|
+
import { parseDate, isDateLike } from "../utils/date.js";
|
|
3
3
|
export function useSort(items, initialSort) {
|
|
4
4
|
const [column, setColumn] = useState(initialSort ?? null);
|
|
5
5
|
const [isDescending, setDescending] = useState(true);
|
|
@@ -20,20 +20,16 @@ export function useSort(items, initialSort) {
|
|
|
20
20
|
if (valB === undefined || valB === null)
|
|
21
21
|
return -1;
|
|
22
22
|
let comparison;
|
|
23
|
-
if (isDateLike(valA) && isDateLike(valB))
|
|
23
|
+
if (isDateLike(valA) && isDateLike(valB))
|
|
24
24
|
comparison =
|
|
25
25
|
parseDate(valA).getTime() -
|
|
26
26
|
parseDate(valB).getTime();
|
|
27
|
-
|
|
28
|
-
else if (typeof valA === "number" &&
|
|
29
|
-
typeof valB === "number") {
|
|
27
|
+
else if (typeof valA === "number" && typeof valB === "number")
|
|
30
28
|
comparison = valA - valB;
|
|
31
|
-
|
|
32
|
-
else {
|
|
29
|
+
else
|
|
33
30
|
comparison = String(valA)
|
|
34
31
|
.toLowerCase()
|
|
35
32
|
.localeCompare(String(valB).toLowerCase());
|
|
36
|
-
}
|
|
37
33
|
return isDescending ? -comparison : comparison;
|
|
38
34
|
});
|
|
39
35
|
}, [items, column, isDescending]);
|
|
@@ -45,7 +41,3 @@ export function useSort(items, initialSort) {
|
|
|
45
41
|
toggleSortDirection: () => setDescending(prev => !prev)
|
|
46
42
|
};
|
|
47
43
|
}
|
|
48
|
-
const isDateLike = (value) => value instanceof Date ||
|
|
49
|
-
(typeof value === "string" &&
|
|
50
|
-
!Number.isNaN(Date.parse(value)) &&
|
|
51
|
-
Number.isNaN(Number(value)));
|
|
@@ -3,3 +3,4 @@ export declare const parseDate: (value: CellValue) => Date;
|
|
|
3
3
|
export declare const formatDateInput: (value: CellValue) => string;
|
|
4
4
|
export declare const getDateRange: <T extends TableRow>(items: T[], column?: keyof T) => DateRange;
|
|
5
5
|
export declare const formatDateLabel: (value: string) => string;
|
|
6
|
+
export declare const isDateLike: (value: CellValue) => boolean;
|