メインコンテンツまでスキップ

パスワードリセットブロック

ResetPassword コンポーネント は、React と TypeScript で構築された、完全にカスタマイズ可能でアクセシブルなパスワードリセットフォームです。リクエストと確認フローの両方に対応する2つのビュー、モダンなデザインパターン、柔軟なカスタマイズオプションを備えた、完全なパスワードリセット UI を提供します。


🚀 インストール

npm install @nodeblocks/frontend-reset-password-block@0.1.1

📖 使用方法

import {ResetPassword} from '@nodeblocks/frontend-reset-password-block';
function BasicResetPassword() {

const [view, setView] = useState<'request' | 'confirm_password'>('request');

return (
<ResetPassword
view={view}
onSendRequest={formData => {
console.log('Reset request sent:', formData);
setView('confirm_password');
}}
onResetPassword={formData => {
console.log('Password reset:', formData);
setView('request');
}}>
<ResetPassword.Title>
{view === 'request' ? 'Reset Your Password' : 'Confirm Password'}
</ResetPassword.Title>
<ResetPassword.Description>
{view === 'request' ? 'Enter your email to receive reset instructions' : 'Enter your new password'}
</ResetPassword.Description>
<ResetPassword.Form>
<ResetPassword.Form.EmailField label="Email Address" placeholder="Enter your email" />
<ResetPassword.Form.PasswordField label="New Password" placeholder="Enter new password" />
<ResetPassword.Form.ConfirmPasswordField label="Confirm Password" placeholder="Confirm new password" />
<ResetPassword.Form.ResetPasswordButton>Reset Password</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
<ResetPassword.Goto>
<a href="#signin">Back to Sign In</a>
</ResetPassword.Goto>
</ResetPassword>
);
}

🔧 Props リファレンス

メインコンポーネントの props

メインの ResetPassword コンポーネントは、childrenonSubmit を除いて HTML div 要素のすべての props を継承し、さらに次を追加します:

PropTypeDefaultDescription
view'request' | 'confirm_password'RequiredDetermines which view to display - either email request form or password confirmation form
onSendRequest(data: T) => voidRequiredCallback function triggered when reset request is submitted
onResetPassword(data: T) => voidRequiredCallback function triggered when new password is submitted
resetPasswordTitleReactNode"Reset Password"Title content for the reset password form
descriptionReactNode"Please enter your email address you registered"Description text displayed below the title
gotoSigninMessageReactNodeデフォルトのサインインリンクナビゲーションリンクセクションの内容
classNamestringundefinedAdditional CSS class name for styling the form container
directionenum"column"Flex direction for action buttons
alignItemsenum"stretch"Alignment of items in the container
gapSizeenum"S"Gap between items in the container
childrenBlocksOverrideundefinedCustom block components to override default rendering

サブコンポーネント

ResetPassword コンポーネントには、いくつかのサブコンポーネントがあります。すべてのサブコンポーネントはメインコンポーネントのコンテキストからデフォルト値を受け取り、props でそれらを上書きできます。

ResetPassword.Title

PropTypeDefaultDescription
childrenReactNodeコンテキストからタイトルコンテンツ。コンテキストの errorTitle を上書きします
sizeenum"2XL"タイトルの Typography サイズ
typeenum"heading"Typography の type
colorenum"low-emphasis"タイトルのカラーテーマ
weightenum"bold"タイトルの weight
classNamestringundefinedスタイル用の追加 CSS クラス名

ResetPassword.Description

PropTypeDefaultDescription
childrenReactNodeコンテキストからタイトルコンテンツ。コンテキストの errorTitle を上書きします
sizeenum"M"説明の Typography サイズ
typeenum"paragraph"Typography の type
colorenum"low-emphasis"説明のカラーテーマ
weightenum"regular"説明の weight
classNamestringundefinedスタイル用の追加 CSS クラス名

ResetPassword.Form

PropTypeDefaultDescription
view'request' | 'confirm_password'親から継承表示するフィールドを決定します
onSendRequest(data: T) => void親から継承メール送信のコールバック
onResetPassword(data: T) => void親から継承パスワード確認のコールバック
classNamestringundefinedスタイル用の追加 CSS クラス名
childrenReactNodeコンテキストからカスタムのフォーム内容

ResetPassword.Form.EmailField

PropTypeDefaultDescription
namestring"email"フォーム data に使用されるフィールド名
errorTextstringundefined入力欄のエラーテキスト
isDisabledbooleanundefined入力欄が無効かどうか
isRequiredbooleanundefined入力欄が必須かどうか
labelstring"Email"入力欄のラベル
labelWeightenum"bold"ラベルの weight
classNamestringundefinedスタイル用の追加 CSS クラス名

