
* Added Short Unique ID npm library * Added unique ID to form-control * Added unique ID to form-group * Unique ID added to <form> * Added unique IDs to control components * Added IDs to label and fieldset * Update Form.astro with requested changes Co-authored-by: Ayo Ayco <ayo@ayco.io> * Adjustments for requested changes. Co-authored-by: Ayo Ayco <ayo@ayco.io>
47 lines
806 B
Text
47 lines
806 B
Text
---
|
|
/**
|
|
* DROPDOWN COMPONENT
|
|
*/
|
|
import type { Dropdown, ControlOption } from '@astro-reactive/common';
|
|
|
|
export interface Props {
|
|
control: Dropdown;
|
|
readOnly?: boolean;
|
|
}
|
|
|
|
const { control, readOnly } = Astro.props;
|
|
|
|
const options = control.options.map((option: string | ControlOption) => {
|
|
if (typeof option === 'string') {
|
|
return {
|
|
label: option,
|
|
value: option,
|
|
};
|
|
}
|
|
return option;
|
|
});
|
|
---
|
|
|
|
<select
|
|
name={control.name}
|
|
id={control.id}
|
|
disabled={readOnly || null}
|
|
>
|
|
{
|
|
control?.placeholder && (
|
|
<option value="" disabled selected={!control?.value}>
|
|
{control.placeholder}
|
|
</option>
|
|
)
|
|
}
|
|
{
|
|
options.map((option: ControlOption) => (
|
|
<option
|
|
value={option.value}
|
|
selected={option.value === control.value}
|
|
>
|
|
{option.label}
|
|
</option>
|
|
))
|
|
}
|
|
</select>
|