Skip to content

Commit 0836978

Browse files
committed
!refactor: remove unvaluable create* utility
1 parent c15fddc commit 0836978

File tree

9 files changed

+78
-248
lines changed

9 files changed

+78
-248
lines changed

cypress/tests/system/create/create-config.js

-15
This file was deleted.

cypress/tests/system/create/create-icons.js

-13
This file was deleted.

cypress/tests/system/create/create-styles.js

-17
This file was deleted.

cypress/tests/system/create/create-theme.js

-18
This file was deleted.
+1-45
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
1-
import {mount} from '@cypress/react';
2-
import React, {createElement as h} from 'react';
3-
import themeSpec from 'uinix-theme-spec';
4-
5-
import {createTheme, load, useTheme} from '../../../../index.js';
6-
import system from '../../../fixtures/test-system.js';
7-
8-
function CustomElement({path = ''}) {
9-
const theme = useTheme(path);
10-
cy.wrap(theme).as('theme');
11-
return <pre>{JSON.stringify(theme, null, 2)}</pre>;
12-
}
1+
import {useTheme} from '../../../../index.js';
132

143
describe('useTheme', () => {
154
it('should throw if system is not loaded', () => {
165
expect(() => useTheme()).to.throw();
176
});
18-
19-
it('should retrieve the theme from the system', () => {
20-
load({h, system});
21-
mount(<CustomElement />);
22-
cy.get('@theme').should('deep.equal', createTheme(system.theme, themeSpec));
23-
});
24-
25-
it.skip('should retrieve the theme values given a property path', () => {
26-
load({h, system});
27-
mount(<CustomElement path="keyframes.flicker" />);
28-
cy.get('@theme').should(
29-
'deep.equal',
30-
createTheme(system.theme).keyframes.flicker,
31-
);
32-
33-
mount(<CustomElement path="colors.palette" />);
34-
cy.get('@theme').should(
35-
'deep.equal',
36-
createTheme(system.theme).colors.palette,
37-
);
38-
39-
mount(<CustomElement path="colors.palette.red1" />);
40-
cy.get('@theme').should(
41-
'deep.equal',
42-
createTheme(system.theme).colors.palette.red1,
43-
);
44-
45-
mount(<CustomElement path="spacings.4" />);
46-
cy.get('@theme').should(
47-
'deep.equal',
48-
createTheme(system.theme).spacings[4],
49-
);
50-
});
517
});

index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ export {
1313
useVariant,
1414
} from './lib/system/hooks.js';
1515
export {load} from './lib/system/load.js';
16-
export {
17-
createConfig,
18-
createIcons,
19-
createStyles,
20-
createSystem,
21-
createTheme,
22-
} from './lib/system/create.js';
16+
export {createSystem} from './lib/system/create.js';
2317

2418
// Utils
2519
export {merge} from 'uinix-fp';

lib/system/create.js

+12-28
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
import {merge} from 'uinix-fp';
22
import {createTheme} from 'uinix-theme';
33

4-
export {createConfig, createIcons, createStyles, createSystem};
5-
6-
const createConfig = (config = {}) =>
7-
merge({
8-
elementShorthandPropsMapping: {},
9-
elementStyles: [],
10-
enableAtomicCss: false,
11-
enableCssVariables: false,
12-
namespace: null,
13-
responsiveBreakpoints: [],
14-
responsiveCssProperties: [],
15-
})(config);
16-
17-
const createIcons = (icons = {}) => icons;
18-
19-
const createStyles = (styles = {}) =>
20-
merge({
4+
const defaultSystem = {
5+
icons: {},
6+
styles: {
217
rules: {},
228
static: {},
239
variants: {},
24-
})(styles);
25-
26-
const createSystem = (system = {}) => {
27-
const {icons, styles, theme, themeSpec = {}} = system;
28-
return {
29-
icons: createIcons(icons),
30-
styles: createStyles(styles),
31-
theme: createTheme(theme, themeSpec),
32-
themeSpec,
33-
};
10+
},
11+
theme: {},
12+
themeSpec: {},
3413
};
3514

36-
export {createTheme} from 'uinix-theme';
15+
export const createSystem = (system = defaultSystem) => {
16+
return merge(defaultSystem)({
17+
...system,
18+
theme: createTheme(system.theme, system.themeSpec),
19+
});
20+
};

lib/system/load.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1+
import {merge} from 'uinix-fp';
12
import {combineStyles, createThemeRenderer} from 'uinix-theme';
23

3-
import {createConfig, createSystem} from './create.js';
4+
import {createSystem} from './create.js';
45

56
export {load, getStore};
67

78
let store;
89

910
const getStore = () => store;
1011

11-
const load = ({config: providedConfig, h, system: providedSystem}) => {
12-
const config = createConfig(providedConfig);
13-
const system = createSystem(providedSystem);
12+
const defaultConfig = {
13+
elementShorthandPropsMapping: {},
14+
elementStyles: [],
15+
enableAtomicCss: false,
16+
enableCssVariables: false,
17+
namespace: null,
18+
responsiveBreakpoints: [],
19+
responsiveCssProperties: [],
20+
};
21+
22+
const load = ({
23+
config: initialConfig = defaultConfig,
24+
h,
25+
system: initialSystem,
26+
}) => {
27+
const config = merge(defaultConfig)(initialConfig);
28+
const system = createSystem(initialSystem);
1429

1530
// TODO: refactor API entry points
1631
const options = {

0 commit comments

Comments
 (0)