サインアップブロック
SignUp コンポーネント は、React と TypeScript で構築された、完全にカスタマイズ可能でアクセシブルなサインアップフォームです。モダンなデザインパターン、フォーム検証、利用規約への同意、柔軟なカスタマイズオプションを備えた、完全なユーザー登録インターフェースを提供します。
🚀 インストール
npm install @nodeblocks/frontend-signup-block@0.3.2
📖 使用方法
import {SignUp} from '@nodeblocks/frontend-signup-block';
- 基本的な使用方法
- 高度な使用方法
function BasicSignUp() {
return (
<SignUp
onChange={(setError, getValues, clearErrors) => {
console.log('Form values:', getValues());
const values = getValues();
if (!values.email) {
setError('email', {message: 'Email is required', type: 'required'});
} else {
clearErrors('email');
}
}}
onSubmit={formData => {
console.log('Form submitted:', formData);
}}
style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
<SignUp.SignUpTitle>Create Your Account</SignUp.SignUpTitle>
<SignUp.EmailField label="Email Address" placeholder="Enter your email" />
<SignUp.PasswordField label="Password" placeholder="Enter your password" />
<SignUp.TermsOfUse name="agreesUserAgreement" label="I agree to the terms of use" />
<SignUp.PrivacyPolicy name="agreesPrivacyPolicy" label="I agree to the privacy policy" />
<SignUp.SignUpButton>Sign Up</SignUp.SignUpButton>
<SignUp.GotoSignIn>
<span>Already have an account? <a href="#signin">Sign In</a></span>
</SignUp.GotoSignIn>
</SignUp>
);
}
function AdvancedSignUp() {
return (
<SignUp
style={{
maxWidth: '550px',
margin: '0 auto',
borderRadius: '20px',
border: '1px solid #e2e8f0',
padding: '40px',
boxShadow: '0 25px 50px rgba(102, 126, 234, 0.3)',
}}
onChange={(setError, getValues, clearErrors) => {
const values = getValues();
if (!values.email) {
setError('email', {message: 'メールアドレスが必要です', type: 'required'});
} else {
clearErrors('email');
}
if (!values.password) {
setError('password', {message: 'パスワードが必要です', type: 'required'});
} else {
clearErrors('password');
}
if (!values.agreesUserAgreement) {
setError('agreesUserAgreement', {message: '利用規約への同意が必要です', type: 'required'});
} else {
clearErrors('agreesUserAgreement');
}
if (!values.agreesPrivacyPolicy) {
setError('agreesPrivacyPolicy', {message: 'プライバシーポリシーへの同意が必要です', type: 'required'});
} else {
clearErrors('agreesPrivacyPolicy');
}
}}
onSubmit={formData => {
console.log('新規登録:', formData);
}}
>
{({defaultBlocks, defaultBlockOrder}) => {
return {
blocks: {
...defaultBlocks,
signUpTitle: {
...defaultBlocks.signUpTitle,
props: {
...defaultBlocks.signUpTitle.props,
style: {
color: 'black',
fontSize: '2.5rem',
fontWeight: 'bold',
textAlign: 'center',
marginBottom: '8px',
},
children: (
<div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '12px'}}>
<svg style={{width: '36px', height: '36px', color: 'rgb(105, 124, 213)'}} fill="currentColor" viewBox="0 0 24 24">
<path d="M12 2C13.1 2 14 2.9 14 4C14 5.1 13.1 6 12 6C10.9 6 10 5.1 10 4C10 2.9 10.9 2 12 2ZM21 9V7L15 4L13 5.3V3.07C13 3.03 13 3 13 3H11C11 3 11 3.03 11 3.07V5.3L9 4L3 7V9H5C5.6 9 6 9.4 6 10V16C6 16.6 6.4 17 7 17H10V19H14V17H17C17.6 17 18 16.6 18 16V10C18 9.4 18.4 9 19 9H21Z" />
</svg>
<span>企業アカウント作成</span>
</div>
),
},
},
emailField: {
...defaultBlocks.emailField,
props: {
...defaultBlocks.emailField.props,
label: 'メールアドレス',
placeholder: '例: user@company.com',
style: {
background: 'rgba(255, 255, 255, 0.95)',
borderRadius: '12px',
fontSize: '16px',
},
},
},
passwordField: {
...defaultBlocks.passwordField,
props: {
...defaultBlocks.passwordField.props,
label: 'パスワード',
placeholder: '8文字以上の安全なパスワード',
style: {
background: 'rgba(255, 255, 255, 0.95)',
borderRadius: '12px',
fontSize: '16px',
},
},
},
termsOfUse: {
...defaultBlocks.termsOfUse,
props: {
...defaultBlocks.termsOfUse.props,
name: 'agreesUserAgreement',
label: (
<span style={{color: 'black', fontSize: '14px'}}>
<a
href="#terms"
style={{
color: 'rgb(105, 124, 213)',
textDecoration: 'none',
fontWeight: 'bold',
}}
>
利用規約
</a>
に同意します
</span>
),
},
},
privacyPolicy: {
...defaultBlocks.privacyPolicy,
props: {
...defaultBlocks.privacyPolicy.props,
name: 'agreesPrivacyPolicy',
label: (
<span style={{color: 'black', fontSize: '14px'}}>
<a
href="#privacy"
style={{
color: 'rgb(105, 124, 213)',
textDecoration: 'none',
fontWeight: 'bold',
}}
>
プライバシーポリシー
</a>
に同意します
</span>
),
},
},
signUpButton: {
...defaultBlocks.signUpButton,
props: {
...defaultBlocks.signUpButton.props,
children: (
<div>アカウントを作成</div>
),
},
},
gotoSignIn: {
...defaultBlocks.gotoSignIn,
props: {
...defaultBlocks.gotoSignIn.props,
style: {
textAlign: 'center',
},
children: (
<div style={{color: 'black', fontSize: '14px'}}>
<span>既にアカウントをお持ちの方は </span>
<a
href="#signin"
style={{
color: 'rgb(105, 124, 213)',
textDecoration: 'none',
fontWeight: 'bold',
}}
>
ログイン
</a>
</div>
),
},
},
},
blockOrder: defaultBlockOrder,
};
}}
</SignUp>
);
}
🔧 Props リファレンス
メインコンポーネントの props
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
onSubmit | SubmitHandler<T> | 必須 | 有効なデータでフォームが送信されたときに呼び出されるコールバック関数 |
onChange | (setError, getValues, clearErrors) => void | 必須 | フォーム値が変更されたときに呼び出されるコールバック関数。検証用のフォーム制御関数を提供します |
defaultData | DefaultValues<T> | undefined | 初回レンダリング時にフィールドへ設定するデフォルトのフォーム値 |
data | T | undefined | 制御されたフォーム値。外部フォーム state 管理に使用します |
children | BlocksOverride | undefined | デフォルトレンダリングを上書きするカスタムブロックコンポーネント |
className | string | undefined | フォームコンテナのスタイル用追加 CSS クラス名 |
Note: このコンポーネントは、一般的な HTML form 要素の props も追加で継承します。
サブコンポーネント
SignUp コンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントは、メインコンポーネントのコンテキストからデフォルト値を受け取り、props を通じてそれらを上書きできます。
SignUp.SignUpTitle
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | コンテキストから | タイトルコンテンツ |
size | enum | "2XL" | タイトルの Typography サイズ |
type | enum | "heading" | Typography の type |
color | enum | "low-emphasis" | タイトルのカラーテーマ |
weight | enum | "bold" | タイトルの weight |
className | string | undefined | スタイル用の追加 CSS クラス名 |
SignUp.EmailField
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
name | string | "email" | フォーム data と検証に使用されるフィールド名 |
label | string | "Email" | 入力の上に表示されるフィールドラベル |
placeholder | string | "Please enter your email" | フィールドが空のときに表示されるプレースホルダーテキスト |
isRequired | boolean | true | フィールドが必須かどうか(赤いアスタリスクを表示します) |
isDisabled | boolean | undefined | 入力が無効かどうか |
errorText | string | undefined | 入力のエラーテキスト |
className | string | undefined | スタイル用の追加 CSS クラス名 |
Note: このコンポーネントは、一般的な HTML input 要素の props も追加で継承します。
SignUp.PasswordField
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
name | string | "password" | フォーム data と検証に使用されるフィールド名 |
label | string | "Password" | 入力の上に表示されるフィールドラベル |
placeholder | string | "Please enter your password" | フィールドが空のときに表示されるプレースホルダーテキスト |
inputType | string | "password" | 入力タイプ。通常は "password" または "text" |
isRequired | boolean | true | フィールドが必須かどうか(赤いアスタリスクを表示します) |
isDisabled | boolean | undefined | 入力が無効かどうか |
errorText | string | undefined | 入力のエラーテキスト |
className | string | undefined | スタイル用の追加 CSS クラス名 |
Note: このコンポーネントは、一般的な HTML input 要素の props も追加で継承します。
SignUp.TermsOfUse
HTML input 要素のすべての props を継承し、次を追加します:
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
name | string | "agreesUserAgreement" | フォーム data と検証に使用されるフィールド名 |
label | ReactNode | デフォルトの利用規約リンク | 利用規約チェックボックスラベルの内容。通常はリンクを含みます |
isRequired | boolean | true | フィールドが必須かどうか(赤いアスタリスクを表示します) |
isDisabled | boolean | undefined | 入力が無効かどうか |
errorText | string | undefined | 入力のエラーテキスト |
className | string | undefined | スタイル用の追加 CSS クラス名 |
SignUp.PrivacyPolicy
HTML input 要素のすべての props を継承し、次を追加します:
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
name | string | "agreesPrivacyPolicy" | フォーム data と検証に使用されるフィールド名 |
label | ReactNode | デフォルトのプライバシーポリシーリンク | プライバシーポリシーチェックボックスラベルの内容。通常はリンクを含みます |
isRequired | boolean | true | フィールドが必須かどうか(赤いアスタリスクを表示します) |
isDisabled | boolean | undefined | 入力が無効かどうか |
errorText | string | undefined | 入力のエラーテキスト |
className | string | undefined | スタイル用の追加 CSS クラス名 |
SignUp.SignUpButton
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | "Sign Up" | ボタンテキストの内容 |
className | string | undefined | スタイル用の追加 CSS クラス名 |
fill | enum | "fill" | ボタンの塗りつぶしスタイル |
icon | enum | undefined | ボタン左側の任意のアイコン |
iconColor | enum | undefined | 左側アイコンの色。指定されない場合は、fill タイプのデフォルト色が使用されます。 |
isDisabled | boolean | false | ボタンが無効で使用できないかどうか |
onClick | function | undefined | ボタンクリックを処理する関数 |
size | enum | "M" | ボタンの縦サイズ |
textAlign | enum | "center" | ボタン内でのアイコンとテキストの位置 |
textColor | enum | "default" | ボタンテキストの色 |
textEmphasis | boolean | false | ボタンテキストの太さ |
textSize | enum | "M" | ボタンテキストのサイズ |
type | enum | "submit" | ボタンの用途(HTML type に影響します) |
SignUp.GotoSignIn
HTML div 要素のすべての props を継承し(children を除く)、次を追加します:
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | デフォルトのサインインリンク | サインインリンクセクションの内容。通常はアンカータグを含みます |
className | string | undefined | スタイル用の追加 CSS クラス名 |
🔧 TypeScript サポート
包括的な型定義を備えた完全な TypeScript サポート:
import {SignUp} from '@nodeblocks/frontend-signup-block';
//in future we will not use react-hook-form, we will use our own form handling
import {UseFormClearErrors, UseFormGetValues, UseFormSetError} from 'react-hook-form';
// Default form data structure
interface DefaultSignUpFormData {
email?: string;
password?: string;
agreesPrivacyPolicy?: boolean;
agreesUserAgreement?: boolean;
}
// Extend with custom fields
interface CustomSignUpFormData extends DefaultSignUpFormData {
firstName?: string;
lastName?: string;
phone?: string;
}
const MySignUpForm = () => {
const handleSubmit = (formData: CustomSignUpFormData) => {
console.log('Form submitted:', formData);
// Handle form submission
};
const handleChange = (
setError: UseFormSetError<CustomSignUpFormData>,
getValues: UseFormGetValues<CustomSignUpFormData>,
clearErrors: UseFormClearErrors<CustomSignUpFormData>,
) => {
const values = getValues();
// Custom validation
if (values.email && !values.email.includes('@')) {
setError('email', {message: 'Invalid email format'});
} else {
clearErrors('email');
}
};
return (
<SignUp<DefaultSignUpFormData>
onSubmit={handleSubmit}
onChange={handleChange}
defaultData={{email: 'user@example.com'}}>
<SignUp.SignUpTitle>Create Account</SignUp.SignUpTitle>
<SignUp.EmailField />
<SignUp.PasswordField />
<SignUp.TermsOfUse
name="agreesUserAgreement"
label={
<span>
I agree to the <a href="#terms">Terms of Service</a>
</span>
}
/>
<SignUp.PrivacyPolicy
name="agreesPrivacyPolicy"
label={
<span>
I agree to the <a href="#privacy">Privacy Policy</a>
</span>
}
/>
<SignUp.SignUpButton>Register</SignUp.SignUpButton>
<SignUp.GotoSignIn>
<span>
Already have an account? <a href="#signin">Sign In</a>
</span>
</SignUp.GotoSignIn>
</SignUp>
);
};
React、TypeScript、モダンなウェブ標準を使用して❤️で構築されました。