Skip to content

Commit 6415cfa

Browse files
committed
refactor: remove nanostores, refactor to load.js and hooks.js
1 parent 2711daf commit 6415cfa

27 files changed

+77
-77
lines changed

cypress/tests/system/api/use-css.js renamed to cypress/tests/system/hooks/use-css.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import {useCss} from '../../../../lib/system/api.js';
3+
import {useCss} from '../../../../lib/system/hooks.js';
44
import {mount} from '../../../utils/index.js';
55

66
const style1 = {

cypress/tests/system/api/use.h.js renamed to cypress/tests/system/hooks/use.h.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {createElement as h} from 'react';
22

3-
import {load, useH} from '../../../../lib/system/api.js';
3+
import {useH} from '../../../../lib/system/hooks.js';
4+
import {load} from '../../../../lib/system/load.js';
45

56
describe('useH', () => {
67
it('should throw if system is not loaded', () => {

cypress/tests/system/config/element-shorthand-props-mapping.js renamed to cypress/tests/system/load/config/element-shorthand-props-mapping.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

3-
import {Element, Icon, Layout, Text} from '../../../../index.js';
4-
import {mount} from '../../../utils/index.js';
3+
import {Element, Icon, Layout, Text} from '../../../../../index.js';
4+
import {mount} from '../../../../utils/index.js';
55

66
describe('config.elementShorthandPropsMapping', () => {
77
it('should not apply shorthand props style if not configured', () => {

cypress/tests/system/config/element-styles.js renamed to cypress/tests/system/load/config/element-styles.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

3-
import {Element, Icon, Layout, Text} from '../../../../index.js';
4-
import {mount} from '../../../utils/index.js';
3+
import {Element, Icon, Layout, Text} from '../../../../../index.js';
4+
import {mount} from '../../../../utils/index.js';
55

66
const system = {
77
config: {

cypress/tests/system/config/enable-atomic-css.js renamed to cypress/tests/system/load/config/enable-atomic-css.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

3-
import {Element} from '../../../../index.js';
4-
import {mount} from '../../../utils/index.js';
3+
import {Element} from '../../../../../index.js';
4+
import {mount} from '../../../../utils/index.js';
55

66
const styles = [
77
{backgroundColor: 'rgb(225, 225, 225)', padding: '42px'},

cypress/tests/system/config/responsive-css-properties.js renamed to cypress/tests/system/load/config/responsive-css-properties.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

3-
import {Element, Icon, Layout, Text} from '../../../../index.js';
4-
import {mount} from '../../../utils/index.js';
3+
import {Element, Icon, Layout, Text} from '../../../../../index.js';
4+
import {mount} from '../../../../utils/index.js';
55

66
const responsiveStyles = {
77
color: ['rgb(255, 0, 0)', 'rgb(0, 255, 0)', 'rgb(0, 0, 255)'],
File renamed without changes.

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export {Text} from './lib/components/text.js';
66

77
// System
88
export {
9-
load,
109
useIcon,
1110
useStyles,
1211
useSystem,
1312
useTheme,
1413
useVariant,
15-
} from './lib/system/api.js';
14+
} from './lib/system/hooks.js';
15+
export {load} from './lib/system/load.js';
1616
export {
1717
createConfig,
1818
createIcons,
@@ -22,4 +22,4 @@ export {
2222
} from './lib/system/create.js';
2323

2424
// Utils
25-
export {merge} from 'uinix-fp';
25+
export {merge, props} from 'uinix-fp';

lib/components/element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCss, useH, useSystem, useVariant} from '../system/api.js';
1+
import {useCss, useH, useSystem, useVariant} from '../system/hooks.js';
22
import {mergeClassNames} from '../util/merge-class-names.js';
33
import {mergeStyles} from '../util/merge-styles.js';
44
import {resolveShorthandProps} from '../util/resolve-shorthand-props.js';

lib/components/icon.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import parse from 'rehype-parse';
33
import {filter} from 'uinix-fp';
44
import unified from 'unified';
55

6-
import {useH, useIcon} from '../system/api.js';
6+
import {useH, useIcon} from '../system/hooks.js';
77
import {mergeStyles} from '../util/merge-styles.js';
88
import {Element} from './element.js';
99

lib/components/text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {filter} from 'uinix-fp';
22

3-
import {useTypographyVariant} from '../system/api.js';
3+
import {useTypographyVariant} from '../system/hooks.js';
44
import {mergeStyles} from '../util/merge-styles.js';
55
import {Element} from './element.js';
66

lib/system/api.js

-59
This file was deleted.

lib/system/hooks.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {props} from 'uinix-fp';
2+
3+
import {getStore} from './load.js';
4+
5+
export {
6+
useCss,
7+
useH,
8+
useIcon,
9+
useStyles,
10+
useSystem,
11+
useTheme,
12+
useTypographyVariant,
13+
useVariant,
14+
};
15+
16+
const useCss = (props) => getStore().css(props);
17+
18+
const useH = () => getStore().h;
19+
20+
const useIcon = (icon) => useSystem().icons[icon];
21+
22+
const useStyles = () => useSystem().styles;
23+
24+
const useSystem = () => getStore().system;
25+
26+
const useTheme = () => useSystem().theme;
27+
28+
const useTypographyVariant = (variant) =>
29+
props(`typography.variants.${variant}`)(useSystem().styles);
30+
31+
const useVariant = (variant) =>
32+
props(`variants.${variant}`)(useSystem().styles);

lib/system/load.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {combineRules} from 'fela';
2+
import {render} from 'fela-dom';
3+
4+
import {createRenderer} from '../renderer/create-renderer.js';
5+
import {createSystem} from './create.js';
6+
7+
export {load, getStore};
8+
9+
let store;
10+
11+
const getStore = () => store;
12+
13+
const load = (h, providedSystem) => {
14+
const system = createSystem(providedSystem);
15+
const renderer = createRenderer(system);
16+
const css =
17+
(props = {}) =>
18+
(...rules) =>
19+
renderer.renderRule(combineRules(...rules), {
20+
...props,
21+
theme: system.theme,
22+
});
23+
24+
render(renderer);
25+
26+
store = {css, h, system};
27+
};

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"fela-plugin-responsive-value": "^11.6.1",
3636
"fela-preset-web": "^11.6.1",
3737
"hast-to-hyperscript": "^10.0.0",
38-
"nanostores": "^0.3.3",
3938
"rehype-parse": "^7.0.1",
4039
"uinix-theme": "^0.2.2",
4140
"unified": "^9.2.1"
@@ -67,7 +66,7 @@
6766
"solid-js": "^0.26.5",
6867
"tape": "^5.2.2",
6968
"type-coverage": "^2.17.5",
70-
"typescript": "^4.3.2",
69+
"typescript": "^4.3.4",
7170
"uinix-scripts": "^0.1.2",
7271
"webpack": "^5.39.1",
7372
"webpack-dev-server": "^3.11.2",

0 commit comments

Comments
 (0)