@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.
@@ -1,5 +1,5 @@
1
1
  interface Props {
2
- size?: "sm" | "md";
2
+ size?: "sm" | "md" | "lg";
3
3
  label: string;
4
4
  value: boolean;
5
5
  update: (x: boolean) => void;
@@ -1,21 +1,24 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { RowBox } from "../../container/flex.js";
2
+ import { RowBox } from "@bouku/core";
3
3
  import Check from "../../../assets/icons/check.svg";
4
- import { cn } from "../../../utils/functions/_.js";
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 = getStyle({
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 getStyle = tv({
13
+ const baseStyles = tv({
14
14
  slots: {
15
15
  container: "items-center",
16
- box: "flex justify-center items-center hover:bg-accent border rounded border-outline duration-200 cursor-pointer",
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-dark"
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;
@@ -41,3 +41,6 @@ export const formatDateLabel = (value) => {
41
41
  year: "numeric"
42
42
  });
43
43
  };
44
+ export const isDateLike = (value) => value instanceof Date || (typeof value === "string" &&
45
+ !Number.isNaN(Date.parse(value)) &&
46
+ Number.isNaN(Number(value)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bouku/core",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",