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

基本情報ブロック

BasicInformationコンポーネントは、ReactとTypeScriptで構築された、ユーザーの基本情報を収集するための完全にカスタマイズ可能でアクセシブルなフォームです。モダンなデザインパターン、フォームバリデーション、柔軟なカスタマイズオプションを備えた完全な住所と連絡先情報のインターフェースを提供します。


🚀 インストール

npm install @nodeblocks/frontend-basic-information-block

📖 使用方法

import {BasicInformation} from '@nodeblocks/frontend-basic-information-block';
ライブエディター
function BasicInformationForm() {
  return (
    <BasicInformation
      onChange={(setError, getValues) => {
        console.log('フォーム値:', getValues());
        const values = getValues();
        if (!values.NameInput) {
          setError('NameInput', {message: '氏名は必須です', type: 'required'});
        }
      }}
      onSubmit={formData => {
        console.log('フォームが送信されました:', formData);
      }}
      onInvalid={errors => {
        console.log('フォームバリデーションエラー:', errors);
      }}>
      <BasicInformation.Title>基本情報</BasicInformation.Title>
      <BasicInformation.Subtitle>基本情報を入力してください</BasicInformation.Subtitle>
      <BasicInformation.NameInput />
      <BasicInformation.FuriganaInput />
      <BasicInformation.PostalCodeInput />
      <BasicInformation.PrefectureSelect />
      <BasicInformation.CityInput />
      <BasicInformation.AddressInput />
      <BasicInformation.PhoneInput />
      <BasicInformation.SubmitButton>送信</BasicInformation.SubmitButton>
    </BasicInformation>
  );
}
結果
Loading...

🔧 プロパティリファレンス

メインコンポーネントのプロパティ

メインのBasicInformationコンポーネントは、HTML form要素のすべてのプロパティを継承し(onSubmitonChangechildrenはオーバーライド)、以下を追加します:

プロパティデフォルト説明
onSubmit(data: T) => void必須有効なデータでフォームが送信されたときにトリガーされるコールバック関数
onChange(setError, getValues) => void必須フォーム値が変更されたときにトリガーされるコールバック関数。バリデーション用のフォーム制御関数を提供
onInvalid(errors: FieldErrors<T>) => void必須フォーム送信でバリデーションが失敗したときにトリガーされるコールバック関数
defaultValuesDefaultValues<T>undefined初期レンダリング時にフィールドに設定するデフォルトフォーム値
childrenBlocksOverrideundefinedデフォルトレンダリングをオーバーライドするカスタムブロックコンポーネント
classNamestringundefinedフォームコンテナスタイリング用の追加CSSクラス名

サブコンポーネント

BasicInformationコンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントは、メインコンポーネントのコンテキストからデフォルト値を受け取り、プロパティを通じてこれらの値をオーバーライドできます。

BasicInformation.Title

HTML h2要素のすべてのプロパティを継承し、以下を追加します:

プロパティデフォルト説明
childrenReactNode"基本情報"タイトルとして表示するコンテンツ

BasicInformation.Subtitle

HTML div要素のすべてのプロパティを継承し、以下を追加します:

プロパティデフォルト説明
childrenReactNodeデフォルト必須フィールドメッセージサブタイトルとして表示するコンテンツ - 通常は必須フィールド情報を表示

BasicInformation.NameInput

deepMergeを使用してデフォルトフィールドオプションと渡されたプロパティを結合します。内部Inputコンポーネントのすべてのプロパティを継承し、以下を追加します:

プロパティデフォルト説明
namestring"NameInput"フォームデータ用のフィールド名
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring"氏名"入力フィールドのラベル
labelWeightenum"bold"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

注意: このコンポーネントは追加で一般的なHTML input要素プロパティを継承します。

BasicInformation.FuriganaInput

プロパティデフォルト説明
namestring"FuriganaInput"フォームデータ用のフィールド名
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring"フリガナ"入力フィールドのラベル
labelWeightenum"bold"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

注意: このコンポーネントは追加で一般的なHTML input要素プロパティを継承します。

BasicInformation.PostalCodeInput

プロパティデフォルト説明
namestring"PostalCodeInput"フォームデータ用のフィールド名
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring"郵便番号"入力フィールドのラベル
labelWeightenum"bold"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

注意: このコンポーネントは追加で一般的なHTML input要素プロパティを継承します。

BasicInformation.PrefectureSelect

プロパティデフォルト説明
namestring"PrefectureSelect"フォームデータ用のフィールド名
labelstring"都道府県"フィールドラベル
labelWeightenum"bold"ラベルの太さ
selectOptionValuesArray<{value: string, label: string}>[]都道府県オプションの配列
isRequiredbooleanundefinedフィールドが必須かどうか
isDisabledbooleanundefined入力が無効かどうか
errorTextstringundefined入力のエラーテキスト
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントは追加で一般的なHTML select要素プロパティを継承します。

