@omnia/fx-models
Version:
Provide Omnia Fx Models Stuffs.
144 lines (143 loc) • 6.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useThemeMethods = void 0;
const ThemeDefinitionV2_1 = require("./ThemeDefinitionV2");
const TypographyDefinition_1 = require("./TypographyDefinition");
const useThemeMethods = (themedefinition) => {
const colorSchema = (colorSchemaType) => {
if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.primary) {
return themedefinition.primary;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.secondary) {
return themedefinition.secondary;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.accent1) {
return themedefinition.accent1;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.accent2) {
return themedefinition.accent2;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.accent3) {
return themedefinition.accent3;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.background) {
return themedefinition.background;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.neutral) {
return themedefinition.neutral;
}
else if (colorSchemaType === ThemeDefinitionV2_1.ColorSchemaTypes.error) {
return themedefinition.error;
}
return themedefinition.background;
};
const typography = (typographyType) => {
if (typographyType === TypographyDefinition_1.TypographyTypes.h1) {
return themedefinition.typography.h1;
}
else if (typographyType === TypographyDefinition_1.TypographyTypes.h2) {
return themedefinition.typography.h2;
}
else if (typographyType === TypographyDefinition_1.TypographyTypes.h3) {
return themedefinition.typography.h3;
}
else if (typographyType === TypographyDefinition_1.TypographyTypes.caption) {
return themedefinition.typography.caption;
}
else if (typographyType === TypographyDefinition_1.TypographyTypes.link) {
return themedefinition.typography.link;
}
else if (typographyType === TypographyDefinition_1.TypographyTypes.text) {
return themedefinition.typography.text;
}
return themedefinition.typography.text;
};
const color = (colorSchemaType, colorType) => {
const mappedColorSchema = colorSchema(colorSchemaType);
if (colorType === ThemeDefinitionV2_1.ColorTypes.base) {
return mappedColorSchema.base.color;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.baseTone) {
return mappedColorSchema.base.colorToned;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onBase) {
return mappedColorSchema.onBase.color;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onBaseTone) {
return mappedColorSchema.onBase.colorToned;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.container) {
return mappedColorSchema.container.color;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.containerTone) {
return mappedColorSchema.container.colorToned;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onContainer) {
return mappedColorSchema.onContainer.color;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onContainerTone) {
return mappedColorSchema.onContainer.colorToned;
}
return colorType;
};
const colorDefinition = (colorSchemaType, colorType) => {
const mappedColorSchema = colorSchema(colorSchemaType);
if (colorType === ThemeDefinitionV2_1.ColorTypes.base
|| colorType === ThemeDefinitionV2_1.ColorTypes.baseTone) {
return mappedColorSchema.base;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onBase
||
colorType === ThemeDefinitionV2_1.ColorTypes.onBaseTone) {
return mappedColorSchema.onBase;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.container
||
colorType === ThemeDefinitionV2_1.ColorTypes.containerTone) {
return mappedColorSchema.container;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onContainer
||
colorType === ThemeDefinitionV2_1.ColorTypes.onContainerTone) {
return mappedColorSchema.onContainer;
}
return mappedColorSchema.base;
};
const complementaryColorType = (colorType) => {
if (colorType === ThemeDefinitionV2_1.ColorTypes.base
|| colorType === ThemeDefinitionV2_1.ColorTypes.baseTone) {
return ThemeDefinitionV2_1.ColorTypes.onBase;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onBase
|| colorType === ThemeDefinitionV2_1.ColorTypes.onBaseTone) {
return ThemeDefinitionV2_1.ColorTypes.base;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.container
|| colorType === ThemeDefinitionV2_1.ColorTypes.containerTone) {
return ThemeDefinitionV2_1.ColorTypes.onContainer;
}
else if (colorType === ThemeDefinitionV2_1.ColorTypes.onContainer
|| colorType === ThemeDefinitionV2_1.ColorTypes.onContainerTone) {
return ThemeDefinitionV2_1.ColorTypes.container;
}
return colorType;
};
const complementaryColor = (colorSchemaType, colorType) => {
const matchingColorType = complementaryColorType(colorType);
return color(colorSchemaType, matchingColorType);
};
const complementaryColorDefinition = (colorSchemaType, colorType) => {
const matchingColorType = complementaryColorType(colorType);
return colorDefinition(colorSchemaType, matchingColorType);
};
return {
colorSchema,
typography,
color,
colorDefinition,
complementaryColorType,
complementaryColor,
complementaryColorDefinition
};
};
exports.useThemeMethods = useThemeMethods;