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

商品作成ブロック

CreateProductコンポーネントは、ReactとTypeScriptで構築された完全にカスタマイズ可能でアクセシブルな商品作成フォームです。画像アップロード、カテゴリ選択、位置情報、モダンなデザインパターンを備えた商品登録のための完全なインターフェースを提供します。


🚀 インストール

npm install @nodeblocks/frontend-create-product-block

📖 使用方法

import {CreateProduct} from '@nodeblocks/frontend-create-product-block';
ライブエディター
function BasicCreateProduct() {
  const categoryOptions = [
    { value: 'electronics', label: '電子機器' },
    { value: 'clothing', label: '衣類' },
    { value: 'home', label: 'ホーム・ガーデン' }
  ];

  return (
    <CreateProduct
      categoryOptions={categoryOptions}
      onSubmit={(formData) => {
        console.log('商品が作成されました:', formData);
      }}
      onChange={(setError, getValues, clearErrors) => {
        const values = getValues();
        console.log('フォーム値:', values);
      }}
      onAcceptAttachment={(files) => {
        console.log('ファイルが承認されました:', files);
      }}
      onUploadAttachment={(file) => {
        console.log('ファイルをアップロード中:', file);
        // ファイルアップロードロジックを処理
      }}
      onClearAttachment={() => {
        console.log('添付ファイルがクリアされました');
      }}>
      <CreateProduct.MainInfo>
        <CreateProduct.MainInfo.SectionTitle>商品情報</CreateProduct.MainInfo.SectionTitle>
        <CreateProduct.MainInfo.Dropzone />
        <CreateProduct.MainInfo.NameField />
      </CreateProduct.MainInfo>
      
      <CreateProduct.BasicInfo>
        <CreateProduct.BasicInfo.Title />
        <CreateProduct.BasicInfo.CategoryField />
        <CreateProduct.BasicInfo.DescriptionField />
      </CreateProduct.BasicInfo>
      
      <CreateProduct.AdditionalInfo>
        <CreateProduct.AdditionalInfo.Title />
        <CreateProduct.AdditionalInfo.Subtitle />
        <CreateProduct.AdditionalInfo.Address1Field />
        <CreateProduct.AdditionalInfo.Address2Field />
      </CreateProduct.AdditionalInfo>
      
      <CreateProduct.Actions>
        <CreateProduct.Actions.SubmitButton>商品を作成</CreateProduct.Actions.SubmitButton>
      </CreateProduct.Actions>
    </CreateProduct>
  );
}
結果
Loading...

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

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

プロパティデフォルト説明
onSubmit(data: T, event?: React.BaseSyntheticEvent) => void必須有効なデータでフォームが送信されたときにトリガーされるコールバック関数
onChange(setError, getValues, clearErrors) => void必須フォーム値が変更されたときにトリガーされるコールバック関数
categoryOptionsOptionValue[]undefinedカテゴリ選択フィールド用のカテゴリオプションの配列
onAcceptAttachment(files: File[]) => voidundefinedファイルがアップロード用に承認されたときに発生するコールバック
onUploadAttachment(file: File) => voidundefinedファイルアップロードがトリガーされたときに発生するコールバック
onRejectAttachment(files: File[]) => voidundefinedファイルが拒否されたときに発生するコールバック
onClearAttachment() => voidundefined添付ファイルがクリアされたときに発生するコールバック
defaultDataDefaultValues<T>undefined初期レンダリング時にフィールドに設定するデフォルトフォーム値
dataTundefined制御されたフォーム値 - 外部フォーム状態管理に使用
classNamestringundefinedフォームコンテナスタイリング用の追加CSSクラス名
childrenBlocksOverrideundefinedデフォルトレンダリングをオーバーライドするカスタムブロックコンポーネント

注意: このコンポーネントはすべてのHTML div 要素プロパティを継承します。

サブコンポーネント

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

CreateProduct.MainInfo

画像アップロードと商品名を含むメイン商品情報のコンテナ。

