ナビゲーションバーブロック
Navbarコンポーネントは、ReactとTypeScriptで構築された完全にカスタマイズ可能でアクセシブルなナビゲーションバーです。モダンなデザインパターン、柔軟なレイアウトセクション、カスタマイズ可能なコンテンツエリアを備えた完全なWebサイトナビゲーションインターフェースを提供します。
🚀 インストール
npm install @nodeblocks/frontend-navbar-block@0.2.0
📖 使用法
import {Navbar} from '@nodeblocks/frontend-navbar-block';
- 基本的な使用法
- 高度な使用法
function BasicNavbar() { return ( <Navbar leftContent={<Navbar.Logo src="/img/icon-small.png" alt="Company Logo" style={{height: 32}} />} centerContent={ <div style={{display: 'flex', gap: 16}}> <Navbar.Link href="#home">ホーム</Navbar.Link> <Navbar.Link href="#about">概要</Navbar.Link> <Navbar.Link href="#services">サービス</Navbar.Link> <Navbar.Link href="#contact">お問い合わせ</Navbar.Link> </div> } rightContent={<Navbar.ButtonLink href="#login">ログイン</Navbar.ButtonLink>} sx={{backgroundColor: 'white', boxShadow: 1}} > <Navbar.Left /> <Navbar.Center /> <Navbar.Right /> </Navbar> ); }
function AdvancedNavbar() { return ( <div style={{ background: 'linear-gradient(135deg, #0f172a 0%, #1e293b 100%)', padding: '24px', borderRadius: 16, }} > <Navbar leftContent={null} centerContent={null} rightContent={null} sx={{ backgroundColor: 'rgba(255,255,255,0.03)', backdropFilter: 'blur(20px)', border: '1px solid rgba(255,255,255,0.08)', borderRadius: 3, py: 1.5, px: 3, }} > {({defaultBlocks, defaultBlockOrder}) => ({ blocks: { ...defaultBlocks, // 🏢 Brand Section left: { ...defaultBlocks.left, props: { ...defaultBlocks.left.props, sx: {alignItems: 'center'}, children: ( <div style={{display: 'flex', alignItems: 'center', gap: 10}}> <div style={{ width: 36, height: 36, background: 'linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%)', borderRadius: 10, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '1.1rem', boxShadow: '0 4px 12px rgba(59, 130, 246, 0.4)', }} > ⚡ </div> <div> <div style={{ color: 'white', fontWeight: 700, fontSize: '1.1rem', lineHeight: 1.2, }} > Velocity </div> <div style={{ color: 'rgba(148,163,184,0.8)', fontSize: '0.7rem', fontWeight: 500, letterSpacing: 1, textTransform: 'uppercase', }} > プラットフォーム </div> </div> </div> ), }, }, // 🧭 Navigation Links center: { ...defaultBlocks.center, props: { ...defaultBlocks.center.props, sx: { alignItems: 'center', flexGrow: 1, justifyContent: 'center', }, children: ( <div style={{display: 'flex', gap: 8}}> {[ {label: '機能', active: true}, {label: '料金', active: false}, {label: 'ドキュメント', active: false}, {label: 'ブログ', active: false}, ].map(item => ( <a key={item.label} href={`#${item.label.toLowerCase()}`} style={{ color: item.active ? 'white' : 'rgba(148,163,184,0.9)', padding: '8px 16px', borderRadius: 8, textDecoration: 'none', fontWeight: 500, fontSize: '0.875rem', backgroundColor: item.active ? 'rgba(59,130,246,0.15)' : 'transparent', border: item.active ? '1px solid rgba(59,130,246,0.3)' : '1px solid transparent', transition: 'all 0.2s', }} > {item.label} </a> ))} </div> ), }, }, // 🎯 Actions Section right: { ...defaultBlocks.right, props: { ...defaultBlocks.right.props, sx: {alignItems: 'center'}, children: ( <div style={{display: 'flex', alignItems: 'center', gap: 12}}> <a href="#signin" style={{ color: 'rgba(148,163,184,0.9)', textDecoration: 'none', fontWeight: 500, fontSize: '0.875rem', padding: '8px 12px', transition: 'color 0.2s', }} > サインイン </a> <a href="#start" style={{ background: 'linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%)', color: 'white', textDecoration: 'none', fontWeight: 600, fontSize: '0.875rem', padding: '10px 20px', borderRadius: 10, boxShadow: '0 4px 16px rgba(59, 130, 246, 0.35)', transition: 'all 0.2s', }} > 始める → </a> </div> ), }, }, }, blockOrder: defaultBlockOrder, })} </Navbar> </div> ); }
🔧 プロパティリファレンス
メインコンポーネントプロパティ
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
leftContent | ReactNode | 必須 | ナビゲーションバーの左セクションに表示するコンテンツ(通常はロゴ) |
centerContent | ReactNode | 必須 | ナビゲーションバーの中央セクションに表示するコンテンツ(通常はナビゲーションリンク) |
rightContent | ReactNode | 必須 | ナビゲーションバーの右セクションに表示するコンテンツ(通常はユーザーアクション/ボタン) |
spacing | number | ResponsiveValue | 3 | 左、中央、右セクション間のスペーシング |
direction | StackDirection | 'row' | ナビゲーションバーセクションのレイアウト方向 |
className | string | undefined | ナビゲーションバーコンテナのスタイリング用の追加CSSクラス名 |
sx | SxProps<Theme> | 下記参照 | カスタムスタイリング用のMUIシステムプロパティ |
children | BlocksOverride | undefined | デフォルトブロックをオーバーライドするか、カスタムナビゲーションバーセクションを追加する関数 |
デフォルトsx:
{
alignItems: 'center',
px: 3,
py: 1.5
}
注意: メインコンポーネントはすべてのMUI Stackプロパティを継承します。component="nav"を介してnav要素としてレンダリングされます。
サブコンポーネント
Navbarコンポーネントは複数のサブコンポーネントを提供します。すべてのサブコンポーネントは、メインコンポーネントのコンテキストからデフォルト値を受け取り、プロパティを通じてこれらの値をオーバーライドできます。
Navbar.Left
ナビゲーションバーの左セクションをレンダリングします。通常はロゴを含みます。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | コンテキストのleftContent | 左セクションに表示するコンテンツ(コンテキストのleftContentをオーバーライド) |
leftContent | ReactNode | コンテキストから | 左コンテンツを提供する別の方法(コンテキストをオーバーライド) |
spacing | number | ResponsiveValue | 1 | 子要素間のスペーシング |
direction | StackDirection | 'row' | レイアウト方向 |
sx | SxProps<Theme> | { alignItems: 'center' } | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Stackプロパティを継承します。
Navbar.Center
ナビゲーションバーの中央セクションをレンダリングします。通常はナビゲーションリンクを含みます。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | コンテキストのcenterContent | 中央セクションに表示するコンテンツ(コンテキストのcenterContentをオーバーライド) |
centerContent | ReactNode | コンテキストから | 中央コンテンツを提供する別の方法(コンテキストをオーバーライド) |
spacing | number | ResponsiveValue | 2 | 子要素間のスペーシング |
direction | StackDirection | 'row' | レイアウト方向 |
sx | SxProps<Theme> | 下記参照 | カスタムスタイリング用のMUIシステムプロパティ |
デフォルトsx:
{
alignItems: 'center',
flexGrow: 1
}
注意: このコンポーネントはすべてのMUI Stackプロパティを継承します。flexGrow: 1により、左右のセクション間の利用可能なスペースを占有します。
Navbar.Right
ナビゲーションバーの右セクションをレンダリングします。通常はユーザーアクション/ボタンを含みます。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
children | ReactNode | コンテキストのrightContent | 右セクションに表示するコンテンツ(コンテキストのrightContentをオーバーライド) |
rightContent | ReactNode | コンテキストから | 右コンテンツを提供する別の方法(コンテキストをオーバーライド) |
spacing | number | ResponsiveValue | 1 | 子要素間のスペーシング |
direction | StackDirection | 'row' | レイアウト方向 |
sx | SxProps<Theme> | 下記参照 | カスタムスタイリング用のMUIシステムプロパティ |
デフォルトsx:
{
alignItems: 'center',
justifyContent: 'flex-end'
}
注意: このコンポーネントはすべてのMUI Stackプロパティを継承します。
Navbar.Logo
ナビゲーションバーのロゴ画像をレンダリングします。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
src | string | 必須 | ロゴ画像のソースURL |
alt | string | 必須 | ロゴ画像の代替テキスト |
component | string | 'img' | ルートノードに使用されるコンポーネント(固定) |
sx | SxProps<Theme> | undefined | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはすべてのMUI Box<'img'>プロパティを継承します。
Navbar.Link
ナビゲーションリンクをレンダリングします。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
href | string | 必須 | リンクの宛先URL |
children | ReactNode | 必須 | リンク内に表示するコンテンツ |
spacing | number | ResponsiveValue | 0.5 | 子要素間のスペーシング(アイコン用) |
direction | StackDirection | 'row' | レイアウト方向 |
underline | 'none' | 'hover' | 'always' | 'hover' | リンクの下線動作(MUI Linkから) |
color | string | 'inherit' | リンクの色 |
sx | SxProps<Theme> | 下記参照 | カスタムスタイリング用のMUIシステムプロパティ |
デフォルトsx:
{
display: 'inline-flex',
alignItems: 'center'
}
注意: このコンポーネントはcomponent={Link}を持つMUI Stackを使用します。StackPropsとMUI Linkプロパティの両方を継承します。
Navbar.ButtonLink
ボタンスタイルのリンクをレンダリングします。
| プロパティ | 型 | デフォルト | 説明 |
|---|---|---|---|
href | string | 必須 | ボタンリンクの宛先URL |
children | ReactNode | 必須 | ボタン内に表示するコンテンツ |
variant | 'text' | 'outlined' | 'contained' | 'contained' | ボタンバリアント |
size | 'small' | 'medium' | 'large' | 'small' | ボタンサイズ |
color | string | 'primary' | ボタンの色 |
spacing | number | ResponsiveValue | 0.5 | 子要素間のスペーシング(アイコン用) |
direction | StackDirection | 'row' | レイアウト方向 |
sx | SxProps<Theme> | undefined | カスタムスタイリング用のMUIシステムプロパティ |
注意: このコンポーネントはcomponent={Button}を持つMUI Stackを使用します。StackPropsとMUI Buttonプロパティの両方を継承します。
🎨 設定例
カスタムロゴスタイリング
<Navbar.Logo
src="/logo.svg"
alt="会社ロゴ"
sx={{height: 40, width: 'auto'}}
/>
カスタムナビゲーションリンク
<Navbar.Link href="#products" sx={{fontWeight: 600, color: 'primary.main'}}>
プロダクト
</Navbar.Link>
カスタムボタンリンク
<Navbar.ButtonLink href="#register" variant="contained" sx={{px: 3, py: 1}}>
始める
</Navbar.ButtonLink>
カスタムスタイルコンポーネント
function StyledNavbarComponents() {
return (
<Navbar
leftContent={<Navbar.Logo src="/logo.svg" alt="会社ロゴ" sx={{height: 40, width: 'auto'}} />}
centerContent={
<Navbar.Link href="#products" sx={{fontWeight: 600, color: 'primary.main'}}>
プロダクト
</Navbar.Link>
}
rightContent={
<Navbar.ButtonLink href="#register" variant="contained" sx={{px: 3, py: 1}}>
始める
</Navbar.ButtonLink>
}
>
<Navbar.Left />
<Navbar.Center />
<Navbar.Right />
</Navbar>
);
}
🔧 TypeScriptサポート
包括的な型定義による完全なTypeScriptサポート:
import {Stack} from '@mui/material';
import {Navbar} from '@nodeblocks/frontend-navbar-block';
import React from 'react';
// Example with comprehensive typing
function CustomNavbar() {
return (
<Navbar
leftContent={<Navbar.Logo src="/logo.svg" alt="ロゴ" />}
centerContent={
<Stack direction="row" spacing={2}>
<Navbar.Link href="#home">ホーム</Navbar.Link>
<Navbar.Link href="#products">プロダクト</Navbar.Link>
<Navbar.Link href="#about">概要</Navbar.Link>
</Stack>
}
rightContent={
<Stack direction="row" spacing={1}>
<Navbar.ButtonLink href="#login" variant="text">
ログイン
</Navbar.ButtonLink>
<Navbar.ButtonLink href="#register">登録</Navbar.ButtonLink>
</Stack>
}
spacing={4}
sx={{
backgroundColor: 'background.paper',
boxShadow: 1,
borderRadius: 2,
}}
>
<Navbar.Left sx={{minWidth: 150}} />
<Navbar.Center justifyContent="center" />
<Navbar.Right sx={{minWidth: 200}} />
</Navbar>
);
}
📝 注意事項
- メインコンポーネントはデフォルトで
component="nav"とdirection="row"、spacing={3}を持つMUIStackを使用します。 - すべてのセクションコンポーネント(
Left、Center、Right)はMUIStackプロパティを継承し、スタイリング用のsxプロパティをサポートします。 CenterセクションはデフォルトでflexGrow: 1を持ち、利用可能なスペースを拡張して埋めます。RightセクションはデフォルトでjustifyContent: 'flex-end'を持ち、コンテンツを右に配置します。Navbar.LogoはMUIBoxをcomponent="img"で使用し、MUIスタイリングサポートで適切な画像レンダリングを行います。Navbar.LinkはMUIStackレイアウトとMUILinkナビゲーションを組み合わせ、テキストと一緒にアイコンを使用できます。Navbar.ButtonLinkはMUIStackレイアウトとMUIButtonを組み合わせ、デフォルトでvariant="contained"とsize="small"を使用します。- コンテキスト値(
leftContent、centerContent、rightContent)はReact Contextを介して共有され、サブコンポーネントレベルでオーバーライドできます。
React、TypeScript、MUIを使用して❤️で構築されました。