ヒーローブロック
Heroコンポーネントは、ReactとTypeScriptで構築された完全にカスタマイズ可能でアクセシブルなヒーローセクションです。モダンなデザインパターン、画像表示、柔軟なカスタマイズオプションを備えた完全なヒーローインターフェースを提供します。一貫したスタイリングのためにMUIコンポーネント上に構築されています。
🚀 インストール
npm install @nodeblocks/frontend-hero-block@0.2.0
📖 使用法
import {Hero} from '@nodeblocks/frontend-hero-block';
- 基本的な使用法
- 高度な使用法
function BasicHero() { return ( <Hero buttonText="始める" byline="私たちのプラットフォームへようこそ" imageUrl="/img/undraw_docusaurus_mountain.svg" onClickButton={() => { console.log('ヒーローボタンがクリックされました'); }} > <Hero.HeroContent> <Hero.HeroContent.HeroByline /> <Hero.HeroContent.ActionButton /> </Hero.HeroContent> <Hero.HeroImg /> </Hero> ); }
function AdvancedHero() { return ( <Hero buttonText="無料で始める" byline="AI搭載ツールでより速く製品を構築" imageUrl="/img/undraw_docusaurus_mountain.svg" onClickButton={() => console.log('ヒーローボタンがクリックされました')} secondaryText="50,000人以上の開発者が3倍速く機能をリリース。複雑なセットアップは不要です。" tertiaryText="世界中の一流企業のチームに信頼されています" 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, }} > 新機能: AIコードアシスタントが利用可能になりました </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', }} > デモを見る </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> ); }
🔧 プロパティリファレンス
メインコンポーネントプロパティ
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
buttonText | string | 必須 | アクションボタンに表示するテキスト |
byline | ReactNode | 必須 | ヒーローセクションのメインヘッドラインテキスト |
imageUrl | string | 必須 | ヒーローセクションに表示する画像のURL |
onClickButton | () => void | 必須 | アクションボタンがクリックされたときにトリガーされるコールバック関数 |
secondaryText | ReactNode | undefined | バイラインの下に表示されるセカンダリテキスト |
tertiaryText | ReactNode | undefined | アクションボタンの近くに表示されるターシャリテキスト |
className | string | undefined | ヒーローコンテナのスタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | undefined | カスタムスタイリング用のMUIシステムプロパティ |
children | BlocksOverride | undefined | デフォルトレンダリングをオーバーライドするカスタムブロックコンポーネント |
注意: このコンポーネントはすべてのMUI Stackコンポーネントプロパティを継承します。
サブコンポーネント
Heroコンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントは、メインコンポーネントのコンテキストからデフォルト値を受け取り、プロパティを通じてこれらの値をオーバーライドできます。
Hero.HeroImg
MUI Boxをcomponent="img"で使用してヒーロー画像をレンダリングします。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
imageUrl | string | コンテキスト値 | 画像のURL(コンテキストから) |
src | string | undefined | 画像のURL(imageUrlをオーバーライド) |
alt | string | 'hero image' | 画像の代替テキスト |
component | ElementType | 'img' | レンダリングするコンポーネントタイプ |
className | string | undefined | スタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | undefined | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Boxコンポーネントプロパティを継承します。画像ソースの優先順位: srcプロパティ > imageUrlコンテキスト値。
Hero.HeroContent
MUI Stackを使用したヒーローテキストコンテンツのコンテナ。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
spacing | number | string | 3 | 子要素間のスペース |
children | ReactNode | デフォルトレイアウト | カスタムコンテンツ(デフォルトレイアウトを置き換え) |
className | string | undefined | スタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | { alignItems: 'center', py: 5.5 } | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Stackコンポーネントプロパティを継承します。childrenが提供されない場合、HeroByline、SecondaryText、ActionButton、TertiaryTextを含むデフォルトレイアウトをレンダリングします。
Hero.HeroContent.HeroByline
MUI Typographyを使用してメインヘッドラインをレンダリングします。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
byline | ReactNode | コンテキスト値 | ヘッドラインコンテンツ(コンテキストから) |
children | ReactNode | undefined | ヘッドラインコンテンツ(bylineをオーバーライド) |
variant | TypographyVariant | 'h6' | MUI Typographyバリアント |
className | string | undefined | スタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | undefined | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Typographyコンポーネントプロパティを継承します。優先順位: childrenプロパティ > bylineコンテキスト値。
Hero.HeroContent.SecondaryText
MUI Typographyを使用してセカンダリテキストをレンダリングします。コンテンツが提供されない場合はnullを返します。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
secondaryText | ReactNode | コンテキスト値 | セカンダリテキストコンテンツ(コンテキストから) |
children | ReactNode | undefined | セカンダリテキストコンテンツ(secondaryTextをオーバーライド) |
variant | TypographyVariant | 'h2' | MUI Typographyバリアント |
className | string | undefined | スタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | { textAlign: 'center' } | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Typographyコンポーネントプロパティを継承します。childrenもsecondaryTextも提供されない場合はnullを返します。
Hero.HeroContent.ActionButton
MUI Buttonを使用してコールトゥアクションボタンをレンダリングします。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
buttonText | string | コンテキスト値 | ボタンテキスト(コンテキストから) |
children | ReactNode | undefined | ボタンコンテンツ(buttonTextをオーバーライド) |
onClickButton | () => void | コンテキスト値 | クリックハンドラー(コンテキストから) |
onClick | () => void | undefined | クリックハンドラー(onClickButtonをオーバーライド) |
variant | ButtonVariant | 'contained' | MUI Buttonバリアント |
className | string | undefined | スタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | { fontWeight: 600, px: 4, py: 1.5 } | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Buttonコンポーネントプロパティを継承します。クリックハンドラーの優先順位: onClickプロパティ > onClickButtonコンテキスト値。
Hero.HeroContent.TertiaryText
MUI Typographyを使用してターシャリテキストをレンダリングします。コンテンツが提供されない場合はnullを返します。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
tertiaryText | ReactNode | コンテキスト値 | ターシャリテキストコンテンツ(コンテキストから) |
children | ReactNode | undefined | ターシャリテキストコンテンツ(tertiaryTextをオーバーライド) |
color | TypographyColor | 'primary' | MUI Typographyカラー |
variant | TypographyVariant | 'button' | MUI Typographyバリアント |
className | string | undefined | スタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | テーマベースのスタイリング | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Typographyコンポーネントプロパティを継承します。childrenもtertiaryTextも提供されない場合はnullを返します。デフォルトのsxにはbody1からのlineHeightとh1からのfontWeightが含まれます。
🎨 設定例
カスタムヒーローレイアウト
<Hero
buttonText="詳細を見る"
byline="自信を持ってイノベーションを"
imageUrl="/hero.jpg"
onClickButton={() => {}}
sx={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
px: 8,
py: 10,
}}
/>
カスタムヒーロー画像スタイリング
<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)',
},
}}
/>
カスタムアクションボタンスタイリング
<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サポート
包括的な型定義による完全なTypeScriptサポート:
import {Hero} from '@nodeblocks/frontend-hero-block';
import {StackProps, BoxProps, TypographyProps, ButtonProps} from '@mui/material';
import {ReactNode} from 'react';
// メインコンポーネントプロパティはMUI StackPropsを拡張
interface HeroProps extends Omit<StackProps, 'children'> {
buttonText: string;
byline: ReactNode;
onClickButton: () => void;
imageUrl: string;
secondaryText?: ReactNode;
tertiaryText?: ReactNode;
children?: BlocksOverride;
}
// コンテキストタイプ(すべてのサブコンポーネントに渡される値)
interface HeroContextValue {
buttonText: string;
byline: ReactNode;
onClickButton: () => void;
imageUrl: string;
secondaryText?: ReactNode;
tertiaryText?: ReactNode;
}
// 型付きプロパティの例
function TypedHeroExample() {
return (
<Hero
buttonText="始める"
byline="私たちのプラットフォームへようこそ"
imageUrl="/hero-image.jpg"
onClickButton={() => console.log('クリックされました')}
secondaryText="より速く素晴らしい製品を構築"
tertiaryText="クレジットカード不要"
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>
);
}
📝 注意事項
- コンポーネントはルートコンテナとしてMUIの
Stackを使用します - Hero.HeroContentはデフォルトの
spacing={3}を使用し、py: 5.5パディングでコンテンツを垂直方向に中央揃えします - Hero.HeroImgはMUI
Boxをcomponent="img"で使用し、デフォルトの代替テキストは"hero image"です - ActionButtonはデフォルトスタイリングとして
fontWeight: 600、px: 4、py: 1.5を持ちます - SecondaryTextとTertiaryTextはコンテンツが提供されない場合
nullを返します - TertiaryTextは
lineHeightとfontWeightにテーマベースのスタイリングを使用します - すべてのサブコンポーネントはMUIシステムスタイリング用の
sxプロパティをサポートします - ブロックオーバーライドパターンにより、カスタムブロックの挿入と並べ替えが可能です
React、TypeScript、MUIを使用して❤️で構築されました。