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

注文テーブルリストブロック

ListOrderTableコンポーネントは、ReactとTypeScriptで構築された完全にカスタマイズ可能でアクセシブルな注文テーブルインターフェースです。モダンなデザインパターン、ソート可能な列、アクションドロップダウン、タブ、ページネーションサポート、ローディング状態、および高度な注文管理アプリケーション向けの柔軟なカスタマイズオプションを備えた完全な表形式注文リスト体験を提供します。


🚀 インストール

npm install @nodeblocks/frontend-list-order-table-block@0.1.0

📖 使用法

import {ListOrderTable} from '@nodeblocks/frontend-list-order-table-block';
ライブエディター
function BasicListOrderTable() {
  const [currentTab, setCurrentTab] = useState('pending');
  const [isLoading] = useState(false);

  const orderData = [
    {
      id: '1',
      createdAt: '2024-01-15T10:30:00Z',
      orderName: 'ORD-001',
      title: 'オフィス用品注文',
      status: 'pending',
    },
    {
      id: '2',
      createdAt: '2024-01-14T14:20:00Z',
      orderName: 'ORD-002',
      title: 'ソフトウェアライセンス',
      status: 'accepted',
    },
  ];

  const tabs = [{label: '保留中の注文'}, {label: '承認済み注文'}, {label: 'キャンセル済み注文'}];

  const labels = {
    emptyStateMessage: '注文が見つかりません',
    actions: {
      headerAction: '注文作成'
    },
    headerRow: {
      createdAt: '作成日',
      title: '注文タイトル',
      orderName: '注文ID'
    },
      rowActions: {
      accepted: '注文承認',
      canceled: '注文キャンセル',
      processing: '処理中にマーク',
    },
  };

  const handleOrderAccepted = (orderId, title) => {
    console.log('注文が承認されました:', orderId, title);
  };

  const handleOrderRejected = (orderId, title) => {
    console.log('注文が拒否されました:', orderId, title);
  };

  const handleOrderProcessing = (orderId, title) => {
    console.log('注文処理中:', orderId, title);
  };

  const handleNavigate = (path) => {
    console.log('ナビゲート先:', path);
  };

  const getRowHref = (row) => `#${row.id}`;
  const getUpdateRowHref = (row) => `#${row.id}/edit`;

  return (
    <ListOrderTable
      listOrderTableTitle="注文管理"
      labels={labels}
      isLoading={isLoading}
      onNavigate={handleNavigate}
      onOrderAccepted={handleOrderAccepted}
      onOrderRejected={handleOrderRejected}
      onOrderProcessing={handleOrderProcessing}
      data={orderData}
      rowHref={getRowHref}
      updateRowHref={getUpdateRowHref}
      tabs={tabs}
      currentTab={currentTab}
      onTabChange={setCurrentTab}
      createHref="#new"
      style={{
        backgroundColor: 'white',
        padding: '8px',
      }}
    >
      <ListOrderTable.Header style={{display: 'flex', justifyContent: 'space-between'}}>
        <ListOrderTable.Title />
        <ListOrderTable.Action />
      </ListOrderTable.Header>
      <ListOrderTable.Content>
        {isLoading ? (
          <ListOrderTable.Loader />
        ) : (
          <>
            <ListOrderTable.Tabs />
            <ListOrderTable.Table />
          </>
        )}
      </ListOrderTable.Content>
    </ListOrderTable>
  );
}
結果
Loading...

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

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

プロパティデフォルト説明
listOrderTableTitleReactNode必須注文テーブルセクションのタイトル
labelsTableLabels必須テーブルヘッダー、アクション、メッセージのラベルオブジェクト
isLoadingbooleanundefinedテーブルが現在読み込み中かどうか
onNavigate(to: string) => void必須ナビゲーション用のコールバック関数
onOrderAccepted(id: string, title?: string) => void必須注文が承認されたときのコールバック関数
onOrderRejected(id: string, title?: string) => void必須注文が拒否されたときのコールバック関数
onOrderProcessing(id: string, title?: string) => void必須注文が処理中としてマークされたときのコールバック関数
dataListOrderTableRowData[]必須注文データオブジェクトの配列
rowHref(row: ListOrderTableRowData) => string必須行リンクURLを生成する関数
updateRowHref(row: ListOrderTableRowData) => string必須更新行リンクURLを生成する関数
tabsTabData[]必須タブ設定オブジェクトの配列
currentTabstringundefined現在アクティブなタブ識別子
onTabChange(tab: string) => voidundefinedタブが変更されたときのコールバック関数
createHrefstring必須新規注文作成用のURL
pagination{currentPage: number; onPageChange: (page: number) => void; totalPages: number}undefinedページネーション設定オブジェクト
classNamestringundefinedコンテナスタイリング用の追加CSSクラス名
childrenBlocksOverrideundefinedデフォルトブロックをオーバーライドまたはカスタムコンポーネントレンダリングするための関数

