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

Commit 3edb2ba

Browse files
committed
refactor(progress): use api
1 parent 7451f2f commit 3edb2ba

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

packages/chakra-ui-core/src/CProgress/CProgress.js

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
import { css, keyframes } from 'emotion'
1313
import CBox from '../CBox'
14-
import { generateStripe, valueToPercent, forwardProps } from '../utils'
15-
import { baseProps } from '../config/props'
14+
import { generateStripe, valueToPercent, createStyledAttrsMixin } from '../utils'
1615

1716
const stripe = keyframes({
1817
from: { backgroundPosition: '1rem 0' },
@@ -39,18 +38,20 @@ const progressbarSizes = {
3938
*/
4039
const CProgressLabel = {
4140
name: 'CProgressLabel',
42-
props: baseProps,
43-
render (h) {
41+
functional: true,
42+
render (h, { data, slots, ...rest }) {
4443
return h(CBox, {
44+
...rest,
4545
props: {
46-
textAlign: 'center',
47-
width: '100%',
48-
...forwardProps(this.$props)
46+
as: data.attrs.as
4947
},
5048
attrs: {
49+
textAlign: 'center',
50+
width: '100%',
51+
...data.attrs,
5152
'data-chakra-component': 'CProgressLabel'
5253
}
53-
}, this.$slots.default)
54+
}, slots().default)
5455
}
5556
}
5657

@@ -64,23 +65,22 @@ const CProgressLabel = {
6465
*/
6566
const CProgressTrack = {
6667
name: 'CProgressTrack',
68+
functional: true,
6769
props: {
68-
...baseProps,
6970
size: [String, Number, Array]
7071
},
71-
render (h) {
72+
render (h, { props, slots, data, ...rest }) {
7273
return h(CBox, {
73-
props: {
74+
...rest,
75+
attrs: {
7476
pos: 'relative',
75-
height: progressbarSizes[this.size || 'md'],
77+
height: progressbarSizes[props.size || 'md'],
7678
overflow: 'hidden',
7779
w: '100%',
78-
...forwardProps(this.$props)
79-
},
80-
attrs: {
80+
...data.attrs,
8181
'data-chakra-component': 'CProgressTrack'
8282
}
83-
}, this.$slots.default)
83+
}, slots().default)
8484
}
8585
}
8686

@@ -93,9 +93,8 @@ const CProgressTrack = {
9393
* @see Docs https://vue.chakra-ui.com/progress
9494
*/
9595
const CProgressIndicator = {
96-
name: 'CProgressIndicator',
96+
mixins: [createStyledAttrsMixin('CProgressIndicator')],
9797
props: {
98-
...baseProps,
9998
isIndeterminate: Boolean,
10099
min: Number,
101100
max: Number,
@@ -104,23 +103,27 @@ const CProgressIndicator = {
104103
computed: {
105104
percent () {
106105
return valueToPercent(this.value, this.min, this.max)
106+
},
107+
componentStyles () {
108+
return {
109+
height: '100%',
110+
transition: 'all 0.3s',
111+
width: `${this.percent}%`
112+
}
107113
}
108114
},
109115
render (h) {
110-
return h(CBox, {
111-
props: {
112-
height: '100%',
113-
transition: 'all 0.3s',
114-
width: `${this.percent}%`,
115-
...forwardProps(this.$props)
116-
},
116+
return h(this.as || 'div', {
117+
class: [this.className],
117118
attrs: {
119+
...this.computedAttrs,
118120
'aria-valuemax': this.max,
119121
'aria-valuemin': this.min,
120122
'aria-valuenow': this.isIndeterminate ? null : this.value,
121123
role: 'progressbar',
122124
'data-chakra-component': 'CProgressIndicator'
123-
}
125+
},
126+
on: this.computedListeners
124127
}, this.$slots.default)
125128
}
126129
}
@@ -135,9 +138,9 @@ const CProgressIndicator = {
135138
*/
136139
const CProgress = {
137140
name: 'CProgress',
141+
inheritAttrs: false,
138142
inject: ['$chakraColorMode'],
139143
props: {
140-
...baseProps,
141144
color: {
142145
type: String,
143146
default: 'blue'
@@ -201,13 +204,13 @@ const CProgress = {
201204

202205
return h(CProgressTrack, {
203206
props: {
204-
size: this.size,
205-
bg: trackColor[this.colorMode],
206-
borderRadius: _borderRadius,
207-
...forwardProps(this.$props)
207+
size: this.size
208208
},
209209
attrs: {
210-
'data-chakra-component': 'CProgress'
210+
bg: trackColor[this.colorMode],
211+
borderRadius: _borderRadius,
212+
'data-chakra-component': 'CProgress',
213+
...this.$attrs
211214
}
212215
}, [
213216
h(CProgressIndicator, {
@@ -218,7 +221,9 @@ const CProgress = {
218221
props: {
219222
min: this.min,
220223
max: this.max,
221-
value: this.value,
224+
value: this.value
225+
},
226+
attrs: {
222227
bg: indicatorColor[this.colorMode],
223228
borderRadius: this.__borderRadius,
224229
...this.isIndeterminate && {

0 commit comments

Comments
 (0)