Skip to content

Commit

Permalink
Improve required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Dec 18, 2024
1 parent 7115e4d commit c33948b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion web/src/components/input/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ export const BaseInput = ({
errorMessage,
description,
width = 'fit',
required,
...rest
}: BaseInputProperties) => {
const id = useId();

return (
<div className="space-y-2 w-full">
{label && <Label htmlFor={id}>{label}</Label>}
{label && (
<Label htmlFor={id}>
{label}
{required && (
<span
className={clsx('', errorMessage && 'text-red-500')}
>
*
</span>
)}
</Label>
)}
<div
className={clsx(
'flex items-stretch justify-start gap-2',
Expand All @@ -44,6 +56,7 @@ export const BaseInput = ({
width === 'full' && 'w-full'
)}
onChange={(event) => onChange?.(event.target.value)}
required={required}
{...rest}
/>
</div>
Expand Down
6 changes: 6 additions & 0 deletions web/src/routes/settings/fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ const FieldDefinitionEditor = ({
<BaseInput
label="Definition ID"
name="definition_id"
placeholder="battery_capacity"
value={field.state.value}
onChange={field.handleChange}
onBlur={field.handleBlur}
width="full"
readOnly={!!fieldDef}
errorMessage={field.state.meta.errors.join(', ')}
required
/>
)}
</form.Field>
Expand All @@ -105,11 +107,13 @@ const FieldDefinitionEditor = ({
<BaseInput
label="Name"
name="name"
placeholder="Battery Capacity"
value={field.state.value}
onChange={field.handleChange}
onBlur={field.handleBlur}
width="full"
errorMessage={field.state.meta.errors.join(', ')}
required
/>
)}
</form.Field>
Expand All @@ -119,6 +123,7 @@ const FieldDefinitionEditor = ({
<BaseInput
label="Description"
name="description"
placeholder="The capacity of the battery in mAh"
value={field.state.value}
onChange={field.handleChange}
onBlur={field.handleBlur}
Expand All @@ -133,6 +138,7 @@ const FieldDefinitionEditor = ({
<BaseInput
label="Placeholder"
name="placeholder"
placeholder="Capacity (ex 500mAh)"
value={field.state.value}
onChange={field.handleChange}
onBlur={field.handleBlur}
Expand Down

0 comments on commit c33948b

Please sign in to comment.