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

ViewUserブロック

ViewUser は、MUI 上に構築されたキー・バリュー表示ブロックで、ヘッダー(タイトルと任意のアクションボタン)、任意のサブヘッダーを備えています。

インストール

npm install @nodeblocks/frontend-view-user-block

必要なもの

項目用途
labels.headerTitleヘッダーのメイン見出し
dataユーザーフィールドを Record<string, ReactNode>(行キーがラベルになる)または値のみの行用の ReactNode[] として渡す
labels.subheaderTitle (任意)ヘッダー下のセカンダリ行(例: 登録日)
labels.headerActionButton + headerAction (任意)アウトラインのヘッダーボタンのラベルとクリックハンドラー
layout (任意)one-column はキー/バリュー行を縦に積む; two-column は横並びで表示(デフォルト)
ユーザーデータはアプリ側で管理する

ViewUser はユーザー状態を保持しません — ページから labelsdata、任意の headerAction を渡してください。オブジェクト形式の data のキーが行ラベルになり、値は文字列または React ノード(複数行テキスト、リンク、レイアウト)にできます。labels.headerActionButtonheaderAction を設定すると、ハンドラー付きのヘッダーアクションボタンが表示されます。

コード例

ライブエディター
function Example() {
  const labels = {
    headerTitle: '佐藤 花子',
    subheaderTitle: '2023年11月22日から会員',
  };

  const data = {
    メール: 'hanako.sato@example.com',
    電話: '+81 (555) 123-4567',
    役割: 'フロントエンドエンジニア',
    所在地: '東京都渋谷区',
  };

  return <ViewUser labels={labels} data={data} />;
}
結果
Loading...

主要プロパティ

コアプロパティ

プロパティ必須デフォルト説明
dataRecord<string, ReactNode> | ReactNode[]いいえundefined行コンテンツ: オブジェクトのキーがフィールドラベルになる; 配列は値のみの行をレンダリング
labels{ headerTitle?: string; headerActionButton?: string; subheaderTitle?: string }いいえ{}ヘッダータイトル、任意のアクションボタンラベル、サブヘッダーのテキスト

コンテンツプロパティ

プロパティ必須デフォルト説明
labels.headerTitlestringいいえundefinedViewUser.Header のメイン見出し
labels.subheaderTitlestringいいえundefinedヘッダー下のセカンダリ行(ViewUser.Subheader
labels.headerActionButtonstringいいえundefinedアウトラインのヘッダーボタンのラベル; labels.headerActionButton または headerAction が設定されている場合(または ViewUser.HeaderActionButton に渡されている場合)に表示
headerAction() => voidいいえundefinedデフォルトのヘッダーアクションボタンがクリックされたときに呼び出される
layout'one-column' | 'two-column'いいえ'two-column'行レイアウト: キー/バリューを縦に積む vs 横並びの列

レイアウトと構成プロパティ

プロパティ必須デフォルト説明
childrenBlocksOverride | ReactNodeいいえundefined複合 JSX の子、または blocksblockOrder を返す関数オーバーライド
classNamestringいいえundefinedルートスタックのクラス名(nbb-view-user
sxSxPropsいいえundefinedルートスタック用の MUI システムスタイル(デフォルトレンダーには margin: 'auto' を含む)

ViewUserStackPropschildren を除く)を継承します。デフォルトの defaultBlockOrder: headersubheaderitemListitemitemKeyitemValue

サブコンポーネントのプロパティ

サブコンポーネントはコンテキストから読み取り、同じコンテンツキーをプロパティとして渡すとローカルで上書きできます。

サブコンポーネント主要プロパティ継承ベース
ViewUser.HeaderlabelsheaderTitleheaderActionButton)、headerActionchildrenclassNamesxStackPropsStack + Typography + 任意の ViewUser.HeaderActionButton
ViewUser.HeaderActionButtonlabelsheaderActionButton)、headerActionchildrenclassNameonClickButtonPropsButtonvariant="outlined"size="medium"
ViewUser.SubheaderlabelssubheaderTitleheaderTitleheaderActionButton)、childrenclassNamesxStackPropsStack + Typography
ViewUser.ItemListdatachildrenclassNamesxListPropsListcomponent="dl")+ ViewUser.Item
ViewUser.ItemlayoutchildrenclassNamesxListItemPropsListItem
ViewUser.Item.KeylayoutchildrenclassNamesxTypographyPropsTypographycomponent="dt"variant="subtitle1"
ViewUser.Item.ValuelayoutchildrenclassNamesxTypographyPropsTypographycomponent="dd"variant="body2"

デフォルト UI ブロック

ブロックベース備考
ViewUser(ルート)Stackspacing={3}margin: 'auto' の縦レイアウト(nbb-view-user
headerViewUser.HeaderStacklabels.headerTitlelabels.headerActionButton、またはカスタム children が設定されている場合にレンダリング; headerAction または labels.headerActionButton が設定されている場合は ViewUser.HeaderActionButton を含む
subheaderViewUser.SubheaderStacklabels.subheaderTitle またはカスタム children が設定されている場合にレンダリング
itemListViewUser.ItemListListdata オブジェクトのエントリまたは配列の値をキー/バリュー行にマッピング

デフォルトのルートレンダリング順序: headersubheaderitemList

TypeScript

import * as React from 'react';
import { ViewUser } from '@nodeblocks/frontend-view-user-block';
import type { ReactNode } from 'react';

type UserLabels = {
headerTitle?: string;
headerActionButton?: string;
subheaderTitle?: string;
};

type UserData = Record<string, ReactNode> | ReactNode[];

export function UserDetailView() {
const labels: UserLabels = {
headerTitle: '佐藤 花子',
subheaderTitle: '2023年11月22日から会員',
headerActionButton: 'プロフィールを編集',
};

const data: UserData = {
メール: 'hanako.sato@example.com',
電話: '+81 (555) 123-4567',
役割: 'フロントエンドエンジニア',
};

return (
<ViewUser
labels={labels}
data={data}
headerAction={() => {
/* 遷移または編集ダイアログを開く */
}}
/>
);
}