shelving
Version:
Toolkit for using data in JavaScript.
17 lines (16 loc) • 878 B
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { useStore } from "../../react/useStore.js";
import { Field } from "./Field.js";
import { requireForm, useField } from "./FormContext.js";
import { SchemaInput } from "./SchemaInput.js";
/** Show a `<Field>` for a named property in the current form. */
export function FormField({ name, ...props }) {
const field = useField(name);
const { schema, message } = field;
return (_jsx(Field, { ...schema, message: message, required: props.required, children: _jsx(SchemaInput, { ...field, ...props }) }));
}
/** List of `<Field>` elements for every schema property in the current form. */
export function FormFields() {
const form = useStore(requireForm());
return (_jsx(_Fragment, { children: Object.keys(form.schema.props).map(name => (_jsx(FormField, { name: name }, name))) }));
}