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.
π Installationβ
npm install @nodeblocks/frontend-hero-block
π 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 style={{color: 'black'}} /> <Hero.HeroContent.ActionButton /> </Hero.HeroContent> <Hero.HeroImg /> </Hero> ); }
function AdvancedHero() { return ( <Hero buttonText="Get Started" byline="Welcome to Our Platform" imageUrl="/img/undraw_docusaurus_mountain.svg" onClickButton={() => { console.log('Hero button clicked'); }} secondaryText="Streamline operations and boost productivity" tertiaryText="Free 30-day trial β’ No credit card required"> {({ defaultBlocks, defaultBlockOrder }) => ({ blocks: { ...defaultBlocks, // πΌοΈ Custom Hero Image with props override heroImg: { ...defaultBlocks.heroImg, props: { ...defaultBlocks.heroImg.props, className: "custom-hero-image", style: { borderRadius: '12px', boxShadow: '0 10px 30px rgba(0,0,0,0.2)', transform: 'scale(1.05)', transition: 'all 0.3s ease', padding: '16px' }, width: 500, height: 350 }, }, // π Rich Hero Content with full component override heroContent: ( <div style={{ padding: '40px', backgroundColor: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', borderRadius: '16px', color: 'white', textAlign: 'center' }}> <div style={{ marginBottom: '30px' }}> <h1 style={{ fontSize: '3.5rem', fontWeight: 'bold', marginBottom: '15px', color: 'black' }}> π Transform Your Business </h1> <p style={{ fontSize: '1.2rem', opacity: 0.9, marginBottom: '0', color: 'black' }}> Experience the power of our cutting-edge platform designed to boost productivity </p> </div> <div style={{ marginBottom: '20px' }}> <button style={{ backgroundColor: '#ff6b6b', color: 'white', border: 'none', padding: '15px 30px', fontSize: '1.1rem', borderRadius: '50px', cursor: 'pointer', fontWeight: 'bold', boxShadow: '0 4px 15px rgba(255,107,107,0.4)', transition: 'all 0.3s ease' }} onMouseOver={(e) => { e.target.style.transform = 'translateY(-2px)'; e.target.style.boxShadow = '0 6px 20px rgba(255,107,107,0.6)'; }} onMouseOut={(e) => { e.target.style.transform = 'translateY(0)'; e.target.style.boxShadow = '0 4px 15px rgba(255,107,107,0.4)'; }} > π― Start Free Trial </button> </div> <div style={{ display: 'flex', justifyContent: 'center', gap: '20px', fontSize: '0.9rem', opacity: 0.8, color: 'black' }}> <span>β No credit card required</span> <span>β 30-day free trial</span> <span>β Cancel anytime</span> </div> </div> ), }, blockOrder: defaultBlockOrder, })} </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 |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: The main component inherits all HTML div
element 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β
Prop | Type | Default | Description |
---|---|---|---|
src | string | Context imageUrl | URL of the image to display (overrides context imageUrl) |
Note: This component inherits all HTML img
element props.
Hero.HeroContentβ
This component acts as a container and automatically renders the nested content components unless custom children are provided.
Note: This component inherits all HTML div
element props.
Hero.HeroContent.HeroBylineβ
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | Context byline | Content to display as the main headline (overrides context byline) |
Note: This component inherits all HTML h6
element props.
Hero.HeroContent.SecondaryTextβ
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | Context secondaryText | Content to display as secondary text (overrides context secondaryText) |
Note: This component inherits all HTML h3
element props.
Hero.HeroContent.ActionButtonβ
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | Context buttonText | Button content/text (overrides context buttonText) |
onClick | () => void | Context onClickButton | Click handler for the action button (overrides context onClickButton) |
Note: This component inherits all HTML button
element props.
Hero.HeroContent.TertiaryTextβ
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | Context tertiaryText | Content to display as tertiary text (overrides context tertiaryText) |
Note: This component inherits all HTML span
element props.
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {Hero} from '@nodeblocks/frontend-hero-block';
import {ComponentProps, ReactNode} from 'react';
// Main component interface
interface HeroProps extends Omit<ComponentProps<'div'>, 'children'> {
buttonText: string;
byline: ReactNode;
onClickButton: () => void;
imageUrl: string;
secondaryText?: ReactNode;
tertiaryText?: ReactNode;
className?: string;
}
// Example with comprehensive hero configuration
function CustomHero() {
const handleButtonClick = () => {
console.log('Hero button clicked!');
// Handle navigation or action
};
return (
<Hero
buttonText="Get Started Today"
byline="Transform Your Business with Our Platform"
imageUrl="/assets/hero-image.jpg"
onClickButton={handleButtonClick}
secondaryText="Streamline operations and boost productivity"
tertiaryText="Free 30-day trial β’ No credit card required"
className="custom-hero-section"
style={{ minHeight: '600px' }}
id="hero-section">
<Hero.HeroContent className="hero-content-custom">
<div>
<Hero.HeroContent.HeroByline
className="custom-headline"
style={{ fontSize: '3rem', fontWeight: 'bold' }}
/>
<Hero.HeroContent.SecondaryText
className="custom-subtext"
style={{ color: '#666', marginTop: '1rem' }}
/>
</div>
<div>
<Hero.HeroContent.ActionButton
className="custom-cta-button"
type="button"
disabled={false}
>
π Start Free Trial
</Hero.HeroContent.ActionButton>
<Hero.HeroContent.TertiaryText
className="custom-disclaimer"
style={{ fontSize: '0.9rem', opacity: 0.8 }}
/>
</div>
</Hero.HeroContent>
<Hero.HeroImg
className="hero-image-custom"
alt="Hero background image"
width={600}
height={400}
loading="lazy"
/>
</Hero>
);
}
Built with β€οΈ using React, TypeScript, and modern web standards.