Skip to main content

Password

A basic widget for getting the user password input.

import { Password } from "rizzui";

Default

The default style of Password component.

import { Password } from "rizzui";

export default function App() {
return (
<Password
label="Password"
placeholder="Enter your password"
/>
);
}

Variants

You can change the style of Password using variant property.

import { Password } from "rizzui";

export default function App() {
return (
<>
<Password
label="Outline"
placeholder="Enter your password"
variant="outline"
/>
<Password
label="Flat"
placeholder="Enter your password"
variant="flat"
/>
<Password
label="Text"
placeholder="Enter your password"
variant="text"
/>
</>
);
}

Sizes

You can change the style of Password using size property.

import { Password } from "rizzui";

export default function App() {
return (
<>
<Password
label="Small"
placeholder="Enter your password"
size="sm"
/>
<Password
label="Default"
placeholder="Enter your password"
/>
<Password
label="Large"
placeholder="Enter your password"
size="lg"
/>
<Password
label="Extra Large"
placeholder="Enter your password"
size="xl"
/>
</>
);
}

Rounded

You can change the style of Password using rounded property.

import { Password } from "rizzui";

export default function App() {
return (
<>
<Password
label="Rounded None"
placeholder="Enter your password"
rounded="none"
/>
<Password
label="Rounded Small"
placeholder="Enter your password"
rounded="sm"
/>
<Password
label="Rounded Default"
placeholder="Enter your password"
/>
<Password
label="Rounded Large"
placeholder="Enter your password"
rounded="lg"
/>
<Password
label="Rounded Full"
placeholder="Enter your password"
rounded="pill"
/>
</>
);
}

Prefix & Visibility Icon

You can change the style of Password using prefix, visibilityToggleIcon property.

import { Password } from "rizzui";
import { LockClosedIcon, LockOpenIcon } from "@heroicons/react/24/outline";

export default function App() {
return (
<>
<Password
label="Password"
placeholder="Enter your password"
prefix={<LockClosedIcon className="h-[18px] w-[18px]" />}
/>
<Password
label="Custom Visibility Icon"
placeholder="Enter your password"
visibilityToggleIcon={(visible) =>
visible ? (
<LockOpenIcon className="h-auto w-5" />
) : (
<LockClosedIcon className="h-auto w-5" />
)
}
/>
</>
);
}

With Clearable Button

You can create clearable Password using clearable property.

import { useState } from "react";
import { Password } from "rizzui";

export default function App() {
const [state, setState] = useState("my_password");

return (
<>
<Password
label="Password"
value={state}
clearable={true}
onClear={() => setState("")}
onChange={(e) => setState(e.target.value)}
placeholder="Your password"
/>
</>
);
}

Disabled

You can disable Password using disabled. Disabled password fileds does not have any effect of property color property.

import { Password } from "rizzui";

export default function App() {
return (
<Password
label="Active Disabled"
placeholder="Enter you passwrod"
color="primary"
disabled
/>
);
}

With Helper Text

You can show help text to Password using helperText property.

import { Password } from "rizzui";

export default function App() {
return (
<Password
label="Password"
placeholder="Enter your password"
helperText="This is helper text"
/>
);
}

With Error Message

You can show the validation error message using error property.

import { Password } from "rizzui";

export default function App() {
return (
<Password
label="Password"
placeholder="Enter your password"
error="This field is required."
/>
);
}

With External State

You can manage visibility state externally using isPasswordVisible.

import React from "react";
import { Password, Flex, Button } from "rizzui";

export default function App() {
const [showPassword, setShowPassword] = React.useState(false);
return (
<Flex
align="end"
justify="center"
>
<Password
label="Visibility Toggle from outside"
placeholder="Your password"
hideVisibilityToggleIcon
isPasswordVisible={showPassword}
className="grow"
/>
<Button onClick={() => setShowPassword(!showPassword)}>
{showPassword ? "Hide" : "Show"}
</Button>
</Flex>
);
}

API Reference


Password Props

Here is the API documentation of the Password component. And the rest of the props are the same as the original html input field type password.

PropsTypeDescriptionDefault
labelReactNodeSet field label__
labelWeightLabelWeightSet label font weight"medium"
placeholderstringSet input placeholder text__
variantPasswordVariantsThe variants of the component are:"outline"
sizePasswordSizesThe size of the component. "sm" is equivalent to the dense input styling."md"
roundedPasswordRoundedsThe rounded variants are:"md"
disabledbooleanWhether the input is disabled or not__
clearablebooleanAdd clearable option__
hideVisibilityToggleIconbooleanHides visibility toggle icon__
isPasswordVisiblebooleanControl password visibility from outside.__
onClearPasswordOnclearclear event__
prefixReactNodeThe prefix is design for adding any icon or text on the Input field's start (it's a left icon for the ltr and right icon for the rtl)__
visibilityToggleIcon((visible: boolean) => ReactNode)It is the password visibility toggle icon.__
helperTextReactNodeAdd helper text. It could be string or a React component__
errorstringShow error message using this prop__
labelClassNamestringOverride default CSS style of label__
inputClassNamestringOverride default CSS style of input__
prefixClassNamestringOverride default CSS style of prefix__
visibilityToggleIconClassNamestringOverride default CSS style of password show/hide toggle icon__
helperClassNamestringOverride default CSS style of helperText__
errorClassNamestringOverride default CSS style of error message__
classNamestringAdd custom classes to the root of the component__
refRef<HTMLInputElement>__
...InputHTMLAttributesnative props like value, onChange, onFocus, onBlur ...__

Password Variants

type PasswordVariants = "outline" | "flat" | "text";

Label Weight

type LabelWeight = "normal" | "medium" | "semibold" | "bold";

Password Sizes

type PasswordSizes = "sm" | "md" | "lg" | "xl";

Password Rounded

type PasswordRounded = "sm" | "md" | "lg" | "none" | "pill";

Password onClear

type PasswordOnclear = (event) => void;