I have created an Input component that contains a label.
Since it was created as a component for text input, the type of input element is limited to text format.
Base
- Node.js:20.8.0
- TypeScript:5.2.2
- React:18.2.0
- Next.js:13.5.4
Other major libraries
This application/site was created as a submission to a DevChallenges challenge. The challenge was to build an application to complete the given user stories.
- User story: I can see error state
- User story: I can choose to disable input
- User story: I can choose to have helper text
- User story: I can choose to have an icon on the left or right (Use Google Icon and at least 5 variants)
- User story: I can have different input sizes
- User story: I can have different colors
- User story: I can choose to have input take the width of the parent
- User story: I can have multiline input like a textarea
- User story: When I hover or focus, I can see visual indicators
- User story: I can still access all input attributes → ※1
- User story (optional): Show input in a similar way like the design or use Storybook. Otherwise, showing the input in multiple states is enough
※1:
excluded some props whose settings conflict with custom props.
Also, Since it was created as a component for text input, the type of input element is limited to text format.
// Input Component
type InputType = 'text' | 'email' | 'password' | 'search' | 'tel' | 'url';
type InputProps = (
| (Omit<ComponentPropsWithRef<'input'>, 'size' | 'type'> & {
multiline?: false;
row?: undefined;
})
| (Omit<ComponentPropsWithRef<'textarea'>, 'rows' | 'cols'> & {
multiline: true;
row?: number;
})
) & {
type?: InputType;
error?: boolean;
size?: Size;
fullWidth?: boolean;
color?: Color;
label?: string;
helperText?: string;
startIcon?: IconName;
endIcon?: IconName;
};
To clone and run this application, you'll need Git and Node.js (which comes with npm) installed on your computer. From your command line:
# Clone this repository
git clone https://github.com/h-yoshikawa44/input-component.git
or
git clone git@github.com:h-yoshikawa44/input-component.git
# Install dependencies
npm install
# Run the app
npm run dev
ComponentPropsWithRef
makes it easy to get prop type information for existing elements such asinput
.- How to style a parent element when the child element has focus.
- How to make the hover of the parent element work when the child element is hovered.
- Types of css pseudo-classes that I was only partially aware of so far.
- How to create an input component with an icon inside.
- Material UI
- 実践プロトタイピング Wevフロントエンド&バックエンドでプロトタイピング ※書籍
- CSS疑似クラスを活用した、モダンでインタラクティブなフォームの作り方
- 子要素にhoverやclickがあったときに親要素に反応させたい
- Website:h-yoshikawa44.com
- GitHub:@h-yoshikawa44
- Twitter:@yoshi44_lion