@umituz/web-design-system 2.4.2 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MainNavbar Component (Organism)
|
|
3
|
+
* @description Full-featured navigation bar with logo, links, theme toggle, language selector, and mobile menu
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useState, useEffect, useRef, useMemo } from 'react';
|
|
7
|
+
import { Link, useLocation } from 'react-router-dom';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import type { BaseProps } from '../../domain/types';
|
|
10
|
+
|
|
11
|
+
export interface NavItem {
|
|
12
|
+
name: string;
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Language {
|
|
17
|
+
code: string;
|
|
18
|
+
name: string;
|
|
19
|
+
flag: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MainNavbarProps extends BaseProps {
|
|
23
|
+
logo?: React.ReactNode;
|
|
24
|
+
appName: string;
|
|
25
|
+
navItems: NavItem[];
|
|
26
|
+
supportedLanguages: Record<string, Language>;
|
|
27
|
+
currentLanguage: string;
|
|
28
|
+
onLanguageChange: (code: string) => void;
|
|
29
|
+
theme: 'light' | 'dark';
|
|
30
|
+
onThemeToggle: () => void;
|
|
31
|
+
githubUrl?: string;
|
|
32
|
+
githubLabel?: string;
|
|
33
|
+
translations?: {
|
|
34
|
+
language: string;
|
|
35
|
+
switchToMode: (mode: string) => string;
|
|
36
|
+
lightMode: string;
|
|
37
|
+
darkMode: string;
|
|
38
|
+
github: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const MainNavbar = ({
|
|
43
|
+
logo,
|
|
44
|
+
appName,
|
|
45
|
+
navItems,
|
|
46
|
+
supportedLanguages,
|
|
47
|
+
currentLanguage,
|
|
48
|
+
onLanguageChange,
|
|
49
|
+
theme,
|
|
50
|
+
onThemeToggle,
|
|
51
|
+
githubUrl,
|
|
52
|
+
githubLabel = 'GitHub',
|
|
53
|
+
translations = {
|
|
54
|
+
language: 'Language',
|
|
55
|
+
switchToMode: (mode: string) => `Switch to ${mode} mode`,
|
|
56
|
+
lightMode: 'Light Mode',
|
|
57
|
+
darkMode: 'Dark Mode',
|
|
58
|
+
github: 'GitHub',
|
|
59
|
+
},
|
|
60
|
+
className,
|
|
61
|
+
}: MainNavbarProps) => {
|
|
62
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
63
|
+
const [isLangOpen, setIsLangOpen] = useState(false);
|
|
64
|
+
const location = useLocation();
|
|
65
|
+
const langDropdownRef = useRef<HTMLDivElement>(null);
|
|
66
|
+
|
|
67
|
+
const navItemsMemo = useMemo(() => navItems, [JSON.stringify(navItems)]);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
71
|
+
if (langDropdownRef.current && !langDropdownRef.current.contains(event.target as Node)) {
|
|
72
|
+
setIsLangOpen(false);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (isLangOpen) {
|
|
77
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
78
|
+
return () => {
|
|
79
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}, [isLangOpen]);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<nav className={`bg-bg-primary sticky top-0 z-50 border-b border-border transition-theme ${className || ''}`}>
|
|
86
|
+
<div className="max-w-7xl mx-auto px-4">
|
|
87
|
+
<div className="flex justify-between h-16 items-center">
|
|
88
|
+
{/* Logo */}
|
|
89
|
+
<Link to="/" className="flex items-center gap-2">
|
|
90
|
+
{logo || <span className="text-xl font-bold text-text-primary">{appName}</span>}
|
|
91
|
+
</Link>
|
|
92
|
+
|
|
93
|
+
{/* Desktop Menu */}
|
|
94
|
+
<div className="hidden md:flex items-center space-x-6">
|
|
95
|
+
{navItemsMemo.map((item) => {
|
|
96
|
+
const isActive = location.pathname === item.path;
|
|
97
|
+
return (
|
|
98
|
+
<Link
|
|
99
|
+
key={item.path}
|
|
100
|
+
to={item.path}
|
|
101
|
+
className={`font-medium transition-colors transition-theme ${
|
|
102
|
+
isActive ? 'text-primary-light' : 'text-text-secondary hover:text-primary-light'
|
|
103
|
+
}`}
|
|
104
|
+
>
|
|
105
|
+
{item.name}
|
|
106
|
+
</Link>
|
|
107
|
+
);
|
|
108
|
+
})}
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
{/* Actions */}
|
|
112
|
+
<div className="flex items-center gap-2 md:gap-3">
|
|
113
|
+
{/* Language Selector */}
|
|
114
|
+
<div className="relative" ref={langDropdownRef}>
|
|
115
|
+
<button
|
|
116
|
+
onClick={() => setIsLangOpen(!isLangOpen)}
|
|
117
|
+
className="p-2 rounded-lg bg-bg-secondary text-text-secondary hover:text-primary-light border border-border hover:border-primary-light transition-all transition-theme hidden md:block"
|
|
118
|
+
title={translations.language}
|
|
119
|
+
type="button"
|
|
120
|
+
>
|
|
121
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
122
|
+
<path d="m5 8 6 6" />
|
|
123
|
+
<path d="m4 14 6-6 2-3" />
|
|
124
|
+
<path d="M2 5h12" />
|
|
125
|
+
<path d="M7 2h1" />
|
|
126
|
+
<path d="m22 22-5-10-5 10" />
|
|
127
|
+
<path d="M14 18h6" />
|
|
128
|
+
</svg>
|
|
129
|
+
</button>
|
|
130
|
+
|
|
131
|
+
{isLangOpen && (
|
|
132
|
+
<div className="absolute right-0 top-full mt-2 w-48 bg-bg-card rounded-lg border border-border shadow-xl z-50">
|
|
133
|
+
{Object.entries(supportedLanguages).map(([code, { name, flag }]) => (
|
|
134
|
+
<button
|
|
135
|
+
key={code}
|
|
136
|
+
onClick={() => {
|
|
137
|
+
onLanguageChange(code);
|
|
138
|
+
setIsLangOpen(false);
|
|
139
|
+
}}
|
|
140
|
+
className={`w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-bg-tertiary transition-colors transition-theme ${
|
|
141
|
+
currentLanguage === code ? 'bg-bg-tertiary text-primary-light' : 'text-text-secondary'
|
|
142
|
+
}`}
|
|
143
|
+
type="button"
|
|
144
|
+
>
|
|
145
|
+
<span className="text-xl">{flag}</span>
|
|
146
|
+
<span className="text-sm">{name}</span>
|
|
147
|
+
{currentLanguage === code && (
|
|
148
|
+
<span className="ml-auto text-primary-light">✓</span>
|
|
149
|
+
)}
|
|
150
|
+
</button>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
{/* Theme Toggle */}
|
|
157
|
+
<button
|
|
158
|
+
onClick={onThemeToggle}
|
|
159
|
+
className="p-2 rounded-lg bg-bg-secondary text-text-secondary hover:text-primary-light border border-border hover:border-primary-light transition-all transition-theme"
|
|
160
|
+
title={translations.switchToMode(theme === 'dark' ? 'light' : 'dark')}
|
|
161
|
+
aria-label={`Switch to ${theme === 'dark' ? 'light' : 'dark'} mode`}
|
|
162
|
+
type="button"
|
|
163
|
+
>
|
|
164
|
+
{theme === 'dark' ? (
|
|
165
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
166
|
+
<circle cx="12" cy="12" r="4" />
|
|
167
|
+
<path d="M12 2v2" />
|
|
168
|
+
<path d="M12 20v2" />
|
|
169
|
+
<path d="m4.93 4.93 1.41 1.41" />
|
|
170
|
+
<path d="m17.66 17.66 1.41 1.41" />
|
|
171
|
+
<path d="M2 12h2" />
|
|
172
|
+
<path d="M20 12h2" />
|
|
173
|
+
<path d="m6.34 17.66-1.41 1.41" />
|
|
174
|
+
<path d="m19.07 4.93-1.41 1.41" />
|
|
175
|
+
</svg>
|
|
176
|
+
) : (
|
|
177
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
178
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
179
|
+
</svg>
|
|
180
|
+
)}
|
|
181
|
+
</button>
|
|
182
|
+
|
|
183
|
+
{/* GitHub */}
|
|
184
|
+
{githubUrl && (
|
|
185
|
+
<a
|
|
186
|
+
href={githubUrl}
|
|
187
|
+
target="_blank"
|
|
188
|
+
rel="noopener noreferrer"
|
|
189
|
+
className="hidden md:flex items-center gap-2 px-4 py-2 bg-bg-secondary text-text-secondary rounded-lg border border-border hover:border-primary-light hover:text-text-primary transition-all transition-theme"
|
|
190
|
+
>
|
|
191
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
|
|
192
|
+
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
|
|
193
|
+
</svg>
|
|
194
|
+
<span className="font-medium">{githubLabel}</span>
|
|
195
|
+
</a>
|
|
196
|
+
)}
|
|
197
|
+
|
|
198
|
+
{/* Mobile Button */}
|
|
199
|
+
<button
|
|
200
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
201
|
+
className="md:hidden text-text-secondary"
|
|
202
|
+
type="button"
|
|
203
|
+
aria-label="Toggle menu"
|
|
204
|
+
>
|
|
205
|
+
{isOpen ? (
|
|
206
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
207
|
+
<path d="M18 6L6 18M6 6l12 12" />
|
|
208
|
+
</svg>
|
|
209
|
+
) : (
|
|
210
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
211
|
+
<line x1="4" x2="20" y1="12" y2="12" />
|
|
212
|
+
<line x1="4" x2="20" y1="6" y2="6" />
|
|
213
|
+
<line x1="4" x2="20" y1="18" y2="18" />
|
|
214
|
+
</svg>
|
|
215
|
+
)}
|
|
216
|
+
</button>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
|
|
221
|
+
{/* Mobile Menu */}
|
|
222
|
+
{isOpen && (
|
|
223
|
+
<div className="md:hidden bg-bg-secondary border-t border-border transition-theme">
|
|
224
|
+
<div className="px-4 py-4 space-y-2">
|
|
225
|
+
{/* Theme Toggle Mobile */}
|
|
226
|
+
<button
|
|
227
|
+
onClick={onThemeToggle}
|
|
228
|
+
className="w-full flex items-center gap-3 px-4 py-3 rounded-lg text-text-secondary hover:bg-bg-tertiary transition-all transition-theme"
|
|
229
|
+
type="button"
|
|
230
|
+
>
|
|
231
|
+
{theme === 'dark' ? (
|
|
232
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
233
|
+
<circle cx="12" cy="12" r="4" />
|
|
234
|
+
<path d="M12 2v2" />
|
|
235
|
+
<path d="M12 20v2" />
|
|
236
|
+
<path d="m4.93 4.93 1.41 1.41" />
|
|
237
|
+
<path d="m17.66 17.66 1.41 1.41" />
|
|
238
|
+
<path d="M2 12h2" />
|
|
239
|
+
<path d="M20 12h2" />
|
|
240
|
+
<path d="m6.34 17.66-1.41 1.41" />
|
|
241
|
+
<path d="m19.07 4.93-1.41 1.41" />
|
|
242
|
+
</svg>
|
|
243
|
+
) : (
|
|
244
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
245
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
246
|
+
</svg>
|
|
247
|
+
)}
|
|
248
|
+
<span>{theme === 'dark' ? translations.lightMode : translations.darkMode}</span>
|
|
249
|
+
</button>
|
|
250
|
+
|
|
251
|
+
{/* Language Selector Mobile */}
|
|
252
|
+
<div className="px-4 py-2">
|
|
253
|
+
<div className="text-text-secondary text-sm mb-2">{translations.language}</div>
|
|
254
|
+
<div className="grid grid-cols-2 gap-2">
|
|
255
|
+
{Object.entries(supportedLanguages).map(([code, { name, flag }]) => (
|
|
256
|
+
<button
|
|
257
|
+
key={code}
|
|
258
|
+
onClick={() => onLanguageChange(code)}
|
|
259
|
+
className={`flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-all transition-theme ${
|
|
260
|
+
currentLanguage === code
|
|
261
|
+
? 'bg-primary-light text-text-primary'
|
|
262
|
+
: 'bg-bg-primary text-text-secondary hover:bg-bg-tertiary'
|
|
263
|
+
}`}
|
|
264
|
+
type="button"
|
|
265
|
+
>
|
|
266
|
+
<span>{flag}</span>
|
|
267
|
+
<span>{name}</span>
|
|
268
|
+
</button>
|
|
269
|
+
))}
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
|
|
273
|
+
{navItemsMemo.map((item) => {
|
|
274
|
+
const isActive = location.pathname === item.path;
|
|
275
|
+
return (
|
|
276
|
+
<Link
|
|
277
|
+
key={item.path}
|
|
278
|
+
to={item.path}
|
|
279
|
+
className={`block px-4 py-2 rounded-lg font-medium transition-theme ${
|
|
280
|
+
isActive ? 'text-primary-light bg-bg-tertiary' : 'text-text-secondary hover:bg-bg-tertiary'
|
|
281
|
+
}`}
|
|
282
|
+
onClick={() => setIsOpen(false)}
|
|
283
|
+
>
|
|
284
|
+
{item.name}
|
|
285
|
+
</Link>
|
|
286
|
+
);
|
|
287
|
+
})}
|
|
288
|
+
|
|
289
|
+
{githubUrl && (
|
|
290
|
+
<a
|
|
291
|
+
href={githubUrl}
|
|
292
|
+
target="_blank"
|
|
293
|
+
rel="noopener noreferrer"
|
|
294
|
+
className="flex items-center gap-2 px-4 py-2 text-text-secondary hover:text-text-primary rounded-lg hover:bg-bg-tertiary transition-all transition-theme"
|
|
295
|
+
>
|
|
296
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
|
|
297
|
+
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
|
|
298
|
+
</svg>
|
|
299
|
+
<span>{githubLabel}</span>
|
|
300
|
+
</a>
|
|
301
|
+
)}
|
|
302
|
+
</div>
|
|
303
|
+
</div>
|
|
304
|
+
)}
|
|
305
|
+
</nav>
|
|
306
|
+
);
|
|
307
|
+
};
|
|
@@ -149,3 +149,7 @@ export type { FilterBarProps, Category, SortOption } from './FilterBar';
|
|
|
149
149
|
|
|
150
150
|
export { FilterSidebar } from './FilterSidebar';
|
|
151
151
|
export type { FilterSidebarProps } from './FilterSidebar';
|
|
152
|
+
|
|
153
|
+
// NEW: Navigation Components
|
|
154
|
+
export { MainNavbar } from './MainNavbar';
|
|
155
|
+
export type { MainNavbarProps, NavItem, Language } from './MainNavbar';
|