Skip to content

Commit

Permalink
add dev enviroment warning for css property (#3)
Browse files Browse the repository at this point in the history

* feat: add warning when css immutable property is wrong
  • Loading branch information
coding-jimmy committed Jul 3, 2022
1 parent f8b7890 commit edd447b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 20 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
"@types/react-dom": "17.0.2"
},
"devDependencies": {
"vite": "^2.9.12",
"zx": "^7.0.0",
"jest": "^27.5.1",
"jest-extended": "^2.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.2",
"@babel/core": "^7.17.2",
"@c3/cli": "^1.0.100",
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
"@c3/cli": "workspace:^1.0.107",
"@changesets/cli": "^2.22.0",
"@jest/types": "^28.1.1",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-typescript": "^8.3.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.178",
"@types/node": "^17.0.13",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.2",
"@types/styled-components": "^5.1.21",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
Expand All @@ -41,11 +37,15 @@
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.3.0",
"husky": ">=6",
"jest": "^27.5.1",
"jest-extended": "^2.0.0",
"js-beautify": "^1.14.0",
"lint-staged": ">=10",
"prettier": "2.6.1",
"tslib": "^2.3.1",
"typescript": "^4.5.5"
"typescript": "^4.5.5",
"vite": "^2.9.12",
"zx": "^7.0.0"
},
"scripts": {
"build-storybook": "build-storybook",
Expand Down
3 changes: 1 addition & 2 deletions packages/stitches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"types/*.d.ts"
],
"publishConfig": {
"access": "public",
"main": "dist/stitches.umd.js"
"access": "public"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions packages/stitches/src/createStitches.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export const createStitches = config => {
config: Object.assign(instance.config, config),
css: instance.css,
});
window.stitch = instance;
window.config = config;
return instance;
};
14 changes: 12 additions & 2 deletions packages/stitches/src/styled.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { internal, createMemo, isVairants as isVariants } from './utils';
import { isEqual } from 'lodash-es';
import { isUndefined } from '@c3/utils';
import { isUndefined, __DEV__ } from '@c3/utils';

const createCssFunctionMap = createMemo();

Expand Down Expand Up @@ -59,6 +59,7 @@ export const createStyledFunction = ({ config, css }) =>
styledComponent.toString = toString;
styledComponent[internal] = cssComponent[internal];


return React.memo(styledComponent, (prev, next) => {
const prevKeys = Object.keys(prev);
const nextKeys = Object.keys(next);
Expand All @@ -81,7 +82,15 @@ export const createStyledFunction = ({ config, css }) =>
}
}
if (key === 'css') {
if (isUndefined(next[key].isImmutable) || next[key].isImmutable) {
const isImmutable = next[key].isImmutable;
if (isUndefined(isImmutable) || !!isImmutable) {
if (__DEV__) {
if (!isEqual(prev[key], next[key])) {
throw new Error(
'error: "css" is considered as immutable,but its value changed. please set isImmutable to false'
);
}
}
continue;
}
}
Expand All @@ -92,6 +101,7 @@ export const createStyledFunction = ({ config, css }) =>
}
return eq;
});

};

return styled;
Expand Down
2 changes: 1 addition & 1 deletion packages/stitches/src/utils/bp2media.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const bp2media = bps => {
return {};
}
const res = {
m1: ` (max-width: ${bps[0]}px)`,
m1: ` (max-width: ${bps[0]-1}px)`,
};
bps
.map((bp, i) => ` (min-width: ${bp}px)`)
Expand Down
7 changes: 6 additions & 1 deletion packages/stitches/src/utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { origin, rvw } from '@c3/css';
// }}>

//[mobile,laptop,desktop]
export const convertResponsiveArrayForVariant = (value) => {
export const convertResponsiveArrayForVariant = value => {
const values = toArray(value);
switch (values.length) {
case 1: {
Expand All @@ -29,6 +29,11 @@ export const convertResponsiveArrayForVariant = (value) => {
}
};

const globalStyle = {
'@m1': {},
'@m2': {},
'@m3': {},
};
export const convertResponsiveArrayForStyle = (key, value) => {
const values = toArray(value);
switch (values.length) {
Expand Down
5 changes: 2 additions & 3 deletions packages/utils/src/dbg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const ls =

export const __MOCK__ = !!ls.getItem('mock');

//FIXME
// export const __DEV__ = import.meta.env.DEV;
export const __DEV__ = false;
//TODO:
export const __DEV__ = globalThis.location?.hostname === 'localhost';

export const logtype = s(ls.getItem('dbg')).split(',');

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
build: {
minify: false,
minify: true,
lib: {
entry: './src/index.ts',
name: 'css',
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit edd447b

Please sign in to comment.