Files
kycnotme/web/src/components/InputTextArea.astro

38 lines
1.1 KiB
Plaintext
Raw Normal View History

2025-05-19 10:23:36 +00:00
---
2025-05-19 16:57:10 +00:00
import { omit } from 'lodash-es'
2025-05-19 10:23:36 +00:00
import { cn } from '../lib/cn'
import { baseInputClassNames } from '../lib/formInputs'
import InputWrapper from './InputWrapper.astro'
2025-05-19 16:57:10 +00:00
import type { ComponentProps, HTMLAttributes } from 'astro/types'
2025-05-19 10:23:36 +00:00
2025-05-19 16:57:10 +00:00
type Props = Omit<ComponentProps<typeof InputWrapper>, 'children' | 'inputId' | 'required'> & {
inputProps?: Omit<HTMLAttributes<'textarea'>, 'name'>
2025-05-19 10:23:36 +00:00
value?: string
}
2025-05-19 16:57:10 +00:00
const { inputProps, value, ...wrapperProps } = Astro.props
2025-05-19 10:23:36 +00:00
2025-05-19 16:57:10 +00:00
const inputId = inputProps?.id ?? Astro.locals.makeId(`input-${wrapperProps.name}`)
2025-05-19 10:23:36 +00:00
const hasError = !!wrapperProps.error && wrapperProps.error.length > 0
---
2025-05-19 16:57:10 +00:00
<InputWrapper inputId={inputId} required={inputProps?.required} {...wrapperProps}>
2025-05-19 10:23:36 +00:00
<textarea
transition:persist
2025-05-19 16:57:10 +00:00
{...omit(inputProps, ['class', 'id', 'name'])}
2025-05-19 10:23:36 +00:00
id={inputId}
class={cn(
baseInputClassNames.input,
baseInputClassNames.textarea,
2025-05-19 16:57:10 +00:00
inputProps?.class,
2025-05-19 10:23:36 +00:00
hasError && baseInputClassNames.error,
2025-05-19 16:57:10 +00:00
!!inputProps?.disabled && baseInputClassNames.disabled
2025-05-19 10:23:36 +00:00
)}
2025-05-21 07:03:39 +00:00
name={wrapperProps.name}
set:text={value}
/>
2025-05-19 10:23:36 +00:00
</InputWrapper>