@bouku/core 0.2.3 → 0.2.5
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/card/media.js +1 -1
- package/dist/components/container/_.d.ts +1 -1
- package/dist/components/container/_.js +2 -2
- package/dist/components/text/badge.d.ts +2 -2
- package/dist/components/text/badge.js +5 -7
- package/dist/utils/functions/style.js +8 -1
- package/dist/utils/hooks/state.d.ts +6 -1
- package/dist/utils/hooks/state.js +35 -6
- package/dist/utils/types/element.d.ts +4 -0
- package/package.json +1 -1
|
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
7
|
const flex_1 = require("../container/flex");
|
|
8
8
|
const badge_1 = __importDefault(require("../text/badge"));
|
|
9
|
-
const MediaCard = ({ media, title, subtitle, badge, styles = {}, }) => ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: `items-center gap-3 ${styles.container ?? ""}`, children: [(0, jsx_runtime_1.jsx)("img", { src: media, className: "size-10 w-10 h-10 border border-border rounded", alt: title }), (0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { style: "gap-px min-w-0", children: [(0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: "items-center gap-2 min-w-0", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-primary text-sm font-semibold truncate ${styles.title ?? ""}`, children: title }), badge && (0, jsx_runtime_1.jsx)(badge_1.default, { size: "
|
|
9
|
+
const MediaCard = ({ media, title, subtitle, badge, styles = {}, }) => ((0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: `items-center gap-3 ${styles.container ?? ""}`, children: [(0, jsx_runtime_1.jsx)("img", { src: media, className: "size-10 w-10 h-10 border border-border rounded", alt: title }), (0, jsx_runtime_1.jsxs)(flex_1.ColumnBox, { style: "gap-px min-w-0", children: [(0, jsx_runtime_1.jsxs)(flex_1.RowBox, { style: "items-center gap-2 min-w-0", children: [(0, jsx_runtime_1.jsx)("span", { className: `text-primary text-sm font-semibold truncate ${styles.title ?? ""}`, children: title }), badge && (0, jsx_runtime_1.jsx)(badge_1.default, { size: "sm", children: badge })] }), subtitle && ((0, jsx_runtime_1.jsx)("span", { className: `text-xs text-primary-dark ${styles.subtitle}`, children: subtitle }))] })] }));
|
|
10
10
|
exports.default = MediaCard;
|
|
@@ -17,13 +17,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.ScrollBox = exports.
|
|
20
|
+
exports.ScrollBox = exports.RnD = exports.FadeBox = exports.AbsoluteBox = void 0;
|
|
21
21
|
var absolute_1 = require("./absolute");
|
|
22
22
|
Object.defineProperty(exports, "AbsoluteBox", { enumerable: true, get: function () { return __importDefault(absolute_1).default; } });
|
|
23
23
|
var fade_1 = require("./fade");
|
|
24
24
|
Object.defineProperty(exports, "FadeBox", { enumerable: true, get: function () { return __importDefault(fade_1).default; } });
|
|
25
25
|
var rnd_1 = require("./rnd");
|
|
26
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "RnD", { enumerable: true, get: function () { return __importDefault(rnd_1).default; } });
|
|
27
27
|
var scroll_1 = require("./scroll");
|
|
28
28
|
Object.defineProperty(exports, "ScrollBox", { enumerable: true, get: function () { return __importDefault(scroll_1).default; } });
|
|
29
29
|
__exportStar(require("./flex"), exports);
|
|
@@ -2,7 +2,7 @@ import type { Component } from "../../utils";
|
|
|
2
2
|
type Props = Component & {
|
|
3
3
|
color?: string;
|
|
4
4
|
icon?: React.ReactNode;
|
|
5
|
-
size?: "
|
|
5
|
+
size?: "sm" | "md" | "lg";
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Color-themed badge component.
|
|
@@ -14,5 +14,5 @@ type Props = Component & {
|
|
|
14
14
|
*
|
|
15
15
|
* @param {string} color - Color of badge. (optional, default = accent)
|
|
16
16
|
**/
|
|
17
|
-
export declare function Badge({ style, color, size,
|
|
17
|
+
export declare function Badge({ style, color, size, children }: Props): import("react").JSX.Element | null;
|
|
18
18
|
export default Badge;
|
|
@@ -14,11 +14,9 @@ const tailwind_variants_1 = require("tailwind-variants");
|
|
|
14
14
|
*
|
|
15
15
|
* @param {string} color - Color of badge. (optional, default = accent)
|
|
16
16
|
**/
|
|
17
|
-
function Badge({ style, color = "--color-accent", size = "md",
|
|
17
|
+
function Badge({ style, color = "--color-accent", size = "md", children }) {
|
|
18
18
|
if (!children)
|
|
19
19
|
return null;
|
|
20
|
-
if (color === "future")
|
|
21
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2 test-badge", children: [icon && (0, jsx_runtime_1.jsx)("div", { className: "text-primary-dark", children: icon }), (0, jsx_runtime_1.jsx)("span", { children: children })] }));
|
|
22
20
|
return ((0, jsx_runtime_1.jsx)("span", { className: (0, style_1.cn)(base({ size }), style), style: styles(color), children: children }));
|
|
23
21
|
}
|
|
24
22
|
const styles = (color) => ({
|
|
@@ -30,12 +28,12 @@ const styles = (color) => ({
|
|
|
30
28
|
color: "var(--color-primary)"
|
|
31
29
|
});
|
|
32
30
|
const base = (0, tailwind_variants_1.tv)({
|
|
33
|
-
base: "w-min",
|
|
31
|
+
base: "w-min px-2 py-1",
|
|
34
32
|
variants: {
|
|
35
33
|
size: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
sm: "text-xs",
|
|
35
|
+
md: "text-sm",
|
|
36
|
+
lg: "text-base"
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
});
|
|
@@ -51,10 +51,17 @@ function opacitize(color, opacity = 0.5) {
|
|
|
51
51
|
transparent
|
|
52
52
|
)
|
|
53
53
|
`;
|
|
54
|
+
if (color.startsWith("--"))
|
|
55
|
+
return `
|
|
56
|
+
color-mix(
|
|
57
|
+
in srgb,
|
|
58
|
+
var(${color}) ${opacity * 100}%,
|
|
59
|
+
transparent
|
|
60
|
+
)
|
|
61
|
+
`;
|
|
54
62
|
const { r, g, b } = parseHex(color);
|
|
55
63
|
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
56
64
|
}
|
|
57
|
-
;
|
|
58
65
|
const parseHex = (input) => {
|
|
59
66
|
let hex = input.replace("#", "");
|
|
60
67
|
if (hex.length === 3)
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface GetValueOptions<T> {
|
|
2
|
+
fetcher: () => Promise<T>;
|
|
3
|
+
callback?: () => void;
|
|
4
|
+
interval?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function useValue<T>({ fetcher, callback, interval }: GetValueOptions<T>): readonly [T | null | undefined, boolean];
|
|
2
7
|
export declare function useList<T extends {
|
|
3
8
|
id?: string;
|
|
4
9
|
}>(initial?: T[]): {
|
|
@@ -4,13 +4,42 @@ exports.useValue = useValue;
|
|
|
4
4
|
exports.useList = useList;
|
|
5
5
|
exports.useMap = useMap;
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
-
function useValue(
|
|
8
|
-
const [value, setValue] = (0, react_1.useState)(
|
|
7
|
+
function useValue({ fetcher, callback, interval }) {
|
|
8
|
+
const [value, setValue] = (0, react_1.useState)();
|
|
9
|
+
const [isLoading, setLoading] = (0, react_1.useState)(true);
|
|
10
|
+
const fetchValue = async (showLoading = false) => {
|
|
11
|
+
if (showLoading)
|
|
12
|
+
setLoading(true);
|
|
13
|
+
try {
|
|
14
|
+
console.log("fetching");
|
|
15
|
+
const result = await fetcher();
|
|
16
|
+
const nextValue = result ?? null;
|
|
17
|
+
setValue(current => Object.is(current, nextValue)
|
|
18
|
+
? current
|
|
19
|
+
: nextValue);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.error(err);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
if (showLoading)
|
|
26
|
+
setLoading(false);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
(0, react_1.useEffect)(() => {
|
|
30
|
+
fetchValue(true);
|
|
31
|
+
}, []);
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
if (!interval || value)
|
|
34
|
+
return;
|
|
35
|
+
const id = setInterval(() => fetchValue(), interval * 1000);
|
|
36
|
+
return () => clearInterval(id);
|
|
37
|
+
}, [interval, value]);
|
|
9
38
|
(0, react_1.useEffect)(() => {
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
}, [value]);
|
|
13
|
-
return value;
|
|
39
|
+
if (value && callback)
|
|
40
|
+
callback();
|
|
41
|
+
}, [value, callback]);
|
|
42
|
+
return [value, isLoading];
|
|
14
43
|
}
|
|
15
44
|
function useList(initial = []) {
|
|
16
45
|
const [items, setItems] = (0, react_1.useState)(initial);
|