@bouko/react 0.3.2 → 0.3.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.
|
@@ -7,6 +7,7 @@ const styles = tv({
|
|
|
7
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
8
|
variants: {
|
|
9
9
|
variant: {
|
|
10
|
+
primary: "bg-primary hover:bg-primary-dark border-primary-dark text-background",
|
|
10
11
|
ghost: "bg-transparent border-transparent"
|
|
11
12
|
}
|
|
12
13
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type OptionField } from "@bouko/form";
|
|
2
|
+
type Props<T> = OptionField<T> & {
|
|
3
|
+
placeholder?: string;
|
|
4
|
+
};
|
|
5
|
+
export default function Select<T>({ id, style, label, required, value, options, update, note }: Props<T>): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -3,12 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { AnimatePresence, motion } from "framer-motion";
|
|
5
5
|
import Chevron from "../assets/icons/chevron.svg";
|
|
6
|
+
import { setField } from "@bouko/form";
|
|
6
7
|
import { cn } from "@bouko/style";
|
|
7
|
-
export default function Select({ style, label, required = true, value, options, update, note }) {
|
|
8
|
+
export default function Select({ id, style, label, required = true, value, options, update, note }) {
|
|
8
9
|
const [isOpen, setOpen] = useState(false);
|
|
9
10
|
const active = options.find(x => x.id === value);
|
|
10
11
|
const select = (x) => {
|
|
11
|
-
update
|
|
12
|
+
setField(update, id, x);
|
|
12
13
|
setOpen(false);
|
|
13
14
|
};
|
|
14
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")) })] }));
|