View Product Block
The ViewProduct Component is a fully customizable product display component built with TypeScript. It provides a complete interface for viewing product details including organization information, product images, chips, tags, sections, and customizable actions with modern design patterns.
π Installationβ
npm install @nodeblocks/frontend-view-product-block
π Usageβ
import {ViewProduct} from '@nodeblocks/frontend-view-product-block';
- Basic Usage
- Advanced Usage
function BasicViewProduct() { const chips = [ { label: 'New' }, { label: 'Featured' } ]; const tags = [ { icon: 'star', label: 'Premium' }, { label: ['Electronics', 'Mobile'] } ]; const sections = [ { icon: 'info', label: 'Model', value: 'iPhone 15 Pro' }, { icon: 'attach_money', label: 'Price', value: '$999' }, { label: 'Availability', value: 'In Stock' } ]; const actions = [ { label: 'Add to Cart', onClick: () => console.log('Added to cart') }, { label: 'Buy Now', onClick: () => console.log('Buy now clicked') } ]; return ( <ViewProduct organizationName="TechStore" organizationBannerLink="#organization/techstore" organizationLogoUrl="/img/icon.png" imageUrl="/img/undraw_docusaurus_react.svg" imageAlt="iPhone 15 Pro" chips={chips} headerTitle="iPhone 15 Pro - Latest Model" tags={tags} sections={sections} actions={actions} style={{backgroundColor: 'white', padding: '16px'}}> <ViewProduct.Header> <ViewProduct.CompanyName /> <ViewProduct.Image /> <ViewProduct.Chips /> <ViewProduct.Title /> </ViewProduct.Header> <ViewProduct.Content /> <ViewProduct.Actions /> </ViewProduct> ); }
function AdvancedViewProduct() { const chips = [ { label: 'π₯ Bestseller' }, { label: 'β‘ Fast Shipping' }, { label: 'π― Limited Edition' } ]; const tags = [ { icon: 'star', label: 'β 4.9 Premium Rating' }, { icon: 'verified', label: ['π‘οΈ Certified', 'π Secure', 'π Premium'] } ]; const sections = [ { icon: 'info', label: 'π± Model', value: 'MacBook Pro 16" M3 Max' }, { icon: 'attach_money', label: 'π° Price', value: '$3,499' }, { icon: 'inventory', label: 'π¦ Stock', value: 'In Stock - 12 left' }, { icon: 'local_shipping', label: 'π Delivery', value: 'Free Next-Day' }, { icon: 'support_agent', label: 'π οΈ Warranty', value: '3 Years AppleCare+' } ]; const actions = [ { label: 'π Add to Cart', onClick: () => console.log('Added to cart') }, { label: 'β‘ Buy Now', onClick: () => console.log('Buy now clicked') }, { label: 'π Add to Wishlist', onClick: () => console.log('Added to wishlist') } ]; return ( <ViewProduct organizationName="π Apple Store Premium" organizationBannerLink="#apple-store" organizationLogoUrl="/img/icon.png" imageUrl="/img/undraw_docusaurus_react.svg" imageAlt="MacBook Pro 16 M3 Max" chips={chips} headerTitle="π» MacBook Pro 16 Ultimate Performance" tags={tags} sections={sections} actions={actions} style={{backgroundColor: '#f8f9fa', padding: '24px', borderRadius: '16px'}}> {({ defaultBlocks, defaultBlockOrder }) => ({ blocks: { ...defaultBlocks, // Enhanced header with premium gradient and glass effect header: { ...defaultBlocks.header, props: { ...defaultBlocks.header.props, style: { ...defaultBlocks.header.props?.style, background: 'linear-gradient(145deg, #ffffff 0%, #f8fafc 100%)', backdropFilter: 'blur(20px)', borderRadius: '24px', padding: '40px', color: 'white', marginBottom: '32px', boxShadow: '0 25px 50px rgba(99, 102, 241, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.1)', border: '1px solid rgba(255, 255, 255, 0.2)', position: 'relative', overflow: 'hidden' } } }, // Custom content override using sections prop content: { ...defaultBlocks.content, props: { ...defaultBlocks.content.props, children: ( <div style={{ background: 'linear-gradient(145deg, #ffffff 0%, #f8fafc 100%)', borderRadius: '20px', padding: '24px', marginBottom: '32px', boxShadow: '0 10px 30px rgba(0, 0, 0, 0.08)', border: '1px solid rgba(226, 232, 240, 0.8)' }}> {/* Enhanced Sections Display */} <h3 style={{ fontSize: '18px', fontWeight: '700', color: '#1e293b', marginBottom: '20px', margin: '0 0 20px 0' }}> π Product Details </h3> <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))', gap: '16px', marginBottom: '24px' }}> {sections.map((section, index) => ( <div key={index} style={{ background: 'white', borderRadius: '12px', padding: '16px', boxShadow: '0 4px 15px rgba(0, 0, 0, 0.05)', border: '1px solid rgba(226, 232, 240, 0.8)', display: 'flex', alignItems: 'center', gap: '12px' }}> <div style={{ width: '40px', height: '40px', background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', borderRadius: '10px', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '18px', color: 'white' }}> {section.icon ? 'π' : 'β’'} </div> <div> <p style={{ fontSize: '12px', color: '#64748b', margin: '0 0 4px 0' }}> {section.label} </p> <p style={{ fontSize: '14px', fontWeight: '600', color: '#1e293b', margin: 0 }}> {section.value} </p> </div> </div> ))} </div> {/* Customer Review */} <div style={{ background: 'linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%)', borderRadius: '12px', padding: '20px' }}> <div style={{ display: 'flex', alignItems: 'center', gap: '12px', marginBottom: '12px' }}> <div style={{ width: '40px', height: '40px', background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'white', fontSize: '16px', fontWeight: '600' }}> S </div> <div> <p style={{ fontSize: '14px', fontWeight: '600', color: '#1e293b', margin: '0 0 4px 0' }}> Sarah Johnson </p> <div style={{ display: 'flex', gap: '2px' }}> {Array.from({ length: 5 }, (_, i) => ( <span key={i} style={{ color: '#fbbf24', fontSize: '12px' }}>β</span> ))} </div> </div> </div> <p style={{ fontSize: '14px', color: '#64748b', lineHeight: '1.5', margin: 0, fontStyle: 'italic' }}> "Incredible performance for video editing. The M3 Max chip handles 8K footage effortlessly!" </p> </div> </div> ) } }, // Enhanced actions with modern button styling and hover effects actions: { ...defaultBlocks.actions, props: { ...defaultBlocks.actions.props, style: { ...defaultBlocks.actions.props?.style, background: 'linear-gradient(145deg, #ffffff 0%, #f8fafc 100%)', borderRadius: '20px', padding: '32px', textAlign: 'center', boxShadow: '0 20px 40px rgba(102, 126, 234, 0.25)', border: '1px solid rgba(255, 255, 255, 0.2)', position: 'relative', overflow: 'hidden' } } } }, blockOrder: defaultBlockOrder })} </ViewProduct> ); }
π§ Props Referenceβ
Main Component Propsβ
Prop | Type | Default | Description |
---|---|---|---|
organizationName | string | undefined | Name of the organization selling the product |
organizationBannerLink | string | undefined | URL link for the organization banner |
organizationLogoUrl | string | undefined | URL for the organization logo image |
imageUrl | string | Required | Source URL for the main product image |
imageAlt | string | undefined | Alt text for the product image |
chips | Array<{label: string}> | Required | Array of chip labels to display |
headerTitle | string | Required | Main title text for the product |
tags | Array<{icon?: IconType, label: string | string[]}> | Required | Array of tags with optional icons |
sections | Array<{icon?: IconType, label: string, value: string}> | Required | Array of information sections |
actions | Array<{label: ReactNode, onClick: () => void}> | undefined | Array of action buttons |
className | string | undefined | Additional CSS class name for styling the container |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: This component inherits all HTML div
element props.
Sub-Componentsβ
The ViewProduct 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.
ViewProduct.CompanyNameβ
Displays the organization name as a heading.
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | From context | Custom content to override default company name |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Imageβ
Displays the main product image.
Prop | Type | Default | Description |
---|---|---|---|
imageUrl | string | From context | Source URL for the product image |
imageAlt | string | From context | Alt text for the product image |
children | ReactNode | From context | Custom content to override default image |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Chipsβ
Container for displaying product chips.
Prop | Type | Default | Description |
---|---|---|---|
chips | Array<{label: string}> | From context | Array of chips to display |
children | ReactNode | From context | Custom content to override default chips |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Titleβ
Displays the product title as a heading.
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | From context | Custom content to override default title |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Headerβ
Container for the product header including company name, image, chips, and title.
Prop | Type | Default | Description |
---|---|---|---|
organizationName | string | From context | Organization name for the header |
organizationLogo | string | From context | Organization logo URL |
organizationBannerLink | string | From context | Organization banner link |
imageUrl | string | From context | Product image URL |
imageAlt | string | From context | Product image alt text |
chips | Array<{label: string}> | From context | Array of chips |
headerTitle | string | From context | Product title |
children | ReactNode | From context | Custom content to override default header content |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Sectionsβ
Container that displays multiple information sections.
Prop | Type | Default | Description |
---|---|---|---|
sections | Array<{icon?: IconType, label: string, value: string}> | From context | Array of sections to display |
children | ReactNode | From context | Custom content to override default sections |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Tagsβ
Container for displaying product tags.
Prop | Type | Default | Description |
---|---|---|---|
tags | Array<{icon?: IconType, label: string | string[]}> | From context | Array of tags to display |
children | ReactNode | From context | Custom content to override default tags |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.CompanyBannerβ
Displays a clickable banner for the organization.
Prop | Type | Default | Description |
---|---|---|---|
companyName | ReactNode | From context | Company name to display |
link | string | From context | URL for the banner link |
icon | enum | undefined | Optional icon for the banner |
logo | string | From context | Logo URL for the banner |
children | ReactNode | From context | Custom content to override default banner |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML a
element props.
ViewProduct.Contentβ
Container for the main product content including tags, sections, and company banner.
Prop | Type | Default | Description |
---|---|---|---|
tags | Array<{icon?: IconType, label: string | string[]}> | From context | Array of tags |
sections | Array<{icon?: IconType, label: string, value: string}> | From context | Array of sections |
organizationName | string | From context | Organization name |
organizationBannerLink | string | From context | Organization banner link |
organizationLogoUrl | string | From context | Organization logo URL |
children | ReactNode | From context | Custom content to override default content |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
ViewProduct.Actionsβ
Container for action buttons.
Prop | Type | Default | Description |
---|---|---|---|
actions | Array<{label: ReactNode, onClick: () => void}> | From context | Array of action buttons |
children | ReactNode | From context | Custom content to override default actions |
className | string | undefined | Additional CSS class name for styling |
Note: This component inherits all HTML div
element props.
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import ViewProduct from '@nodeblocks/frontend-view-product-block';
import { ReactNode } from 'react';
interface ProductChip {
label: string;
}
interface ProductTag {
icon?: IconType;
label: string | string[];
}
interface ProductSection {
icon?: IconType;
label: string;
value: string;
}
interface ProductAction {
label: ReactNode;
onClick: () => void;
}
interface ViewProductProps {
organizationName?: string;
organizationBannerLink?: string;
organizationLogoUrl?: string;
imageUrl: string;
imageAlt?: string;
chips: ProductChip[];
headerTitle: string;
tags: ProductTag[];
sections: ProductSection[];
actions?: ProductAction[];
className?: string;
children?: ReactNode;
}
interface CustomProductData {
id: string;
name: string;
price: number;
category: string;
brand: string;
availability: 'in-stock' | 'out-of-stock' | 'pre-order';
rating: number;
features: string[];
specifications: {
[key: string]: string;
};
}
const ProductDetailsView = () => {
const productData: CustomProductData = {
id: 'PROD-2024-001',
name: 'Premium Wireless Headphones',
price: 299.99,
category: 'Electronics',
brand: 'AudioTech',
availability: 'in-stock',
rating: 4.8,
features: ['Noise Cancellation', 'Bluetooth 5.0', 'Fast Charging'],
specifications: {
'Battery Life': '30 hours',
'Driver Size': '40mm',
'Weight': '250g'
}
};
const chips: ProductChip[] = [
{ label: 'Best Seller' },
{ label: 'Free Shipping' }
];
const tags: ProductTag[] = [
{ icon: 'star', label: `${productData.rating} Rating` },
{ label: productData.features }
];
const sections: ProductSection[] = [
{ icon: 'info', label: 'Brand', value: productData.brand },
{ icon: 'category', label: 'Category', value: productData.category },
{ icon: 'attach_money', label: 'Price', value: `$${productData.price}` },
{ icon: 'inventory', label: 'Availability', value: productData.availability },
...Object.entries(productData.specifications).map(([key, value]) => ({
label: key,
value: value
}))
];
const actions: ProductAction[] = [
{
label: 'Add to Cart',
onClick: () => console.log(`Added ${productData.name} to cart`)
},
{
label: 'Buy Now',
onClick: () => console.log(`Purchasing ${productData.name}`)
}
];
return (
<ViewProduct
organizationName="AudioTech Store"
organizationBannerLink="/brands/audiotech"
organizationLogoUrl="/audiotech-logo.png"
imageUrl="/headphones-image.jpg"
imageAlt={productData.name}
chips={chips}
headerTitle={productData.name}
tags={tags}
sections={sections}
actions={actions}
className="custom-product-view">
<ViewProduct.Header />
<ViewProduct.Content />
<ViewProduct.Actions />
</ViewProduct>
);
};
// Custom component overrides with TypeScript
const CustomProductView = () => {
const customChips: ProductChip[] = [
{ label: 'Limited Edition' },
{ label: '24h Delivery' }
];
const customTags: ProductTag[] = [
{ icon: 'local_fire_department', label: 'Hot Deal' },
{ icon: 'verified', label: ['Certified', 'Warranty Included'] }
];
const customSections: ProductSection[] = [
{ icon: 'timer', label: 'Delivery Time', value: '24 hours' },
{ icon: 'local_shipping', label: 'Shipping', value: 'Free' },
{
icon: 'support_agent',
label: 'Support',
value: '24/7 Customer Service'
}
];
return (
<ViewProduct
organizationName="Premium Electronics"
headerTitle="Exclusive Gaming Headset"
imageUrl="/gaming-headset.jpg"
chips={customChips}
tags={customTags}
sections={customSections}>
<ViewProduct.Header className="custom-header">
<ViewProduct.CompanyName />
<div className="custom-image-container">
<ViewProduct.Image />
</div>
<ViewProduct.Chips />
<ViewProduct.Title />
</ViewProduct.Header>
<ViewProduct.Content>
<div className="custom-content-layout">
<ViewProduct.Tags />
<ViewProduct.Sections />
<ViewProduct.CompanyBanner />
</div>
</ViewProduct.Content>
<ViewProduct.Actions />
</ViewProduct>
);
};
Built with β€οΈ using modern web standards.