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

商品作成ブロック

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


🚀 インストール

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

📖 使用方法

import {CreateProduct} from '@nodeblocks/frontend-create-product-block';
function BasicCreateProduct() {
const categoryOptions = [
{ value: 'electronics', label: 'Electronics' },
{ value: 'clothing', label: 'Clothing' },
{ value: 'home', label: 'Home & Garden' }
];

return (
<CreateProduct
categoryOptions={categoryOptions}
onSubmit={(formData) => {
console.log('Product created:', formData);
}}
onChange={(setError, getValues, clearErrors) => {
const values = getValues();
console.log('Form values:', values);
}}
onAcceptAttachment={(files) => {
console.log('File accepted:', files);
}}
onUploadAttachment={(file) => {
console.log('Uploading file:', file);
// Handle file upload logic
}}
onClearAttachment={() => {
console.log('Attachment cleared');
}}>
<CreateProduct.MainInfo>
<CreateProduct.MainInfo.SectionTitle>Product Information</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>Create Product</CreateProduct.Actions.SubmitButton>
</CreateProduct.Actions>
</CreateProduct>
);
}

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

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

プロパティデフォルト説明
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 要素のすべての props を継承します。

サブコンポーネント

CreateProduct コンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントはメインコンポーネントのコンテキストからデフォルト値を受け取り、props でそれらを上書きできます。

CreateProduct.MainInfo

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

プロパティデフォルト説明
childrenReactNodeundefinedデフォルトのメイン情報フィールドを上書きするカスタム内容
directionenum"column"アクションボタンの flex 方向
alignItemsenum"stretch"コンテナ内アイテムの配置
gapSizeenum"S"コンテナ内アイテム間の間隔
CreateProduct.MainInfo.SectionTitle
プロパティデフォルト説明
childrenReactNode"メイン情報"メイン情報セクションのタイトル内容
sizeenum"L"タイトルの Typography サイズ
typeenum"heading"Typography の種類
colorenum"low-emphasis"タイトルの配色テーマ
weightenum"bold"Typography のウェイト
classNamestringundefinedスタイル用の追加 CSS クラス名
CreateProduct.MainInfo.Dropzone
プロパティデフォルト説明
beforeUploadMessagestring"アップロード"ファイルアップロード前に表示されるメッセージ
beforeUploadSubtitlestring"アップロードするファイルを選択してください。"ファイルアップロード前に表示されるサブタイトル
afterUploadOptionsButtonstring"オプション"アップロード後のオプションボタンの文言
replaceFileButtonstring"新しいファイルを選択"ファイル置換ボタンの文言
deleteFileButtonstring"削除"ファイル削除ボタンの文言
maxFilesnumber1許可される最大ファイル数
acceptstring"image/*"受け入れ可能なファイル प्रकार
maxSizenumber5242880最大ファイルサイズ(バイト、5MB)
classNamestringundefinedスタイル用の追加 CSS クラス名
CreateProduct.MainInfo.NameField
プロパティデフォルト説明
namestring"name"フォームデータと検証に使用するフィールド名
labelstring"商品名"入力の上に表示されるフィールドラベル
labelWeightenum"regular"フィールドラベルの太さ
namestring"applicationUserEmail"フォームデータのフィールド名
classNamestringundefinedスタイル用の追加 CSS クラス名
errorTextstringundefined入力のエラーテキスト
isDisabledbooleanundefined入力が無効かどうか
isRequiredbooleanundefined入力が必須かどうか
onOperationClick() => voidundefined操作用 onClick コールバック
postfixTextstringundefinedコンポーネントの後ろに配置するテキスト
showPasswordbooleanundefinedパスワードを表示するかどうか

Note: 注: このコンポーネントは、共通の HTML input 要素 props も追加で継承します。

CreateProduct.BasicInfo

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

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

Note: 注: このコンポーネントは、共通の HTML select 要素 props も追加で継承します。

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

Note: 注: このコンポーネントは、共通の HTML textarea 要素 props も追加で継承します。

CreateProduct.AdditionalInfo

所在地の詳細を含む追加商品情報のコンテナです。

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

Note: 注: このコンポーネントは HTML select 要素のすべての props を継承します。

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

Note: 注: このコンポーネントは、共通の HTML input 要素 props も追加で継承します。

CreateProduct.Actions

フォーム操作ボタンのコンテナです。

プロパティデフォルト説明
childrenBlocksOverrideundefinedデフォルトのアクションボタンを上書きするカスタム内容
classNamestringundefinedスタイル用の追加 CSS クラス名

注: このコンポーネントは HTML div 要素のすべての props を継承します。

CreateProduct.Actions.SubmitButton
プロパティデフォルト説明
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 も追加で継承します。

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

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

CreateProduct.TextField

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

Note: 注: このコンポーネントは、共通の HTML input 要素 props も追加で継承します。

CreateProduct.TimeField

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

Note: 注: このコンポーネントは、共通の HTML input 要素 props も追加で継承します。

CreateProduct.CheckboxField

プロパティデフォルト説明
namestring必須フォームデータのフィールド名
labelstringRequiredチェックボックスのラベル
messagestringundefinedチェックボックスの説明メッセージ
showMessagebooleantrueWhether to show the message
classNamestringundefinedスタイル用の追加 CSS クラス名

Note: 注: このコンポーネントは HTML checkbox 要素のすべての props を継承します。

CreateProduct.SelectField

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

Note: 注: このコンポーネントは、共通の HTML select 要素 props も追加で継承します。


🔧 TypeScript サポート

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

import {CreateProduct} from '@nodeblocks/frontend-create-product-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';

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) => {
// Type-safe form handling
console.log('Product data:', data);
console.log('Event:', event);
};

const handleChange = (
setError: UseFormSetError<CustomProductFormData>,
getValues: UseFormGetValues<CustomProductFormData>,
clearErrors: UseFormClearErrors<CustomProductFormData>,
) => {
const values = getValues();
// Validate form values and set errors if needed
if (!values.name) {
setError('name', {message: 'Product name is required'});
} else {
clearErrors('name');
}
};

const categoryOptions = [
{value: 'electronics', label: 'Electronics'},
{value: 'clothing', label: 'Clothing'},
{value: 'home', label: 'Home & Garden'},
];

const CreateProductForm = () => {
return (
<CreateProduct<CustomProductFormData>
onSubmit={handleSubmit}
onChange={handleChange}
categoryOptions={categoryOptions}
onAcceptAttachment={files => console.log('Files accepted:', files)}
onUploadAttachment={file => console.log('Uploading:', file)}
onClearAttachment={() => console.log('Attachment cleared')}>
<CreateProduct.MainInfo>
<CreateProduct.MainInfo.SectionTitle>Product Details</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>Create Product</CreateProduct.Actions.SubmitButton>
</CreateProduct.Actions>
</CreateProduct>
);
};

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