注意: メインコンポーネントはMUI Stackプロパティを継承します。

サブコンポーネント

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

ListOrderTable.Title

プロパティデフォルト説明
childrenReactNodeコンテキストからタイトルコンテンツ - コンテキストのlistOrderTableTitleをオーバーライド
listOrderTableTitleReactNodeコンテキストからchildrenが提供されない場合のタイトルテキスト
variantTypographyProps['variant']"h4"MUI Typographyバリアント
componentElementType"h1"レンダリングするHTML要素
classNamestringundefinedスタイリング用の追加CSSクラス名

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

ListOrderTable.Action

プロパティデフォルト説明
childrenReactNodeundefinedデフォルトアクションレンダリングをオーバーライドするカスタムコンテンツ
createHrefstringコンテキストから作成アクションボタンのURL
labelsTableLabelsコンテキストからアクションテキストのラベル
onNavigate(to: string) => voidコンテキストから作成ボタンのナビゲーションコールバック
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはMUI Stackプロパティを継承します(direction"row"に固定)。

ListOrderTable.Header

プロパティデフォルト説明
childrenReactNodeundefinedデフォルトヘッダーレンダリングをオーバーライドするカスタムコンテンツ
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはMUI Stackプロパティを継承します。デフォルトレイアウトはdirection="row"justifyContent: 'space-between'alignItems: 'center'です。

ListOrderTable.Loader

プロパティデフォルト説明
childrenReactNodeCircularProgressカスタムローディングインジケーターコンテンツ
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはMUI Stackプロパティを継承します。デフォルトの整列はalignItems: 'center'です。

ListOrderTable.Content

プロパティデフォルト説明
childrenReactNodeundefinedデフォルトコンテンツレンダリングをオーバーライドするカスタムコンテンツ
isLoadingbooleanコンテキストからコンテキストからのローディング状態
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはMUI Boxプロパティを継承します。カスタムchildrenを使用せずローディング中でない場合、spacing={3}のStack内にTabsTableをレンダリングします。

ListOrderTable.Tabs

プロパティデフォルト説明
tabsTabData[]コンテキストからタブ設定オブジェクトの配列
currentTabstringコンテキストから現在アクティブなタブラベル
onTabChange(tab: string) => voidコンテキストからタブ変更コールバック関数
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはMUI Tabsプロパティを継承します(valueonChangevariantは内部で管理されます)。デフォルトでvariant="fullWidth"を使用します。

ListOrderTable.Table

プロパティデフォルト説明
labelsTableLabelsコンテキストからテーブルヘッダー、アクション、メッセージのラベルオブジェクト
dataListOrderTableRowData[]コンテキストからテーブルデータの配列
rowHref(row: ListOrderTableRowData) => stringコンテキストから行リンクURLを生成する関数
onNavigate(to: string) => voidコンテキストから行クリック時のナビゲーションコールバック
onOrderAcceptedDropdownItemActionコンテキストから注文が承認されたときのコールバック
onOrderRejectedDropdownItemActionコンテキストから注文が拒否されたときのコールバック
onOrderProcessingDropdownItemActionコンテキストから注文が処理中としてマークされたときのコールバック
paginationPaginationPropsコンテキストからページネーション設定オブジェクト
spacingnumber3要素間のStackスペーシング
classNamestringundefinedスタイリング用の追加CSSクラス名

注意: このコンポーネントはMUI Stackプロパティを継承します。


🎨 設定例

Custom Header Styling

<ListOrderTable.Header 
sx={{
bgcolor: 'primary.light',
borderRadius: 2,
p: 2
}}
/>

Custom Title Styling

<ListOrderTable.Title 
variant="h3"
component="h2"
sx={{ color: 'primary.main', fontWeight: 700 }}
/>

Custom Action Button

<ListOrderTable.Action>
<Button variant="outlined" startIcon={<Add />}>
カスタム作成ボタン
</Button>
</ListOrderTable.Action>

Custom Table Styling

<ListOrderTable.Table 
sx={{
'& .MuiTableCell-root': {
borderBottom: '2px solid',
borderColor: 'divider'
}
}}
/>

Using Block Override Pattern

