Skip to content

Prompt as Code | GPT Image 2 / 2.5 提示词与案例库,530+ 个案例、20+ 套工业级模板与可复用 Skills,新增 2.5 同提示词对比专区,附完整提示词与生成记录,持续更新。

Refine account and language menus

freestylefly77035f3635d2
diff --git a/src/main.jsx b/src/main.jsx
index 56ab14c..8e67f6d 100644
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -1,8 +1,9 @@
-import React, { useEffect, useMemo, useState } from 'react';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
import { createRoot } from 'react-dom/client';
import {
ArrowUpRight,
Bot,
+ ChevronDown,
Check,
Coins,
Copy,
@@ -572,23 +573,77 @@ function FilterPill({ active, children, onClick }) {
);
}
+function useDropdownDismiss(open, setOpen) {
+ const ref = useRef(null);
+
+ useEffect(() => {
+ if (!open) return undefined;
+
+ function handlePointerDown(event) {
+ if (ref.current && !ref.current.contains(event.target)) {
+ setOpen(false);
+ }
+ }
+
+ function handleKeyDown(event) {
+ if (event.key === 'Escape') {
+ setOpen(false);
+ }
+ }
+
+ document.addEventListener('pointerdown', handlePointerDown);
+ document.addEventListener('keydown', handleKeyDown);
+ return () => {
+ document.removeEventListener('pointerdown', handlePointerDown);
+ document.removeEventListener('keydown', handleKeyDown);
+ };
+ }, [open, setOpen]);
+
+ return ref;
+}
+
function LanguageSwitch({ language, setLanguage }) {
+ const [open, setOpen] = useState(false);
+ const ref = useDropdownDismiss(open, setOpen);
+ const languageOptions = [
+ { value: 'en', label: 'English', short: 'EN' },
+ { value: 'zh', label: '中文', short: '中文' }
+ ];
+ const activeLanguage = languageOptions.find((option) => option.value === language) || languageOptions[0];
+
return (
- <div className="languageSwitch" aria-label="Language switcher">
- <button
- className={cx(language === 'en' && 'active')}
- type="button"
- onClick={() => setLanguage('en')}
- >
- EN
- </button>
+ <div className="dropdownControl languageSwitch" ref={ref}>
<button
- className={cx(language === 'zh' && 'active')}
+ className={cx('dropdownTrigger', open && 'open')}
type="button"
- onClick={() => setLanguage('zh')}
+ aria-label="Language"
+ aria-haspopup="menu"
+ aria-expanded={open}
+ onClick={() => setOpen((current) => !current)}
>
- 中文
+ <span>{activeLanguage.short}</span>
+ <ChevronDown size={15} />
</button>
+ {open ? (
+ <div className="dropdownMenu languageMenu" role="menu">
+ {languageOptions.map((option) => (
+ <button
+ className={cx(option.value === language && 'active')}
+ type="button"
+ role="menuitemradio"
+ aria-checked={option.value === language}
+ onClick={() => {
+ setLanguage(option.value);
+ setOpen(false);
+ }}
+ key={option.value}
+ >
+ <span>{option.label}</span>
+ <strong>{option.short}</strong>
+ </button>
+ ))}
+ </div>
+ ) : null}
</div>
);
}
@@ -750,6 +805,8 @@ function AuthModal({ open, language, onClose }) {
function UserMenu({ language, session, profile, onSignIn, onSignOut, onAdmin }) {
const t = copy[language];
+ const [open, setOpen] = useState(false);
+ const ref = useDropdownDismiss(open, setOpen);
if (!session) {
return (
@@ -761,29 +818,77 @@ function UserMenu({ language, session, profile, onSignIn, onSignOut, onAdmin })
}
const email = profile?.email || session.user?.email || t.account;
+ const displayName = profile?.fullName || session.user?.user_metadata?.name || email;
return (
- <div className="userMenu">
- <div className="accountChip">
- <UserCircle size={17} />
- <span>{email}</span>
- {profile?.isSuperAdmin ? <strong>{t.superAdmin}</strong> : null}
- </div>
- <div className="creditChip">
- <Coins size={16} />
- <span>{profile?.creditBalance || 0} {t.credits}</span>
- <span>{profile?.freeUsed ? t.freeUsedShort : t.freeReady}</span>
- </div>
- {profile?.isSuperAdmin ? (
- <button className="iconTextButton" type="button" onClick={onAdmin}>
- <ShieldCheck size={17} />
- {t.adminPanel}
- </button>
- ) : null}
- <button className="iconTextButton" type="button" onClick={onSignOut}>
- <LogOut size={17} />
- {t.signOut}
+ <div className="dropdownControl userMenu" ref={ref}>
+ <button
+ className={cx('userTrigger', open && 'open')}
+ type="button"
+ aria-label={t.account}
+ aria-haspopup="menu"
+ aria-expanded={open}
+ onClick={() => setOpen((current) => !current)}
+ >
+ <span className="avatarBadge">
+ <UserCircle size={18} />
+ </span>
+ <ChevronDown size={15} />
</button>
+ {open ? (
+ <div className="dropdownMenu userDropdown" role="menu">
+ <div className="userSummary">
+ <UserCircle size={32} />
+ <div>
+ <strong>{displayName}</strong>
+ <span>{email}</span>
+ </div>
+ </div>
+ <div className="userStats">
+ {profile?.isSuperAdmin ? (
+ <span className="userStat admin">
+ <ShieldCheck size={15} />
+ {t.superAdmin}
+ </span>
+ ) : null}
+ <span className="userStat">
+ <Coins size={15} />
+ {profile?.creditBalance || 0} {t.credits}
+ </span>
+ <span className="userStat">
+ <PackageCheck size={15} />
+ {profile?.freeUsed ? t.freeUsedShort : t.freeReady}
+ </span>
+ </div>
+ <div className="dropdownDivider" />
+ {profile?.isSuperAdmin ? (
+ <button
+ className="dropdownAction"
+ type="button"
+ role="menuitem"
+ onClick={() => {
+ setOpen(false);
+ onAdmin();
+ }}
+ >
+ <ShieldCheck size={17} />
+ {t.adminPanel}
+ </button>
+ ) : null}
+ <button
+ className="dropdownAction danger"
+ type="button"
+ role="menuitem"
+ onClick={() => {
+ setOpen(false);
+ onSignOut();
+ }}
+ >
+ <LogOut size={17} />
+ {t.signOut}
+ </button>
+ </div>
+ ) : null}
</div>
);
}
diff --git a/src/styles.css b/src/styles.css
index 7357418..40432f8 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -129,28 +129,96 @@ button {
color: #ffffff;
}
-.languageSwitch {
+.dropdownControl {
+ position: relative;
display: inline-flex;
align-items: center;
- gap: 4px;
+}
+
+.languageSwitch,
+.userMenu {
+ border: 0;
+ background: transparent;
+ box-shadow: none;
+}
+
+.dropdownTrigger,
+.userTrigger {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
min-height: 42px;
- padding: 4px;
+ border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
+ background: rgba(9, 15, 32, 0.68);
+ color: #dfeaff;
+ font-weight: 900;
+ white-space: nowrap;
+ box-shadow: 0 20px 70px rgba(0, 0, 0, 0.28);
}
-.languageSwitch button {
- min-width: 42px;
- min-height: 32px;
+.dropdownTrigger {
+ min-width: 82px;
+ padding: 0 12px;
+}
+
+.dropdownTrigger:hover,
+.dropdownTrigger.open,
+.userTrigger:hover,
+.userTrigger.open {
+ border-color: rgba(103, 232, 249, 0.62);
+ background: rgba(103, 232, 249, 0.13);
+ color: #ffffff;
+}
+
+.dropdownTrigger svg,
+.userTrigger svg {
+ color: #9eeeff;
+}
+
+.dropdownMenu {
+ position: absolute;
+ top: calc(100% + 8px);
+ right: 0;
+ z-index: 60;
+ min-width: 172px;
+ border: 1px solid rgba(255, 255, 255, 0.14);
+ border-radius: 8px;
+ padding: 8px;
+ background: rgba(7, 12, 26, 0.96);
+ box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
+ backdrop-filter: blur(18px);
+}
+
+.languageMenu button,
+.dropdownAction {
+ display: flex;
+ align-items: center;
+ width: 100%;
+ min-height: 38px;
border: 0;
border-radius: 7px;
+ padding: 0 10px;
background: transparent;
- color: #b7c7df;
- font-weight: 800;
+ color: #c9d8ef;
+ font-weight: 850;
+ text-align: left;
}
-.languageSwitch button:hover,
-.languageSwitch button.active {
- background: linear-gradient(135deg, rgba(66, 230, 255, 0.22), rgba(120, 255, 185, 0.18));
+.languageMenu button {
+ justify-content: space-between;
+}
+
+.languageMenu button strong {
+ color: #8ef6ff;
+ font-size: 12px;
+}
+
+.languageMenu button:hover,
+.languageMenu button.active,
+.dropdownAction:hover {
+ background: rgba(103, 232, 249, 0.12);
color: #ffffff;
}
@@ -224,37 +292,106 @@ button {
left: 106%;
}
-.userMenu {
+.userTrigger {
+ min-width: 58px;
+ padding: 0 9px 0 8px;
+}
+
+.avatarBadge {
display: inline-flex;
align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ border-radius: 7px;
+ background: rgba(103, 232, 249, 0.12);
+ color: #9eeeff;
+}
+
+.userDropdown {
+ min-width: 292px;
+}
+
+.userSummary {
+ display: grid;
+ grid-template-columns: auto minmax(0, 1fr);
+ gap: 10px;
+ align-items: center;
+ padding: 8px 8px 10px;
+}
+
+.userSummary svg {
+ color: #9eeeff;
+}
+
+.userSummary strong,
+.userSummary span {
+ display: block;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.userSummary strong {
+ color: #ffffff;
+ font-size: 14px;
+}
+
+.userSummary span {
+ margin-top: 3px;
+ color: #9aaac0;
+ font-size: 12px;
+}
+
+.userStats {
+ display: grid;
gap: 6px;
- min-height: 42px;
- border-radius: 8px;
- padding: 4px;
+ padding: 6px 8px;
}
-.accountChip,
-.creditChip {
+.userStat {
display: inline-flex;
align-items: center;
gap: 7px;
- min-height: 34px;
+ min-height: 30px;
border-radius: 7px;
padding: 0 9px;
background: rgba(255, 255, 255, 0.06);
- color: #c9d8ef;
+ color: #d4e1f5;
font-size: 12px;
- font-weight: 800;
+ font-weight: 850;
}
-.accountChip span {
- max-width: 150px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
+.userStat svg {
+ color: #ffe1a8;
+}
+
+.userStat.admin {
+ border: 1px solid rgba(120, 255, 185, 0.3);
+ background: rgba(120, 255, 185, 0.1);
+ color: #c8ffb8;
+}
+
+.userStat.admin svg {
+ color: #c8ffb8;
+}
+
+.dropdownDivider {
+ height: 1px;
+ margin: 8px 4px;
+ background: rgba(255, 255, 255, 0.1);
+}
+
+.dropdownAction {
+ gap: 9px;
+ justify-content: flex-start;
+}
+
+.dropdownAction.danger:hover {
+ background: rgba(255, 90, 120, 0.12);
+ color: #ffd0d8;
}
-.accountChip strong,
.roleBadge {
display: inline-flex;
align-items: center;
@@ -268,10 +405,6 @@ button {
font-weight: 900;
}
-.creditChip {
- color: #ffe1a8;
-}
-
.iconTextButton {
min-height: 34px;
padding: 0 10px;
@@ -1825,14 +1958,6 @@ button {
justify-content: flex-end;
}
- .accountChip span {
- max-width: 120px;
- }
-
- .creditChip {
- display: none;
- }
-
.hero {
grid-template-columns: 1fr;
min-height: auto;
@@ -1937,23 +2062,32 @@ button {
gap: 6px;
}
- .userMenu {
- flex-wrap: wrap;
- }
-
.accountButton,
- .userMenu,
- .languageSwitch {
+ .dropdownTrigger,
+ .userTrigger {
min-height: 38px;
}
- .accountButton {
+ .accountButton,
+ .userMenu {
margin-left: auto;
}
- .languageSwitch button {
- min-width: 36px;
- padding: 0 7px;
+ .dropdownTrigger {
+ min-width: 70px;
+ padding: 0 10px;
+ }
+
+ .userTrigger {
+ padding-right: 9px;
+ }
+
+ .dropdownMenu {
+ max-width: calc(100vw - 24px);
+ }
+
+ .userDropdown {
+ min-width: min(292px, calc(100vw - 24px));
}
.hero {