View Order Block
The ViewOrder Component is a fully customizable order display component built with React and TypeScript. It provides a complete interface for viewing order details including header, status information, and customizable information rows with modern design patterns.
π Installationβ
npm install @nodeblocks/frontend-view-order-block@0.2.0
π Usageβ
import {ViewOrder} from '@nodeblocks/frontend-view-order-block';
- Basic Usage
- Advanced Usage
function BasicViewOrder() { const orderInfoRows = [ {label: 'Order ID', value: '#12345'}, {label: 'Customer', value: 'John Doe'}, {label: 'Date', value: '2024-01-15'}, {label: 'Total', value: '$199.99'}, ]; return ( <ViewOrder headerLabel="Order Details" statusText="Processing" statusLabel="Current Status" infoRows={orderInfoRows} style={{backgroundColor: 'white', padding: '16px'}} > <ViewOrder.Header /> <ViewOrder.InfoRowList /> </ViewOrder> ); }
function AdvancedViewOrder() { const orderInfoRows = [ { label: 'π¦ Order ID', value: ( <span style={{ fontFamily: 'monospace', background: 'rgba(105, 124, 213, 0.1)', padding: '4px 8px', borderRadius: '6px', fontWeight: 'bold', }} > #ORD-2024-789 </span> ), }, { label: 'π€ Customer', value: ( <div style={{display: 'flex', alignItems: 'center', gap: '8px'}}> <div style={{ width: '32px', height: '32px', borderRadius: '50%', background: 'linear-gradient(135deg, rgb(105, 124, 213), rgb(85, 104, 193))', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'white', fontSize: '14px', fontWeight: 'bold', }} > JD </div> <span style={{fontWeight: '600', color: '#2c3e50'}}>John Doe</span> </div> ), }, { label: 'π Order Date', value: ( <div style={{ background: 'linear-gradient(135deg, #e8f5e8, #f0f8f0)', padding: '8px 12px', borderRadius: '8px', border: '1px solid #4CAF50', color: '#2e7d32', fontWeight: 'bold', }} > January 15, 2024 </div> ), }, { label: 'π° Total Amount', value: ( <div style={{ fontSize: '24px', fontWeight: 'bold', color: '#27ae60', }} > $1,299.99 </div> ), }, ]; return ( <ViewOrder headerLabel="π― Order #ORD-2024-789" statusText="β Delivered" statusLabel="" infoRows={orderInfoRows} > {({defaultBlocks, defaultBlockOrder}) => ({ blocks: { header: { ...defaultBlocks.header, props: { ...defaultBlocks.header.props, sx: { background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', color: 'white', padding: '24px', borderRadius: '16px 16px 0 0', '& .nbb-view-order-status': { color: 'black', fontWeight: 'bold', }, }, }, }, infoRowList: { ...defaultBlocks.infoRowList, props: { ...defaultBlocks.infoRowList.props, sx: { background: 'white', padding: '24px', borderRadius: '0 0 16px 16px', boxShadow: '0 4px 20px rgba(0,0,0,0.1)', }, }, }, }, blockOrder: defaultBlockOrder, })} </ViewOrder> ); }
π§ Props Referenceβ
Main Component Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
headerLabel | string | "Order Details" | Label text for the order header section |
statusText | string | undefined | Text content for the order status display |
statusLabel | string | "Status" | Label text for the status field |
imageSrc | string | undefined | Source URL for an order image (available in context) |
infoRows | Array<{label: string, value: ReactNode}> | [] | Array of information rows to display |
className | string | undefined | Additional CSS class name for styling the container |
children | BlocksOverride | undefined | Function to override default blocks or custom component rendering |
Note: The main component inherits MUI Stack props. Root container uses spacing={4} and sx={{ p: 3 }} by default.
Sub-Componentsβ
The ViewOrder component provides several sub-components for different sections. All sub-components receive their default values from the main component's context and can override these values through props.
ViewOrder.Headerβ
Container for the order header including title and status information.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | undefined | Custom content to override default header rendering |
headerLabel | string | From context | Label text for the header |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits MUI Stack props. Default layout is direction="row" with spacing={4}, justifyContent: 'space-between', and alignItems: 'center'.
ViewOrder.Statusβ
Displays the order status information with label and styled status box.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | undefined | Custom content to override default status rendering |
statusLabel | string | From context | Label for the status field |
statusText | string | From context | Text content for the status |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits MUI Stack props. Uses spacing={1} by default. The status box has a minimum width of 200px.
ViewOrder.InfoRowβ
Displays a single information row with label and value.
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | Required | Label content for the information row |
value | ReactNode | Required | Value content for the information row |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits MUI Stack props. Uses direction="row" with a bottom border divider. Label has minimum width of 180px.
ViewOrder.InfoRowListβ
Container that displays multiple information rows from the infoRows array.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | undefined | Custom content to override default info rows rendering |
infoRows | Array<{label: string, value: ReactNode}> | From context | Array of info rows to display |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits MUI Stack props. Has a top border divider by default.
π¨ Configuration examplesβ
Custom Styled Componentsβ
function StyledViewOrderComponents() {
const orderInfoRows = [
{label: 'Order ID', value: '#12345'},
{label: 'Status', value: 'Completed'},
];
return (
<ViewOrder headerLabel="Styled Order" statusText="Completed" statusLabel="Status" infoRows={orderInfoRows}>
<ViewOrder.Header
sx={{
bgcolor: 'primary.main',
color: 'white',
borderRadius: 2,
p: 3,
}}
/>
<ViewOrder.Status
sx={{
'& .nbb-view-order-status': {
bgcolor: 'success.main',
color: 'white',
},
}}
/>
<ViewOrder.InfoRowList
sx={{
bgcolor: 'grey.50',
borderRadius: 2,
p: 2,
}}
/>
</ViewOrder>
);
}
Block Override Patternβ
function BlockOverrideViewOrder() {
const orderInfoRows = [
{label: 'Order ID', value: '#12345'},
{label: 'Total', value: '$99.99'},
];
return (
<ViewOrder headerLabel="Order" statusText="Pending" statusLabel="Status" infoRows={orderInfoRows}>
{({defaultBlocks, defaultBlockOrder}) => ({
blocks: {
header: {
...defaultBlocks.header,
props: {
...defaultBlocks.header.props,
sx: {background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'},
},
},
},
blockOrder: defaultBlockOrder,
})}
</ViewOrder>
);
}
Complete Order Detailsβ
function CompleteOrderDetails() {
const orderItems = [
{name: 'Product A', qty: 2, price: 49.99},
{name: 'Product B', qty: 1, price: 89.99},
{name: 'Shipping', qty: 1, price: 9.99},
];
const orderInfoRows = [
{
label: 'Order Number',
value: (
<span
style={{
fontFamily: 'monospace',
fontWeight: 'bold',
color: '#3b82f6',
}}
>
#ORD-2024-12345
</span>
),
},
{label: 'Date Placed', value: 'January 15, 2024'},
{label: 'Payment Method', value: 'Credit Card (****1234)'},
{
label: 'Items',
value: (
<div style={{display: 'flex', flexDirection: 'column', gap: '4px'}}>
{orderItems.map((item, index) => (
<div
key={index}
style={{
display: 'flex',
justifyContent: 'space-between',
fontSize: '14px',
}}
>
<span>
{item.name} Γ {item.qty}
</span>
<span style={{fontWeight: '500'}}>${item.price.toFixed(2)}</span>
</div>
))}
</div>
),
},
{
label: 'Subtotal',
value: (
<span style={{fontWeight: '600'}}>
${orderItems.reduce((sum, item) => sum + item.price * item.qty, 0).toFixed(2)}
</span>
),
},
{
label: 'Shipping Address',
value: (
<div style={{fontSize: '14px', lineHeight: '1.5'}}>
John Doe
<br />
123 Main Street
<br />
New York, NY 10001
<br />
United States
</div>
),
},
];
return (
<ViewOrder
headerLabel="Order Confirmation"
statusText="Shipped"
statusLabel="Delivery Status"
infoRows={orderInfoRows}
>
<ViewOrder.Header />
<ViewOrder.InfoRowList />
</ViewOrder>
);
}
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {ViewOrder} from '@nodeblocks/frontend-view-order-block';
import {ReactNode} from 'react';
// Info row interface
interface OrderInfoRow {
label: string;
value: ReactNode;
}
// Custom order data interface
interface CustomOrderData {
orderId: string;
customerName: string;
status: 'pending' | 'processing' | 'shipped' | 'delivered' | 'cancelled';
total: number;
items: {
id: string;
name: string;
quantity: number;
price: number;
}[];
shippingAddress: {
street: string;
city: string;
country: string;
};
}
function TypedViewOrderExample() {
const orderData: CustomOrderData = {
orderId: 'ORD-2024-001',
customerName: 'John Doe',
status: 'processing',
total: 299.99,
items: [
{id: '1', name: 'Premium Headphones', quantity: 1, price: 199.99},
{id: '2', name: 'USB Cable', quantity: 2, price: 50.0},
],
shippingAddress: {
street: '123 Main St',
city: 'New York',
country: 'USA',
},
};
const orderInfoRows: OrderInfoRow[] = [
{label: 'Order ID', value: orderData.orderId},
{label: 'Customer', value: orderData.customerName},
{label: 'Total Amount', value: `$${orderData.total}`},
{label: 'Items Count', value: String(orderData.items.length)},
{
label: 'Shipping Address',
value: `${orderData.shippingAddress.street}, ${orderData.shippingAddress.city}, ${orderData.shippingAddress.country}`,
},
];
return (
<ViewOrder
headerLabel="Order Information"
statusText={orderData.status.charAt(0).toUpperCase() + orderData.status.slice(1)}
statusLabel="Current Status"
infoRows={orderInfoRows}
className="custom-order-view"
>
<ViewOrder.Header />
<ViewOrder.InfoRowList />
</ViewOrder>
);
}
π Notesβ
- The root component uses MUI's
Stackwith defaultspacing={4}andsx={{ p: 3 }}padding - Default header label is
"Order Details"if not provided - Default status label is
"Status"if not provided - The
imageSrcprop is available in context but not used by default sub-components (available for custom implementations) ViewOrder.Headerrenders a title Typography andViewOrder.Statusby defaultViewOrder.Statusdisplays a styled box with minimum width of 200px and centered textViewOrder.InfoRowhas a label column with minimum width of 180pxViewOrder.InfoRowListhas a top border and renders allinfoRowsusingViewOrder.InfoRow- All sub-components inherit MUI
Stackprops and support thesxprop for styling - Block override pattern allows customizing, replacing, or reordering default blocks
Built with β€οΈ using React, TypeScript, and MUI.