= {}) =>
(props: Props): Html => {
let { children, ...attributes } = props
let Tag = tag
return (
{children}
)
}
export const FieldSet = part('fieldset', 'field-set')
export const FieldGroup = part('div', 'field-group')
export const FieldContent = part('div', 'field-content')
export const FieldLabel = part('label', 'field-label')
export const FieldTitle = part('div', 'field-title')
export const FieldDescription = part('p', 'field-description')
// `variant="label"` makes the legend the size of a label, for a set inside a field.
export function FieldLegend(props: Props & { variant?: 'legend' | 'label' | undefined }): Html {
let { variant = 'legend', children, ...attributes } = props
return (
)
}
// Set `data-invalid` on a field whose value is wrong, to color its label and description.
export function Field(
props: Props & { orientation?: 'vertical' | 'horizontal' | 'responsive' | undefined },
): Html {
let { orientation = 'vertical', children, ...attributes } = props
return (
{children}
)
}
// A line between fields, with optional text in the middle, like "Or".
export function FieldSeparator(props: Props): Html {
let { children, ...attributes } = props
return (
{children != null ? {children} : null}
)
}
// The field's error: its children, or a list of `errors` (one shows on its own). Datastar's
// `data-show` or `data-text` can show and fill it as the value changes.
export function FieldError(props: Props & { errors?: string[] | undefined }): Html {
let { errors, children, ...attributes } = props
let content: Child = children
if (content == null && errors?.length) {
content =
errors.length === 1 ? (
errors[0]
) : (
{errors.map((error) => (
- {error}
))}
)
}
return (
{content}
)
}