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

Commit 73b17b2

Browse files
committed
feat(button): converted button to render function
1 parent ff211cb commit 73b17b2

File tree

8 files changed

+126
-83
lines changed

8 files changed

+126
-83
lines changed

src/App.vue

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
<template>
22
<theme-provider :theme="theme">
3-
<PseudoBox
4-
px="4"
5-
py="2"
6-
:as="element ? 'button' : 'section'"
7-
bg="blue.400"
8-
color="white"
9-
:_hover="{
10-
bg: 'red.200',
11-
color: 'red.700'
12-
}"
13-
@click="toggle"
3+
<Box
4+
w="100vw"
5+
h="100vh"
6+
m="0"
7+
d="flex"
8+
justify-content="center"
9+
align-items="center"
10+
bg="gray.100"
1411
>
15-
I am an anchor
16-
</PseudoBox>
17-
<PseudoBox
18-
px="4"
19-
py="2"
20-
as="footer"
21-
bg="blue.400"
22-
color="white"
23-
:_hover="{
24-
bg: 'red.200',
25-
color: 'red.700'
26-
}"
27-
>
28-
I am an anchor
29-
30-
</PseudoBox>
12+
<Button @click="alert">
13+
I am a button
14+
</Button>
15+
</Box>
3116
</theme-provider>
3217
</template>
3318