プロパティデフォルト説明
childrenReactNodeundefinedデフォルトメイン情報フィールドをオーバーライドするカスタムコンテンツ
directionenum"column"アクションボタンのフレックス方向
alignItemsenum"stretch"コンテナ内のアイテムの整列
gapSizeenum"S"コンテナ内のアイテム間のギャップ
CreateProduct.MainInfo.SectionTitle
プロパティデフォルト説明
childrenReactNode"Main Info"メイン情報セクションのタイトルコンテンツ
sizeenum"L"タイトルのタイポグラフィサイズ
typeenum"heading"タイポグラフィタイプ
colorenum"low-emphasis"タイトルのカラーテーマ
weightenum"bold"タイポグラフィの太さ
classNamestringundefinedスタイリング用の追加CSSクラス名
CreateProduct.MainInfo.Dropzone
プロパティデフォルト説明
beforeUploadMessagestring"Upload"ファイルアップロード前に表示されるメッセージ
beforeUploadSubtitlestring"Select a file to upload."ファイルアップロード前に表示されるサブタイトル
afterUploadOptionsButtonstring"Options"アップロード後のオプションボタンのテキスト
replaceFileButtonstring"Select a new file"ファイル置換ボタンのテキスト
deleteFileButtonstring"Delete"ファイル削除ボタンのテキスト
maxFilesnumber1許可される最大ファイル数
acceptstring"image/*"受け入れるファイルタイプ
maxSizenumber5242880最大ファイルサイズ(バイト単位、5MB)
classNamestringundefinedスタイリング用の追加CSSクラス名
CreateProduct.MainInfo.NameField
プロパティデフォルト説明
namestring"name"フォームデータとバリデーションに使用されるフィールド名
labelstring"Name"入力の上に表示されるフィールドラベル
labelWeightenum"regular"フィールドラベルの太さ
classNamestringundefinedスタイリング用の追加CSSクラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
onOperationClick() => voidundefined操作onClickコールバック
postfixTextstringundefinedコンポーネントの後に配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

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

CreateProduct.BasicInfo

カテゴリと説明を含む基本商品情報のコンテナ。

プロパティデフォルト説明
childrenBlocksOverrideundefinedデフォルト基本情報フィールドをオーバーライドするカスタムコンテンツ
classNamestringundefinedスタイリング用の追加CSSクラス名
directionenum"column"アクションボタンのフレックス方向
alignItemsenum"stretch"コンテナ内のアイテムの整列
gapSizeenum"S"コンテナ内のアイテム間のギャップ
CreateProduct.BasicInfo.Title
プロパティデフォルト説明
childrenReactNode"Basic Information"基本情報セクションのタイトルコンテンツ
sizeenum"L"タイトルのタイポグラフィサイズ
typeenum"heading"タイポグラフィタイプ
colorenum"low-emphasis"タイトルのカラーテーマ
weightenum"bold"タイポグラフィの太さ
classNamestringundefinedスタイリング用の追加CSSクラス名
CreateProduct.BasicInfo.CategoryField
プロパティデフォルト説明
namestring"categoryId"フォームデータのフィールド名
labelstring"Categories"フィールドラベル
labelWeightenum"regular"ラベルの太さ
selectOptionValuesArray<{value: string, label: string}>[]カテゴリオプションの配列
isRequiredbooleanundefinedフィールドが必須かどうか
isDisabledbooleanundefined入力が無効かどうか
errorTextstringundefined入力のエラーテキスト
classNamestringundefinedスタイリング用の追加CSSクラス名

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

CreateProduct.BasicInfo.DescriptionField
プロパティデフォルト説明
namestring"description"フォームデータのフィールド名
labelstring"Description"入力フィールドのラベル
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
labelWeightenumundefinedラベルの太さ
classNamestringundefinedスタイリング用の追加CSSクラス名

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

CreateProduct.AdditionalInfo

位置詳細を含む追加商品情報のコンテナ。

プロパティデフォルト説明
childrenBlocksOverrideundefinedデフォルト追加情報フィールドをオーバーライドするカスタムコンテンツ
classNamestringundefinedスタイリング用の追加CSSクラス名
directionenum"column"アクションボタンのフレックス方向
alignItemsenum"stretch"コンテナ内のアイテムの整列
gapSizeenum"S"コンテナ内のアイテム間のギャップ
CreateProduct.AdditionalInfo.Title
プロパティデフォルト説明
childrenReactNode"Additional Information"追加情報セクションのタイトルコンテンツ
sizeenum"L"タイトルのタイポグラフィサイズ
typeenum"heading"タイポグラフィタイプ
colorenum"low-emphasis"タイトルのカラーテーマ
weightenum"bold"タイポグラフィの太さ
classNamestringundefinedスタイリング用の追加CSSクラス名
CreateProduct.AdditionalInfo.Subtitle
プロパティデフォルト説明
childrenReactNode"Location"位置セクションのサブタイトルコンテンツ
sizeenum"S"タイトルのタイポグラフィサイズ
typeenum"heading"タイポグラフィタイプ
colorenum"low-emphasis"タイトルのカラーテーマ
weightenum"regular"タイポグラフィの太さ
classNamestringundefinedスタイリング用の追加CSSクラス名
CreateProduct.AdditionalInfo.Address1Field
プロパティデフォルト説明
namestring"address1"フォームデータのフィールド名
labelstring"Prefecture"フィールドラベル
labelWeightenum"regular"ラベルの太さ
selectOptionValuesArray<{value: string, label: string}>[]都道府県オプションの配列
isRequiredbooleanundefinedフィールドが必須かどうか
isDisabledbooleanundefined入力が無効かどうか
errorTextstringundefined入力のエラーテキスト
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはすべてのHTML select 要素プロパティを継承します。

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

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

