css-in-props 0.9.4 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/package.json +3 -5
- package/src/registry.js +13 -13
- package/src/transform/classname.js +9 -2
package/README.md
CHANGED
|
@@ -13,12 +13,10 @@ yarn add css-in-props
|
|
|
13
13
|
|
|
14
14
|
2. Import the component from Symbols
|
|
15
15
|
```
|
|
16
|
-
import {
|
|
16
|
+
import { setClassname } from 'css-in-props'
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
3. Use it inside your DOMQL code
|
|
20
20
|
```
|
|
21
|
-
const Box = ({ children, ...props }) => <div className={
|
|
22
|
-
transformEmotion(transformClassname(props))
|
|
23
|
-
}>{children}</div>
|
|
21
|
+
const Box = ({ children, ...props }) => <div className={setClassname(props)}>{children}</div>
|
|
24
22
|
```
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Utilize props as CSS methods",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "symbo.ls",
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.7",
|
|
7
7
|
"repository": "https://github.com/symbo-ls/smbls",
|
|
8
8
|
"main": "src/index.js",
|
|
9
9
|
"files": [
|
|
@@ -21,12 +21,10 @@
|
|
|
21
21
|
"reinstall": "rm yarn.lock && rm -rf node_modules/rackai && yarn",
|
|
22
22
|
"bump": "npx np"
|
|
23
23
|
},
|
|
24
|
-
"
|
|
24
|
+
"devDependencies": {
|
|
25
25
|
"@domql/utils": "^2.2.1",
|
|
26
26
|
"@emotion/css": "^11.10.0",
|
|
27
|
-
"@symbo.ls/scratch": "^0.3.19"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
27
|
+
"@symbo.ls/scratch": "^0.3.19",
|
|
30
28
|
"@babel/core": "^7.14.6",
|
|
31
29
|
"babel-eslint": "^10.0.3",
|
|
32
30
|
"emotion": "^10.0.27",
|
package/src/registry.js
CHANGED
|
@@ -82,8 +82,8 @@ export const theme = {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export const block = {
|
|
85
|
-
round: props => props.round ? (
|
|
86
|
-
borderRadius: props => props.borderRadius ? (
|
|
85
|
+
round: props => props.round ? (mapBasedOnRatio(props, 'borderRadius') || ({ borderRadius: props.round })) : null,
|
|
86
|
+
borderRadius: props => props.borderRadius ? (mapBasedOnRatio(props, 'borderRadius') || ({ borderRadius: props.borderRadius })) : null,
|
|
87
87
|
|
|
88
88
|
transition: props => props.transition && ({ transition: props.transition }),
|
|
89
89
|
transitionProperty: props => props.transitionProperty && ({
|
|
@@ -105,8 +105,8 @@ export const block = {
|
|
|
105
105
|
if (typeof props.boxSize !== 'string') return
|
|
106
106
|
const [height, width] = props.boxSize.split(' ')
|
|
107
107
|
return {
|
|
108
|
-
...
|
|
109
|
-
...
|
|
108
|
+
...mapBasedOnRatio({ height, spacingRatio: props.spacingRatio }, 'height'),
|
|
109
|
+
...mapBasedOnRatio({ width, spacingRatio: props.spacingRatio }, 'width')
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
112
|
|
|
@@ -116,8 +116,8 @@ export const block = {
|
|
|
116
116
|
if (typeof props.widthRange !== 'string') return
|
|
117
117
|
const [minWidth, maxWidth] = props.widthRange.split(' ')
|
|
118
118
|
return {
|
|
119
|
-
...
|
|
120
|
-
...
|
|
119
|
+
...mapBasedOnRatio({ minWidth, spacingRatio: props.spacingRatio }, 'minWidth'),
|
|
120
|
+
...mapBasedOnRatio({ maxWidth, spacingRatio: props.spacingRatio }, 'maxWidth')
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
|
|
@@ -127,8 +127,8 @@ export const block = {
|
|
|
127
127
|
if (typeof props.heightRange !== 'string') return
|
|
128
128
|
const [minHeight, maxHeight] = props.heightRange.split(' ')
|
|
129
129
|
return {
|
|
130
|
-
...
|
|
131
|
-
...
|
|
130
|
+
...mapBasedOnRatio({ minHeight, spacingRatio: props.spacingRatio }, 'minHeight'),
|
|
131
|
+
...mapBasedOnRatio({ maxHeight, spacingRatio: props.spacingRatio }, 'maxHeight')
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
134
|
|
|
@@ -169,13 +169,13 @@ export const position = {
|
|
|
169
169
|
inset: props => {
|
|
170
170
|
const { inset } = props
|
|
171
171
|
if (typeof inset !== 'string') return
|
|
172
|
-
return { inset: inset.split(' ').map(v =>
|
|
172
|
+
return { inset: inset.split(' ').map(v => mapBasedOnRatio(v, 'k').k).join(' ') }
|
|
173
173
|
},
|
|
174
174
|
|
|
175
|
-
left: props =>
|
|
176
|
-
top: props =>
|
|
177
|
-
right: props =>
|
|
178
|
-
bottom: props =>
|
|
175
|
+
left: props => mapBasedOnRatio(props, 'left'),
|
|
176
|
+
top: props => mapBasedOnRatio(props, 'top'),
|
|
177
|
+
right: props => mapBasedOnRatio(props, 'right'),
|
|
178
|
+
bottom: props => mapBasedOnRatio(props, 'bottom')
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
export const text = {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { merge, isFunction } from '@domql/utils'
|
|
3
|
+
import { merge, isFunction, isObject, isArray } from '@domql/utils'
|
|
4
4
|
import { keySetters } from './subProps'
|
|
5
5
|
|
|
6
6
|
import { registry } from '../registry'
|
|
7
7
|
|
|
8
8
|
export const transformClassname = props => {
|
|
9
9
|
const CLASS_NAMES = {}
|
|
10
|
+
if (!isObject(props)) return
|
|
10
11
|
|
|
11
12
|
for (const key in props) {
|
|
12
13
|
const setter = keySetters[key.slice(0, 1)]
|
|
@@ -14,7 +15,13 @@ export const transformClassname = props => {
|
|
|
14
15
|
const hasCSS = reg[key]
|
|
15
16
|
|
|
16
17
|
if (setter) setter(key, props[key], CLASS_NAMES)
|
|
17
|
-
else if (isFunction(hasCSS))
|
|
18
|
+
else if (isFunction(hasCSS)) {
|
|
19
|
+
const stack = hasCSS(props)
|
|
20
|
+
const exec = isArray(stack) ? stack.reduce((a, c) => {
|
|
21
|
+
return merge(a, c)
|
|
22
|
+
}, {}) : stack
|
|
23
|
+
merge(CLASS_NAMES, exec)
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
return CLASS_NAMES
|