重构对于Scheme类型的展示。

This commit is contained in:
徐涛
2025-01-24 10:48:36 +08:00
parent b2357811b6
commit 2b17a5de0f
7 changed files with 88 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
import { find, isNil } from 'lodash-es';
import { MaterialDesign2SchemeStorage } from './material-2-scheme';
import { MaterialDesign3SchemeStorage } from './material-3-scheme';
import { QSchemeStorage } from './q-scheme';
@@ -29,14 +30,28 @@ export type ColorDescription = {
export type SchemeType = 'q_scheme' | 'swatch_scheme' | 'material_2' | 'material_3';
export type SchemeTypeOption = {
label: string;
short: string;
value: SchemeType;
};
export const SchemeTypeOptions: SchemeTypeOption[] = [
{ label: 'Q Scheme', value: 'q_scheme' },
{ label: 'Swatch Scheme', value: 'swatch_scheme' },
{ label: 'Material Design 2 Scheme', value: 'material_2' },
{ label: 'Material Design 3 Scheme', value: 'material_3' },
{ label: 'Q Scheme', short: 'Q', value: 'q_scheme' },
{ label: 'Swatch Scheme', short: 'Swatch', value: 'swatch_scheme' },
{ label: 'Material Design 2 Scheme', short: 'M2', value: 'material_2' },
{ label: 'Material Design 3 Scheme', short: 'M3', value: 'material_3' },
];
export function schemeType(
value?: SchemeTypeOption['value'] | null,
short?: boolean,
): string | null {
const useShort = short ?? false;
const foundType = find(SchemeTypeOptions, { value }) as SchemeTypeOption | undefined;
if (isNil(foundType)) {
return null;
}
return useShort ? foundType.short : foundType.label;
}
export type SchemeContent<SchemeStorage> = {
id: string;
name: string;