BasicInformation.CityInput

プロパティデフォルト説明
namestring"CityInput"フォームデータ用のフィールド名
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring"市区町村"入力フィールドのラベル
labelWeightenum"bold"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

注意: このコンポーネントは追加で一般的なHTML input要素プロパティを継承します。

BasicInformation.AddressInput

プロパティデフォルト説明
namestring"AddressInput"フォームデータ用のフィールド名
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring"町名・番地・建物"入力フィールドのラベル
labelWeightenum"bold"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

注意: このコンポーネントは追加で一般的なHTML input要素プロパティを継承します。

BasicInformation.PhoneInput

プロパティデフォルト説明
namestring"PhoneInput"フォームデータ用のフィールド名
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring"連絡先電話番号"入力フィールドのラベル
labelWeightenum"bold"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか
inputModestring"numeric"モバイルキーボード用の入力モード

注意: このコンポーネントは追加で一般的なHTML input要素プロパティを継承します。

BasicInformation.SubmitButton

@basaldev/blocks-frontend-frameworkButtonコンポーネントのすべてのプロパティを継承し、以下を追加します:

プロパティデフォルト説明
childrenReactNode"次へ"ボタン内に配置するテキスト
classNamestringundefinedスタイリング用の追加CSSクラス名
fillenum"fill"ボタンフィルスタイル
iconenumundefinedボタン左側のオプションアイコン
iconColorenumundefined左側アイコンの色。提供されない場合、フィルタイプのデフォルト色が使用されます
isDisabledbooleanfalseボタンが無効で使用できないかどうか
onClickfunctionundefinedボタンクリックを処理する関数
sizeenum"M"ボタンの縦サイズ
textAlignenum"center"ボタン内でのアイコンとテキストの位置
textColorenum"default"ボタンテキストの色
textEmphasisbooleanfalseボタンテキストの太さ
textSizeenum"M"ボタンテキストのサイズ
typeenum"submit"ボタンの目的(htmlタイプに影響)

注意: このコンポーネントは追加で一般的なHTML button要素プロパティを継承します。

追加フィールドコンポーネント

コンポーネントはカスタムフォームで使用できる追加のフィールドタイプも提供します:

BasicInformation.Input

プロパティデフォルト説明
namestring必須フォームデータ用のフィールド名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelstring必須入力フィールドのラベル
labelWeightenum"regular"ラベルの太さ
onOperationClick() => voidundefined操作のonClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

🔧 TypeScript サポート

包括的な型定義による完全なTypeScriptサポート:

import {BasicInformation} from '@nodeblocks/frontend-basic-information-block';
//将来的にはreact-hook-formを使用せず、独自のフォーム処理を使用します
import {FieldErrors, UseFormGetValues, UseFormSetError} from 'react-hook-form';

// デフォルトフォームデータ構造
interface DefaultBasicInformationFormData {
NameInput: string;
FuriganaInput: string;
PostalCodeInput: string;
PrefectureSelect: string;
CityInput: string;
AddressInput: string;
PhoneInput: string;
}

// カスタムフィールドで拡張(コンポーネントはユニオン型を使用)

const MyBasicInformationForm = () => {
const handleSubmit = (formData: DefaultBasicInformationFormData) => {
console.log('フォームが送信されました:', formData);
// フォーム送信を処理
};

const handleInvalid = (errors: FieldErrors<DefaultBasicInformationFormData>) => {
console.log('バリデーションエラー:', errors);
// バリデーションエラーを処理
};

const handleChange = (
setError: UseFormSetError<DefaultBasicInformationFormData>,
getValues: UseFormGetValues<DefaultBasicInformationFormData>,
) => {
const values = getValues();

// カスタムバリデーション
if (values.PhoneInput && values.PhoneInput.length < 10) {
setError('PhoneInput', {message: '電話番号が短すぎます'});
}
};

return (
<BasicInformation<DefaultBasicInformationFormData>
onSubmit={handleSubmit}
onInvalid={handleInvalid}
onChange={handleChange}
defaultValues={{NameInput: '山田太郎'}}>
<BasicInformation.Title>基本情報</BasicInformation.Title>
<BasicInformation.Subtitle>詳細をご入力ください</BasicInformation.Subtitle>
<BasicInformation.NameInput />
<BasicInformation.FuriganaInput />
<BasicInformation.PostalCodeInput />
<BasicInformation.PrefectureSelect />
<BasicInformation.CityInput />
<BasicInformation.AddressInput />
<BasicInformation.PhoneInput />
<BasicInformation.SubmitButton>送信</BasicInformation.SubmitButton>
</BasicInformation>
);
};

React、TypeScript、モダンなウェブ標準を使用して❤️で構築されました。