@bouko/react 0.2.5 → 0.2.7

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,8 +1,9 @@
1
1
  import type { ReactNode } from "react";
2
2
  type Props = {
3
+ variant?: "ghost";
3
4
  style?: string;
4
5
  onClick?: () => void;
5
6
  children: ReactNode;
6
7
  };
7
- export default function Button({ style, ...props }: Props): import("react/jsx-runtime").JSX.Element;
8
+ export default function Button({ variant, style, ...props }: Props): import("react/jsx-runtime").JSX.Element;
8
9
  export {};
@@ -1,5 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { cn } from "@bouko/style";
3
- export default function Button({ style, ...props }) {
4
- return (_jsx("button", { className: cn("px-4 py-2 duration-200 cursor-pointer", "bg-accent hover:bg-accent-dark border border-accent-dark rounded", "font-semibold text-slate-100", style), ...props }));
2
+ import { cn, tv } from "@bouko/style";
3
+ export default function Button({ variant, style, ...props }) {
4
+ return (_jsx("button", { className: cn(styles({ variant }), style), ...props }));
5
5
  }
6
+ const styles = tv({
7
+ base: "px-4 py-2 bg-accent hover:bg-accent-dark border border-accent-dark rounded font-semibold text-primary duration-200 cursor-pointer",
8
+ variants: {
9
+ variant: {
10
+ ghost: "bg-transparent border-transparent"
11
+ }
12
+ }
13
+ });
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ type Props = {
3
+ container?: string;
4
+ title: ReactNode;
5
+ subtitle: ReactNode;
6
+ reverse?: boolean;
7
+ };
8
+ export default function Heading({ container, title, subtitle, reverse }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ColumnBox } from "./flex";
3
+ import { cn } from "@bouko/style";
4
+ export default function Heading({ container, title, subtitle, reverse }) {
5
+ return (_jsxs(ColumnBox, { style: cn(container, reverse && "flex-col-reverse"), children: [_jsx("span", { className: styles.title, children: title }), _jsx("span", { className: styles.subtitle, children: subtitle })] }));
6
+ }
7
+ const styles = {
8
+ title: "flex items-center gap-2 font-bold",
9
+ subtitle: "text-sm font-semibold"
10
+ };
@@ -0,0 +1 @@
1
+ export declare const formatText: (text: string) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const delimiterConfig = [
3
+ { delimiter: "**", render: (text, key) => _jsx("span", { className: "font-bold", children: text }, key) },
4
+ { delimiter: "~~", render: (text, key) => _jsx("span", { className: "font-semibold", children: text }, key) },
5
+ { delimiter: "^^", render: (text, key) => _jsx("span", { className: "text-accent", children: text }, key) },
6
+ ];
7
+ const escapeRegex = (str) => str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
8
+ const delimiters = delimiterConfig.map(({ delimiter }) => escapeRegex(delimiter) + ".*?" + escapeRegex(delimiter)).join("|");
9
+ const WRAPPED_TEXT_REGEX = new RegExp(`(${delimiters})`, "g");
10
+ const isWrapped = (x, wrapper) => x.startsWith(wrapper) && x.endsWith(wrapper);
11
+ export const formatText = (text) => {
12
+ const parts = text
13
+ .split(WRAPPED_TEXT_REGEX)
14
+ .filter(Boolean);
15
+ const formatted = parts.map((x, i) => {
16
+ if (isWrapped(x, "**")) {
17
+ // Remove only the first and last occurrence of the delimiter
18
+ const content = x.slice(2, -2);
19
+ return _jsx("span", { className: "font-bold", children: content }, i);
20
+ }
21
+ else if (isWrapped(x, "~~")) {
22
+ const content = x.slice(2, -2);
23
+ return _jsx("span", { className: "font-semibold", children: content }, i);
24
+ }
25
+ else if (isWrapped(x, "^^")) {
26
+ const content = x.slice(2, -2);
27
+ return _jsx("span", { className: "text-accent", children: content }, i);
28
+ }
29
+ return x;
30
+ });
31
+ return _jsx("span", { children: formatted });
32
+ };
package/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export { default as CheckBox } from "./components/checkbox";
8
8
  export * from "./components/flex";
9
9
  export * from "./core/types";
10
10
  export * from "./core/functions";
11
+ export * from "./core/format";
package/dist/index.js CHANGED
@@ -8,3 +8,4 @@ export { default as CheckBox } from "./components/checkbox";
8
8
  export * from "./components/flex";
9
9
  export * from "./core/types";
10
10
  export * from "./core/functions";
11
+ export * from "./core/format";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "0.2.5",
4
+ "version": "0.2.7",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",