🎨 style(sidebar): unify highlight color & assign unique icon for Models
• Removed obsolete `sidebarIconColors` map and `getItemColor` util from
SiderBar/render; all selected states now use the single CSS variable
`--semi-color-primary` for both text and icons.
• Simplified `getLucideIcon`:
– Added `Package` to Lucide imports.
– Switched “models” case to `<Package />`, avoiding duplication with
the Layers glyph.
– Replaced per-key color logic with `iconColor` derived from the new
uniform highlight color.
• Stripped any unused imports / dead code paths after the refactor.
• Lint passes; sidebar hover/focus behavior unchanged while visual
consistency is improved.
This commit is contained in:
@@ -20,7 +20,7 @@ For commercial licensing, please contact support@quantumnous.com
|
|||||||
import React, { useEffect, useMemo, useState } from 'react';
|
import React, { useEffect, useMemo, useState } from 'react';
|
||||||
import { Link, useLocation } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { getLucideIcon, sidebarIconColors } from '../../helpers/render.js';
|
import { getLucideIcon } from '../../helpers/render.js';
|
||||||
import { ChevronLeft } from 'lucide-react';
|
import { ChevronLeft } from 'lucide-react';
|
||||||
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed.js';
|
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed.js';
|
||||||
import {
|
import {
|
||||||
@@ -251,28 +251,8 @@ const SiderBar = ({ onNavigate = () => { } }) => {
|
|||||||
}
|
}
|
||||||
}, [collapsed]);
|
}, [collapsed]);
|
||||||
|
|
||||||
// 获取菜单项对应的颜色
|
// 选中高亮颜色(统一)
|
||||||
const getItemColor = (itemKey) => {
|
const SELECTED_COLOR = 'var(--semi-color-primary)';
|
||||||
switch (itemKey) {
|
|
||||||
case 'detail': return sidebarIconColors.dashboard;
|
|
||||||
case 'playground': return sidebarIconColors.terminal;
|
|
||||||
case 'chat': return sidebarIconColors.message;
|
|
||||||
case 'token': return sidebarIconColors.key;
|
|
||||||
case 'log': return sidebarIconColors.chart;
|
|
||||||
case 'midjourney': return sidebarIconColors.image;
|
|
||||||
case 'task': return sidebarIconColors.check;
|
|
||||||
case 'topup': return sidebarIconColors.credit;
|
|
||||||
case 'channel': return sidebarIconColors.layers;
|
|
||||||
case 'redemption': return sidebarIconColors.gift;
|
|
||||||
case 'user':
|
|
||||||
case 'personal': return sidebarIconColors.user;
|
|
||||||
case 'setting': return sidebarIconColors.settings;
|
|
||||||
default:
|
|
||||||
// 处理聊天项
|
|
||||||
if (itemKey && itemKey.startsWith('chat')) return sidebarIconColors.message;
|
|
||||||
return 'currentColor';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 渲染自定义菜单项
|
// 渲染自定义菜单项
|
||||||
const renderNavItem = (item) => {
|
const renderNavItem = (item) => {
|
||||||
@@ -280,7 +260,7 @@ const SiderBar = ({ onNavigate = () => { } }) => {
|
|||||||
if (item.className === 'tableHiddle') return null;
|
if (item.className === 'tableHiddle') return null;
|
||||||
|
|
||||||
const isSelected = selectedKeys.includes(item.itemKey);
|
const isSelected = selectedKeys.includes(item.itemKey);
|
||||||
const textColor = isSelected ? getItemColor(item.itemKey) : 'inherit';
|
const textColor = isSelected ? SELECTED_COLOR : 'inherit';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Nav.Item
|
<Nav.Item
|
||||||
@@ -307,7 +287,7 @@ const SiderBar = ({ onNavigate = () => { } }) => {
|
|||||||
const renderSubItem = (item) => {
|
const renderSubItem = (item) => {
|
||||||
if (item.items && item.items.length > 0) {
|
if (item.items && item.items.length > 0) {
|
||||||
const isSelected = selectedKeys.includes(item.itemKey);
|
const isSelected = selectedKeys.includes(item.itemKey);
|
||||||
const textColor = isSelected ? getItemColor(item.itemKey) : 'inherit';
|
const textColor = isSelected ? SELECTED_COLOR : 'inherit';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Nav.Sub
|
<Nav.Sub
|
||||||
@@ -328,7 +308,7 @@ const SiderBar = ({ onNavigate = () => { } }) => {
|
|||||||
>
|
>
|
||||||
{item.items.map((subItem) => {
|
{item.items.map((subItem) => {
|
||||||
const isSubSelected = selectedKeys.includes(subItem.itemKey);
|
const isSubSelected = selectedKeys.includes(subItem.itemKey);
|
||||||
const subTextColor = isSubSelected ? getItemColor(subItem.itemKey) : 'inherit';
|
const subTextColor = isSubSelected ? SELECTED_COLOR : 'inherit';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Nav.Item
|
<Nav.Item
|
||||||
|
|||||||
@@ -70,29 +70,15 @@ import {
|
|||||||
User,
|
User,
|
||||||
Settings,
|
Settings,
|
||||||
CircleUser,
|
CircleUser,
|
||||||
|
Package,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
|
||||||
// 侧边栏图标颜色映射
|
|
||||||
export const sidebarIconColors = {
|
|
||||||
dashboard: '#10B981', // 绿色
|
|
||||||
terminal: '#10B981', // 绿色
|
|
||||||
message: '#06B6D4', // 青色
|
|
||||||
key: '#3B82F6', // 蓝色
|
|
||||||
chart: '#F59E0B', // 琥珀色
|
|
||||||
image: '#EC4899', // 粉色
|
|
||||||
check: '#F59E0B', // 琥珀色
|
|
||||||
credit: '#F97316', // 橙色
|
|
||||||
layers: '#EF4444', // 红色
|
|
||||||
gift: '#F43F5E', // 玫红色
|
|
||||||
user: '#10B981', // 绿色
|
|
||||||
settings: '#F97316', // 橙色
|
|
||||||
models: '#10B981', // 绿色
|
|
||||||
};
|
|
||||||
|
|
||||||
// 获取侧边栏Lucide图标组件
|
// 获取侧边栏Lucide图标组件
|
||||||
export function getLucideIcon(key, selected = false) {
|
export function getLucideIcon(key, selected = false) {
|
||||||
const size = 16;
|
const size = 16;
|
||||||
const strokeWidth = 2;
|
const strokeWidth = 2;
|
||||||
|
const SELECTED_COLOR = 'var(--semi-color-primary)';
|
||||||
|
const iconColor = selected ? SELECTED_COLOR : 'currentColor';
|
||||||
const commonProps = {
|
const commonProps = {
|
||||||
size,
|
size,
|
||||||
strokeWidth,
|
strokeWidth,
|
||||||
@@ -105,70 +91,70 @@ export function getLucideIcon(key, selected = false) {
|
|||||||
return (
|
return (
|
||||||
<LayoutDashboard
|
<LayoutDashboard
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.dashboard : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'playground':
|
case 'playground':
|
||||||
return (
|
return (
|
||||||
<TerminalSquare
|
<TerminalSquare
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.terminal : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'chat':
|
case 'chat':
|
||||||
return (
|
return (
|
||||||
<MessageSquare
|
<MessageSquare
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.message : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'token':
|
case 'token':
|
||||||
return (
|
return (
|
||||||
<Key
|
<Key
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.key : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'log':
|
case 'log':
|
||||||
return (
|
return (
|
||||||
<BarChart3
|
<BarChart3
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.chart : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'midjourney':
|
case 'midjourney':
|
||||||
return (
|
return (
|
||||||
<ImageIcon
|
<ImageIcon
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.image : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'task':
|
case 'task':
|
||||||
return (
|
return (
|
||||||
<CheckSquare
|
<CheckSquare
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.check : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'topup':
|
case 'topup':
|
||||||
return (
|
return (
|
||||||
<CreditCard
|
<CreditCard
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.credit : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'channel':
|
case 'channel':
|
||||||
return (
|
return (
|
||||||
<Layers
|
<Layers
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.layers : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'redemption':
|
case 'redemption':
|
||||||
return (
|
return (
|
||||||
<Gift
|
<Gift
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.gift : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'user':
|
case 'user':
|
||||||
@@ -176,28 +162,28 @@ export function getLucideIcon(key, selected = false) {
|
|||||||
return (
|
return (
|
||||||
<User
|
<User
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.user : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'models':
|
case 'models':
|
||||||
return (
|
return (
|
||||||
<Layers
|
<Package
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.models : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'setting':
|
case 'setting':
|
||||||
return (
|
return (
|
||||||
<Settings
|
<Settings
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.settings : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<CircleUser
|
<CircleUser
|
||||||
{...commonProps}
|
{...commonProps}
|
||||||
color={selected ? sidebarIconColors.user : 'currentColor'}
|
color={iconColor}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user