パスワードリセットブロック
ResetPasswordコンポーネントは、React、TypeScript、MUIで構築された完全にカスタマイズ可能でアクセシブルなパスワードリセットフォームです。モダンなデザインパターン、リクエストと確認フローの両方に対応したデュアルビューサポート、柔軟なカスタマイズオプションを備えた完全なパスワードリセットインターフェースを提供します。
🚀 インストール
npm install @nodeblocks/frontend-reset-password-block@0.2.0
📖 使用法
import {ResetPassword} from '@nodeblocks/frontend-reset-password-block';
- 基本的な使用法
- パスワード確認ビュー
- 高度な使用法
function SimpleResetPasswordRequest() { const handleSendRequest = (data) => { console.log('パスワードリセットリクエストが送信されました:', data); }; const handleResetPassword = (data) => { console.log('パスワードがリセットされました:', data); }; return ( <ResetPassword view="request" resetPasswordTitle="パスワードをリセット" description="パスワードリセットリンクを受け取るためにメールアドレスを入力してください" gotoSigninMessage="パスワードを思い出しましたか?サインイン" onSendRequest={handleSendRequest} onResetPassword={handleResetPassword} sx={{maxWidth: 400, mx: 'auto', p: 3}} > <ResetPassword.Title /> <ResetPassword.Description /> <ResetPassword.Form> <ResetPassword.Form.EmailField /> <ResetPassword.Form.ResetPasswordButton>リセットリンクを送信</ResetPassword.Form.ResetPasswordButton> </ResetPassword.Form> <ResetPassword.Goto /> </ResetPassword> ); }
function SimpleResetPasswordConfirm() { const handleSendRequest = (data) => { console.log('リクエスト:', data); }; const handleResetPassword = (data) => { console.log('パスワードがリセットされました:', data); }; return ( <ResetPassword view="confirm_password" resetPasswordTitle="新しいパスワードを作成" description="下記に新しいパスワードを入力してください" 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>パスワードをリセット</ResetPassword.Form.ResetPasswordButton> </ResetPassword.Form> </ResetPassword> ); }
function AdvancedResetPassword() { const [showPassword, setShowPassword] = useState(false); const handleSendRequest = (data) => { console.log('リセットメールを送信中:', data); }; const handleResetPassword = (data) => { console.log('パスワードをリセット中:', data); }; return ( <ResetPassword view="confirm_password" resetPasswordTitle="パスワードをリセット" description="アカウントを保護するために強力なパスワードを作成してください" 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', }} > パスワードをリセット </h1> <p style={{ color: 'rgba(255,255,255,0.8)', fontSize: '15px', margin: 0, }} > アカウントを保護するために強力なパスワードを作成してください </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', }} > パスワードには以下が含まれている必要があります: </p> <ul style={{ margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: '8px', }} > {[ '8文字以上', '大文字を1つ', '小文字を1つ', '数字を1つ', '特殊文字を1つ', ].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)', }, }} > パスワードをリセット </ResetPassword.Form.ResetPasswordButton> </ResetPassword.Form> ); return { blocks: { ...defaultBlocks, title: customHeader, description: <></>, form: styledForm, }, blockOrder: defaultBlockOrder, }; }} </ResetPassword> ); }
🔧 プロパティリファレンス
メインコンポーネントのプロパティ
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
view | 'request' | 'confirm_password' | 必須 | 表示するビューを決定 - メールリクエストフォームまたはパスワード確認フォーム |
onSendRequest | (data: T) => void | 必須 | リセットリクエストが送信されたときにトリガーされるコールバック関数 |
onResetPassword | (data: T) => void | 必須 | 新しいパスワードが送信されたときにトリガーされるコールバック関数 |
resetPasswordTitle | ReactNode | "Reset Password" | パスワードリセットフォームのタイトルコンテンツ |
description | ReactNode | "Please enter your email address you registered" | タイトル下に表示される説明テキスト |
gotoSigninMessage | ReactNode | デフォルトサインインリンク | ナビゲーションリンクセクションのコンテンツ |
showPassword | boolean | false | パスワードフィールドの表示を制御(デフォルトで内部管理) |
onShowPasswordClick | (show: boolean) => void | 内部ハンドラー | パスワード表示切り替えのコールバック |
className | string | undefined | フォームコンテナスタイリング用の追加CSSクラス名 |
sx | SxProps | undefined | カスタムスタイリング用のMUI sxプロパティ |
children | BlocksOverride | undefined | デフォルトレンダリングをオーバーライドするカスタムブロックコンポーネント |
注意: このコンポーネントはMUI StackProps(childrenとonSubmitを除く)を拡張します。デフォルトスペーシングは4、パディングはpy: 6とpx: 5です。
サブコンポーネント
ResetPasswordコンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントは、メインコンポーネントのコンテキストからデフォルト値を受け取り、プロパティを通じてこれらの値をオーバーライドできます。
ResetPassword.Title
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
resetPasswordTitle | ReactNode | コンテキストから | タイトルコンテンツ |
children | ReactNode | "Reset Password" | カスタムタイトルコンテンツ(resetPasswordTitleをオーバーライド) |
className | string | undefined | スタイリング用の追加CSSクラス名 |
variant | string | "h4" | MUI Typographyバリアント |
component | string | "h1" | レンダリングするHTML要素 |
sx | SxProps | undefined | デフォルトtextAlign: 'center'を持つMUI sxプロパティ |
注意: このコンポーネントはMUI TypographyProps を拡張します。
ResetPassword.Description
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
description | ReactNode | コンテキストから | 説明コンテンツ |
children | ReactNode | "Please enter your email address you registered" | カスタム説明コンテンツ |
className | string | undefined | スタイリング用の追加CSSクラス名 |
variant | string | "body2" | MUI Typographyバリアント |
sx | SxProps | undefined | デフォルトtextAlign: 'center'を持つMUI sxプロパティ |
注意: このコンポーネントはMUI TypographyProps を拡張します。
ResetPassword.Form
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
view | 'request' | 'confirm_password' | コンテキストから | 表示するフィールドを決定 |
onSendRequest | (data: T) => void | コンテキストから | メール送信のコールバック |
onResetPassword | (data: T) => void | コンテキストから | パスワード確認のコールバック |
className | string | undefined | スタイリング用の追加CSSクラス名 |
children | ReactNode | デフォルトフォームフィールド | カスタムフォームコンテンツ |
注意: このコンポーネントはcomponent="form"を持つMUI StackProps<'form'>を拡張します。デフォルトスペーシングは4です。
ResetPassword.Form.EmailField
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
view | 'request' | 'confirm_password' | コンテキストから | view === 'request'のときのみレンダリング |
name | string | "email" | フォームデータに使用されるフィールド名 |
label | string | "Email" | 入力フィールドのラベル |
placeholder | string | "Please enter your email" | プレースホルダーテキスト |
fullWidth | boolean | true | フィールドが全幅を占めるかどうか |
className | string | undefined | スタイリング用の追加CSSクラス名 |
注意: このコンポーネントはMUI TextFieldProps を拡張します。requestビューでのみ表示されます。
ResetPassword.Form.PasswordField
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
view | 'request' | 'confirm_password' | コンテキストから | view === 'confirm_password'のときのみレンダリング |
showPassword | boolean | コンテキストから | パスワード表示を制御 |
onShowPasswordClick | (show: boolean) => void | コンテキストから | パスワード表示切り替え |
name | string | "password" | フォームデータに使用されるフィールド名 |
label | string | "Password" | 入力フィールドのラベル |
placeholder | string | "Please enter your new password" | プレースホルダーテキスト |
fullWidth | boolean | true | フィールドが全幅を占めるかどうか |
className | string | undefined | スタイリング用の追加CSSクラス名 |
注意: このコンポーネントはMUI TextFieldProps を拡張します。confirm_passwordビューでのみ表示されます。showPasswordとonShowPasswordClickが提供されている場合、表示切り替えアイコンを含みます。
ResetPassword.Form.ConfirmPasswordField
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
view | 'request' | 'confirm_password' | コンテキストから | view === 'confirm_password'のときのみレンダリング |
showPassword | boolean | コンテキストから | パスワード表示を制御 |
onShowPasswordClick | (show: boolean) => void | コンテキストから | パスワード表示切り替え |
name | string | "confirmPassword" | フォームデータに使用されるフィールド名 |
label | string | "Confirm Password" | 入力フィールドのラベル |
placeholder | string | "Please confirm your password" | プレースホルダーテキスト |
fullWidth | boolean | true | フィールドが全幅を占めるかどうか |
className | string | undefined | スタイリング用の追加CSSクラス名 |
注意: このコンポーネントはMUI TextFieldProps を拡張します。confirm_passwordビューでのみ表示されます。showPasswordとonShowPasswordClickが提供されている場合、表示切り替えアイコンを含みます。
ResetPassword.Form.ResetPasswordButton
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | "Reset Password" | ボタンテキスト |
variant | string | "contained" | MUI Buttonバリアント |
fullWidth | boolean | true | ボタンが全幅を占めるかどうか |
type | string | "submit" | HTMLボタンタイプ |
className | string | undefined | スタイリング用の追加CSSクラス名 |
注意: このコンポーネントはMUI ButtonProps を拡張します。
ResetPassword.Goto
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
gotoSigninMessage | ReactNode | コンテキストから | カスタムナビゲーションメッセージ |
children | ReactNode | /auth/loginへのリンク | ナビゲーションセクション用のカスタムコンテンツ |
className | string | undefined | スタイリング用の追加CSSクラス名 |
variant | string | "body2" | MUI Typographyバリアント |
sx | SxProps | undefined | デフォルトtextAlign: 'center'を持つMUI sxプロパティ |
注意: このコンポーネントはMUI TypographyProps を拡張します。
🎨 設定例
カスタムタイトルスタイリング
<ResetPassword.Title
variant="h3"
sx={{
color: 'primary.main',
fontWeight: 'bold',
}}
>
パスワードをお忘れですか?
</ResetPassword.Title>
カスタムフィールドラベル
<ResetPassword.Form>
<ResetPassword.Form.EmailField
label="メールアドレス"
placeholder="name@example.com"
helperText="このアドレスにリセットリンクを送信します"
/>
<ResetPassword.Form.PasswordField
label="新しいパスワードを作成"
placeholder="8文字以上"
/>
<ResetPassword.Form.ConfirmPasswordField
label="新しいパスワードを確認"
placeholder="パスワードを再入力"
/>
<ResetPassword.Form.ResetPasswordButton>
リセットリンクを送信
</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
ブロックオーバーライドパターン
<ResetPassword view="request" onSendRequest={handleSend} onResetPassword={handleReset}>
{({ defaultBlocks, defaultBlockOrder }) => ({
blocks: {
...defaultBlocks,
// カスタムセキュリティ通知を追加
securityNote: (
<Alert severity="info" sx={{ textAlign: 'center' }}>
セキュリティのため、リセットリンクは24時間で期限切れになります
</Alert>
),
},
blockOrder: ['title', 'description', 'securityNote', 'form', 'goto'],
})}
</ResetPassword>
カスタムナビゲーションリンク
<ResetPassword.Goto>
<span>
パスワードを思い出しましたか?{' '}
<Link href="#login" sx={{ fontWeight: 'medium' }}>
サインインに戻る
</Link>
</span>
</ResetPassword.Goto>
カスタムスタイリング
function CustomStyledResetPassword() {
const handleSendRequest = (data) => {
console.log('リクエスト:', data);
};
const handleResetPassword = (data) => {
console.log('リセット:', data);
};
return (
<ResetPassword
view="request"
resetPasswordTitle="パスワードをお忘れですか?"
description="心配ありません。リセット手順をお送りします"
gotoSigninMessage="サインインに戻る"
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',
},
}}
>
リセットリンクを送信
</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
<ResetPassword.Goto
sx={{
mt: 3,
textAlign: 'center',
color: 'grey.400',
'& a': {
color: 'primary.light',
},
}}
/>
</ResetPassword>
);
}
🔧 TypeScriptサポート
包括的な型定義による完全なTypeScriptサポート:
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('リセットリンクを送信中:', data);
// API呼び出しをシミュレートしてから確認ビューに切り替え
setTimeout(() => setView('confirm_password'), 1000);
};
const handleResetPassword = (data: ResetPasswordFormData): void => {
console.log('パスワードがリセットされました:', data);
// パスワードリセットのAPI呼び出し
};
return (
<ResetPassword
view={view}
resetPasswordTitle={view === 'request' ? 'パスワードをリセット' : '新しいパスワードを作成'}
description={
view === 'request' ? 'リセットリンクを受け取るためにメールアドレスを入力してください' : '新しいパスワードを入力して確認してください'
}
gotoSigninMessage="パスワードを思い出しましたか?サインイン"
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' ? 'リセットリンクを送信' : 'パスワードをリセット'}
</ResetPassword.Form.ResetPasswordButton>
</ResetPassword.Form>
{view === 'request' && <ResetPassword.Goto />}
</ResetPassword>
);
}
📝 注意事項
- コンポーネントはMUIの
Stackコンポーネントをベースとして使用し、柔軟なレイアウトオプションを提供します - デフォルトスペーシングは
4、パディングはpy: 6とpx: 5です viewプロパティは表示されるフィールドを制御します:'request': メールフィールドのみを表示'confirm_password': パスワードとパスワード確認フィールドを表示
- フォーム送信は
onSubmitイベントで内部的に処理されます showPasswordコンテキストが利用可能な場合、パスワード表示切り替えが組み込まれています- パスワードフィールドには切り替え用のMUI
Visibility/VisibilityOffアイコンが含まれます - デフォルトブロック:
title、description、form、goto - CSSクラスはBEMスタイルの命名に従います:
nbb-reset-password、nbb-reset-password-titleなど - コンポーネントは
margin: 'auto'で中央揃えになり、大画面ではminWidth: { lg: 496 }があります - デフォルトの「サインインに戻る」リンクは
/auth/loginを指します
React、TypeScript、MUIを使用して❤️で構築されました。