Navbarブロック
Navbarコンポーネントは、ReactとTypeScriptで構築された完全にカスタマイズ可能でアクセシブルなナビゲーションバーです。モダンなデザインパターン、柔軟なレイアウトセクション、カスタマイズ可能なコンテンツエリアを備えた完全なWebサイトナビゲーションインターフェースを提供します。
🚀 インストール
npm install @nodeblocks/frontend-navbar-block
📖 使用法
import {Navbar} from '@nodeblocks/frontend-navbar-block';
- 基本的な使用法
- 高度な使用法
ライブエディター
function BasicNavbar() { return ( <Navbar leftContent={ <Navbar.Logo src="/img/icon-small.png" alt="Company Logo" style={{height: '32px'}} /> } centerContent={ <div style={{display: 'flex', gap: '16px'}}> <Navbar.Link href="#home"><span>ホーム</span></Navbar.Link> <Navbar.Link href="#about"><span>概要</span></Navbar.Link> <Navbar.Link href="#services"><span>サービス</span></Navbar.Link> <Navbar.Link href="#contact"><span>お問い合わせ</span></Navbar.Link> </div> } rightContent={ <Navbar.ButtonLink href="#login">ログイン</Navbar.ButtonLink> }> <Navbar.Left /> <Navbar.Center /> <Navbar.Right /> </Navbar> ); }
結果
Loading...
ライブエディター
function AdvancedNavbar() { return ( <Navbar leftContent={ <Navbar.Logo src="/img/icon-small.png" alt="Company Logo" style={{height: '32px'}} /> } centerContent={ <div style={{display: 'flex', gap: '16px'}}> <Navbar.Link href="#home"><span>ホーム</span></Navbar.Link> <Navbar.Link href="#about"><span>概要</span></Navbar.Link> <Navbar.Link href="#services"><span>サービス</span></Navbar.Link> <Navbar.Link href="#contact"><span>お問い合わせ</span></Navbar.Link> </div> } rightContent={ <Navbar.ButtonLink href="#login">ログイン</Navbar.ButtonLink> }> {({ defaultBlocks, defaultBlockOrder }) => ({ blocks: { ...defaultBlocks, // 🏢 プロパティオーバーライド付きカスタム左セクション left: { ...defaultBlocks.left, props: { ...defaultBlocks.left.props, className: "custom-navbar-left", style: { display: 'flex', alignItems: 'center', gap: '15px', padding: '10px 20px', backgroundColor: '#f8f9fa', borderRadius: '12px', border: '2px solid #e9ecef' }, children: ( <div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}> <div style={{ width: '40px', height: '40px', backgroundColor: '#007bff', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'white', fontSize: '1.2rem', fontWeight: 'bold' }}> 🚀 </div> <div> <div style={{ fontWeight: 'bold', fontSize: '1.1rem', color: '#343a40' }}> TechCorp </div> <div style={{ fontSize: '0.8rem', color: '#6c757d' }}> イノベーションハブ </div> </div> </div> ) }, }, // 🧭 完全なコンポーネントオーバーライド付きリッチセンターナビゲーション center: ( <div style={{ display: 'flex', alignItems: 'center', gap: '8px', padding: '8px 16px', backgroundColor: '#fff', borderRadius: '50px', border: '1px solid #e9ecef', boxShadow: '0 2px 8px rgba(0,0,0,0.1)' }}> {[ { href: '#home', label: '🏠 ホーム', color: '#007bff' }, { href: '#products', label: '📦 プロダクト', color: '#28a745' }, { href: '#about', label: '👥 概要', color: '#17a2b8' }, { href: '#contact', label: '📞 お問い合わせ', color: '#fd7e14' } ].map((item, index) => ( <a key={index} href={item.href} style={{ display: 'flex', alignItems: 'center', gap: '6px', padding: '10px 16px', borderRadius: '25px', textDecoration: 'none', color: '#495057', fontSize: '0.9rem', fontWeight: '500', transition: 'all 0.3s ease', border: '1px solid transparent' }} onMouseEnter={(e) => { e.currentTarget.style.backgroundColor = item.color; e.currentTarget.style.color = 'white'; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = `0 4px 12px ${item.color}30`; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = 'transparent'; e.currentTarget.style.color = '#495057'; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }} > {item.label} </a> ))} </div> ), // 🎯 プロパティオーバーライド付きカスタム右セクション right: { ...defaultBlocks.right, props: { ...defaultBlocks.right.props, className: "custom-navbar-right", style: { display: 'flex', alignItems: 'center', gap: '12px' }, children: ( <div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}> {/* 検索ボタン */} <button style={{ background: 'none', border: '2px solid #6c757d', borderRadius: '50%', width: '40px', height: '40px', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', fontSize: '1rem', transition: 'all 0.3s ease' }} onMouseEnter={(e) => { e.currentTarget.style.borderColor = '#007bff'; e.currentTarget.style.backgroundColor = '#007bff'; e.currentTarget.style.color = 'white'; }} onMouseLeave={(e) => { e.currentTarget.style.borderColor = '#6c757d'; e.currentTarget.style.backgroundColor = 'transparent'; e.currentTarget.style.color = 'inherit'; }}> 🔍 </button> {/* ログインボタン */} <button style={{ background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', border: 'none', borderRadius: '25px', padding: '10px 20px', color: 'white', fontSize: '0.9rem', fontWeight: '600', cursor: 'pointer', transition: 'all 0.3s ease', boxShadow: '0 4px 15px rgba(102, 126, 234, 0.3)' }} onMouseEnter={(e) => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 6px 20px rgba(102, 126, 234, 0.4)'; }} onMouseLeave={(e) => { e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 4px 15px rgba(102, 126, 234, 0.3)'; }}> 🔐 サインイン </button> {/* プロファイルアバター */} <div style={{ width: '36px', height: '36px', borderRadius: '50%', backgroundColor: '#28a745', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'white', fontSize: '1rem', fontWeight: 'bold', cursor: 'pointer', transition: 'all 0.3s ease' }} onMouseEnter={(e) => { e.currentTarget.style.transform = 'scale(1.1)'; e.currentTarget.style.boxShadow = '0 4px 15px rgba(40, 167, 69, 0.3)'; }} onMouseLeave={(e) => { e.currentTarget.style.transform = 'scale(1)'; e.currentTarget.style.boxShadow = 'none'; }}> 👤 </div> </div> ) }, }, }, blockOrder: defaultBlockOrder, })} </Navbar> ); }
結果
Loading...
🔧 プロパティリファレンス
メインコンポーネントプロパティ
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
leftContent | ReactNode | 必須 | ナビゲーションバーの左セクションに表示するコンテンツ(通常はロゴ) |
centerContent | ReactNode | 必須 | ナビゲーションバーの中央セクションに表示するコンテンツ(通常はナビゲーションリンク) |
rightContent | ReactNode | 必須 | ナビゲーションバーの右セクションに表示するコンテンツ(通常はユーザーアクション/ボタン) |
className | string | undefined | ナビゲーションバーコンテナのスタイリング用の追加CSSクラス名 |
children | BlocksOverride | undefined | デフォルトブロックをオーバーライドするか、カスタムナビゲーションバーセクションを追加する関数 |
注意: メインコンポーネントはすべてのHTML nav
要素プロパティを継承します。
サブコンポーネント
Navbarコンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントは、メインコンポーネントのコンテキストからデフォルト値を受け取り、プロパティを通じてこれらの値をオーバーライドできます。
Navbar.Left
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
children | ReactNode | コンテキストのleftContent | 左セクションに表示するコンテンツ(コンテキストのleftContentをオーバーライド) |
注意: このコンポーネントはHTML div
要素プロパティを継承します。
Navbar.Center
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
children | ReactNode | コンテキストのcenterContent | 中央セクションに表示するコンテンツ(コンテキストのcenterContentをオーバーライド) |
注意: このコンポーネントはHTML div
要素プロパティを継承します。
Navbar.Right
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
children | ReactNode | コンテキストのrightContent | 右セクションに表示するコンテンツ(コンテキストのrightContentをオーバーライド) |
注意: このコンポーネントはHTML div
要素プロパティを継承します。
Navbar.Logo
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
src | string | 必須 | ロゴ画像のソースURL |
alt | string | 必須 | ロゴ画像の代替テキスト |
注意: このコンポーネントはHTML img
要素プロパティを継承します。
Navbar.Link
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
href | string | 必須 | リンクの宛先URL |
children | ReactNode | 必須 | リンク内に表示するコンテンツ |
Navbar.ButtonLink
プロパティ | 型 | デフォルト | 説明 |
---|---|---|---|
href | string | 必須 | ボタンリンクの宛先URL |
children | ReactNode | 必須 | ボタン内に表示するコンテンツ |
🔧 TypeScriptサポート
包括的な型定義による完全なTypeScriptサポート:
import {Navbar} from '@nodeblocks/frontend-navbar-block';
import {ComponentProps, ReactNode} from 'react';
// メインコンポーネントインターフェース
interface NavbarProps extends Omit<ComponentProps<'nav'>, 'children'> {
leftContent: ReactNode;
centerContent: ReactNode;
rightContent: ReactNode;
className?: string;
}
// 包括的な型付きの使用例
const customNavbar: NavbarProps = {
leftContent: <Navbar.Logo src="/logo.svg" alt="ロゴ" />,
centerContent: (
<nav>
<Navbar.Link href="#home">ホーム</Navbar.Link>
<Navbar.Link href="#products">プロダクト</Navbar.Link>
<Navbar.Link href="#about">概要</Navbar.Link>
</nav>
),
rightContent: (
<div>
<Navbar.ButtonLink href="#login">ログイン</Navbar.ButtonLink>
<Navbar.ButtonLink href="#register">登録</Navbar.ButtonLink>
</div>
),
className: 'my-custom-navbar',
};
// サブコンポーネントカスタマイゼーション例
function AdvancedNavbar() {
return (
<Navbar {...customNavbar}>
<Navbar.Left />
<Navbar.Center />
<Navbar.Right
onClick={e => console.log('右セクションがクリックされました')}
style={{backgroundColor: 'lightgray'}}
className="my-custom-right-section">
{/* これはコンテキストのrightContentをオーバーライドします */}
<Navbar.ButtonLink href="#custom-action">カスタムアクション</Navbar.ButtonLink>
</Navbar.Right>
</Navbar>
);
}
React、TypeScript、モダンWebスタンダードを使用して❤️で構築されました。