Reset Password Block
The ResetPassword Component is a fully customizable and accessible reset password form built with React, TypeScript, and MUI. It provides a complete password reset interface with modern design patterns, dual-view support for both request and confirmation flows, and flexible customization options.
π Installationβ
npm install @nodeblocks/frontend-reset-password-block@0.2.0
π Usageβ
import {ResetPassword} from '@nodeblocks/frontend-reset-password-block';
- Basic Usage
- Confirm Password View
- Advanced Usage
function SimpleResetPasswordRequest() { const handleSendRequest = (data) => { console.log('Password reset request sent for:', data); }; const handleResetPassword = (data) => { console.log('Password reset:', data); }; return ( <ResetPassword view="request" resetPasswordTitle="Reset Password" description="Enter your email to receive a password reset link" gotoSigninMessage="Remember your password? Sign in" onSendRequest={handleSendRequest} onResetPassword={handleResetPassword} sx={{maxWidth: 400, mx: 'auto', p: 3}} > <ResetPassword.Title /> <ResetPassword.Description /> <ResetPassword.Form> <ResetPassword.Form.EmailField /> <ResetPassword.Form.ResetPasswordButton>Send Reset Link</ResetPassword.Form.ResetPasswordButton> </ResetPassword.Form> <ResetPassword.Goto /> </ResetPassword> ); }
function SimpleResetPasswordConfirm() { const handleSendRequest = (data) => { console.log('Request:', data); }; const handleResetPassword = (data) => { console.log('Password reset:', data); }; return ( <ResetPassword view="confirm_password" resetPasswordTitle="Create New Password" description="Enter your new password below" onSendRequest={handleSendRequest} onResetPassword={handleResetPassword} sx={{maxWidth: 400, mx: 'auto', p: 3}} > <ResetPassword.Title /> <ResetPassword.Description /> <ResetPassword.Form> <ResetPassword.Form.PasswordField /> <ResetPassword.Form.ConfirmPasswordField /> <ResetPassword.Form.ResetPasswordButton>Reset Password</ResetPassword.Form.ResetPasswordButton> </ResetPassword.Form> </ResetPassword> ); }
function AdvancedResetPassword() { const [showPassword, setShowPassword] = useState(false); const handleSendRequest = (data) => { console.log('Sending reset email:', data); }; const handleResetPassword = (data) => { console.log('Resetting password:', data); }; return ( <ResetPassword view="confirm_password" resetPasswordTitle="Reset Your Password" description="Create a strong password to secure your account" onSendRequest={handleSendRequest} onResetPassword={handleResetPassword} showPassword={showPassword} onShowPasswordClick={setShowPassword} sx={{ maxWidth: 480, mx: 'auto', p: 0, }} > {({defaultBlocks, defaultBlockOrder}) => { const customHeader = ( <div style={{ textAlign: 'center', marginBottom: '32px', padding: '32px 24px', background: 'linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%)', borderRadius: '24px 24px 0 0', }} > <div style={{ width: '72px', height: '72px', borderRadius: '20px', background: 'rgba(255,255,255,0.2)', display: 'flex', alignItems: 'center', justifyContent: 'center', margin: '0 auto 20px', fontSize: '32px', }} > π </div> <h1 style={{ color: '#ffffff', fontSize: '28px', fontWeight: '700', margin: '0 0 8px 0', }} > Reset Your Password </h1> <p style={{ color: 'rgba(255,255,255,0.8)', fontSize: '15px', margin: 0, }} > Create a strong password to secure your account </p> </div> ); const passwordRequirements = ( <div style={{ padding: '16px', background: '#f8fafc', borderRadius: '12px', marginBottom: '24px', }} > <p style={{ fontSize: '13px', fontWeight: '600', color: '#475569', margin: '0 0 12px 0', }} > Password must contain: </p> <ul style={{ margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: '8px', }} > {[ 'At least 8 characters', 'One uppercase letter', 'One lowercase letter', 'One number', 'One special character', ].map((req, i) => ( <li key={i} style={{ display: 'flex', alignItems: 'center', gap: '8px', fontSize: '13px', color: '#10b981', }} > <span>β</span> {req} </li> ))} </ul> </div> ); const styledForm = ( <ResetPassword.Form sx={{ px: 3, pb: 3, }} > <ResetPassword.Form.PasswordField sx={{ mb: 2, '& .MuiOutlinedInput-root': { borderRadius: '12px', bgcolor: '#f8fafc', '&:hover .MuiOutlinedInput-notchedOutline': { borderColor: '#6366f1', }, '&.Mui-focused .MuiOutlinedInput-notchedOutline': { borderColor: '#6366f1', borderWidth: '2px', }, }, }} /> {passwordRequirements} <ResetPassword.Form.ConfirmPasswordField sx={{ mb: 3, '& .MuiOutlinedInput-root': { borderRadius: '12px', bgcolor: '#f8fafc', '&:hover .MuiOutlinedInput-notchedOutline': { borderColor: '#6366f1', }, '&.Mui-focused .MuiOutlinedInput-notchedOutline': { borderColor: '#6366f1', borderWidth: '2px', }, }, }} /> <ResetPassword.Form.ResetPasswordButton sx={{ py: 1.5, borderRadius: '12px', fontSize: '16px', fontWeight: '600', textTransform: 'none', background: 'linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%)', boxShadow: '0 4px 14px rgba(99, 102, 241, 0.4)', '&:hover': { background: 'linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%)', boxShadow: '0 6px 20px rgba(99, 102, 241, 0.5)', }, }} > Reset Password </ResetPassword.Form.ResetPasswordButton> </ResetPassword.Form> ); return { blocks: { ...defaultBlocks, title: customHeader, description: <></>, form: styledForm, }, blockOrder: defaultBlockOrder, }; }} </ResetPassword> ); }
π§ Props Referenceβ
Main Component Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
view | 'request' | 'confirm_password' | Required | Determines which view to display - either email request form or password confirmation form |
onSendRequest | (data: T) => void | Required | Callback function triggered when reset request is submitted |
onResetPassword | (data: T) => void | Required | Callback function triggered when new password is submitted |
resetPasswordTitle | ReactNode | "Reset Password" | Title content for the reset password form |
description | ReactNode | "Please enter your email address you registered" | Description text displayed below the title |
gotoSigninMessage | ReactNode | Default signin link | Content for the navigation link section |
showPassword | boolean | false | Controls password field visibility (managed internally by default) |
onShowPasswordClick | (show: boolean) => void | Internal handler | Callback for password visibility toggle |
className | string | undefined | Additional CSS class name for styling the form container |
sx | SxProps | undefined | MUI sx prop for custom styling |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: This component extends MUI StackProps (excluding children and onSubmit). Default spacing is 4, with py: 6 and px: 5 padding.
Sub-Componentsβ
The ResetPassword component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
ResetPassword.Titleβ
| Prop | Type | Default | Description |
|---|---|---|---|
resetPasswordTitle | ReactNode | From context | Title content |
children | ReactNode | "Reset Password" | Custom title content (overrides resetPasswordTitle) |
className | string | undefined | Additional CSS class name for styling |
variant | string | "h4" | MUI Typography variant |
component | string | "h1" | HTML element to render |
sx | SxProps | undefined | MUI sx prop with default textAlign: 'center' |
Note: This component extends MUI TypographyProps.
ResetPassword.Descriptionβ
| Prop | Type | Default | Description |
|---|---|---|---|
description | ReactNode | From context | Description content |
children | ReactNode | "Please enter your email address you registered" | Custom description content |
className | string | undefined | Additional CSS class name for styling |
variant | string | "body2" | MUI Typography variant |
sx | SxProps | undefined | MUI sx prop with default textAlign: 'center' |
Note: This component extends MUI TypographyProps.
ResetPassword.Formβ
| Prop | Type | Default | Description |
|---|---|---|---|
view | 'request' | 'confirm_password' | From context | Determines which fields to display |
onSendRequest | (data: T) => void | From context | Callback for email submission |
onResetPassword | (data: T) => void | From context | Callback for password confirmation |
className | string | undefined | Additional CSS class name for styling |
children | ReactNode | Default form fields | Custom form content |
Note: This component extends MUI StackProps<'form'> with component="form". Default spacing is 4.
ResetPassword.Form.EmailFieldβ
| Prop | Type | Default | Description |
|---|---|---|---|
view | 'request' | 'confirm_password' | From context | Only renders when view === 'request' |
name | string | "email" | Field name used for form data |
label | string | "Email" | Label of the input field |
placeholder | string | "Please enter your email" | Placeholder text |
fullWidth | boolean | true | Whether field takes full width |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI TextFieldProps. Only visible in request view.
ResetPassword.Form.PasswordFieldβ
| Prop | Type | Default | Description |
|---|---|---|---|
view | 'request' | 'confirm_password' | From context | Only renders when view === 'confirm_password' |
showPassword | boolean | From context | Controls password visibility |
onShowPasswordClick | (show: boolean) => void | From context | Toggle password visibility |
name | string | "password" | Field name used for form data |
label | string | "Password" | Label of the input field |
placeholder | string | "Please enter your new password" | Placeholder text |
fullWidth | boolean | true | Whether field takes full width |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI TextFieldProps. Only visible in confirm_password view. Includes visibility toggle icon when showPassword and onShowPasswordClick are provided.
ResetPassword.Form.ConfirmPasswordFieldβ
| Prop | Type | Default | Description |
|---|---|---|---|
view | 'request' | 'confirm_password' | From context | Only renders when view === 'confirm_password' |
showPassword | boolean | From context | Controls password visibility |
onShowPasswordClick | (show: boolean) => void | From context | Toggle password visibility |
name | string | "confirmPassword" | Field name used for form data |
label | string | "Confirm Password" | Label of the input field |
placeholder | string | "Please confirm your password" | Placeholder text |
fullWidth | boolean | true | Whether field takes full width |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI TextFieldProps. Only visible in confirm_password view. Includes visibility toggle icon when showPassword and onShowPasswordClick are provided.
ResetPassword.Form.ResetPasswordButtonβ
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | "Reset Password" | Button text |
variant | string | "contained" | MUI Button variant |
fullWidth | boolean | true | Whether button takes full width |
type | string | "submit" | HTML button type |
className | string | undefined | Additional CSS class name for styling |
Note: This component extends MUI ButtonProps.
ResetPassword.Gotoβ
| Prop | Type | Default | Description |
|---|---|---|---|
gotoSigninMessage | ReactNode | From context | Custom navigation message |
children | ReactNode | Link to /auth/login | Custom content for the navigation section |
className | string | undefined | Additional CSS class name for styling |
variant | string | "body2" | MUI Typography variant |
sx | SxProps | undefined | MUI sx prop with default textAlign: 'center' |
Note: This component extends MUI TypographyProps.
π¨ Configuration examplesβ
Custom Title Stylingβ
<ResetPassword.Title
variant="h3"
sx={{
color: 'primary.main',
fontWeight: 'bold',
}}
>
Forgot Your Password?
</ResetPassword.Title>
Custom Field Labelsβ
<ResetPassword.Form>
<ResetPassword.Form.EmailField
label="Your Email Address"
placeholder="name@example.com"
helperText="We'll send a reset link to this address"
/>
<ResetPassword.Form.PasswordField
label="Create New Password"
placeholder="At least 8 characters"
/>
<ResetPassword.Form.ConfirmPasswordField
label="Confirm New Password"
placeholder="Re-enter your password"
/>
<ResetPassword.Form.ResetPasswordButton>
Send Reset Link
</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
Block Override Patternβ
<ResetPassword view="request" onSendRequest={handleSend} onResetPassword={handleReset}>
{({ defaultBlocks, defaultBlockOrder }) => ({
blocks: {
...defaultBlocks,
// Add custom security notice
securityNote: (
<Alert severity="info" sx={{ textAlign: 'center' }}>
For your security, the reset link expires in 24 hours
</Alert>
),
},
blockOrder: ['title', 'description', 'securityNote', 'form', 'goto'],
})}
</ResetPassword>
Custom Navigation Linkβ
<ResetPassword.Goto>
<span>
Remember your password?{' '}
<Link href="#login" sx={{ fontWeight: 'medium' }}>
Back to Sign In
</Link>
</span>
</ResetPassword.Goto>
Custom Stylingβ
function CustomStyledResetPassword() {
const handleSendRequest = (data) => {
console.log('Request:', data);
};
const handleResetPassword = (data) => {
console.log('Reset:', data);
};
return (
<ResetPassword
view="request"
resetPasswordTitle="Forgot Password?"
description="No worries, we'll send you reset instructions"
gotoSigninMessage="Back to sign in"
onSendRequest={handleSendRequest}
onResetPassword={handleResetPassword}
sx={{
maxWidth: 420,
mx: 'auto',
p: 4,
bgcolor: 'grey.900',
color: 'grey.100',
borderRadius: 3,
}}
>
<ResetPassword.Title
sx={{
mb: 1,
color: 'grey.100',
fontWeight: 700,
}}
/>
<ResetPassword.Description
sx={{
mb: 3,
color: 'grey.400',
}}
/>
<ResetPassword.Form>
<ResetPassword.Form.EmailField
sx={{
mb: 3,
'& .MuiInputLabel-root': {color: 'grey.400'},
'& .MuiOutlinedInput-root': {
color: 'grey.100',
'& .MuiOutlinedInput-notchedOutline': {
borderColor: 'grey.600',
},
'&:hover .MuiOutlinedInput-notchedOutline': {
borderColor: 'primary.main',
},
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
borderColor: 'primary.main',
},
},
}}
/>
<ResetPassword.Form.ResetPasswordButton
sx={{
bgcolor: 'primary.main',
'&:hover': {
bgcolor: 'primary.dark',
},
}}
>
Send Reset Link
</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
<ResetPassword.Goto
sx={{
mt: 3,
textAlign: 'center',
color: 'grey.400',
'& a': {
color: 'primary.light',
},
}}
/>
</ResetPassword>
);
}
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {ResetPassword} from '@nodeblocks/frontend-reset-password-block';
import React, {useState} from 'react';
type ResetPasswordFormData =
| {
email?: string;
}
| {
password?: string;
confirmPassword?: string;
};
function TypedResetPassword() {
const [view, setView] = useState<'request' | 'confirm_password'>('request');
const [showPassword, setShowPassword] = useState(false);
const handleSendRequest = (data: ResetPasswordFormData): void => {
console.log('Sending reset link:', data);
// Simulate API call then switch to confirm view
setTimeout(() => setView('confirm_password'), 1000);
};
const handleResetPassword = (data: ResetPasswordFormData): void => {
console.log('Password reset:', data);
// API call to reset password
};
return (
<ResetPassword
view={view}
resetPasswordTitle={view === 'request' ? 'Reset Password' : 'Create New Password'}
description={
view === 'request' ? 'Enter your email to receive a reset link' : 'Enter and confirm your new password'
}
gotoSigninMessage="Remember your password? Sign in"
onSendRequest={handleSendRequest}
onResetPassword={handleResetPassword}
showPassword={showPassword}
onShowPasswordClick={setShowPassword}
sx={{
maxWidth: 400,
mx: 'auto',
p: 3,
border: '1px solid #e5e7eb',
borderRadius: 2,
}}
>
<ResetPassword.Title />
<ResetPassword.Description />
<ResetPassword.Form>
{view === 'request' ? (
<ResetPassword.Form.EmailField />
) : (
<>
<ResetPassword.Form.PasswordField />
<ResetPassword.Form.ConfirmPasswordField />
</>
)}
<ResetPassword.Form.ResetPasswordButton>
{view === 'request' ? 'Send Reset Link' : 'Reset Password'}
</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
{view === 'request' && <ResetPassword.Goto />}
</ResetPassword>
);
}
π Notesβ
- The component uses MUI's
Stackcomponent as its base, providing flexible layout options - Default spacing is
4with paddingpy: 6andpx: 5 - The
viewprop controls which fields are displayed:'request': Shows only the email field'confirm_password': Shows password and confirm password fields
- Form submission is handled internally via
onSubmitevent - Password visibility toggle is built-in when
showPasswordcontext is available - Password fields include MUI's
Visibility/VisibilityOfficons for toggle - Default blocks are:
title,description,form,goto - CSS classes follow BEM-style naming:
nbb-reset-password,nbb-reset-password-title, etc. - The component centers itself with
margin: 'auto'and hasminWidth: { lg: 496 }on large screens - Default "Back to Sign In" link points to
/auth/login
Built with β€οΈ using React, TypeScript, and MUI.