Note: このコンポーネントは、一般的な HTML input 要素の props も追加で継承します。

ResetPassword.Form.PasswordField

PropTypeDefaultDescription
namestring"password"フォーム data に使用されるフィールド名
errorTextstringundefined入力欄のエラーテキスト
isDisabledbooleanundefined入力欄が無効かどうか
isRequiredbooleanundefined入力欄が必須かどうか
labelstring"Password"入力欄のラベル
labelWeightenum"bold"ラベルの weight
classNamestringundefinedスタイル用の追加 CSS クラス名
showPasswordbooleanundefinedパスワードを表示するかどうか
onShowPasswordClickfunctionundefinedパスワード表示切り替えを処理する関数

Note: このコンポーネントは、一般的な HTML input 要素の props も追加で継承します。

ResetPassword.Form.ConfirmPasswordField

PropTypeDefaultDescription
namestring"confirmPassword"Field name used for form data
errorTextstringundefinedError text for the input
isDisabledbooleanundefinedWhether the input is disabled
isRequiredbooleanundefinedWhether the input is required
labelstring"Confirm Password"Label of the input field
labelWeightenum"bold"Label weight
classNamestringundefinedAdditional CSS class name for styling
showPasswordbooleanundefinedWhether to show password
onShowPasswordClickfunctionundefinedFunction to handle password visibility toggle

Note: This component additional inherits some common HTML input element props.

ResetPassword.Form.ResetPasswordButton

PropTypeDefaultDescription
childrenReactNodeコンテキストからボタン内に配置するテキスト
classNamestringundefinedスタイル用の追加 CSS クラス名
fillenum"fill"ボタンの塗りつぶしスタイル
iconenumundefinedボタン左側に表示する任意のアイコン
iconColorenumundefinedボタン左側のアイコンの色。指定しない場合は、fill の種類に応じたデフォルト色が使われます。
isDisabledbooleanfalseボタンが無効で使用できないかどうか
onClickfunctionundefinedボタンのクリックを処理する関数
sizeenum"M"ボタンの縦方向のサイズ
textAlignenum"center"ボタン内でのアイコンとテキストの配置
textColorenum"default"ボタンのテキスト色
textEmphasisbooleanfalseボタンのテキストの太さ
textSizeenum"M"ボタンのテキストサイズ
typeenum"submit"ボタンの用途(HTML type に影響します)

Note: このコンポーネントは、一般的な HTML button 要素の props も追加で継承します。

ResetPassword.Goto

PropTypeDefaultDescription
childrenReactNodeデフォルトのサインインリンクナビゲーションリンクセクションの内容。通常はアンカータグを含みます
classNamestringundefinedスタイル用の追加 CSS クラス名

🔧 TypeScript サポート

包括的な型定義を備えた完全な TypeScript サポート:

import {ResetPassword} from '@nodeblocks/frontend-reset-password-block';

// Default form data structure for email request
interface ResetPasswordEmailData {
email?: string;
}

// Default form data structure for password confirmation
interface ResetPasswordConfirmData {
password?: string;
confirmPassword?: string;
}

// Combined form data type
type ResetPasswordFormData = ResetPasswordEmailData | ResetPasswordConfirmData;

// Extend with custom fields
interface CustomResetPasswordFormData extends ResetPasswordFormData {
customField?: string;
}

const MyResetPasswordForm = () => {
const handleSendRequest = (formData: ResetPasswordFormData) => {
console.log('Reset request sent:', formData);
// Handle email submission
};

const handleResetPassword = (formData: ResetPasswordFormData) => {
console.log('Password reset:', formData);
// Handle password reset
};

return (
<ResetPassword<CustomResetPasswordFormData>
view="request"
onSendRequest={handleSendRequest}
onResetPassword={handleResetPassword}
resetPasswordTitle="Forgot Your Password?"
description="Enter your email address and we'll send you reset instructions">
<ResetPassword.Title>Reset Your Password</ResetPassword.Title>
<ResetPassword.Description>
Don't worry, it happens to everyone. Enter your email below.
</ResetPassword.Description>
<ResetPassword.Form>
<ResetPassword.Form.EmailField />
<ResetPassword.Form.PasswordField />
<ResetPassword.Form.ConfirmPasswordField />
<ResetPassword.Form.ResetPasswordButton>Send Reset Link</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
<ResetPassword.Goto>
<span>
Remember your password? <a href="#signin">Sign In</a>
</span>
</ResetPassword.Goto>
</ResetPassword>
);
};

React、TypeScript、そして最新の Web 標準を使用して構築されています。