Skip to content

Commit

Permalink
fix: colors schemas typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Erta committed Nov 22, 2022
1 parent 979bff1 commit 08142ba
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 15 deletions.
5 changes: 0 additions & 5 deletions packages/core/src/parsers/colors/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export function parseColor({
scale: 'colors',
});
}
return baseParser({
value,
property,
scale: 'colors',
});
}

return baseParser({
Expand Down
13 changes: 9 additions & 4 deletions packages/core/tests/parsers/colors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Theme } from "@morfeo/spec"
import { parsers, theme } from '../../src';

const THEME = {
Expand All @@ -8,12 +9,12 @@ const THEME = {
foreground: '#000',
},
colorSchemas: {
dark: {
default: {
background: 'secondary',
foreground: 'primary',
},
},
} as const;
} as any as Theme;

describe('colors', () => {
beforeAll(() => {
Expand All @@ -31,25 +32,29 @@ describe('colors', () => {
test('should resolve color based on colorSchema', () => {
const result = parsers.resolve({
bg: 'background',
// @ts-expect-error
color: 'foreground',
colorSchema: 'dark',
colorSchema: 'default',
});
expect(result).toEqual({ backgroundColor: '#000', color: '#e3e3e3' });
});

test("should return the original value if colorSchema doesn't exist", () => {
const result = parsers.resolve({
bg: 'background',
// @ts-expect-error
color: 'foreground',
// @ts-expect-error
colorSchema: 'unexistingSchema',
});
expect(result).toEqual({ backgroundColor: '#e3e3e3', color: '#000' });
});

test("should return the original value if the input value doesn't exist on color schema", () => {
const result = parsers.resolve({
// @ts-expect-error
bg: 'unexistingValue',
colorSchema: 'dark',
colorSchema: 'default',
});
expect(result).toEqual({ backgroundColor: 'unexistingValue' });
});
Expand Down
5 changes: 5 additions & 0 deletions packages/preset-default/src/base/colorSchemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ColorSchemas } from '@morfeo/spec';

export const colorSchemas: ColorSchemas = {
default: {},
};
5 changes: 2 additions & 3 deletions packages/preset-default/src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { spacings } from './spacings';
import { transitions } from './transitions';
import { zIndices } from './zIndices';
import { darkColors, lightColors } from './colors';
import { colorSchemas } from './colorSchemas';
import { components, darkComponents } from './components';

const fonts = {
Expand All @@ -42,10 +43,8 @@ export const baseTheme: Omit<Theme, 'colors'> = {
borderWidths,
borderStyles,
mediaQueries: {},
colorSchemas,
letterSpacings,
colorSchemas: {
default: {},
},
};

export const darkTheme = {
Expand Down
3 changes: 3 additions & 0 deletions packages/spec/src/allProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
transitionsMap,
borderWidthsMap,
borderStylesMap,
colorSchemasMap,
letterSpacingsMap,
} from './properties';
import { createPropertiesMap } from './createPropertiesMap';
Expand Down Expand Up @@ -63,6 +64,7 @@ export const transitionsProperties = createPropertiesMap(
transitionsMap,
'transitions',
);
export const colorSchemasProperties = createPropertiesMap(colorSchemasMap, 'colorSchemas');

export const allProperties = {
...fontProperties,
Expand All @@ -81,5 +83,6 @@ export const allProperties = {
...transitionsProperties,
...borderWidthsProperties,
...borderStylesProperties,
...colorSchemasProperties,
...letterSpacingProperties,
};
4 changes: 4 additions & 0 deletions packages/spec/src/properties/colorSchemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const colorSchemasMap = [
'schema',
'colorSchema',
] as const;
1 change: 0 additions & 1 deletion packages/spec/src/properties/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const colorsMap = [
'color',
'stroke',
'caretColor',
'colorSchema',
'borderColor',
'outlineColor',
'borderTopColor',
Expand Down
1 change: 1 addition & 0 deletions packages/spec/src/properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './gradients';
export * from './opacities';
export * from './components';
export * from './transitions';
export * from './colorSchemas';
2 changes: 1 addition & 1 deletion packages/spec/src/types/colorSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Color } from './colors';

export interface ColorSchemas {
default: {
[key in Color]: Color;
[key in Color]?: Color;
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/spec/src/types/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export type BaseTheme = {
borderWidths: BorderWidths;
mediaQueries: MediaQueries;
borderStyles: BorderStyles;
letterSpacings: LetterSpacings;
colorSchemas: ColorSchemas;
letterSpacings: LetterSpacings;
};

export interface Theme extends BaseTheme {
Expand Down

0 comments on commit 08142ba

Please sign in to comment.