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

Commit da5ccb2

Browse files
committed
feat(box): implemented box component with styled component
1 parent 7297fa9 commit da5ccb2

File tree

11 files changed

+688
-30
lines changed

11 files changed

+688
-30
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@babel/preset-env": "^7.6.3",
16+
"@styled-system/should-forward-prop": "^5.1.2",
1617
"@vue/composition-api": "^0.3.2",
1718
"core-js": "^2.6.5",
1819
"css-loader": "^3.2.0",

src/App.vue

+47-12
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,71 @@
11
<template>
2-
<div>
2+
<theme-provider :theme="theme">
33
{{ state.greeting }}
4-
<Button>{{ state.buttonText }}</Button>
5-
<Button @click="increment" variant="ghost" color="success" size="lg" > Increment </Button>
6-
<Button @click="increment" variant="flat" color="warning" size="lg" > Increment </Button>
7-
<Button @click="increment" variant="ghost" color="danger" size="md" > Increment </Button>
8-
<Button @click="increment" variant="link" color="dark" size="lg" > Increment </Button>
4+
<Button variant="ghost" color="success" size="lg" @click="increment">{{ state.buttonText }}</Button>
95
<br>
106
<h1>{{ state.count }}</h1>
11-
</div>
7+
<br>
8+
<Box
9+
:w="['auto']"
10+
px="5"
11+
py="5"
12+
shadow="lg"
13+
my="5"
14+
mb="5"
15+
rounded="sm"
16+
background-color="yellow.200"
17+
color="yellow.700"
18+
>
19+
This is the new box component
20+
</Box>
21+
<Box
22+
@click="increment"
23+
w="auto"
24+
background-color="indigo.700"
25+
shadow="md"
26+
px="4"
27+
py="4"
28+
rounded="lg"
29+
d="flex"
30+
color="indigo.100"
31+
>
32+
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?
33+
</Box>
34+
</theme-provider>
1235
</template>
1336

1437
<script>
38+
import ThemeProvider from './components/ThemeProvider'
1539
import Button from './components/Button'
16-
import { useIncrement as useFeature } from './use-increment'
40+
import Box from './components/Box'
41+
import theme from './lib/theme'
42+
import { useIncrement } from './use-increment'
1743
1844
export default {
1945
setup () {
20-
const { state, increment } = useFeature()
46+
const { state, increment } = useIncrement()
2147
2248
return {
2349
state,
24-
increment
50+
increment,
51+
theme
2552
}
2653
},
2754
name: 'App',
2855
components: {
29-
Button
56+
Button,
57+
ThemeProvider,
58+
Box
3059
}
3160
}
3261
</script>
3362

3463
<style lang="scss" scoped>
35-
64+
html,
65+
body {
66+
font-family: Rubik, sans-serif
67+
}
68+
.top-box {
69+
margin-bottom: 100px;
70+
}
3671
</style>

