Improve input customization

This commit is contained in:
IRBorisov 2023-08-10 14:13:34 +03:00
parent 535c45e50f
commit 05a7ed215b
2 changed files with 18 additions and 24 deletions

View File

@ -1,24 +1,20 @@
import { TextareaHTMLAttributes } from 'react';
import Label from './Label'; import Label from './Label';
interface TextAreaProps { interface TextAreaProps
id: string extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'className'> {
label: string label: string
required?: boolean
disabled?: boolean
spellCheck?: boolean
placeholder?: string
widthClass?: string widthClass?: string
rows?: number colorClass?: string
value?: string | ReadonlyArray<string> | number | undefined;
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void
onFocus?: () => void
} }
function TextArea({ function TextArea({
id, label, placeholder, id, label, required,
required, spellCheck, disabled, widthClass = 'w-full',
widthClass = 'w-full', rows = 4, value, colorClass = 'colorClass',
onChange, onFocus rows = 4,
...props
}: TextAreaProps) { }: TextAreaProps) {
return ( return (
<div className='flex flex-col items-start [&:not(:first-child)]:mt-3'> <div className='flex flex-col items-start [&:not(:first-child)]:mt-3'>
@ -28,15 +24,10 @@ function TextArea({
htmlFor={id} htmlFor={id}
/> />
<textarea id={id} <textarea id={id}
className={`px-3 py-2 mt-2 leading-tight border shadow clr-input ${widthClass}`} className={`px-3 py-2 mt-2 leading-tight border shadow ${colorClass} ${widthClass}`}
rows={rows} rows={rows}
placeholder={placeholder}
required={required} required={required}
value={value} {...props}
onChange={onChange}
onFocus={onFocus}
disabled={disabled}
spellCheck={spellCheck}
/> />
</div> </div>
); );

View File

@ -3,14 +3,17 @@ import { type InputHTMLAttributes } from 'react';
import Label from './Label'; import Label from './Label';
interface TextInputProps interface TextInputProps
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'className'> { extends Omit<InputHTMLAttributes<HTMLInputElement>, 'className'> {
id: string id: string
label: string label: string
widthClass?: string widthClass?: string
colorClass?: string
} }
function TextInput({ function TextInput({
id, required, label, widthClass = 'w-full', id, required, label,
widthClass = 'w-full',
colorClass = 'clr-input',
...props ...props
}: TextInputProps) { }: TextInputProps) {
return ( return (
@ -21,7 +24,7 @@ function TextInput({
htmlFor={id} htmlFor={id}
/> />
<input id={id} <input id={id}
className={`px-3 py-2 mt-2 leading-tight border shadow truncate hover:text-clip clr-input ${widthClass}`} className={`px-3 py-2 mt-2 leading-tight border shadow truncate hover:text-clip ${colorClass} ${widthClass}`}
required={required} required={required}
{...props} {...props}
/> />