3419
<script>
3520
import ThemeProvider from './components/ThemeProvider'
36-
import { Box, PseudoBox } from './lib/core/'
21+
import { Box, Button } from './lib/core/'
3722
import theme from './lib/theme'
3823
3924
export default {
@@ -47,22 +32,24 @@ export default {
4732
name: 'App',
4833
components: {
4934
ThemeProvider,
50-
PseudoBox
35+
Box,
36+
Button
5137
},
5238
methods: {
5339
toggle () {
5440
this.element = !this.element
41+
},
42+
alert () {
43+
alert('clicked')
5544
}
5645
}
5746
}
5847
</script>
5948

60-
<style lang="scss" scoped>
49+
<style lang="scss">
6150
html,
6251
body {
63-
font-family: Rubik, sans-serif
64-
}
65-
.top-box {
66-
margin-bottom: 100px;
52+
font-family: Rubik, sans-serif;
53+
margin: 0
6754
}
6855
</style>

src/components/Box/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const system = compose(
5454

5555
/**
5656
* The Box component is the base reusable component which is the building block for all other Kiwi UI components.
57-
* The Box component by default renders a `<div/>` element.
57+
* It by default renders the `<div/>` element.
5858
*/
5959
const Box = styled('div', {
6060
...baseProps

src/components/Button/index.vue

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
1-
<template>
2-
<button
3-
tabindex="0"
4-
:style="{
5-
borderRadius: rounded === true ? '999px' : '5px',
6-
padding: `${py}em ${px}em`,
7-
fontSize: size === 'sm' ? '0.8rem' :
8-
size === 'lg' ? '1.5rem' : '1rem'
9-
}"
10-
:disabled="disabled"
11-
class="k-button"
12-
:class="[color, variant, { ripple, shadow, rounded, disabled }]"
13-
@click="$emit('click', $event)"
14-
@keydown.space="$emit('click', $event)"
15-
@keydown.enter="$emit('click', $event)"
16-
>
17-
<slot></slot>
18-
</button>
19-
</template>
20-
211
<script>
2+
import PseudoBox from '../PseudoBox'
3+
import styleProps from '../../lib/config/props'
4+
5+
let generatedProps = {
6+
lineHeight: '3rem'
7+
}
8+
/**
9+
* @description The Button component is an accessible rich component that does what a button does :)
10+
*/
2211
export default {
2312
name: 'Button',
13+
components: {
14+
PseudoBox
15+
},
2416
inject: ['$theme', '$colorMode'],
2517
props: {
2618
as: {
2719
type: String,
28-
default: 'button',
29-
validator: (value) => value.match(/^(button|div|a)$/)
20+
default: 'button'
21+
},
22+
type: {
23+
type: String,
24+
default: 'button'
3025
},
31-
color: {
26+
cast: {
3227
type: String,
3328
default: 'primary',
3429
validator: (value) =>
@@ -40,9 +35,9 @@ export default {
4035
validator: (value) =>
4136
value.match(/^(solid|outlined|ghost|flat|link)$/)
4237
},
43-
active: {
44-
type: Boolean,
45-
default: false
38+
variantColor: {
39+
type: [String, Array],
40+
default: 'gray'
4641
},
4742
disabled: {
4843
type: Boolean,
@@ -52,6 +47,10 @@ export default {
5247
type: Boolean,
5348
default: false
5449
},
50+
isActive: {
51+
type: Boolean,
52+
default: false
53+
},
5554
size: {
5655
type: String,
5756
default: 'md',
@@ -62,14 +61,6 @@ export default {
6261
default: 'Loading',
6362
validator: (value) => typeof value === 'string'
6463
},
65-
px: {
66-
type: Number,
67-
validator: (value) => value >= 0
68-
},
69-
py: {
70-
type: Number,
71-
validator: (value) => value >= 0
72-
},
7364
iconSpacing: {
7465
type: String,
7566
validator: (value) => value >= 0
@@ -82,14 +73,37 @@ export default {
8273
type: Boolean,
8374
default: true
8475
},
85-
shadow: {
86-
type: Boolean,
87-
default: false
88-
}
76+
...styleProps
77+
},
78+
render (h) {
79+
return h(PseudoBox, {
80+
props: {
81+
as: this.as,
82+
p: '3',
83+
outline: 'none',
84+
cursor: 'pointer',
85+
fontSize: 'md',
86+
fontWeight: '700',
87+
border: 'none',
88+
transition: 'all 0.2s ease-in',
89+
rounded: 'md',
90+
_focus: {
91+
outline: 'none',
92+
boxShadow: 'outline'
93+
},
94+
...generatedProps
95+
},
96+
attrs: {
97+
type: this.type,
98+
tabIndex: 0,
99+
disabled: this.disabled || this.isLoading,
100+
ariaDisabled: this.disabled || this.isLoading,
101+
dataActive: this.isActive ? 'true' : undefined
102+
},
103+
on: {
104+
click: ($event) => this.$emit('click', $event)
105+
}
106+
}, this.$slots.default)
89107
}
90108
}
91109
</script>
92-
93-
<style lang="scss" scoped>
94-
@import "../../lib/styles/components/Button";
95-
</style>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import styled from 'vue-styled-components'
2+
import Box from '../Box'
3+
4+
const VisuallyHidden = styled(Box)`
5+
border: 0px;
6+
clip: rect(0px, 0px, 0px, 0px);
7+
height: 1px;
8+
width: 1px;
9+
margin: -1px;
10+
padding: 0px;
11+
overflow: hidden;
12+
white-space: nowrap;
13+
position: absolute;
14+
`
15+
16+
export default VisuallyHidden

src/lib/config/props/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
export { default as baseProps } from './props'
1+
import baseProps from './props'
2+
import pseudoProps from './pseudo'
23
export { default as propsConfig } from './props.config'
3-
export { default as pseudoProps } from './pseudo'
4+
5+
export {
6+
baseProps,
7+
pseudoProps
8+
}
9+
10+
/**
11+
* Style props object
12+
*/
13+
const styleProps = {
14+
...baseProps,
15+
...pseudoProps
16+
}
17+
18+
export default styleProps

src/lib/config/props/props.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,20 @@ const baseProps = {
6262
overflowX: [String, Array],
6363
overflowY: [String, Array],
6464
textTransform: [String, Array],
65-
animation: [String, Array]
65+
animation: [String, Array],
66+
alignItems: [String, Array],
67+
alignContent: [String, Array],
68+
justifyContent: [String, Array],
69+
flexWrap: [String, Array],
70+
flexBasis: [String, Array],
71+
flexDirection: [String, Array],
72+
flex: [String, Array],
73+
justifySelf: [String, Array],
74+
alignSelf: [String, Array],
75+
order: [String, Array],
76+
outline: [String, Array],
77+
cursor: [String, Array],
78+
transition: [String, Array]
6679
// appearance: [String, Array],
6780
// transform: [String, Array],
6881
// transformOrigin: [String, Array],
@@ -74,9 +87,7 @@ const baseProps = {
7487
// overflowWrap: [String, Array],
7588
// textOverflow: [String, Array],
7689
// boxSizing: [String, Array],
77-
// cursor: [String, Array],
7890
// resize: [String, Array],
79-
// transition: [String, Array],
8091
// listStyleType: [String, Array],
8192
// listStylePosition: [String, Array],
8293
// listStyleImage: [String, Array],
@@ -85,7 +96,6 @@ const baseProps = {
8596
// objectFit: [String, Array],
8697
// objectPosition: [String, Array],
8798
// backgroundAttachment: [String, Array],
88-
// outline: [String, Array],
8999
// float: [String, Array],
90100
// willChange: [String, Array]
91101
}

src/lib/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as Box } from '../../components/Box'
22
export { default as PseudoBox } from '../../components/PseudoBox'
3+
export { default as Button } from '../../components/Button'

0 commit comments

Comments
 (0)