Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 5b2233a

Browse files
committed
refactor(props): filtering props with lodash-es
1 parent 4f45c59 commit 5b2233a

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"core-js": "^2.6.5",
1919
"css-loader": "^3.2.0",
2020
"esm": "^3.2.25",
21+
"lodash-es": "^4.17.15",
2122
"register-service-worker": "^1.6.2",
2223
"style-loader": "^1.0.0",
2324
"vue": "^2.6.10",

src/App.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
mb="5"
1515
rounded="sm"
1616
background-color="blue.200"
17+
border-left="4px"
1718
color="blue.700"
19+
font-family="body"
1820
>
1921
This is box component
2022
</Box>
21-
<Box>
23+
<Box bg="yellow.200" border-left="4px" font-family="body" rounded="md" shadow="md" p="3" color="yellow.800">
24+
<Box font-family="heading" font-size="3xl" mb="2">Random Title</Box>
2225
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Debitis incidunt dolor impedit facilis doloribus accusamus aspernatur autem amet voluptate aliquid asperiores, repellendus tempora reiciendis. Aliquid sunt quasi rem magnam, voluptate cumque libero necessitatibus ut minima numquam fugiat? Blanditiis unde earum sint labore quidem quod adipisci quae incidunt dolorum rerum, laboriosam ipsa consectetur, laborum dolore porro quaerat debitis iusto qui pariatur dicta! Quo ab exercitationem possimus, facere vero perferendis quam illum expedita dolores qui tenetur voluptatem sequi eos reprehenderit ut excepturi, ratione nostrum dolor officia labore quis? Dolor, beatae! Eaque autem vero libero. Veritatis placeat blanditiis error, deleniti autem ab quaerat?
2326
</Box>
27+
28+
<Box bg="red.200" border-left="4px" my="5" rounded="md" shadow="md" p="3" color="red.800">
29+
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Debitis incidunt
30+
</Box>
2431
</theme-provider>
2532
</template>
2633

src/components/Box/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import styled from 'vue-styled-components'
2+
import pickBy from 'lodash-es/pickBy'
23
import { background, border, color, borderRadius, flexbox, grid, layout, position, shadow, space, typography, compose } from 'styled-system'
3-
import { baseBoxProps } from './props'
4+
import allProps from './props'
45
import styledConfig from './config'
56

67
const baseEllipsis = {
@@ -59,23 +60,19 @@ const system = compose(
5960
* @returns {Object} Sanitized props object with defined values.
6061
*/
6162
function cleanProps (props) {
62-
for (const prop in props) {
63-
if (/* props[prop] === null|| */ props[prop] === undefined) {
64-
delete props[prop]
65-
}
66-
}
67-
return props
63+
const pure = pickBy(props, (prop) => !!prop)
64+
return pure
6865
}
6966

7067
/**
7168
* Note: All styled components in vue-styled-components forward all their props.
72-
* If the prop is not registered in the child, it is then it is bound as a native
69+
* If the prop is not registered in the component, it is then it is bound as a native
7370
* HTML attribute
7471
* @see https://github.com/styled-components/vue-styled-components#passed-props
7572
* TODO: Will need to revisit this for Image component.
7673
*/
7774
const Box = styled('div', {
78-
...baseBoxProps
75+
...allProps
7976
})`
8077
${props => {
8178
const sanitizedProps = cleanProps(props)

src/components/Box/props.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const baseBoxProps = {
1111
truncate: [Boolean, Number],
1212
px: [Number, String, Array],
1313
py: [Number, String, Array],
14+
m: [Number, String, Array],
1415
mt: [Number, String, Array],
1516
mr: [Number, String, Array],
1617
ml: [Number, String, Array],
@@ -44,8 +45,20 @@ const allProps = {
4445
d: [String, Array],
4546
lineClamp: [String, Number, Array],
4647
truncate: [Boolean, Number],
48+
p: [Number, String, Array],
49+
pt: [Number, String, Array],
50+
pr: [Number, String, Array],
51+
pb: [Number, String, Array],
52+
pl: [Number, String, Array],
4753
px: [Number, String, Array],
4854
py: [Number, String, Array],
55+
m: [Number, String, Array],
56+
mt: [Number, String, Array],
57+
mr: [Number, String, Array],
58+
ml: [Number, String, Array],
59+
mb: [Number, String, Array],
60+
mx: [Number, String, Array],
61+
my: [Number, String, Array],
4962
rounded: [String, Array],
5063
roundedTop: [String, Array],
5164
roundedBottom: [String, Array],
@@ -55,6 +68,8 @@ const allProps = {
5568
roundedTopLeft: [String, Array],
5669
roundedBottomRight: [String, Array],
5770
roundedBottomLeft: [String, Array],
71+
border: [String, Array],
72+
borderLeft: [String, Array],
5873
shadow: [Number, String, Array],
5974
backgroundColor: String,
6075
pos: [String, Array],
@@ -65,6 +80,9 @@ const allProps = {
6580
bgPos: [String, Array],
6681
bgRepeat: [String, Array],
6782
borderWidth: [String, Array],
83+
fontFamily: [String, Array],
84+
fontSize: [String, Array],
85+
textAlign: [String, Array],
6886
textDecoration: [String, Array],
6987
overflowX: [String, Array],
7088
overflowY: [String, Array],

src/lib/theme/borders.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ const borders = {
88
'4px': '4px solid'
99
}
1010

11+
export const borderWidths = {
12+
'sm': '1px',
13+
'md': '2px',
14+
'lg': '4px'
15+
}
16+
1117
export default borders

src/lib/theme/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import colors from './colors'
22
import typography from './typography'
3-
import borders from './borders'
3+
import borders, { borderWidths } from './borders'
44
import opacity from './opacity'
55
import radii from './radii'
66
import shadows from './shadows'
@@ -12,6 +12,7 @@ const space = baseSizes
1212
const theme = {
1313
colors,
1414
borders,
15+
borderWidths,
1516
opacity,
1617
radii,
1718
shadows,

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9024,6 +9024,11 @@ locate-path@^5.0.0:
90249024
dependencies:
90259025
p-locate "^4.1.0"
90269026

9027+
lodash-es@^4.17.15:
9028+
version "4.17.15"
9029+
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
9030+
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==
9031+
90279032
lodash._reinterpolate@^3.0.0:
90289033
version "3.0.0"
90299034
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"

0 commit comments

Comments
 (0)