- add Timestamp component with moment relative time and ISO tooltip - add Timestamp stories (JustNow, MinutesAgo, HoursAgo, DaysAgo, MonthsAgo) - add ESLint 10 with typescript-eslint, react-hooks, react-refresh, prettier - add Prettier config with singleQuote, semi, trailingComma all, printWidth 100 - add lint, lint:fix, format, test:storybook scripts to package.json - fix react-hooks/set-state-in-effect in all page components - auto-fix 113 Prettier formatting issues across src and .storybook
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import React, { useId } from 'react';
|
|
import styles from './Input.module.css';
|
|
|
|
export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'id'> {
|
|
label?: string;
|
|
hint?: string;
|
|
error?: string;
|
|
}
|
|
|
|
export function Input({ label, hint, error, className, ...props }: InputProps) {
|
|
const id = useId();
|
|
return (
|
|
<div className={styles.wrapper}>
|
|
{label && (
|
|
<label htmlFor={id} className={styles.label}>
|
|
{label}
|
|
</label>
|
|
)}
|
|
<input
|
|
id={id}
|
|
className={[styles.input, error ? styles.hasError : '', className]
|
|
.filter(Boolean)
|
|
.join(' ')}
|
|
aria-describedby={error ? `${id}-error` : hint ? `${id}-hint` : undefined}
|
|
aria-invalid={error ? true : undefined}
|
|
{...props}
|
|
/>
|
|
{error ? (
|
|
<span id={`${id}-error`} className={styles.error} role="alert">
|
|
{error}
|
|
</span>
|
|
) : hint ? (
|
|
<span id={`${id}-hint`} className={styles.hint}>
|
|
{hint}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|