Skip to content

Commit

Permalink
fix: cli handling of shadows fixed and shadow parser improved
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed Oct 10, 2021
1 parent cb93138 commit 7cc1a0a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ export default class Build extends Command {
configPath: config,
});

themeKeys.forEach(currentTheme => {
for (const currentTheme of themeKeys) {
const localTheme = require(path.join(
process.cwd(),
allThemes[currentTheme],
));

theme.reset();
theme.set(localTheme.default ? localTheme.default : localTheme);
buildTheme({ ...buildConfiguration, name: currentTheme });
});
}

console.clear();

Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/constants/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export const SLICES_TO_BE_PARSED: SliceToBeParsed[] = [
styleProp: 'bgGradient',
property: 'background',
},
{
name: 'borders',
styleProp: 'border',
property: 'border',
},
];
14 changes: 7 additions & 7 deletions packages/core/src/parsers/shadows.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ParserParams, SliceParsers } from '../types';
import {
BorderWidth,
Opacity,
Radius,
Shadow,
ShadowProperty,
shadowsProperties,
Size,
Spacing,
} from '@morfeo/spec';
import { theme } from '../theme';

Expand All @@ -24,7 +24,9 @@ function firstValid(...params: (string | number | undefined)[]) {
export function shadows({ value, property }: ParserParams<ShadowProperty>) {
const config = theme.getValue('shadows', value as Shadow);
if (!config) {
return {};
return {
[property]: value,
};
}

const color = config.color
Expand All @@ -33,13 +35,11 @@ export function shadows({ value, property }: ParserParams<ShadowProperty>) {

const { width, height } = config.offset || { width: 0, height: 0 };
const parsedWidth = firstValid(
theme.getValue('spacings', width as Spacing),
theme.getValue('sizes', width as Size),
theme.getValue('borderWidths', width as BorderWidth),
width,
);
const parsedHeight = firstValid(
theme.getValue('spacings', height as Spacing),
theme.getValue('sizes', height as Size),
theme.getValue('borderWidths', height as BorderWidth),
height,
);
const radius = firstValid(
Expand Down
13 changes: 7 additions & 6 deletions packages/core/tests/parsers/shadows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ const THEME: Theme = {
primary: 'white',
secondary: 'white',
},
spacings: {
borderWidths: {
s: '10px',
m: '20px',
},
sizes: {
l: '30px',
xl: '40px',
},
Expand Down Expand Up @@ -79,9 +77,12 @@ describe('shadows', () => {
});
});

test('should return an empty object if the shadow is not found', () => {
const result = shadows({ property: 'boxShadow', value: 'none' });
expect(result).toEqual({});
test('should return the passed value if the shadow is not found', () => {
const result = shadows({
property: 'boxShadow',
value: 'invalid box shadow' as any,
});
expect(result).toEqual({ boxShadow: 'invalid box shadow' });
});

test('should use custom colors if they are not inside the theme', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/spec/src/types/borders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type BorderConfig = {
};

export interface Borders {
none: BorderConfig;
primary: BorderConfig;
secondary: BorderConfig;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/spec/src/types/shadows.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { shadowsMap } from '../properties';
import { BorderWidth } from './borders';
import { Color } from './colors';
import { Opacity } from './opacities';
import { Radius } from './radii';
import { Size } from './sizes';

export interface ShadowConfig {
color?: Color;
offset?: {
width: Size;
height: Size;
width: BorderWidth;
height: BorderWidth;
};
radius?: Radius;
opacity?: Opacity;
Expand Down

0 comments on commit 7cc1a0a

Please sign in to comment.