@bouku/core 0.1.9 → 0.2.1
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/_.d.ts +9 -0
- package/dist/components/button/_.js +10 -0
- package/dist/components/button/copy.d.ts +12 -5
- package/dist/components/button/copy.js +13 -4
- package/dist/components/button/normal.d.ts +20 -5
- package/dist/components/button/normal.js +21 -9
- package/dist/components/button/upload.d.ts +5 -6
- package/dist/components/button/upload.js +8 -9
- package/dist/components/card/_.d.ts +2 -0
- package/dist/components/card/_.js +10 -0
- package/dist/components/card/callout.d.ts +8 -0
- package/dist/components/card/callout.js +22 -0
- package/dist/components/card/media.d.ts +15 -0
- package/dist/components/card/media.js +10 -0
- package/dist/components/container/_.d.ts +5 -0
- package/dist/components/container/_.js +29 -0
- package/dist/components/container/absolute.d.ts +9 -0
- package/dist/components/container/absolute.js +12 -0
- package/dist/components/container/fade.d.ts +7 -0
- package/dist/components/container/fade.js +20 -0
- package/dist/components/container/flex.d.ts +17 -0
- package/dist/components/container/flex.js +49 -0
- package/dist/components/container/rnd.d.ts +10 -0
- package/dist/components/container/rnd.js +32 -0
- package/dist/components/container/scroll.d.ts +14 -0
- package/dist/components/container/scroll.js +11 -0
- package/dist/components/index.d.ts +6 -17
- package/dist/components/index.js +6 -29
- package/dist/components/layout/_.d.ts +2 -1
- package/dist/components/layout/_.js +5 -3
- package/dist/components/layout/footer.js +1 -1
- package/dist/components/layout/section.js +1 -1
- package/dist/components/list/search-bar.js +2 -2
- package/dist/components/miscellaneous/accordion/index.d.ts +9 -0
- package/dist/components/miscellaneous/accordion/index.js +22 -0
- package/dist/components/miscellaneous/accordion/tab.d.ts +4 -0
- package/dist/components/miscellaneous/accordion/tab.js +35 -0
- package/dist/components/miscellaneous/dropdown/index.d.ts +10 -0
- package/dist/components/miscellaneous/dropdown/index.js +22 -0
- package/dist/components/miscellaneous/glow/index.d.ts +10 -0
- package/dist/components/miscellaneous/glow/index.js +8 -0
- package/dist/components/miscellaneous/index.d.ts +6 -0
- package/dist/components/miscellaneous/index.js +18 -0
- package/dist/components/miscellaneous/pagination/index.d.ts +9 -0
- package/dist/components/miscellaneous/pagination/index.js +21 -0
- package/dist/components/miscellaneous/progress/index.d.ts +4 -0
- package/dist/components/miscellaneous/progress/index.js +12 -0
- package/dist/components/miscellaneous/table/header.d.ts +10 -0
- package/dist/components/miscellaneous/table/header.js +20 -0
- package/dist/components/miscellaneous/table/index.d.ts +15 -0
- package/dist/components/miscellaneous/table/index.js +37 -0
- package/dist/components/miscellaneous/table/row.d.ts +22 -0
- package/dist/components/miscellaneous/table/row.js +40 -0
- package/dist/components/miscellaneous/table/sorter.d.ts +10 -0
- package/dist/components/miscellaneous/table/sorter.js +53 -0
- package/dist/components/text/_.d.ts +1 -0
- package/dist/components/text/_.js +3 -1
- package/dist/components/text/heading.d.ts +24 -0
- package/dist/components/text/heading.js +26 -0
- package/dist/utils/hooks/clock.d.ts +4 -4
- package/dist/utils/hooks/clock.js +8 -5
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Footer = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const flex_1 = require("
|
|
5
|
+
const flex_1 = require("../container/flex");
|
|
6
6
|
const style_1 = require("../../utils/functions/style");
|
|
7
7
|
const Footer = ({ Left, Center, Right }) => ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: style, equal: true, children: [(0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: "justify-start items-center", children: Left }), (0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: "justify-center items-center", children: Center }), (0, jsx_runtime_1.jsx)("div", { className: "flex justify-end items-center", children: Right })] }));
|
|
8
8
|
exports.Footer = Footer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
const flex_1 = require("
|
|
4
|
+
const flex_1 = require("../container/flex");
|
|
5
5
|
const separator_1 = require("./separator");
|
|
6
6
|
const style_1 = require("../../utils/functions/style");
|
|
7
7
|
/**
|
|
@@ -9,8 +9,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const style_1 = require("../../utils/functions/style");
|
|
11
11
|
const input_1 = __importDefault(require("../text/input"));
|
|
12
|
-
const fade_1 = __importDefault(require("../
|
|
13
|
-
const flex_1 = require("../
|
|
12
|
+
const fade_1 = __importDefault(require("../container/fade"));
|
|
13
|
+
const flex_1 = require("../container/flex");
|
|
14
14
|
const normal_1 = __importDefault(require("../button/normal"));
|
|
15
15
|
function SearchBar({ style = {}, placeholder, trigger, submit, oops = console.log }) {
|
|
16
16
|
const [query, setQuery] = (0, react_1.useState)("");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = Accordion;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const flex_1 = require("../../container/flex");
|
|
8
|
+
const tab_1 = require("./tab");
|
|
9
|
+
function Accordion({ items }) {
|
|
10
|
+
const [activeItem, setActiveItem] = (0, react_1.useState)(0);
|
|
11
|
+
const handleClick = (index) => {
|
|
12
|
+
if (index === activeItem)
|
|
13
|
+
setActiveItem(null);
|
|
14
|
+
else
|
|
15
|
+
setActiveItem(index);
|
|
16
|
+
};
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)(flex_1.ColumnBox, { style: s.container, children: items.map(({ label, content }, i) => ((0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { children: [(0, jsx_runtime_1.jsx)("div", { onClick: () => handleClick(i), children: (0, jsx_runtime_1.jsx)(tab_1.ItemHeader, { isActive: i === activeItem, label: label }) }), i === activeItem && ((0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: s.item, children: content }))] }, i))) }));
|
|
18
|
+
}
|
|
19
|
+
const s = {
|
|
20
|
+
container: "gap-5 max-h-full overflow-y-auto scrollbar-none",
|
|
21
|
+
item: "justify-center items-center mt-5 w-full"
|
|
22
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ItemHeader = ItemHeader;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const chevron_up_svg_1 = __importDefault(require("../../../assets/icons/chevron-up.svg"));
|
|
10
|
+
const tailwind_variants_1 = require("tailwind-variants");
|
|
11
|
+
function ItemHeader({ isActive, label }) {
|
|
12
|
+
const s = getStyles({ isActive });
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: s.container(), children: [(0, jsx_runtime_1.jsx)("span", { className: s.label(), children: label }), (0, jsx_runtime_1.jsx)(chevron_up_svg_1.default, { className: s.chevron() })] }));
|
|
14
|
+
}
|
|
15
|
+
const getStyles = (0, tailwind_variants_1.tv)({
|
|
16
|
+
slots: {
|
|
17
|
+
container: "flex justify-between items-center gap-8 px-3 py-2 border rounded duration-200 cursor-pointer",
|
|
18
|
+
label: "font-bold",
|
|
19
|
+
chevron: "duration-200"
|
|
20
|
+
},
|
|
21
|
+
variants: {
|
|
22
|
+
isActive: {
|
|
23
|
+
true: {
|
|
24
|
+
container: "bg-surface-light border-border-light",
|
|
25
|
+
label: "text-primary",
|
|
26
|
+
chevron: "text-accent rotate-180"
|
|
27
|
+
},
|
|
28
|
+
false: {
|
|
29
|
+
container: "bg-surface hover:bg-surface-light border-border",
|
|
30
|
+
label: "text-primary-dark",
|
|
31
|
+
chevron: "text-primary-dark"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = Dropdown;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const framer_motion_1 = require("framer-motion");
|
|
8
|
+
function Dropdown({ options, children }) {
|
|
9
|
+
const [isOpen, setOpen] = (0, react_1.useState)(false);
|
|
10
|
+
const boom = (action) => {
|
|
11
|
+
action();
|
|
12
|
+
setOpen(false);
|
|
13
|
+
};
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: styles.container, children: [(0, jsx_runtime_1.jsx)("div", { onClick: () => setOpen(true), children: children }), (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: isOpen && ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { className: styles.dropdown, initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: options.map(({ label, action }, i) => ((0, jsx_runtime_1.jsx)("div", { className: "cursor-pointer duration-200 hover:brightness-115", onClick: () => boom(action), children: label }, i))) }, "dropdown")) })] }));
|
|
15
|
+
}
|
|
16
|
+
const styles = {
|
|
17
|
+
container: "relative shrink-0",
|
|
18
|
+
subcontainer: "flex flex-col gap-1 w-full",
|
|
19
|
+
label: "text-xs text-slate-600",
|
|
20
|
+
trigger: "flex justify-between items-center px-3 py-2 bg-slate-200/50 hover:bg-slate-200/80 border border-slate-300 outline-blue-500 rounded text-sm duration-200 cursor-pointer",
|
|
21
|
+
dropdown: "absolute mt-2 z-50 flex flex-col items-end justify-end gap-1 w-full bg-slate-950 rounded border border-border-dark p-3 pr-4 text-sm max-h-46 overflow-y-auto"
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Glow;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const style_1 = require("../../../utils/functions/style");
|
|
6
|
+
function Glow({ className, style }) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: (0, style_1.cn)("absolute size-24 bg-radial from-background", className), style: style }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Accordion } from "./accordion";
|
|
2
|
+
export { default as Table } from "./table";
|
|
3
|
+
export { default as Pagination } from "./pagination";
|
|
4
|
+
export { default as ProgressBar } from "./progress";
|
|
5
|
+
export { default as Glow } from "./glow";
|
|
6
|
+
export { default as Dropdown } from "./dropdown";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Dropdown = exports.Glow = exports.ProgressBar = exports.Pagination = exports.Table = exports.Accordion = void 0;
|
|
7
|
+
var accordion_1 = require("./accordion");
|
|
8
|
+
Object.defineProperty(exports, "Accordion", { enumerable: true, get: function () { return __importDefault(accordion_1).default; } });
|
|
9
|
+
var table_1 = require("./table");
|
|
10
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return __importDefault(table_1).default; } });
|
|
11
|
+
var pagination_1 = require("./pagination");
|
|
12
|
+
Object.defineProperty(exports, "Pagination", { enumerable: true, get: function () { return __importDefault(pagination_1).default; } });
|
|
13
|
+
var progress_1 = require("./progress");
|
|
14
|
+
Object.defineProperty(exports, "ProgressBar", { enumerable: true, get: function () { return __importDefault(progress_1).default; } });
|
|
15
|
+
var glow_1 = require("./glow");
|
|
16
|
+
Object.defineProperty(exports, "Glow", { enumerable: true, get: function () { return __importDefault(glow_1).default; } });
|
|
17
|
+
var dropdown_1 = require("./dropdown");
|
|
18
|
+
Object.defineProperty(exports, "Dropdown", { enumerable: true, get: function () { return __importDefault(dropdown_1).default; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = Pagination;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const chevron_left_svg_1 = __importDefault(require("../../../assets/icons/chevron-left.svg"));
|
|
9
|
+
const chevron_right_svg_1 = __importDefault(require("../../../assets/icons/chevron-right.svg"));
|
|
10
|
+
const flex_1 = require("../../container/flex");
|
|
11
|
+
const normal_1 = require("../../button/normal");
|
|
12
|
+
const style_1 = require("../../../utils/functions/style");
|
|
13
|
+
function Pagination({ style, page, prev, next, totalPages = 99 }) {
|
|
14
|
+
const canPrev = page > 1;
|
|
15
|
+
const canNext = totalPages > 0 ? page < totalPages : true;
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: (0, style_1.cn)(s.container, style), children: [(0, jsx_runtime_1.jsx)(normal_1.Button, { size: "xs", style: "rounded-none rounded-l-sm", action: prev, disabled: !canPrev, children: (0, jsx_runtime_1.jsx)(chevron_left_svg_1.default, {}) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex gap-px justify-center items-center w-11 h-6 px-2 bg-border-dark/20 border-y border-border-dark text-xs font-medium", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-primary", children: page }), "/", (0, jsx_runtime_1.jsx)("span", { className: "text-primary-darker", children: totalPages || 99 })] }), (0, jsx_runtime_1.jsx)(normal_1.Button, { size: "xs", style: "rounded-none rounded-r-sm", action: next, disabled: !canNext, children: (0, jsx_runtime_1.jsx)(chevron_right_svg_1.default, {}) })] }));
|
|
17
|
+
}
|
|
18
|
+
const s = {
|
|
19
|
+
container: "justify-center items-center text-primary-darker select-none",
|
|
20
|
+
subcontainer: "gap-2",
|
|
21
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ProgressBar;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
function ProgressBar({ value, style }) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)(s.container, style), children: (0, jsx_runtime_1.jsx)("div", { className: s.filled, style: { width: (value * 100) + "%" } }) }));
|
|
8
|
+
}
|
|
9
|
+
const s = {
|
|
10
|
+
container: "flex grow h-1 rounded-full bg-surface overflow-hidden",
|
|
11
|
+
filled: "h-full bg-accent"
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CellValue } from "./row";
|
|
2
|
+
type Props<T> = {
|
|
3
|
+
columnLabels: Record<string, string>;
|
|
4
|
+
sortColumn: keyof T | null;
|
|
5
|
+
sortDirection: "asc" | "desc";
|
|
6
|
+
sortBy: (x: string | null) => void;
|
|
7
|
+
toggleSortDirection: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const Header: <T extends Record<keyof T, CellValue>>({ columnLabels, sortColumn, sortDirection, sortBy, toggleSortDirection }: Props<T>) => import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Header = void 0;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const flex_1 = require("../../container/flex");
|
|
11
|
+
const arrow_up_svg_1 = __importDefault(require("../../../assets/icons/arrow-up.svg"));
|
|
12
|
+
const arrow_down_svg_1 = __importDefault(require("../../../assets/icons/arrow-down.svg"));
|
|
13
|
+
const Header = ({ columnLabels, sortColumn, sortDirection, sortBy, toggleSortDirection }) => ((0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: s.container, children: Object.entries(columnLabels).map(([col, label], i) => ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: s.column, children: [(0, jsx_runtime_1.jsx)("span", { className: s.label, onClick: () => sortBy(col), children: label }), col === sortColumn && ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [sortDirection === "desc" && (0, jsx_runtime_1.jsx)(arrow_down_svg_1.default, { className: s.sorter, onClick: () => toggleSortDirection() }), sortDirection === "asc" && (0, jsx_runtime_1.jsx)(arrow_up_svg_1.default, { className: s.sorter, onClick: () => toggleSortDirection() })] }))] }, i))) }));
|
|
14
|
+
exports.Header = Header;
|
|
15
|
+
const s = {
|
|
16
|
+
container: "w-full px-4 py-3 bg-background-light border-b border-border",
|
|
17
|
+
column: "flex-1 gap-1 first:justify-start justify-center last:justify-end items-center uppercase text-primary-dark font-light text-sm",
|
|
18
|
+
label: "hover:brightness-120 duration-200 cursor-pointer",
|
|
19
|
+
sorter: "hover:text-primary cursor-pointer duration-200"
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Row, type Action } from "./row";
|
|
2
|
+
type ColumnOptions = {
|
|
3
|
+
label?: string;
|
|
4
|
+
pad?: number;
|
|
5
|
+
link?: string;
|
|
6
|
+
};
|
|
7
|
+
type Props<T extends Row> = {
|
|
8
|
+
style?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
config: Partial<Record<keyof T, boolean | ColumnOptions>>;
|
|
11
|
+
items: T[];
|
|
12
|
+
actions?: Action<T>[];
|
|
13
|
+
};
|
|
14
|
+
export default function Table<T extends Row>({ style, title, config: initConfig, items, actions }: Props<T>): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = Table;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const sorter_1 = require("./sorter");
|
|
7
|
+
const ts_helper_kit_1 = require("ts-helper-kit");
|
|
8
|
+
const _1 = require("../../../utils/functions/_");
|
|
9
|
+
const flex_1 = require("../../container/flex");
|
|
10
|
+
const header_1 = require("./header");
|
|
11
|
+
const row_1 = require("./row");
|
|
12
|
+
function Table({ style, title, config: initConfig, items, actions }) {
|
|
13
|
+
const { sortedItems, ...sortOptions } = (0, sorter_1.useSort)(items);
|
|
14
|
+
const config = parseConfig(initConfig, !!actions?.length);
|
|
15
|
+
const columns = Object.keys(config);
|
|
16
|
+
const condensedItems = (0, ts_helper_kit_1.condenseArray)(sortedItems, columns);
|
|
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
|
+
}
|
|
19
|
+
function parseConfig(config, hasActions) {
|
|
20
|
+
const parsed = Object.entries(config).reduce((acc, [key, value]) => {
|
|
21
|
+
const label = String(key).replaceAll("_", " ");
|
|
22
|
+
const isObject = typeof value === "object" && value !== null;
|
|
23
|
+
acc[key] = isObject ? { label, ...value } : { label };
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
// Automatically append an actions column if actions exist
|
|
27
|
+
if (hasActions) {
|
|
28
|
+
parsed["actions"] = { label: "Actions" };
|
|
29
|
+
}
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
const s = {
|
|
33
|
+
container: "gap-3 overflow-hidden",
|
|
34
|
+
title: "text-xl font-bold text-primary",
|
|
35
|
+
subcontainer: "grow w-full border border-border rounded-md overflow-hidden",
|
|
36
|
+
rows: "grow overflow-y-auto no-scrollbar"
|
|
37
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const isDateLike: (val: string) => boolean;
|
|
2
|
+
type ColumnOptions = {
|
|
3
|
+
label: string;
|
|
4
|
+
pad?: number;
|
|
5
|
+
link?: string;
|
|
6
|
+
};
|
|
7
|
+
export type Action<T> = {
|
|
8
|
+
variant?: "accent" | "surface" | "error";
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
style?: string;
|
|
11
|
+
handler: (row: T) => void;
|
|
12
|
+
};
|
|
13
|
+
interface Props<T> {
|
|
14
|
+
config: Record<string, ColumnOptions>;
|
|
15
|
+
data: T;
|
|
16
|
+
count: number;
|
|
17
|
+
actions?: Action<T>[];
|
|
18
|
+
}
|
|
19
|
+
export type Row = Record<string, CellValue>;
|
|
20
|
+
export type CellValue = string | number | boolean | object | null;
|
|
21
|
+
export declare function TableRow<T extends Row>({ config, data, actions, count }: Props<T>): import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isDateLike = void 0;
|
|
7
|
+
exports.TableRow = TableRow;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const flex_1 = require("../../container/flex");
|
|
10
|
+
const _1 = require("../../button/_");
|
|
11
|
+
const check_circle_svg_1 = __importDefault(require("../../../assets/icons/check-circle.svg"));
|
|
12
|
+
const x_circle_svg_1 = __importDefault(require("../../../assets/icons/x-circle.svg"));
|
|
13
|
+
const ts_helper_kit_1 = require("ts-helper-kit");
|
|
14
|
+
const isDateLike = (val) => !isNaN(Date.parse(val)) && isNaN(Number(val));
|
|
15
|
+
exports.isDateLike = isDateLike;
|
|
16
|
+
function TableRow({ config, data, actions, count }) {
|
|
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
|
+
}
|
|
26
|
+
const rawValue = data[key];
|
|
27
|
+
const value = rawValue === 0 ? 0 : (data[key] ?? "N/A");
|
|
28
|
+
const options = config[key];
|
|
29
|
+
let cellValue = value;
|
|
30
|
+
if (options && options.pad)
|
|
31
|
+
cellValue = (0, ts_helper_kit_1.padNum)(cellValue, options.pad);
|
|
32
|
+
else if ((0, exports.isDateLike)(cellValue.toString()))
|
|
33
|
+
cellValue = new Date(cellValue.toString()).toLocaleDateString();
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: s.cell, children: [options && options?.link && (0, jsx_runtime_1.jsx)("a", { className: "text-primary underline duration-200 hover:text-accent", href: options.link?.replace("[x]", rawValue), children: cellValue }), options && !options?.link && ((0, jsx_runtime_1.jsx)("span", { className: "truncate", children: value === true ? (0, jsx_runtime_1.jsx)(check_circle_svg_1.default, { className: "text-success" }) : value === false ? (0, jsx_runtime_1.jsx)(x_circle_svg_1.default, { className: "text-error" }) : (typeof cellValue === "object" ? JSON.stringify(cellValue) : cellValue) }))] }, i));
|
|
35
|
+
}), count > 1 && ((0, jsx_runtime_1.jsx)("span", { className: "absolute top-0 left-0 pb-px px-1 bg-surface-light border-b border-r rounded-br border-border-light font-bold font-mono text-px text-accent", children: count }))] }));
|
|
36
|
+
}
|
|
37
|
+
const s = {
|
|
38
|
+
container: "relative w-full px-4 py-4 even:bg-surface border-b border-border last:border-b-0",
|
|
39
|
+
cell: "flex-1 first-of-type:justify-start justify-center last-of-type:justify-end items-center gap-2 font-mono overflow-hidden"
|
|
40
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CellValue } from "./row";
|
|
2
|
+
type SortDirection = "asc" | "desc";
|
|
3
|
+
export declare function useSort<T extends Record<string, CellValue>>(items: T[]): {
|
|
4
|
+
sortedItems: T[];
|
|
5
|
+
sortBy: (col: keyof T | null) => void;
|
|
6
|
+
toggleSortDirection: () => void;
|
|
7
|
+
sortColumn: keyof T | null;
|
|
8
|
+
sortDirection: SortDirection;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSort = useSort;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
function useSort(items) {
|
|
6
|
+
const [column, setColumn] = (0, react_1.useState)(null);
|
|
7
|
+
const [isDescending, setDescending] = (0, react_1.useState)(true);
|
|
8
|
+
const sortBy = (col) => {
|
|
9
|
+
if (col === column)
|
|
10
|
+
return setColumn(null);
|
|
11
|
+
setDescending(true);
|
|
12
|
+
setColumn(col);
|
|
13
|
+
};
|
|
14
|
+
const sortedItems = (0, react_1.useMemo)(() => {
|
|
15
|
+
if (!column)
|
|
16
|
+
return items;
|
|
17
|
+
return [...items].sort((a, b) => {
|
|
18
|
+
const valA = a[column];
|
|
19
|
+
const valB = b[column];
|
|
20
|
+
if (valA === undefined || valA === null)
|
|
21
|
+
return 1;
|
|
22
|
+
if (valB === undefined || valB === null)
|
|
23
|
+
return -1;
|
|
24
|
+
let comparison = 0;
|
|
25
|
+
// 2. Date detection & comparison
|
|
26
|
+
const isDateLike = (val) => val instanceof Date ||
|
|
27
|
+
(typeof val === "string" && !isNaN(Date.parse(val)) && isNaN(Number(val)));
|
|
28
|
+
if (isDateLike(valA) && isDateLike(valB)) {
|
|
29
|
+
const timeA = new Date(valA).getTime();
|
|
30
|
+
const timeB = new Date(valB).getTime();
|
|
31
|
+
// Swap this to timeB - timeA so the base comparison defaults to descending
|
|
32
|
+
comparison = timeA - timeB;
|
|
33
|
+
}
|
|
34
|
+
// 3. Number comparison
|
|
35
|
+
else if (typeof valA === "number" && typeof valB === "number")
|
|
36
|
+
comparison = valA - valB;
|
|
37
|
+
// 4. String / Fallback comparison (case-insensitive)
|
|
38
|
+
else {
|
|
39
|
+
const strA = String(valA).toLowerCase();
|
|
40
|
+
const strB = String(valB).toLowerCase();
|
|
41
|
+
comparison = strA.localeCompare(strB);
|
|
42
|
+
}
|
|
43
|
+
return isDescending ? -comparison : comparison;
|
|
44
|
+
});
|
|
45
|
+
}, [items, column, isDescending]);
|
|
46
|
+
return {
|
|
47
|
+
sortedItems,
|
|
48
|
+
sortBy,
|
|
49
|
+
toggleSortDirection: () => setDescending(p => !p),
|
|
50
|
+
sortColumn: column,
|
|
51
|
+
sortDirection: isDescending ? "desc" : "asc"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Input = exports.Badge = void 0;
|
|
6
|
+
exports.Input = exports.Heading = exports.Badge = void 0;
|
|
7
7
|
var badge_1 = require("./badge");
|
|
8
8
|
Object.defineProperty(exports, "Badge", { enumerable: true, get: function () { return __importDefault(badge_1).default; } });
|
|
9
|
+
var heading_1 = require("./heading");
|
|
10
|
+
Object.defineProperty(exports, "Heading", { enumerable: true, get: function () { return __importDefault(heading_1).default; } });
|
|
9
11
|
var input_1 = require("./input");
|
|
10
12
|
Object.defineProperty(exports, "Input", { enumerable: true, get: function () { return __importDefault(input_1).default; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
badge?: string;
|
|
4
|
+
image?: string;
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
subtitle?: ReactNode;
|
|
7
|
+
style?: Styles;
|
|
8
|
+
};
|
|
9
|
+
type Styles = {
|
|
10
|
+
container?: string;
|
|
11
|
+
badge?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
subtitle?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Text heading with badge, title, subtitle.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} badge - Little note above the title (optional).
|
|
19
|
+
* @param {ReactNode} title - Main title content.
|
|
20
|
+
* @param {ReactNode} subtitle - Subtitle content (optional).
|
|
21
|
+
* @param {Styles} style - Additional styles (optional).
|
|
22
|
+
**/
|
|
23
|
+
export default function Heading({ badge, image, title, subtitle, style }: Props): import("react").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Heading;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const style_1 = require("../../utils/functions/style");
|
|
6
|
+
const flex_1 = require("../container/flex");
|
|
7
|
+
const badge_1 = require("./badge");
|
|
8
|
+
/**
|
|
9
|
+
* Text heading with badge, title, subtitle.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} badge - Little note above the title (optional).
|
|
12
|
+
* @param {ReactNode} title - Main title content.
|
|
13
|
+
* @param {ReactNode} subtitle - Subtitle content (optional).
|
|
14
|
+
* @param {Styles} style - Additional styles (optional).
|
|
15
|
+
**/
|
|
16
|
+
function Heading({ badge, image, title, subtitle, style = {} }) {
|
|
17
|
+
const styles = (0, style_1.mergeStyles)(base, style);
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { style: styles.container, children: [(0, jsx_runtime_1.jsx)(badge_1.Badge, { style: styles.badge, children: badge }), image && (0, jsx_runtime_1.jsx)("img", { className: styles.logo, src: image, alt: "Logo" }), (0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: styles.title, children: title }), (0, jsx_runtime_1.jsx)(flex_1.RowBox, { style: styles.subtitle, children: subtitle })] }));
|
|
19
|
+
}
|
|
20
|
+
const base = {
|
|
21
|
+
container: "items-center",
|
|
22
|
+
badge: "mb-2",
|
|
23
|
+
logo: "mb-5 w-12",
|
|
24
|
+
title: "items-center gap-2 text-2xl sm:text-3xl 2xl:text-4xl font-bold text-primary",
|
|
25
|
+
subtitle: "items-center gap-2 max-sm:text-sm 2xl:text-lg text-center text-primary-light dark:text-primary-dark"
|
|
26
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface Options {
|
|
2
2
|
action: () => Promise<boolean | void>;
|
|
3
|
+
oops?: (x: string) => void;
|
|
3
4
|
duration: number;
|
|
4
5
|
deps: unknown[];
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export default function useInterval({ action, duration, deps, oops }: Props): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function useInterval({ action, oops, duration, deps }: Options): void;
|
|
8
8
|
export {};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.useInterval = useInterval;
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
;
|
|
7
|
+
function useInterval({ action, oops = console.error, duration, deps = [] }) {
|
|
8
|
+
const ref = (0, react_1.useRef)(async () => {
|
|
9
|
+
return false;
|
|
10
|
+
});
|
|
8
11
|
(0, react_1.useEffect)(() => {
|
|
9
12
|
ref.current = action;
|
|
10
13
|
}, [action]);
|
|
11
14
|
(0, react_1.useEffect)(() => {
|
|
12
|
-
if (deps.some(v => v ===
|
|
15
|
+
if (deps.some(v => v === null || v === undefined))
|
|
13
16
|
return;
|
|
14
17
|
const tick = async () => {
|
|
15
18
|
try {
|
|
@@ -21,8 +24,8 @@ function useInterval({ action, duration, deps = [], oops }) {
|
|
|
21
24
|
oops?.(err.message);
|
|
22
25
|
}
|
|
23
26
|
};
|
|
24
|
-
const id = setInterval(tick, duration);
|
|
25
27
|
tick();
|
|
28
|
+
const id = setInterval(tick, duration);
|
|
26
29
|
return () => clearInterval(id);
|
|
27
30
|
}, [duration, ...deps]);
|
|
28
31
|
}
|