How to Create React Custom Input & Password Field (show/hide) in 5 minutes
In the previous post, I shared about how I built Paradise UI, a React component library with Monorepo architecture. I split the library into multiple independent component packages so everyone can pick and install only certain components based on their needs.
In this post, I’m going to share about the TextField component, the first component I made when I started Paradise UI. You might want to save or bookmark this for future reference.
In Paradise UI, TextField component is a native <input>
component that is enhanced so it can be used for some use cases quickly, without having to manage the states or add css style.
Without further ado, let’s see how to implement it.
Installation & Basic Usage
Just pick one of the commands below based on your favorite package manager.
@paradise-ui/text-field
export 1 component and 2 functions:
TextField
component itselfdefaultTextFieldElementClass
a function that will generate default classes for all elements inside TextField componenttailwindTextFieldElementClass
a function that will generate tailwind classes for all elements inside TextField component
Default usage
You need to import the style because all Paradise UI components are unstyled by default.
With Tailwind
If you are using Tailwindcss, you don’t need to import the style, but you have to add Paradise UI path into your Tailwindcss config.
Although the documentation for this component is not ready, you can customize and change all props on this page.
Use cases
Now let’s see some use cases where you can implement TextField
component
Size and Variants
TextField component come with 3 sizes (sm
, md
, lg
) and 3 variants (outlined
, filled
, line
). The default size is md
and the default variant is outlined
.
Size
Variants
Input with Helper & Error message
Paradise UI TextField component also allows you to implement form validation logic and show error messages.
Input with Custom label
You can also pass a custom element or React component to label
props to implement TextField component with a custom label.
Input with Custom icon, prefix & suffix
Like label
, prefix
, and suffix
props are also able to accept custom elements, making them customizable.
Show/Hide Password Field
Showing and hiding password input can also be implemented by changing the type
props upon clicking the custom suffix
.
Advanced Customization
Since all Paradise UI components are unstyled by default, you can entirely implement your custom style. You can refer to style.scss
file before you write your custom css.
You can also change the element class by making a custom element class generator. Since I haven’t completed the documentation yet, you can refer to Alert customization documentation to create a custom element class.
Feedback
This component, along with another component in Paradise UI still in development. Feedback is greatly appreciated for the improvement of this project.
Please kindly give me feedback through a comment section below :smile:.
Thank you, have a good day.