@bouko/react 0.4.2 → 0.4.4

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.
@@ -12,7 +12,7 @@ export default function Attachment({ id, style, label, value, update, required =
12
12
  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: [!value || value.length === 0 && (_jsxs(_Fragment, { 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", onChange: handleFileChange, ref: ref })] })), value && value.length > 0 && value.map((x, i) => (_jsx("span", { className: "text-xs text-slate-500", children: x.name }, i)))] }), note && _jsx("span", { className: styles.note, children: note })] }));
13
13
  }
14
14
  const styles = {
15
- container: "flex flex-col gap-2 overflow-hidden",
15
+ container: "flex flex-col gap-2 w-full shrink-0 overflow-hidden",
16
16
  label: "text-xs text-slate-600",
17
17
  input: "px-3 py-2 bg-slate-200/50 border border-slate-300 outline-blue-500 rounded text-sm",
18
18
  note: "mt-1 text-xs text-slate-500"
@@ -1,2 +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;
1
+ import { type OptionField } from "@bouko/form";
2
+ export default function MultipleChoice<T>({ id, label, options, style, value, update, required }: OptionField<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import Field from "./field";
3
+ import { setField } from "@bouko/form";
3
4
  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))) }) }));
5
+ export default function MultipleChoice({ id, label, options, style, value, update, required = true }) {
6
+ 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: () => setField(update, id, x.id) }), x.label] }, i))) }) }));
6
7
  }
7
8
  const Dot = ({ active, select }) => (_jsx("div", { className: cn(styles.dot, active && "bg-accent border-accent-dark"), onClick: select }));
8
9
  const styles = {
@@ -15,7 +15,7 @@ export default function Select({ id, style, label, required = true, value, optio
15
15
  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")) })] }));
16
16
  }
17
17
  const styles = {
18
- container: "relative",
18
+ container: "relative shrink-0 w-full",
19
19
  subcontainer: "flex flex-col gap-1 w-full",
20
20
  label: "text-xs text-slate-600",
21
21
  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",
@@ -1,8 +1,7 @@
1
- import type { ReactNode, TextareaHTMLAttributes } from "react";
2
- type Props = TextareaHTMLAttributes<HTMLTextAreaElement> & {
3
- label?: string;
4
- style?: string;
5
- note?: ReactNode;
1
+ import { type Field as FieldProps } from "@bouko/form";
2
+ type Props<T> = FieldProps<T> & {
3
+ rows?: number;
4
+ placeholder?: string;
6
5
  };
7
- export default function TextArea({ style, label, required, note, ...props }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export default function TextArea<T>({ id, style, label, required, note, update, ...props }: Props<T>): import("react/jsx-runtime").JSX.Element;
8
7
  export {};
@@ -1,7 +1,8 @@
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 })] }));
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Field from "./field";
3
+ import { setField } from "@bouko/form";
4
+ export default function TextArea({ id, style, label, required = true, note, update, ...props }) {
5
+ return (_jsx(Field, { style: style, label: label, required: required, note: note, children: _jsx("textarea", { className: styles.textarea, onChange: ({ target: { value } }) => setField(update, id, value), ...props }) }));
5
6
  }
6
7
  const styles = {
7
8
  container: "flex flex-col gap-1 overflow-hidden",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "0.4.2",
4
+ "version": "0.4.4",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",