@bouko/react 0.1.9 → 0.2.0
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/attachment.d.ts +11 -0
- package/dist/components/attachment.js +14 -0
- package/dist/components/button.d.ts +8 -0
- package/dist/components/button.js +5 -0
- package/dist/components/field.d.ts +10 -0
- package/dist/components/field.js +11 -0
- package/dist/components/flex.d.ts +9 -0
- package/dist/components/flex.js +8 -0
- package/dist/components/input.d.ts +6 -0
- package/dist/components/input.js +5 -0
- package/dist/components/mcq.d.ts +2 -0
- package/dist/components/mcq.js +12 -0
- package/dist/components/select.d.ts +2 -0
- package/dist/components/select.js +22 -0
- package/dist/components/textarea.d.ts +8 -0
- package/dist/components/textarea.js +11 -0
- package/dist/core/types.d.ts +18 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
|
@@ -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,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,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,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,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 {};
|
package/dist/index.d.ts
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/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";
|