diff --git a/src/leihs/inventory/client/components/basic_form_field.cljs b/src/leihs/inventory/client/components/basic_form_field.cljs new file mode 100644 index 00000000..9d522f2d --- /dev/null +++ b/src/leihs/inventory/client/components/basic_form_field.cljs @@ -0,0 +1,57 @@ +(ns leihs.inventory.client.components.basic-form-field + (:require + ["@@/checkbox" :refer [Checkbox]] + ["@@/dropzone" :refer [Dropzone]] + ["@@/form" :refer [FormField FormItem FormLabel FormControl FormDescription FormMessage]] + ["@@/input" :refer [Input]] + ["@@/textarea" :refer [Textarea]] + [leihs.inventory.client.lib.utils :refer [cj jc]] + [leihs.inventory.client.routes.models.create.components.accessories-list :refer [AccessoryList]] + [uix.core :as uix :refer [defui $]])) + +comment "available form fields" +(def fields-map + {"input" Input + "dropzone" Dropzone + "textarea" Textarea + "checkbox" Checkbox + "accessory-list" AccessoryList}) + +(defui main + "Main function for rendering a form field component. + + Arguments: + - `control`: The control element for the form field. + - `input`: A map containing input properties. + - `class-name`: A string for additional CSS class names for the input field + - `label`: A boolean indicating whether to display the label. + - `description`: A boolean indicating whether to display the description. + - `name`: The name of the form field. + + Default values: + - `label`: true + - `description`: true + - `class-name`: empty string + - `name`: The name from the `input` map." + + [{:keys [control input class-name + label description name] + :or {label true description true + class-name "" name (:name input)}}] + + (let [comp (get fields-map (:component input))] + (when comp + ($ FormField {:control (cj control) + :name name + :render #($ FormItem + (when label ($ FormLabel (:label input))) + ($ FormControl + ($ comp (merge + {:class-name class-name} + (:props input) + (:field (jc %))))) + + (when description ($ FormDescription + ($ :<> (:description input)))) + + ($ FormMessage))})))) diff --git a/src/leihs/inventory/client/components/react/scrollspy/context.jsx b/src/leihs/inventory/client/components/react/scrollspy/context.jsx index f7658124..ff6c9417 100644 --- a/src/leihs/inventory/client/components/react/scrollspy/context.jsx +++ b/src/leihs/inventory/client/components/react/scrollspy/context.jsx @@ -1,4 +1,4 @@ -import React, { useRef, useState } from "react" +import React, { useState } from "react" // Create the context const ScrollspyContext = React.createContext() @@ -10,9 +10,12 @@ export const ScrollspyProvider = ({ children }) => { // Function to add an item function addItem(item) { - if (items.find((i) => i.id === item.id)) return - - setItems((prev) => [...prev, item]) + setItems((prev) => { + if (prev.find((i) => i.id === item.id)) { + return [...prev] + } + return [...prev, item] + }) } const value = { diff --git a/src/leihs/inventory/client/components/react/scrollspy/scrollspy.jsx b/src/leihs/inventory/client/components/react/scrollspy/scrollspy.jsx index 6b166d34..76a95657 100644 --- a/src/leihs/inventory/client/components/react/scrollspy/scrollspy.jsx +++ b/src/leihs/inventory/client/components/react/scrollspy/scrollspy.jsx @@ -7,7 +7,9 @@ import { cn } from "@@/utils" export function Scrollspy({ children, className }) { return ( -
{children}
+
+ {children} +
) } diff --git a/src/leihs/inventory/client/components/react/sortable-list/sortable-list.jsx b/src/leihs/inventory/client/components/react/sortable-list/sortable-list.jsx index af71232d..6c29fcc8 100644 --- a/src/leihs/inventory/client/components/react/sortable-list/sortable-list.jsx +++ b/src/leihs/inventory/client/components/react/sortable-list/sortable-list.jsx @@ -38,17 +38,18 @@ function SortableList({ children, items, onDragEnd, setItems = false }) { ) } -function Draggable({ children, className, id, ...props }) { +function Draggable({ children, className, id, asChild = false, ...props }) { const { transition, transform, setNodeRef } = useSortable({ id }) + const Comp = asChild ? Slot : "div" const style = { transform: CSS.Transform.toString(transform), transition, } return ( -
+ {children} -
+ ) } diff --git a/src/leihs/inventory/client/components/ui/form.jsx b/src/leihs/inventory/client/components/ui/form.jsx index dcadc3e8..e9159ada 100644 --- a/src/leihs/inventory/client/components/ui/form.jsx +++ b/src/leihs/inventory/client/components/ui/form.jsx @@ -1,6 +1,11 @@ import * as React from "react" import { Slot } from "@radix-ui/react-slot" -import { Controller, FormProvider, useFormContext } from "react-hook-form" +import { + Controller, + FormProvider, + useFormContext, + useFieldArray, +} from "react-hook-form" import { cn } from "@/components/ui/utils" import { Label } from "@/components/ui/label" @@ -9,6 +14,21 @@ const Form = FormProvider const FormFieldContext = React.createContext({}) +// const FormFields = ({ ...props }) => { +// const control = props.control; +// +// const { fields, append, remove } = useFieldArray({ +// control, +// name: "" +// }); +// +// return ( +// +// +// +// ) +// } + const FormField = ({ ...props }) => { return ( diff --git a/src/leihs/inventory/client/components/ui/textarea.jsx b/src/leihs/inventory/client/components/ui/textarea.jsx index c2bf2e01..736c6f69 100644 --- a/src/leihs/inventory/client/components/ui/textarea.jsx +++ b/src/leihs/inventory/client/components/ui/textarea.jsx @@ -2,18 +2,61 @@ import * as React from "react" import { cn } from "@/components/ui/utils" -const Textarea = React.forwardRef(({ className, ...props }, ref) => { - return ( -