34 lines
971 B
Text
34 lines
971 B
Text
---
|
|
/**
|
|
* DEFAULT CONTROL COMPONENT
|
|
*/
|
|
import type { Radio } from '@astro-reactive/common';
|
|
import type { FormControl } from '../core/form-control';
|
|
import Input from './controls/Input.astro';
|
|
import RadioGroup from './controls/RadioGroup.astro';
|
|
import Errors from './Errors.astro';
|
|
import Label from './Label.astro';
|
|
|
|
export interface Props {
|
|
control: FormControl;
|
|
showValidationHints: boolean;
|
|
showErrors?: boolean; // feature flag for showing validation errors
|
|
}
|
|
|
|
const { control, showValidationHints, showErrors = false } = Astro.props;
|
|
|
|
const hasErrors: boolean | null = !!control.errors?.length;
|
|
---
|
|
|
|
<div class="field" data-validator-haserrors={hasErrors ? hasErrors.toString() : null}>
|
|
<Label control={control} showValidationHints={showValidationHints}>
|
|
{
|
|
control.type === 'radio' ? (
|
|
<RadioGroup control={control as Radio} />
|
|
) : (
|
|
<Input control={control} />
|
|
)
|
|
}
|
|
{showErrors && <Errors errors={control.errors} />}
|
|
</Label>
|
|
</div>
|