101 lines
4.7 KiB
TypeScript
101 lines
4.7 KiB
TypeScript
import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs';
|
|
import { needsLegacyComponentStyles } from './browserStyleCompatibility';
|
|
import React, { useLayoutEffect, useState } from 'react';
|
|
import ReactDOM from 'react-dom/client';
|
|
import { App, ConfigProvider, theme as antdTheme } from 'antd';
|
|
import zhCN from 'antd/locale/zh_CN';
|
|
import QualityWorkspace from './QualityWorkspace';
|
|
import { getStoredWorkspaceThemeId, getWorkspaceTheme, workspaceThemeStorageKey, type WorkspaceThemeId } from './ui-themes';
|
|
import './styles.css';
|
|
import './dark-theme.css';
|
|
import './quality-table.css';
|
|
import './workspace-finish.css';
|
|
|
|
const legacyComponentStyles = needsLegacyComponentStyles();
|
|
const legacyStyleTransformers = [legacyLogicalPropertiesTransformer];
|
|
|
|
function QualityCenterApp() {
|
|
const [themeId, setThemeId] = useState<WorkspaceThemeId>(getStoredWorkspaceThemeId);
|
|
const appearance = getWorkspaceTheme(themeId);
|
|
const dark = appearance.id === 'dark';
|
|
|
|
useLayoutEffect(() => {
|
|
const root = document.documentElement;
|
|
root.dataset.workspaceTheme = appearance.id;
|
|
root.style.setProperty('--ink', appearance.ink);
|
|
root.style.setProperty('--muted-ink', appearance.secondaryInk);
|
|
root.style.setProperty('--blue', appearance.primary);
|
|
root.style.setProperty('--blue-dark', appearance.primary);
|
|
root.style.setProperty('--blue-soft', appearance.soft);
|
|
root.style.setProperty('--blue-muted', appearance.muted);
|
|
root.style.setProperty('--background', appearance.background);
|
|
root.style.setProperty('--hover', appearance.hover);
|
|
root.style.setProperty('--metric-grid', appearance.metricGrid);
|
|
root.style.setProperty('--metric-grid-head', appearance.metricGridHead);
|
|
root.style.setProperty('--sidebar-surface', dark ? '#111829' : 'color-mix(in srgb, var(--background) 48%, var(--surface))');
|
|
root.style.setProperty('--surface', appearance.surface);
|
|
root.style.setProperty('--surface-subtle', appearance.subtle);
|
|
root.style.setProperty('--surface-elevated', appearance.elevated);
|
|
root.style.setProperty('--line', appearance.line);
|
|
root.style.setProperty('--teal', appearance.teal);
|
|
try { window.localStorage.setItem(workspaceThemeStorageKey, appearance.id); } catch { /* local preference is optional */ }
|
|
}, [appearance]);
|
|
|
|
return (
|
|
<StyleProvider hashPriority={legacyComponentStyles ? 'high' : undefined} transformers={legacyComponentStyles ? legacyStyleTransformers : undefined}>
|
|
<ConfigProvider
|
|
locale={zhCN}
|
|
theme={{
|
|
algorithm: dark ? antdTheme.darkAlgorithm : antdTheme.defaultAlgorithm,
|
|
token: {
|
|
colorPrimary: appearance.primary,
|
|
colorInfo: appearance.primary,
|
|
colorBgBase: appearance.background,
|
|
colorBgLayout: appearance.background,
|
|
colorBgContainer: appearance.surface,
|
|
// Ant Design 6 renders modal panels on `.ant-modal-container` and
|
|
// derives their background from this token. Keep it explicit in
|
|
// light themes so overlays never inherit a transparent default.
|
|
colorBgElevated: appearance.elevated,
|
|
colorText: appearance.ink,
|
|
colorTextSecondary: appearance.secondaryInk,
|
|
colorTextPlaceholder: appearance.placeholder,
|
|
colorBorder: appearance.line,
|
|
colorBorderSecondary: appearance.line,
|
|
borderRadius: 4,
|
|
fontFamily: '"PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
controlHeight: 32,
|
|
fontSize: 13,
|
|
fontSizeSM: 12,
|
|
fontSizeLG: 14,
|
|
},
|
|
components: {
|
|
Button: {
|
|
borderRadius: 4, contentFontSize: 12, contentFontSizeSM: 12, contentFontSizeLG: 13,
|
|
primaryColor: dark ? '#080F1E' : '#FFFFFF',
|
|
...(appearance.id === 'bright' ? { colorPrimary: '#0078D4', colorPrimaryHover: '#006ABD', colorPrimaryActive: '#005EA8' } : {}),
|
|
},
|
|
Input: { borderRadius: 4, inputFontSize: 12, inputFontSizeSM: 12, inputFontSizeLG: 13 },
|
|
Select: { borderRadius: 4, fontSize: 12 },
|
|
Form: { labelFontSize: 12 },
|
|
Segmented: { fontSize: 12 },
|
|
Table: { cellFontSize: 12, cellFontSizeMD: 12, cellFontSizeSM: 12, headerBg: appearance.subtle, rowHoverBg: appearance.hover },
|
|
Modal: { borderRadiusLG: 6 },
|
|
Drawer: { borderRadiusLG: 0 },
|
|
},
|
|
}}
|
|
>
|
|
<App>
|
|
<QualityWorkspace appearance={appearance} onAppearanceChange={setThemeId} />
|
|
</App>
|
|
</ConfigProvider>
|
|
</StyleProvider>
|
|
);
|
|
}
|
|
|
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
<React.StrictMode>
|
|
<QualityCenterApp />
|
|
</React.StrictMode>,
|
|
);
|