Getting Started
Components
- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- ChatButton
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- FormCheckbox
- Form Control
- Form Label
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Select
- SidebarLayout
- Spinner
- Switch
- Tabs
- Tag
- TextField
- ValidationMessage
At least 12 characters
At least one lowercase
At least one uppercase
At least one special character #$%&'()*
At least one number
'use client';
import { Password } from '@/ui/forms/password/Password';
export function PasswordDemo() {
return (
<Password
label="Password"
description="Enter your password"
placeholder="Enter password"
validationMessages={[
{
label: 'At least 12 characters',
status: 'success',
},
{
label: 'At least one lowercase',
status: 'success',
},
{
label: 'At least one uppercase',
status: 'error',
},
{
label: "At least one special character #$%&'()*",
status: 'error',
},
{
label: 'At least one number',
status: 'error',
},
]}
/>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/password.json
Usage
'use client';
import { useState } from 'react';
import { Password } from '@/docs/lib/ui/forms/password/password';
export function Component() {
const [password, setPassword] = useState('');
const validationMessages = [
{
label: 'At least 8 characters',
status: password.length >= 8 ? 'success' : 'default',
},
{
label: 'Contains uppercase letter',
status: /[A-Z]/.test(password) ? 'success' : 'default',
},
{
label: 'Contains number',
status: /\d/.test(password) ? 'success' : 'default',
},
];
return (
<Password
label="Password"
description="Create a secure password"
value={password}
onChange={(name, value) => setPassword(value)}
validationMessages={validationMessages}
required
/>
);
}API Reference
Password
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | undefined | The label text displayed above the input field. |
description | string | undefined | Optional helper text displayed below the label to provide additional context. |
id | string | Auto-generated | Unique identifier for the input element. Auto-generated if not provided. |
name | string | Same as id | The name attribute for the input field, used in form submissions. Defaults to the id value. |
value | string | undefined | The current value of the password field. |
onChange | (name: string, value: string) => void | undefined | Callback function invoked when the value changes. Receives the field name and new value. |
disabled | boolean | false | If true, disables the input field and hides the visibility toggle button. |
required | boolean | false | If true, marks the field as required with an asterisk indicator. |
hideRequiredStar | boolean | false | If true, hides the asterisk indicator even when the field is required. |
validationStatus | "default" | "error" | "success" | "default" | Visual state of the field indicating validation status. Shows check or error icons accordingly. |
errorMessage | string | undefined | Error message displayed below the input when validationStatus is set to "error". |
validationMessages | ValidationMessage[] | [] | Array of validation rules with status indicators displayed below the input field. |
withoutFieldValidation | boolean | false | If true, disables field-level validation styling and error message display while preserving other features. |
dataTestId | string | "Password" | Test identifier for the component, used for testing purposes. |
className | string | undefined | Additional CSS classes to apply to the FormControl container. |
ValidationMessage
| Prop | Type | Description |
|---|---|---|
label | string | The text describing the validation rule. |
status | "default" | "error" | "success" | The current status of the validation rule, which determines the icon and color. |
The Password component also supports all standard HTML input attributes via InputHTMLAttributes<HTMLInputElement>.
Notes
- Show/Hide Toggle: The component includes a visibility toggle button (eye icon) that allows users to switch between masked (
type="password") and visible (type="text") password display. The icon changes from "Invisible" to "Visible" based on the current state. - Automatic Type Reset: When the field is disabled, the input type automatically resets to "password" to ensure security.
- Validation Messages: The
validationMessagesprop accepts an array of validation rules with individual status tracking. Each message displays with an icon (edit, error, or check) and color-coded text (grey, red, or green) based on its status. - Without Field Validation: When
withoutFieldValidationis true, the component hides validation icons and error messages, maintaining a clean default appearance while still allowing custom validation messages to be displayed. - FormControl Integration: Password uses the FormControl component internally, inheriting features like labels, descriptions, error messages, and validation states.
- Validation Icons: When
validationStatusis "error" or "success", appropriate icons (cross or check) appear inside the input field on the right side, before the visibility toggle button. - Disabled State: When disabled, the visibility toggle button is hidden, the input type is locked to "password", the field shows a grey background (
bg-pearl text-grey), and user interaction is prevented. - Automatic ID Generation: If no
idprop is provided, a unique ID is automatically generated using React'suseIdhook. - Value Management: The component uses the internal
useValuehook for state management, which handles value formatting and change callbacks. - Client Component: This component must be used in a client component context (
"use client"). - Accessibility: The input field includes an
aria-labelattribute set to the field name for screen reader support. - Data Attributes: The component includes
data-name="Password"anddata-testidattributes for testing and debugging. - Rounded Pill Design: The input has a rounded pill shape with consistent padding and border styling.
- Dynamic Padding: The input padding adjusts based on whether validation icons are displayed (more padding on the right when icons are present).