src/components/Box/config.js

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { system } from 'styled-system'
2+
/**
3+
* This configuration is meant for the intent of:
4+
* - creating new custom properties for certian styled props
5+
* - creating shorthand properties for some long attribute names.
6+
*/
7+
export const config = {
8+
roundedTop: {
9+
properties: ['borderTopLeftRadius', 'borderTopRightRadius'],
10+
scale: 'radii'
11+
},
12+
roundedBottom: {
13+
properties: ['borderBottomLeftRadius', 'borderBottomRightRadius'],
14+
scale: 'radii'
15+
},
16+
roundedLeft: {
17+
properties: ['borderTopLeftRadius', 'borderBottomLeftRadius'],
18+
scale: 'radii'
19+
},
20+
roundedRight: {
21+
properties: ['borderTopRightRadius', 'borderBottomRightRadius'],
22+
scale: 'radii'
23+
},
24+
roundedTopRight: {
25+
property: 'borderTopRightRadius',
26+
scale: 'radii'
27+
},
28+
roundedTopLeft: {
29+
property: 'borderTopLeftRadius',
30+
scale: 'radii'
31+
},
32+
roundedBottomRight: {
33+
property: 'borderBottomRightRadius',
34+
scale: 'radii'
35+
},
36+
roundedBottomLeft: {
37+
property: 'borderBottomLeftRadius',
38+
scale: 'radii'
39+
},
40+
rounded: {
41+
property: 'borderRadius',
42+
scale: 'radii'
43+
},
44+
d: {
45+
property: 'display'
46+
},
47+
w: {
48+
property: 'width',
49+
scale: 'sizes'
50+
},
51+
minW: {
52+
property: 'minWidth',
53+
scale: 'sizes'
54+
},
55+
maxW: {
56+
property: 'maxWidth',
57+
scale: 'sizes'
58+
},
59+
h: {
60+
property: 'height',
61+
scale: 'sizes'
62+
},
63+
minH: {
64+
property: 'minHeight',
65+
scale: 'sizes'
66+
},
67+
maxH: {
68+
property: 'maxHeight',
69+
scale: 'sizes'
70+
},
71+
bgImg: {
72+
property: 'backgroundImage'
73+
},
74+
bgImage: {
75+
property: 'backgroundImage'
76+
},
77+
bgSize: {
78+
property: 'backgroundSize'
79+
},
80+
bgPos: {
81+
property: 'backgroundPosition'
82+
},
83+
bgRepeat: {
84+
property: 'backgroundRepeat'
85+
},
86+
pos: {
87+
property: 'position'
88+
},
89+
flexDir: {
90+
property: 'flexDirection'
91+
},
92+
shadow: {
93+
property: 'boxShadow',
94+
scale: 'shadows'
95+
},
96+
textDecoration: { property: 'textDecoration' },
97+
overflowX: true,
98+
overflowY: true,
99+
textTransform: true,
100+
animation: true,
101+
appearance: true,
102+
transform: true,
103+
transformOrigin: true,
104+
visibility: true,
105+
whiteSpace: true,
106+
userSelect: true,
107+
pointerEvents: true,
108+
wordBreak: true,
109+
overflowWrap: true,
110+
textOverflow: true,
111+
boxSizing: true,
112+
cursor: true,
113+
resize: true,
114+
transition: true,
115+
listStyleType: true,
116+
listStylePosition: true,
117+
listStyleImage: true,
118+
fill: {
119+
property: 'fill',
120+
scale: 'colors'
121+
},
122+
stroke: {
123+
property: 'stroke',
124+
scale: 'colors'
125+
},
126+
objectFit: true,
127+
objectPosition: true,
128+
backgroundAttachment: {
129+
property: 'backgroundAttachment'
130+
},
131+
outline: true,
132+
float: true,
133+
willChange: true
134+
}
135+
136+
config.bgAttachment = config.backgroundAttachment
137+
config.textDecor = config.textDecoration
138+
config.listStylePos = config.listStylePosition
139+
config.listStyleImg = config.listStyleImage
140+
141+
const styledConfig = system(config)
142+
143+
export default styledConfig

src/components/Box/index.js

+67-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
// import styled from 'vue-styled-components'
1+
import styled from 'vue-styled-components'
2+
import { background, border, color, borderRadius, flexbox, grid, layout, position, shadow, space, typography } from 'styled-system'
3+
import { baseBoxProps } from './props'
4+
import styledConfig from './config'
5+
6+
const baseEllipsis = {
7+
overflow: 'hidden',
8+
textOverflow: 'ellipsis',
9+
whiteSpace: 'nowrap'
10+
}
11+
12+
/**
13+
* @description Truncates text if `truncate` is set to true.
14+
* @param {Object} props Props
15+
*/
16+
const truncate = props => {
17+
if (props.truncate) {
18+
if (!props.lineClamp) {
19+
return baseEllipsis
20+
}
21+
}
22+
}
23+
24+
/**
25+
* @description Clamps text based on number of lines.
26+
* @param {Object} props Props
27+
*/
28+
const clamp = props => {
29+
if (props.lineClamp) {
30+
return {
31+
...baseEllipsis,
32+
'-webkit-box-orient': 'vertical',
33+
'-webkit-line-clamp': `${props.lineClamp}`
34+
}
35+
}
36+
}
37+
38+
// TODO: Implement Ripple (For Button)
39+
40+
/**
41+
* Note: All styled components in vue-styled-components forward all their props.
42+
* If the prop is not registered in the child, it is then it is bound as a native
43+
* HTML attribute
44+
* @see https://github.com/styled-components/vue-styled-components#passed-props
45+
* TODO: Will need to revisit this for Image component.
46+
*/
47+
const Box = styled('div', {
48+
...baseBoxProps
49+
50+
})(
51+
layout,
52+
color,
53+
space,
54+
background,
55+
border,
56+
borderRadius,
57+
grid,
58+
position,
59+
shadow,
60+
typography,
61+
flexbox,
62+
styledConfig,
63+
truncate,
64+
clamp
65+
)
66+
67+
export default Box

0 commit comments

Comments
 (0)