astro-reactive-form/packages/form/components/controls/TextArea.astro
Alexander Samaniego 93a8d49f0a
feat(form): implement unique IDs (#182)
* 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>
2022-11-08 08:53:22 +01:00

39 lines
836 B
Text

---
/**
* TEXT AREA COMPONENT
*/
import type { TextArea } from '@astro-reactive/common';
export interface Props {
control: TextArea;
readOnly?: boolean;
}
const { control, readOnly = false } = Astro.props;
const { validators = [] } = control;
const validatorAttributes: Record<string, string> = validators?.reduce((prev, validator) => {
const split: string[] = validator.split(':');
const label: string = `data-${split[0]}` || 'invalid';
const value: string | null = split.length > 1 ? split[1] ?? null : 'true';
return {
...prev,
[label]: value,
};
}, {});
---
<textarea
name={control.name}
id={control.id}
placeholder={control?.placeholder}
rows={control?.rows ?? 3}
cols={control?.cols ?? 21}
data-label={control?.label}
readonly={readOnly || null}
{...validatorAttributes}
>
{ control.value }
</textarea>