Hero Block
The Hero Component is a fully customizable and accessible hero section built with React and TypeScript. It provides a complete hero interface with modern design patterns, image display, and flexible customization options. Built on top of MUI components for consistent styling.
π Installationβ
npm install @nodeblocks/frontend-hero-block@0.2.0
π Usageβ
import {Hero} from '@nodeblocks/frontend-hero-block';
- Basic Usage
- Advanced Usage
function BasicHero() { return ( <Hero buttonText="Get Started" byline="Welcome to Our Platform" imageUrl="/img/undraw_docusaurus_mountain.svg" onClickButton={() => { console.log('Hero button clicked'); }} > <Hero.HeroContent> <Hero.HeroContent.HeroByline /> <Hero.HeroContent.ActionButton /> </Hero.HeroContent> <Hero.HeroImg /> </Hero> ); }
function AdvancedHero() { return ( <Hero buttonText="Get Started Free" byline="Build Products Faster with AI-Powered Tools" imageUrl="/img/undraw_docusaurus_mountain.svg" onClickButton={() => console.log('Hero button clicked')} secondaryText="Join 50,000+ developers shipping features 3x faster. No complex setup required." tertiaryText="Trusted by teams at leading companies worldwide" sx={{ background: 'linear-gradient(180deg, #0f172a 0%, #1e293b 100%)', minHeight: '580px', alignItems: 'center', justifyContent: 'center', px: 4, py: 6, position: 'relative', overflow: 'hidden', '&::before': { content: '""', position: 'absolute', top: '-50%', left: '50%', transform: 'translateX(-50%)', width: '800px', height: '800px', background: 'radial-gradient(circle, rgba(59, 130, 246, 0.12) 0%, transparent 60%)', pointerEvents: 'none', }, }} > {({defaultBlocks}) => { const badge = ( <div style={{ display: 'inline-flex', alignItems: 'center', gap: '8px', padding: '6px 14px', background: 'rgba(59, 130, 246, 0.15)', borderRadius: '20px', border: '1px solid rgba(59, 130, 246, 0.3)', }} > <span style={{ width: '6px', height: '6px', borderRadius: '50%', background: '#3b82f6', }} /> <span style={{ fontSize: '13px', color: '#60a5fa', fontWeight: 500, }} > New: AI Code Assistant now available </span> </div> ); return { blocks: { ...defaultBlocks, badge, heroContent: ( <Hero.HeroContent spacing={3} sx={{ alignItems: 'center', textAlign: 'center', maxWidth: '680px', py: 0, zIndex: 1, }} > <div> <Hero.HeroContent.HeroByline variant="h2" sx={{ fontWeight: 800, color: '#f8fafc', fontSize: '2.5rem', lineHeight: 1.2, letterSpacing: '-0.02em', mb: 2, }} /> <Hero.HeroContent.SecondaryText variant="body1" sx={{ color: '#94a3b8', fontWeight: 400, textAlign: 'center', fontSize: '1.1rem', lineHeight: 1.7, maxWidth: '520px', mx: 'auto', }} /> </div> <div style={{display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '16px'}}> <div style={{display: 'flex', gap: '12px', alignItems: 'center'}}> <Hero.HeroContent.ActionButton variant="contained" sx={{ bgcolor: '#3b82f6', px: 4, py: 1.5, fontSize: '0.95rem', fontWeight: 600, borderRadius: '10px', textTransform: 'none', boxShadow: '0 4px 14px rgba(59, 130, 246, 0.4)', '&:hover': { bgcolor: '#2563eb', boxShadow: '0 6px 20px rgba(59, 130, 246, 0.5)', }, }} /> <button style={{ background: 'transparent', border: '1px solid #475569', color: '#e2e8f0', padding: '12px 24px', borderRadius: '10px', fontSize: '0.95rem', fontWeight: 500, cursor: 'pointer', }} > View Demo </button> </div> <Hero.HeroContent.TertiaryText sx={{ color: '#64748b', fontSize: '0.875rem', }} /> </div> </Hero.HeroContent> ), heroImg: ( <Hero.HeroImg sx={{ maxWidth: '500px', borderRadius: '16px', border: '1px solid rgba(148, 163, 184, 0.1)', boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.4)', mt: 2, zIndex: 1, }} /> ), }, blockOrder: ['badge', 'heroContent', 'heroImg'], }; }} </Hero> ); }
π§ Props Referenceβ
Main Component Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
buttonText | string | Required | Text to display on the action button |
byline | ReactNode | Required | Main headline text for the hero section |
imageUrl | string | Required | URL of the image to display in the hero section |
onClickButton | () => void | Required | Callback function triggered when the action button is clicked |
secondaryText | ReactNode | undefined | Secondary text displayed below the byline |
tertiaryText | ReactNode | undefined | Tertiary text displayed near the action button |
className | string | undefined | Additional CSS class name for styling the hero container |
sx | SxProps<Theme> | undefined | MUI system props for custom styling |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: This component inherits all MUI Stack component props.
Sub-Componentsβ
The Hero component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
Hero.HeroImgβ
Renders the hero image using MUI Box with component="img".
| Prop | Type | Default | Description |
|---|---|---|---|
imageUrl | string | Context value | URL of the image (from context) |
src | string | undefined | URL of the image (overrides imageUrl) |
alt | string | 'hero image' | Alt text for the image |
component | ElementType | 'img' | Component type to render |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | undefined | MUI system props for custom styling |
Note: This component inherits all MUI Box component props. Priority for image source: src prop > imageUrl context value.
Hero.HeroContentβ
Container for hero text content using MUI Stack.
| Prop | Type | Default | Description |
|---|---|---|---|
spacing | number | string | 3 | Spacing between child elements |
children | ReactNode | Default layout | Custom content (replaces default layout) |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | { alignItems: 'center', py: 5.5 } | MUI system props for custom styling |
Note: This component inherits all MUI Stack component props. When no children provided, renders default layout with HeroByline, SecondaryText, ActionButton, and TertiaryText.
Hero.HeroContent.HeroBylineβ
Renders the main headline using MUI Typography.
| Prop | Type | Default | Description |
|---|---|---|---|
byline | ReactNode | Context value | Headline content (from context) |
children | ReactNode | undefined | Headline content (overrides byline) |
variant | TypographyVariant | 'h6' | MUI Typography variant |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | undefined | MUI system props for custom styling |
Note: This component inherits all MUI Typography component props. Priority: children prop > byline context value.
Hero.HeroContent.SecondaryTextβ
Renders secondary text using MUI Typography. Returns null if no content provided.
| Prop | Type | Default | Description |
|---|---|---|---|
secondaryText | ReactNode | Context value | Secondary text content (from context) |
children | ReactNode | undefined | Secondary text content (overrides secondaryText) |
variant | TypographyVariant | 'h2' | MUI Typography variant |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | { textAlign: 'center' } | MUI system props for custom styling |
Note: This component inherits all MUI Typography component props. Returns null if neither children nor secondaryText is provided.
Hero.HeroContent.ActionButtonβ
Renders the call-to-action button using MUI Button.
| Prop | Type | Default | Description |
|---|---|---|---|
buttonText | string | Context value | Button text (from context) |
children | ReactNode | undefined | Button content (overrides buttonText) |
onClickButton | () => void | Context value | Click handler (from context) |
onClick | () => void | undefined | Click handler (overrides onClickButton) |
variant | ButtonVariant | 'contained' | MUI Button variant |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | { fontWeight: 600, px: 4, py: 1.5 } | MUI system props for custom styling |
Note: This component inherits all MUI Button component props. Priority for click handler: onClick prop > onClickButton context value.
Hero.HeroContent.TertiaryTextβ
Renders tertiary text using MUI Typography. Returns null if no content provided.
| Prop | Type | Default | Description |
|---|---|---|---|
tertiaryText | ReactNode | Context value | Tertiary text content (from context) |
children | ReactNode | undefined | Tertiary text content (overrides tertiaryText) |
color | TypographyColor | 'primary' | MUI Typography color |
variant | TypographyVariant | 'button' | MUI Typography variant |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | Theme-based styling | MUI system props for custom styling |
Note: This component inherits all MUI Typography component props. Returns null if neither children nor tertiaryText is provided. Default sx includes lineHeight from body1 and fontWeight from h1.
π¨ Configuration examplesβ
Custom Hero Layoutβ
<Hero
buttonText="Learn More"
byline="Innovate with Confidence"
imageUrl="/hero.jpg"
onClickButton={() => {}}
sx={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
px: 8,
py: 10,
}}
/>
Custom Hero Image Stylingβ
<Hero.HeroImg
sx={{
maxWidth: 500,
borderRadius: 4,
boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
transition: 'transform 0.3s ease',
'&:hover': {
transform: 'scale(1.02)',
},
}}
/>
Custom Action Button Stylingβ
<Hero.HeroContent.ActionButton
variant="outlined"
sx={{
borderWidth: 2,
px: 6,
py: 2,
fontSize: '1.1rem',
'&:hover': {
borderWidth: 2,
bgcolor: 'primary.main',
color: 'primary.contrastText',
},
}}
/>
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {Hero} from '@nodeblocks/frontend-hero-block';
import {StackProps, BoxProps, TypographyProps, ButtonProps} from '@mui/material';
import {ReactNode} from 'react';
// Main component props extend MUI StackProps
interface HeroProps extends Omit<StackProps, 'children'> {
buttonText: string;
byline: ReactNode;
onClickButton: () => void;
imageUrl: string;
secondaryText?: ReactNode;
tertiaryText?: ReactNode;
children?: BlocksOverride;
}
// Context type (values passed to all sub-components)
interface HeroContextValue {
buttonText: string;
byline: ReactNode;
onClickButton: () => void;
imageUrl: string;
secondaryText?: ReactNode;
tertiaryText?: ReactNode;
}
// Example with typed props
function TypedHeroExample() {
return (
<Hero
buttonText="Get Started"
byline="Welcome to Our Platform"
imageUrl="/hero-image.jpg"
onClickButton={() => console.log('clicked')}
secondaryText="Build amazing products faster"
tertiaryText="No credit card required"
spacing={3}
sx={{minHeight: '80vh'}}
>
<Hero.HeroContent spacing={4}>
<Hero.HeroContent.HeroByline variant="h2" />
<Hero.HeroContent.SecondaryText variant="h5" />
<Hero.HeroContent.ActionButton variant="contained" color="primary" />
<Hero.HeroContent.TertiaryText color="textSecondary" />
</Hero.HeroContent>
<Hero.HeroImg sx={{maxWidth: 500, borderRadius: 2}} />
</Hero>
);
}
π Notesβ
- The component uses MUI's
Stackas the root container - Hero.HeroContent uses default
spacing={3}and centers content vertically withpy: 5.5padding - Hero.HeroImg uses MUI
Boxwithcomponent="img"and default alt text "hero image" - ActionButton has default styling with
fontWeight: 600,px: 4,py: 1.5 - SecondaryText and TertiaryText return
nullwhen no content is provided - TertiaryText uses theme-based styling for
lineHeightandfontWeight - All sub-components support the
sxprop for MUI system styling - Block override pattern allows inserting custom blocks and reordering
Built with β€οΈ using React, TypeScript, and MUI.