@bouko/react 2.4.7 → 2.4.8

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,11 +1,12 @@
1
- import type { ReactNode } from "react";
1
+ import { ReactNode } from "react";
2
2
  export declare type ButtonProps = {
3
3
  variant?: "primary" | "outline" | "ghost";
4
4
  size?: "xs" | "sm" | "md" | "lg";
5
5
  style?: string;
6
- onClick?: () => void;
6
+ icon?: ReactNode;
7
+ action?: () => void;
7
8
  disabled?: boolean;
8
9
  children: ReactNode;
9
10
  };
10
- export declare function Button({ size, variant, style, ...props }: ButtonProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function Button({ size, variant, style, icon, action, disabled, children }: ButtonProps): import("react/jsx-runtime").JSX.Element;
11
12
  export default Button;
@@ -1,7 +1,21 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
2
4
  import { cn, tv } from "@bouko/style";
3
- export function Button({ size, variant, style, ...props }) {
4
- return (_jsx("button", { className: cn(styles({ variant, size }), style), ...props }, void 0));
5
+ import Spinner from "../../assets/icons/spinner.svg";
6
+ export function Button({ size, variant, style, icon, action, disabled, children }) {
7
+ const [isLoading, setLoading] = useState(false);
8
+ const submit = async () => {
9
+ setLoading(true);
10
+ try {
11
+ await action?.();
12
+ }
13
+ catch { }
14
+ setLoading(false);
15
+ };
16
+ return (_jsxs("button", { className: cn(styles({ variant, size }), style), onClick: submit, disabled: disabled || isLoading, children: [icon && isLoading
17
+ ? _jsx(Spinner, { className: "animate-spin" }, void 0)
18
+ : icon, children] }, void 0));
5
19
  }
6
20
  const styles = tv({
7
21
  base: "flex justify-center items-center gap-2 bg-accent hover:bg-accent-dark border border-accent-dark rounded font-semibold text-background-light duration-200 cursor-pointer disabled:cursor-not-allowed",
@@ -10,7 +24,7 @@ const styles = tv({
10
24
  variant: {
11
25
  primary: "bg-primary hover:bg-primary-dark border-primary-dark",
12
26
  outline: "!bg-transparent border-accent hover:border-accent-dark text-primary",
13
- ghost: "!bg-transparent border-transparent text-accent hover:text-accent-dark"
27
+ ghost: "!p-0 !bg-transparent border-transparent text-accent hover:text-accent-dark hover:brightness-110"
14
28
  },
15
29
  size: {
16
30
  xs: "px-3 py-1 text-xs",
@@ -4,8 +4,6 @@ export { default as Heading } from "./heading/normal";
4
4
  export { default as PageHeading } from "./heading/page";
5
5
  export * from "./layout/flex";
6
6
  export { default as Button } from "./button/normal";
7
- export { default as LoadButton } from "./button/load";
8
- export { default as GhostButton } from "./button/ghost";
9
7
  export { default as Badge } from "./text/badge";
10
8
  export { default as Dropdown } from "./dropdown/normal";
11
9
  export { default as FileUploader } from "./upload/file";
@@ -4,8 +4,6 @@ export { default as Heading } from "./heading/normal";
4
4
  export { default as PageHeading } from "./heading/page";
5
5
  export * from "./layout/flex";
6
6
  export { default as Button } from "./button/normal";
7
- export { default as LoadButton } from "./button/load";
8
- export { default as GhostButton } from "./button/ghost";
9
7
  export { default as Badge } from "./text/badge";
10
8
  export { default as Dropdown } from "./dropdown/normal";
11
9
  export { default as FileUploader } from "./upload/file";
@@ -7,7 +7,7 @@ import { RowBox } from "./layout/flex";
7
7
  import { Button } from "./button/normal";
8
8
  export function SearchBar({ style, placeholder, action }) {
9
9
  const [query, search] = useState("");
10
- return (_jsxs(RowBox, { style: cn(styles.container, style?.container), children: [_jsxs("div", { className: "relative grow", children: [_jsx("input", { className: cn("w-full outline-none text-lg placeholder-slate-500 tracking-wide", style?.input), placeholder: placeholder, value: query, onChange: (e) => search(e.target.value), onKeyUp: (e) => e.key === "Enter" ? action(query) : null }, void 0), _jsx("div", { className: "absolute top-0 right-0 w-12 h-full bg-gradient-to-l from-slate-950" }, void 0)] }, void 0), _jsxs(Button, { size: "xs", style: cn("font-mono text-sm font-extrabold", style?.trigger), onClick: () => action(query), children: ["GO ", _jsx(AnglesRight, {}, void 0)] }, void 0)] }, void 0));
10
+ return (_jsxs(RowBox, { style: cn(styles.container, style?.container), children: [_jsxs("div", { className: "relative grow", children: [_jsx("input", { className: cn("w-full outline-none text-lg placeholder-slate-500 tracking-wide", style?.input), placeholder: placeholder, value: query, onChange: (e) => search(e.target.value), onKeyUp: (e) => e.key === "Enter" ? action(query) : null }, void 0), _jsx("div", { className: "absolute top-0 right-0 w-12 h-full bg-gradient-to-l from-slate-950" }, void 0)] }, void 0), _jsxs(Button, { size: "xs", style: cn("font-mono text-sm font-extrabold", style?.trigger), action: () => action(query), children: ["GO ", _jsx(AnglesRight, {}, void 0)] }, void 0)] }, void 0));
11
11
  }
12
12
  const styles = {
13
13
  container: "items-center gap-6 w-xl max-w-full pl-5 pr-4 py-3 bg-slate-950 border border-border rounded-md"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.4.7",
4
+ "version": "2.4.8",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",