<ListOrderTable {...props}>
{({defaultBlocks, defaultBlockOrder}) => ({
blocks: {
header: {
...defaultBlocks.header,
props: {
...defaultBlocks.header.props,
sx: {background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'},
},
},
},
blockOrder: defaultBlockOrder,
})}
</ListOrderTable>

🔧 TypeScriptサポート

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

import {ListOrderTable} from '@nodeblocks/frontend-list-order-table-block';
import {Stack} from '@mui/material';
import {ComponentProps, ReactNode} from 'react';

// Tab data interface
interface TabData {
key?: string;
label: string;
isDisabled?: boolean;
subtitle?: string;
}

// Main component interface
interface ListOrderTableProps<Tabs extends TabData[]> extends Omit<ComponentProps<typeof Stack>, 'children'> {
listOrderTableTitle: ReactNode;
labels: TableLabels;
isLoading?: boolean;
onNavigate: (to: string) => void;
onOrderAccepted: DropdownItemAction;
onOrderRejected: DropdownItemAction;
onOrderProcessing: DropdownItemAction;
data: ListOrderTableRowData[];
rowHref: (row: ListOrderTableRowData) => string;
updateRowHref: (row: ListOrderTableRowData) => string;
tabs: Tabs;
currentTab?: Tabs[number]['label'];
onTabChange?: (tab: Tabs[number]['label']) => void;
createHref: string;
pagination?: PaginationProps;
children?: BlocksOverride;
}

// Row data interface
export interface ListOrderTableRowData {
createdAt: string;
id: string;
orderName: string;
title: string;
status: string;
}

// Action callback type
export type DropdownItemAction = (
order: ListOrderTableRowData['id'],
title?: ListOrderTableRowData['title'],
) => void;

// Pagination props interface
export interface PaginationProps {
className?: string;
currentPage: number;
onPageChange: (page: number) => void;
totalPages: number;
}

// Labels interface
interface TableLabels {
emptyStateMessage: string;
actions?: {
headerAction: string;
};
headerRow: {
createdAt: string;
title: string;
orderName: string;
};
rowActions: {
canceled: string;
processing: string;
accepted: string;
};
}

// Usage example with full typing
function TypedListOrderTableExample() {
const [currentTab, setCurrentTab] = useState('pending');
const [isLoading] = useState(false);

const orders: ListOrderTableRowData[] = [
{
createdAt: '2024-01-15T10:30:00Z',
id: '1',
orderName: 'ORD-001',
title: '注文タイトル',
status: 'pending',
},
];

const tableTabs: TabData[] = [
{label: '保留中', key: 'pending'},
{label: '承認済み', key: 'accepted'},
{label: '拒否済み', key: 'rejected'},
];

const tableLabels: TableLabels = {
emptyStateMessage: '利用可能な注文がありません',
actions: {headerAction: '新規注文'},
headerRow: {
createdAt: '作成日',
title: '注文タイトル',
orderName: '注文番号',
},
rowActions: {
accepted: '承認',
canceled: '拒否',
processing: '処理',
},
};

const onAcceptOrder: DropdownItemAction = (id, title) => {
console.log('注文を承認:', id, title);
};

const onRejectOrder: DropdownItemAction = (id, title) => {
console.log('注文を拒否:', id, title);
};

const onProcessOrder: DropdownItemAction = (id, title) => {
console.log('注文を処理:', id, title);
};

return (
<ListOrderTable
listOrderTableTitle="注文ダッシュボード"
labels={tableLabels}
isLoading={isLoading}
onNavigate={path => console.log('ナビゲート:', path)}
onOrderAccepted={onAcceptOrder}
onOrderRejected={onRejectOrder}
onOrderProcessing={onProcessOrder}
data={orders}
rowHref={row => `/orders/${row.id}`}
updateRowHref={row => `/orders/${row.id}/edit`}
tabs={tableTabs}
currentTab={currentTab}
onTabChange={setCurrentTab}
createHref="#orders/create"
>
<ListOrderTable.Header />
<ListOrderTable.Content />
<ListOrderTable.Table />
</ListOrderTable>
);
}

📝 注意事項

  • ルートコンポーネントはMUIのStackを使用し、デフォルトでspacing={3}sx={{ p: 3 }}パディングを持ちます
  • 日付はluxonライブラリを使用してyyyy/M/d HH:mm形式でフォーマットされます
  • 行タイトルにはホバー時に完全な日時を表示するツールチップがあります
  • テーブルはMUI TableTableContainerTableHeadTableBodyTableRowコンポーネントを使用します
  • 行アクションはMUI MenuMenuItemコンポーネントとアイコンを使用したドロップダウンメニューで表示されます
  • Tabsコンポーネントはタブが提供されないか配列が空の場合はnullを返します
  • 空状態はlabelsのemptyStateMessagePersonアイコンを表示します
  • ページネーションはMUI Paginationコンポーネントをvariant="outlined"shape="rounded"で使用します
  • rowHrefが有効なURLを返す場合、テーブル行はクリック可能です(カーソルがポインターに変わります)
  • すべてのサブコンポーネントはMUIコンポーネントプロパティを継承し、スタイリング用のsxプロパティをサポートします
  • ブロックオーバーライドパターンにより、デフォルトブロックのカスタマイズ、置換、並べ替えが可能です

React、TypeScript、MUIを使用して❤️で構築されました。