@bouku/core 0.4.0 → 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/button/normal.js +2 -2
- package/dist/components/miscellaneous/checkbox/index.d.ts +1 -1
- package/dist/components/miscellaneous/checkbox/index.js +16 -10
- package/dist/components/miscellaneous/dropdown/normal.d.ts +2 -1
- package/dist/components/miscellaneous/dropdown/normal.js +5 -3
- 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
|
@@ -25,10 +25,10 @@ export function Button({ style, size = "md", variant = "surface", icon, action,
|
|
|
25
25
|
: icon, children] }));
|
|
26
26
|
}
|
|
27
27
|
const styles = tv({
|
|
28
|
-
base: "relative flex justify-center items-center border outline-none rounded font-semibold duration-200 cursor-pointer disabled:cursor-not-allowed hover:brightness-
|
|
28
|
+
base: "relative flex justify-center items-center border outline-none rounded font-semibold shadow duration-200 cursor-pointer disabled:cursor-not-allowed hover:brightness-125",
|
|
29
29
|
variants: {
|
|
30
30
|
size: {
|
|
31
|
-
xs: "gap-
|
|
31
|
+
xs: "gap-2 px-3 py-2 text-xs",
|
|
32
32
|
sm: "gap-2 px-3 py-2 text-xs sm:text-sm",
|
|
33
33
|
md: "gap-2 px-4 py-2 text-xs sm:text-sm",
|
|
34
34
|
lg: "gap-3 px-5 py-3 text-base sm:text-lg"
|
|
@@ -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;
|
|
@@ -2,7 +2,8 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
interface Props {
|
|
3
3
|
trigger: ReactNode;
|
|
4
4
|
align?: "left" | "right";
|
|
5
|
+
direction?: "up" | "down";
|
|
5
6
|
children: ReactNode;
|
|
6
7
|
}
|
|
7
|
-
export declare function Dropdown({ trigger, align, children }: Props): import("react").JSX.Element;
|
|
8
|
+
export declare function Dropdown({ trigger, align, direction, children }: Props): import("react").JSX.Element;
|
|
8
9
|
export default Dropdown;
|
|
@@ -4,7 +4,7 @@ import { useState, useRef, useEffect } from "react";
|
|
|
4
4
|
import { AnimatePresence, motion } from "framer-motion";
|
|
5
5
|
import { cn } from "../../../utils/functions/_.js";
|
|
6
6
|
;
|
|
7
|
-
export function Dropdown({ trigger, align = "left", children }) {
|
|
7
|
+
export function Dropdown({ trigger, align = "left", direction = "down", children }) {
|
|
8
8
|
const [isOpen, setOpen] = useState(false);
|
|
9
9
|
const ref = useRef(null);
|
|
10
10
|
useEffect(() => {
|
|
@@ -17,10 +17,12 @@ export function Dropdown({ trigger, align = "left", children }) {
|
|
|
17
17
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
18
18
|
};
|
|
19
19
|
}, []);
|
|
20
|
-
return (_jsxs("div", { ref: ref, className: styles.container, children: [_jsx("div", { onClick: () => setOpen(open => !open), children: trigger }), _jsx(AnimatePresence, { children: isOpen && (_jsx(motion.div, { className: cn(styles.dropdown, align === "left" ? "left-0" : "right-0"
|
|
20
|
+
return (_jsxs("div", { ref: ref, className: styles.container, children: [_jsx("div", { onClick: () => setOpen(open => !open), children: trigger }), _jsx(AnimatePresence, { children: isOpen && (_jsx(motion.div, { className: cn(styles.dropdown, align === "left" ? "left-0" : "right-0", direction === "down"
|
|
21
|
+
? "top-full mt-2"
|
|
22
|
+
: "bottom-full mb-2"), initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: children })) })] }));
|
|
21
23
|
}
|
|
22
24
|
const styles = {
|
|
23
25
|
container: "relative shrink-0",
|
|
24
|
-
dropdown: "absolute
|
|
26
|
+
dropdown: "absolute z-50 flex flex-col gap-2 min-w-full w-max bg-surface-darker rounded-md border border-border-darker p-2 text-sm shadow-md"
|
|
25
27
|
};
|
|
26
28
|
export default Dropdown;
|
|
@@ -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;
|