-
-
Notifications
You must be signed in to change notification settings - Fork 281
feat: Add a language drop-down menu in the Header component, including a link to Chinese documentation #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
360e44d
507d40b
6ab774a
ba2e6ef
85eb80f
186cb80
71f53fe
25b0f48
128eb2a
81cff59
af046e4
8ed8fc2
c282d81
d137a79
4418093
47ed141
25c6669
2be5ccf
8bf998d
51cf417
b756890
1d4a9b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,79 @@ import clsx from 'clsx' | |
| import SEO from '~/components/SEO' | ||
| import ToggleTheme from '~/components/ToggleTheme' | ||
|
|
||
| // 语言选择器组件 | ||
| function LanguageSelector() { | ||
| const [isOpen, setIsOpen] = useState(false) | ||
|
|
||
| useEffect(() => { | ||
| function handleClickOutside(event: MouseEvent) { | ||
| const target = event.target as Element | ||
| if (isOpen && !target.closest('.language-selector')) { | ||
| setIsOpen(false) | ||
| } | ||
| } | ||
|
|
||
| if (isOpen) { | ||
| document.addEventListener('mousedown', handleClickOutside) | ||
| } | ||
|
|
||
| return () => { | ||
| document.removeEventListener('mousedown', handleClickOutside) | ||
| } | ||
| }, [isOpen]) | ||
|
|
||
| return ( | ||
| <div className="relative language-selector mr-6"> | ||
| <button | ||
| type="button" | ||
| className="flex items-center text-gray-700 dark:text-gray-200 hover:text-sky-500 dark:hover:text-sky-400 transition-colors" | ||
| onClick={() => setIsOpen(!isOpen)} | ||
| > | ||
| <span className="mr-1">🌐</span> | ||
| <span>Language</span> | ||
| <svg | ||
| className={clsx( | ||
| 'ml-1 h-4 w-4 transition-transform', | ||
| isOpen ? 'rotate-180' : '' | ||
| )} | ||
| fill="none" | ||
| viewBox="0 0 24 24" | ||
| stroke="currentColor" | ||
| > | ||
| <path | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| strokeWidth={2} | ||
| d="M19 9l-7 7-7-7" | ||
| /> | ||
| </svg> | ||
| </button> | ||
|
|
||
| {isOpen && ( | ||
| <div className="absolute right-0 mt-2 w-48 bg-white dark:bg-gray-800 rounded-md shadow-lg py-1 z-50 border border-gray-200 dark:border-gray-700"> | ||
| <a | ||
| href="https://valtio-xnj9.vercel.app/zh" | ||
|
||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="block px-4 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-sky-500 dark:hover:text-sky-400 transition-colors" | ||
| onClick={() => setIsOpen(false)} | ||
| > | ||
| 中文文档 | ||
eveningwater marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </a> | ||
| <Link href="/"> | ||
|
||
| <a | ||
| className="block px-4 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-sky-500 dark:hover:text-sky-400 transition-colors" | ||
| onClick={() => setIsOpen(false)} | ||
| > | ||
| English | ||
| </a> | ||
| </Link> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export function NavPopover({ | ||
| display = 'md:hidden', | ||
| className = '', | ||
|
|
@@ -80,6 +153,16 @@ export function NavPopover({ | |
| GitHub | ||
| </a> | ||
| </li> | ||
| <li> | ||
| <a | ||
| href="https://valtio-xnj9.vercel.app/zh" | ||
|
||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="hover:text-sky-500 dark:hover:text-sky-400" | ||
| > | ||
| 中文文档 | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| <div className="mt-6 pt-6 border-t border-gray-200 dark:border-gray-200/10"> | ||
| <ToggleTheme /> | ||
|
|
@@ -175,6 +258,7 @@ export default function Header({ | |
| </ul> | ||
| </nav> | ||
| <div className="flex items-center border-l border-gray-200 ml-6 pl-6 dark:border-gray-800"> | ||
| <LanguageSelector /> | ||
| <ToggleTheme /> | ||
| <a | ||
| href="https://github.com/pmndrs/valtio" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.