@bouko/react 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.
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="1em" height="1em">
2
+ <path
3
+ d="M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"
4
+ fill="currentColor"
5
+ />
6
+ </svg>
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" width="1em" height="1em">
2
+ <path
3
+ d="M364.2 83.8c-24.4-24.4-64-24.4-88.4 0l-184 184c-42.1 42.1-42.1 110.3 0 152.4s110.3 42.1 152.4 0l152-152c10.9-10.9 28.7-10.9 39.6 0s10.9 28.7 0 39.6l-152 152c-64 64-167.6 64-231.6 0s-64-167.6 0-231.6l184-184c46.3-46.3 121.3-46.3 167.6 0s46.3 121.3 0 167.6l-176 176c-28.6 28.6-75 28.6-103.6 0s-28.6-75 0-103.6l144-144c10.9-10.9 28.7-10.9 39.6 0s10.9 28.7 0 39.6l-144 144c-6.7 6.7-6.7 17.7 0 24.4s17.7 6.7 24.4 0l176-176c24.4-24.4 24.4-64 0-88.4z"
4
+ fill="currentColor"
5
+ />
6
+ </svg>
@@ -0,0 +1,11 @@
1
+ import { type Dispatch, type SetStateAction } from "react";
2
+ type Props = {
3
+ label?: string;
4
+ style?: string;
5
+ value?: File[];
6
+ required?: boolean;
7
+ update: Dispatch<SetStateAction<File[]>>;
8
+ note?: string;
9
+ };
10
+ export default function Attachment({ style, update, label, required, value, note }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from "react";
3
+ import PaperClip from "../assets/icons/paperclip.svg";
4
+ import { cn } from "@bouko/style";
5
+ export default function Attachment({ style, update, label, required = true, value, note }) {
6
+ const ref = useRef(null);
7
+ return (_jsxs("div", { className: cn(styles.container, style), children: [label && _jsxs("span", { className: styles.label, children: [label, " ", !required ? _jsx("span", { className: "italic text-slate-400", children: "(optional)" }) : ""] }), _jsxs("div", { onClick: () => ref.current?.click(), className: "flex flex-col justify-center items-center py-3 gap-1 w-full cursor-pointer duration-200 hover:bg-slate-200/40 rounded border-2 border-slate-300 border-dashed", children: [_jsxs("span", { className: "flex gap-2 items-center font-semibold text-sm", children: [_jsx(PaperClip, {}), "Drag and drop files, paste screenshots, or"] }), _jsx("span", { className: "text-xs text-slate-500", children: "browse" }), _jsx("input", { type: "file", className: "hidden", ref: ref })] }), note && _jsx("span", { className: styles.note, children: note })] }));
8
+ }
9
+ const styles = {
10
+ container: "flex flex-col gap-2 overflow-hidden",
11
+ label: "text-xs text-slate-600",
12
+ input: "px-3 py-2 bg-slate-200/50 border border-slate-300 outline-blue-500 rounded text-sm",
13
+ note: "mt-1 text-xs text-slate-500"
14
+ };
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from "react";
2
+ type Props = {
3
+ style?: string;
4
+ onClick?: () => void;
5
+ children: ReactNode;
6
+ };
7
+ export default function Button({ style, ...props }: Props): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,5 @@
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 }));
5
+ }
@@ -0,0 +1,10 @@
1
+ import type { InputHTMLAttributes, ReactNode } from "react";
2
+ type Props = InputHTMLAttributes<HTMLInputElement> & {
3
+ label?: string;
4
+ style?: string;
5
+ required?: boolean;
6
+ note?: string;
7
+ children: ReactNode;
8
+ };
9
+ export default function Field({ style, label, required, note, children }: Props): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "@bouko/style";
3
+ export default function Field({ style, label, required = true, note, children }) {
4
+ return (_jsxs("div", { className: cn(styles.container, style), children: [label && _jsxs("span", { className: styles.label, children: [label, " ", !required ? _jsx("span", { className: "italic text-slate-400", children: "(optional)" }) : ""] }), children, note && _jsx("span", { className: styles.note, children: note })] }));
5
+ }
6
+ const styles = {
7
+ container: "flex flex-col gap-1 overflow-hidden",
8
+ label: "text-xs text-slate-600",
9
+ input: "px-3 py-2 bg-slate-200/50 border border-slate-300 outline-blue-500 rounded text-sm",
10
+ note: "mt-1 text-xs text-slate-500"
11
+ };
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ export declare function ColumnBox({ style, children }: {
3
+ style?: string;
4
+ children: ReactNode;
5
+ }): import("react/jsx-runtime").JSX.Element;
6
+ export declare function RowBox({ style, children }: {
7
+ style?: string;
8
+ children: ReactNode;
9
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "@bouko/style";
3
+ export function ColumnBox({ style, children }) {
4
+ return (_jsx("div", { className: cn(style, "flex flex-col"), children: children }));
5
+ }
6
+ export function RowBox({ style, children }) {
7
+ return (_jsx("div", { className: cn(style, "flex"), children: children }));
8
+ }
@@ -0,0 +1,6 @@
1
+ import type { Field as FieldProps } from "../core/types";
2
+ type Props = FieldProps & {
3
+ placeholder?: string;
4
+ };
5
+ export default function Input({ style, label, required, note, update, ...props }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Field from "./field";
3
+ export default function Input({ style, label, required = true, note, update, ...props }) {
4
+ return (_jsx(Field, { style: style, label: label, required: required, note: note, children: _jsx("input", { className: "px-3 py-2 bg-slate-200/50 border border-slate-300 outline-blue-500 rounded text-sm", onChange: ({ target: { value } }) => update(value), ...props }) }));
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { OptionField } from "../core/types";
2
+ export default function MultipleChoice({ label, options, style, value, update, required }: OptionField): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import Field from "./field";
3
+ import { cn } from "@bouko/style";
4
+ export default function MultipleChoice({ label, options, style, value, update, required = true }) {
5
+ return (_jsx(Field, { style: style, label: label, required: required, children: _jsx("div", { className: styles.options, children: options.map((x, i) => (_jsxs("div", { className: styles.item, children: [_jsx(Dot, { ...x, active: x.id === value, select: () => update(x.id) }), x.label] }, i))) }) }));
6
+ }
7
+ const Dot = ({ active, select }) => (_jsx("div", { className: cn(styles.dot, active && "bg-accent border-accent-dark"), onClick: select }));
8
+ const styles = {
9
+ options: "flex flex-col gap-1 w-full",
10
+ item: "flex items-center gap-3 text-sm",
11
+ dot: "size-3 bg-background-dark/50 hover:bg-background-dark duration-200 cursor-pointer border border-background-dark rounded-full"
12
+ };
@@ -0,0 +1,2 @@
1
+ import type { OptionField } from "../core/types";
2
+ export default function Select({ style, label, required, value, options, update, note }: OptionField): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { AnimatePresence, motion } from "framer-motion";
4
+ import Chevron from "../assets/icons/chevron.svg";
5
+ import { cn } from "@bouko/style";
6
+ export default function Select({ style, label, required = true, value, options, update, note }) {
7
+ const [isOpen, setOpen] = useState(false);
8
+ const active = options.find(x => x.id === value);
9
+ const select = (x) => {
10
+ update(x);
11
+ setOpen(false);
12
+ };
13
+ return (_jsxs("div", { className: cn(styles.container, style), children: [_jsxs("div", { className: styles.subcontainer, children: [label && _jsxs("span", { className: styles.label, children: [label, " ", !required ? _jsx("span", { className: "italic text-slate-400", children: "(optional)" }) : ""] }), _jsxs("div", { className: cn(styles.trigger, !active?.label && "capitalize"), onClick: () => setOpen(x => !x), children: [active ? active.label ?? active.id : "None", _jsx(Chevron, { className: cn("text-xs text-slate-400 duration-200", isOpen && "rotate-180") })] }), note && !isOpen && _jsx("span", { className: styles.note, children: note })] }), _jsx(AnimatePresence, { children: isOpen && (_jsx(motion.div, { className: styles.dropdown, initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, children: options.map(({ id, label }) => (_jsx("span", { className: cn("w-full p-2 border-l-3 border-transparent hover:text-blue-600 duration-200 cursor-pointer", active?.id === id && "border-blue-600 bg-blue-500/10", !label && "capitalize"), onClick: () => select(id), children: label ?? id }, id))) }, "dropdown")) })] }));
14
+ }
15
+ const styles = {
16
+ container: "relative",
17
+ subcontainer: "flex flex-col gap-1 w-full",
18
+ label: "text-xs text-slate-600",
19
+ 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",
20
+ dropdown: "absolute mt-2 z-50 flex flex-col gap-1 w-full bg-slate-100 rounded border border-slate-300 py-1 text-xs max-h-46 overflow-y-auto",
21
+ note: "mt-1 text-xs text-slate-500"
22
+ };
@@ -0,0 +1,8 @@
1
+ import type { ReactNode, TextareaHTMLAttributes } from "react";
2
+ type Props = TextareaHTMLAttributes<HTMLTextAreaElement> & {
3
+ label?: string;
4
+ style?: string;
5
+ note?: ReactNode;
6
+ };
7
+ export default function TextArea({ style, label, required, note, ...props }: Props): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "@bouko/style";
3
+ export default function TextArea({ style, label, required = true, note, ...props }) {
4
+ return (_jsxs("div", { className: cn(styles.container, style), children: [label && _jsxs("span", { className: styles.label, children: [label, " ", !required ? _jsx("span", { className: "italic text-slate-400", children: "(optional)" }) : ""] }), _jsx("textarea", { className: styles.textarea, ...props }), note && _jsx("span", { className: styles.note, children: note })] }));
5
+ }
6
+ const styles = {
7
+ container: "flex flex-col gap-1 overflow-hidden",
8
+ label: "text-xs text-slate-600",
9
+ textarea: "px-3 py-2 bg-slate-200/50 border border-slate-300 outline-blue-500 rounded text-sm resize-none",
10
+ note: "mt-1 text-xs text-slate-500"
11
+ };
@@ -0,0 +1,18 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ export type Field = {
3
+ label?: string;
4
+ style?: string;
5
+ value?: string;
6
+ update: Dispatch<SetStateAction<string>>;
7
+ required?: boolean;
8
+ note?: string;
9
+ };
10
+ export type Option = {
11
+ id: string;
12
+ label?: string;
13
+ active?: boolean;
14
+ select?: () => void;
15
+ };
16
+ export type OptionField = Field & {
17
+ options: Option[];
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export { default as Input } from "./components/input";
2
+ export { default as TextArea } from "./components/textarea";
3
+ export { default as Select } from "./components/select";
4
+ export { default as MultipleChoice } from "./components/mcq";
5
+ export { default as Attachment } from "./components/attachment";
6
+ export { default as Button } from "./components/button";
7
+ export * from "./components/flex";
8
+ export * from "./core/types";
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { default as Input } from "./components/input";
2
+ export { default as TextArea } from "./components/textarea";
3
+ export { default as Select } from "./components/select";
4
+ export { default as MultipleChoice } from "./components/mcq";
5
+ export { default as Attachment } from "./components/attachment";
6
+ export { default as Button } from "./components/button";
7
+ export * from "./components/flex";
8
+ export * from "./core/types";
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  "name": "@bouko/react",
4
4
 
5
- "version": "0.1.9",
5
+ "version": "0.2.1",
6
6
 
7
7
  "main": "./dist/index.js",
8
8