Files
ims/components/ui/field.tsx

30 lines
1.1 KiB
TypeScript

import type { InputHTMLAttributes, ReactNode, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react'
import { cx } from './cx'
export const INPUT_CLASS =
'w-full h-9 px-3 rounded-md bg-surface text-[13px] text-ink caret-accent shadow-input ' +
'placeholder:text-faint disabled:opacity-45 disabled:cursor-not-allowed'
export function Field({ label, htmlFor, children }: { label: string; htmlFor: string; children: ReactNode }) {
return (
<div>
<label htmlFor={htmlFor} className="block text-xs text-muted mb-[5px]">
{label}
</label>
{children}
</div>
)
}
export function Input({ className, ...rest }: InputHTMLAttributes<HTMLInputElement>) {
return <input className={cx(INPUT_CLASS, className)} {...rest} />
}
export function Textarea({ className, ...rest }: TextareaHTMLAttributes<HTMLTextAreaElement>) {
return <textarea className={cx(INPUT_CLASS, 'h-auto min-h-[90px] py-2 resize-y', className)} {...rest} />
}
export function Select({ className, ...rest }: SelectHTMLAttributes<HTMLSelectElement>) {
return <select className={cx(INPUT_CLASS, className)} {...rest} />
}