CreateProduct.Actions

フォームアクションボタンのコンテナ。

プロパティデフォルト説明
childrenBlocksOverrideundefinedデフォルトアクションボタンをオーバーライドするカスタムコンテンツ
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはすべてのHTML div 要素プロパティを継承します。

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

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

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

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

CreateProduct.TextField

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

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

CreateProduct.TimeField

プロパティデフォルト説明
namestring必須フォームデータのフィールド名
labelstring必須入力フィールドのラベル
labelWeightenum"regular"ラベルの太さ
isRequiredbooleanundefined入力が必須かどうか
isDisabledbooleanundefined入力が無効かどうか
errorTextstringundefined入力のエラーテキスト
classNamestringundefinedスタイリング用の追加CSSクラス名

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

CreateProduct.CheckboxField

プロパティデフォルト説明
namestring必須フォームデータのフィールド名
labelstring必須チェックボックスラベル
messagestringundefinedチェックボックス説明メッセージ
showMessagebooleantrueメッセージを表示するかどうか
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはすべてのHTML checkbox 要素プロパティを継承します。

CreateProduct.SelectField

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

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


🔧 TypeScript サポート

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

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

interface CustomProductFormData extends Record<string, unknown> {
name: string;
description: string;
address1: string;
address2: string;
categoryId: string;
image: {url: string; type?: string; id?: string};
customField?: string;
}

const handleSubmit = (data: CustomProductFormData, event?: React.BaseSyntheticEvent) => {
// 型安全なフォーム処理
console.log('商品データ:', data);
console.log('イベント:', event);
};

const handleChange = (
setError: UseFormSetError<CustomProductFormData>,
getValues: UseFormGetValues<CustomProductFormData>,
clearErrors: UseFormClearErrors<CustomProductFormData>,
) => {
const values = getValues();
// フォーム値をバリデーションし、必要に応じてエラーを設定
if (!values.name) {
setError('name', {message: '商品名は必須です'});
} else {
clearErrors('name');
}
};

const categoryOptions = [
{value: 'electronics', label: '電子機器'},
{value: 'clothing', label: '衣類'},
{value: 'home', label: 'ホーム・ガーデン'},
];

const CreateProductForm = () => {
return (
<CreateProduct<CustomProductFormData>
onSubmit={handleSubmit}
onChange={handleChange}
categoryOptions={categoryOptions}
onAcceptAttachment={files => console.log('ファイルが承認されました:', files)}
onUploadAttachment={file => console.log('アップロード中:', file)}
onClearAttachment={() => console.log('添付ファイルがクリアされました')}>
<CreateProduct.MainInfo>
<CreateProduct.MainInfo.SectionTitle>商品詳細</CreateProduct.MainInfo.SectionTitle>
<CreateProduct.MainInfo.Dropzone />
<CreateProduct.MainInfo.NameField name="name" />
</CreateProduct.MainInfo>

<CreateProduct.BasicInfo>
<CreateProduct.BasicInfo.Title />
<CreateProduct.BasicInfo.CategoryField />
<CreateProduct.BasicInfo.DescriptionField />
</CreateProduct.BasicInfo>

<CreateProduct.AdditionalInfo>
<CreateProduct.AdditionalInfo.Title />
<CreateProduct.AdditionalInfo.Subtitle />
<CreateProduct.AdditionalInfo.Address1Field />
<CreateProduct.AdditionalInfo.Address2Field />
</CreateProduct.AdditionalInfo>

<CreateProduct.Actions>
<CreateProduct.Actions.SubmitButton>商品を作成</CreateProduct.Actions.SubmitButton>
</CreateProduct.Actions>
</CreateProduct>
);
};

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