From 2c47369772a01a95d0625ffb755d2c638d934144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Mon, 10 Feb 2025 09:51:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90M2=20Scheme?= =?UTF-8?q?=E7=9A=84=E9=A2=84=E8=A7=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page-components/scheme/M2Scheme.tsx | 8 +- .../scheme/m2-scheme/Preview.module.css | 41 ++++++++ .../scheme/m2-scheme/Preview.tsx | 94 +++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/page-components/scheme/m2-scheme/Preview.module.css create mode 100644 src/page-components/scheme/m2-scheme/Preview.tsx diff --git a/src/page-components/scheme/M2Scheme.tsx b/src/page-components/scheme/M2Scheme.tsx index fd2521c..a18d2c3 100644 --- a/src/page-components/scheme/M2Scheme.tsx +++ b/src/page-components/scheme/M2Scheme.tsx @@ -2,6 +2,8 @@ import { isEqual, isNil } from 'lodash-es'; import { useState } from 'react'; import { Tab } from '../../components/Tab'; import { SchemeExport } from './Export'; +import { M2SchemeBuilder } from './m2-scheme/Builder'; +import { M2SchemePreview } from './m2-scheme/Preview'; const tabOptions = [ { title: 'Overview', id: 'overview' }, @@ -21,8 +23,10 @@ export function M2Scheme({ scheme }: M3SchemeProps) { return ( <> - {isEqual(activeTab, 'overview') &&
Preview
} - {isEqual(activeTab, 'builder') &&
Builder
} + {isEqual(activeTab, 'overview') && } + {isEqual(activeTab, 'builder') && ( + setActiveTab('overview')} /> + )} {isEqual(activeTab, 'export') && } ); diff --git a/src/page-components/scheme/m2-scheme/Preview.module.css b/src/page-components/scheme/m2-scheme/Preview.module.css new file mode 100644 index 0000000..157e54f --- /dev/null +++ b/src/page-components/scheme/m2-scheme/Preview.module.css @@ -0,0 +1,41 @@ +@layer pages { + .preview_layout { + padding: var(--spacing-s) var(--spacing-m); + width: 100%; + display: flex; + flex-direction: column; + align-items: stretch; + gap: var(--spacing-m); + } + .preview_block { + width: inherit; + padding: var(--spacing-m) var(--spacing-m); + display: flex; + flex-direction: column; + gap: var(--spacing-m); + font-size: var(--font-size-s); + line-height: 1.1em; + h4 { + font-size: var(--font-size-m); + font-weight: bold; + line-height: 1.7em; + } + } + .horizontal_set { + display: flex; + flex-direction: row; + justify-content: space-evenly; + align-items: stretch; + gap: 0; + } + .color_block { + padding: var(--spacing-s) var(--spacing-xs); + flex: 1; + display: flex; + flex-direction: column; + gap: var(--spacing-xs); + .wacg { + font-size: var(--font-size-xxs); + } + } +} diff --git a/src/page-components/scheme/m2-scheme/Preview.tsx b/src/page-components/scheme/m2-scheme/Preview.tsx new file mode 100644 index 0000000..c6c05a4 --- /dev/null +++ b/src/page-components/scheme/m2-scheme/Preview.tsx @@ -0,0 +1,94 @@ +import { useMemo } from 'react'; +import { useColorFunction } from '../../../ColorFunctionContext'; +import { ScrollArea } from '../../../components/ScrollArea'; +import { Baseline, ColorSet, MaterialDesign2SchemeStorage } from '../../../material-2-scheme'; +import { SchemeContent } from '../../../models'; +import styles from './Preview.module.css'; + +type M2SchemeFunctionColorProps = { + title: string; + color: ColorSet; +}; + +function M2SchemeFunctionColor({ title, color }: M2SchemeFunctionColorProps) { + const { colorFn } = useColorFunction(); + const rootWacgRatio = useMemo(() => { + try { + return colorFn?.wacg_relative_contrast(color.on, color.root) ?? null; + } catch (e) { + console.error('[calc root wacg]', e); + } + return null; + }, [colorFn, color.on, color.root]); + const variantWacgRatio = useMemo(() => { + try { + return colorFn?.wacg_relative_contrast(color.on, color.variant) ?? null; + } catch (e) { + console.error('[calc variant wacg]', e); + } + return null; + }, [colorFn, color.on, color.variant]); + + return ( +
+
+ {title} + WACG: {rootWacgRatio?.toFixed(2)} +
+
+ {title} Variant + WACG: {variantWacgRatio?.toFixed(2)} +
+
+ On {title} +
+
+ ); +} + +type PreviewBlockProps = { + title: string; + baseline: Baseline; +}; + +function PreviewBlock({ title, baseline }: PreviewBlockProps) { + return ( +
+

{title} Scheme

+ + + + + + {Object.entries(baseline.custom_colors).map(([name, set], index) => ( + + ))} +
+ ); +} + +type M2SchemePreviewProps = { + scheme: SchemeContent; +}; + +export function M2SchemePreview({ scheme }: M2SchemePreviewProps) { + return ( + +
+ + +
+
+ ); +}