View Attribute Selection Block
ViewAttributeSelection is a key-value view block built on MUI with a header (title and optional action button), optional subheader.
Installation
- npm
- yarn
- pnpm
- bun
npm install @nodeblocks/frontend-view-attribute-selection-block
yarn add @nodeblocks/frontend-view-attribute-selection-block
pnpm add @nodeblocks/frontend-view-attribute-selection-block
bun add @nodeblocks/frontend-view-attribute-selection-block
What You Need
| Item | Why it matters |
|---|---|
labels.headerTitle | Section title in the header (default 職種) |
data | Selected attributes as ReactNode[] for value-only rows, or Record<string, ReactNode> when each row needs a label |
labels.headerActionButton + headerAction (optional) | Outlined header button label (default 編集) and click handler |
labels.subheaderTitle (optional) | Secondary line under the header |
layout (optional) | one-column stacks key/value rows; two-column shows them side by side (default) |
ViewAttributeSelection does not own selection state — pass labels, data, and optional headerAction from your page. Use a ReactNode[] when rows are value-only (typical for a list of selected roles); use an object when each attribute category needs its own label (for example skill areas in one-column layout). Set labels.headerActionButton and headerAction to show the header edit button.
Code Examples
- Quick Start
- Labels
- Layouts
- Compound Components
- Block Override
function Example() { const data = [ <Box key="roles" sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}> <Typography variant="body2">Frontend Engineer (not selected)</Typography> <Typography variant="body2">Backend Engineer (5 years)</Typography> <Typography variant="body2">Database Engineer (5 years)</Typography> </Box>, ]; return <ViewAttributeSelection data={data} />; }
Customize header copy, the edit action, subheader, and row content. Use layout="one-column" when each labeled category should stack vertically.
function Example() { const [lastAction, setLastAction] = React.useState(''); const labels = { headerTitle: 'Job roles', subheaderTitle: 'Last updated March 12, 2026', headerActionButton: 'Edit roles', }; const data = { Frontend: 'React.js / Vue.js / JavaScript (ES6+) / HTML5 / Tailwind CSS', Backend: 'Node.js / Flask / PHP', 'Full stack': '-', Database: 'MongoDB / MySQL / DynamoDB / Firebase', Mobile: '-', Testing: '-', DevOps: '-', Security: '-', }; return ( <Box> <ViewAttributeSelection labels={labels} data={data} layout="one-column" headerAction={() => setLastAction('Edit roles')} /> {lastAction ? ( <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mt: 1 }}> Last action: {lastAction} </Typography> ) : null} </Box> ); }
Put headerTitle, subheaderTitle, and headerActionButton on the root labels object (or on ViewAttributeSelection.Header / ViewAttributeSelection.HeaderActionButton in compound layouts). Omit labels to use the built-in defaults 職種 and 編集. Row labels come from data object keys when using object-shaped data.
Try different layouts for labeled attribute rows.
function Example() { const [layout, setLayout] = React.useState('two-column'); const labels = { headerTitle: 'Skills profile', headerActionButton: 'Edit', }; const data = { Frontend: 'React · TypeScript · Tailwind CSS', Backend: 'Node.js · PostgreSQL', DevOps: 'Docker · GitHub Actions', Mobile: 'React Native', }; return ( <Box> <Box sx={{ display: 'flex', gap: 1, mb: 2 }}> <Box component="button" type="button" onClick={() => setLayout('two-column')} sx={{ px: 1.5, py: 0.75, borderRadius: 1, border: '1px solid', borderColor: layout === 'two-column' ? 'primary.main' : 'divider', bgcolor: layout === 'two-column' ? 'primary.main' : 'background.paper', color: layout === 'two-column' ? 'primary.contrastText' : 'text.primary', cursor: 'pointer', fontSize: 14, fontWeight: layout === 'two-column' ? 600 : 400, }} > Two column </Box> <Box component="button" type="button" onClick={() => setLayout('one-column')} sx={{ px: 1.5, py: 0.75, borderRadius: 1, border: '1px solid', borderColor: layout === 'one-column' ? 'primary.main' : 'divider', bgcolor: layout === 'one-column' ? 'primary.main' : 'background.paper', color: layout === 'one-column' ? 'primary.contrastText' : 'text.primary', cursor: 'pointer', fontSize: 14, fontWeight: layout === 'one-column' ? 600 : 400, }} > One column </Box> </Box> <ViewAttributeSelection labels={labels} data={data} layout={layout} /> </Box> ); }
two-column (default) shows each field label and value side by side. one-column stacks the label above the value with relaxed padding — useful for long skill lists or narrow viewports.
Compose ViewAttributeSelection.Header and ViewAttributeSelection.ItemList directly. Pass labels, data, and headerAction on children instead of only on the root.
function Example() { const [lastAction, setLastAction] = React.useState(''); const data = [ <Box key="roles" sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}> <Typography variant="body2">Product Designer (3 years)</Typography> <Typography variant="body2">UX Researcher (2 years)</Typography> <Typography variant="body2">Design Systems (1 year)</Typography> </Box>, ]; return ( <Box> <ViewAttributeSelection layout="two-column"> <ViewAttributeSelection.Header labels={{ headerTitle: 'Registered roles', headerActionButton: 'Edit roles', }} headerAction={() => setLastAction('Edit roles')} sx={{ px: 2, py: 1.5, bgcolor: 'grey.50', borderRadius: 2, border: '1px solid', borderColor: 'divider', }} /> <ViewAttributeSelection.ItemList data={data} sx={{ border: '1px solid', borderColor: 'divider', borderRadius: 2, overflow: 'hidden', '& .MuiListItem-root': { bgcolor: 'background.paper' }, }} /> </ViewAttributeSelection> {lastAction ? ( <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mt: 1 }}> Last action: {lastAction} </Typography> ) : null} </Box> ); }
Use function children with defaultBlocks and defaultBlockOrder to inject blocks, replace defaults, and control order.
function Example() { const [noticeVisible, setNoticeVisible] = React.useState(true); const labels = { headerTitle: 'Job roles', subheaderTitle: 'Selections are read-only on this page', }; const data = [ <Box key="roles" sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}> <Typography variant="body2">Frontend Engineer (not selected)</Typography> <Typography variant="body2">Backend Engineer (5 years)</Typography> <Typography variant="body2">Database Engineer (5 years)</Typography> </Box>, ]; return ( <ViewAttributeSelection labels={labels} data={data}> {({ defaultBlocks, defaultBlockOrder }) => ({ blocks: { ...defaultBlocks, selectionNotice: noticeVisible ? ( <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 2, px: 2, py: 1.5, mb: 1, borderRadius: 2, bgcolor: 'info.main', color: 'info.contrastText', }} > <Typography variant="body2" sx={{ fontWeight: 600 }}> Demo: this is a custom block above the attribute list </Typography> <Box component="button" type="button" onClick={() => setNoticeVisible(false)} aria-label="Dismiss notification" sx={{ flexShrink: 0, border: '1px solid rgba(255,255,255,0.35)', bgcolor: 'rgba(255,255,255,0.12)', color: 'inherit', borderRadius: '50%', width: 28, height: 28, cursor: 'pointer', fontSize: 16, lineHeight: 1, }} > × </Box> </Box> ) : null, header: ( <ViewAttributeSelection.Header labels={labels} sx={{ px: 2, py: 2, borderRadius: 2, border: '1px solid', borderColor: 'divider', bgcolor: 'background.paper', }} /> ), itemList: ( <ViewAttributeSelection.ItemList data={data} sx={{ mt: 2, border: '1px solid', borderColor: 'divider', borderRadius: 2, '& .MuiListItem-root:nth-of-type(even)': { bgcolor: 'grey.50' }, }} /> ), }, blockOrder: [ ...(noticeVisible ? ['selectionNotice'] : []), 'header', 'subheader', 'itemList', ], })} </ViewAttributeSelection> ); }
When to use block overrides
Default defaultBlockOrder is header, subheader, itemList, item, itemKey, itemValue. The default render uses itemList to map data; the separate item / itemKey / itemValue entries are for granular overrides. This example prepends a dismissible selectionNotice, replaces header and itemList with styled variants, and omits unused block keys from blockOrder.
Important Props
Core Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
data | Record<string, ReactNode> | ReactNode[] | No | [] | Row content: object keys become field labels; arrays render value-only rows |
labels | { headerTitle?: string; headerActionButton?: string; subheaderTitle?: string } | No | {} (merged with block defaults below) | Header title, optional action button label, and subheader copy |
Content Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
labels.headerTitle | string | No | 職種 | Main heading in ViewAttributeSelection.Header |
labels.subheaderTitle | string | No | undefined | Secondary line under the header (ViewAttributeSelection.Subheader) |
labels.headerActionButton | string | No | 編集 | Label for the outlined header button; shown when labels.headerActionButton or headerAction is set. |
headerAction | () => void | No | undefined | Invoked when the default header action button is clicked. |
layout | 'one-column' | 'two-column' | No | 'two-column' | Row layout: stacked key/value vs side-by-side columns |
Layout and Composition Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
children | BlocksOverride | ReactNode | No | undefined | Compound JSX children or function override returning blocks and blockOrder |
className | string | No | undefined | Class name on the root stack (nbb-view-attribute-selection) |
sx | SxProps | No | undefined | MUI system styles for the root stack (default render includes margin: 'auto') |
ViewAttributeSelection inherits StackProps (except children). Default defaultBlockOrder: header, subheader, itemList, item, itemKey, itemValue.
Sub-component props
Sub-components read from context and accept the same content keys as props to override locally.
| Sub-component | Main Props | Inherits | Built on |
|---|---|---|---|
ViewAttributeSelection.Header | labels (headerTitle, headerActionButton), headerAction, children, className, sx | StackProps | Stack + Typography + optional ViewAttributeSelection.HeaderActionButton |
ViewAttributeSelection.HeaderActionButton | labels (headerActionButton), headerAction, children, className, onClick | ButtonProps | Button (variant="outlined", size="medium") |
ViewAttributeSelection.Subheader | labels (subheaderTitle, headerTitle, headerActionButton), children, className, sx | StackProps | Stack + Typography |
ViewAttributeSelection.ItemList | data, children, className, sx | ListProps | List (component="dl") + ViewAttributeSelection.Item rows |
ViewAttributeSelection.Item | layout, children, className, sx | ListItemProps | ListItem |
ViewAttributeSelection.Item.Key | layout, children, className, sx | TypographyProps | Typography (component="dt", variant="subtitle1") |
ViewAttributeSelection.Item.Value | layout, children, className, sx | TypographyProps | Typography (component="dd", variant="body2") |
Default UI Blocks
| Block | Built on | Notes |
|---|---|---|
ViewAttributeSelection (root) | Stack | Column layout with spacing={3}, margin: 'auto' (nbb-view-attribute-selection) |
header (ViewAttributeSelection.Header) | Stack | Renders when labels.headerTitle, labels.headerActionButton, or custom children is set; includes ViewAttributeSelection.HeaderActionButton when headerAction or labels.headerActionButton is set |
subheader (ViewAttributeSelection.Subheader) | Stack | Renders when labels.subheaderTitle or custom children is set |
itemList (ViewAttributeSelection.ItemList) | List | Maps data object entries or array values to key/value rows |
Default root render order: header → subheader → itemList.
TypeScript
import * as React from 'react';
import { ViewAttributeSelection } from '@nodeblocks/frontend-view-attribute-selection-block';
import type { ReactNode } from 'react';
type AttributeSelectionLabels = {
headerTitle?: string;
headerActionButton?: string;
subheaderTitle?: string;
};
type AttributeSelectionData = Record<string, ReactNode> | ReactNode[];
export function AttributeSelectionDetailView() {
const labels: AttributeSelectionLabels = {
headerTitle: 'Job roles',
headerActionButton: 'Edit roles',
};
const data: AttributeSelectionData = [
<div key="roles">
<div>Frontend Engineer (not selected)</div>
<div>Backend Engineer (5 years)</div>
</div>,
];
return (
<ViewAttributeSelection
labels={labels}
data={data}
headerAction={() => {
/* navigate or open edit dialog */
}}
/>
);
}