Skip to main content

Password

A basic widget for getting the user password input.

'use client';

import { Password } from 'rizzui/password';

Default​

The default style of Password component.

'use client';

import { Password } from 'rizzui/password';

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

Variants​

You can change the style of Password using variant property.

'use client';

import { Password } from 'rizzui/password';

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.

'use client';

import { Password } from 'rizzui/password';

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" />
</>
);
}

Prefix & Visibility Icon​

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

'use client';

import { Password } from 'rizzui/password';
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.

'use client';

import { useState } from 'react';
import { Password } from 'rizzui/password';

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 property.

'use client';

import { Password } from 'rizzui/password';

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

With Helper Text​

You can show help text to Password using helperText property.

This is helper text
'use client';

import { Password } from 'rizzui/password';

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.

'use client';

import { Password } from 'rizzui/password';

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.

'use client';

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"
disabledbooleanWhether the input is disabled or not__
clearablebooleanAdd clearable option__
hideVisibilityToggleIconbooleanHides visibility toggle icon__
isPasswordVisiblebooleanControl password visibility from outside.__
onClearPasswordOnclearCallback function called when the clear button is clicked__
prefixReactNodeThe prefix is designed 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)Custom password visibility toggle icon. Receives the current visibility state as a parameter.__
helperTextReactNodeAdd helper text. Can be a 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';

Password onClear​

type PasswordOnclear = (event) => void;