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

Commit b5cb72c

Browse files
committed
refactor(stat): use functional api
1 parent 59f55e3 commit b5cb72c

File tree

1 file changed

+49
-36
lines changed
  • packages/chakra-ui-core/src/CStat

1 file changed

+49
-36
lines changed

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

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ const arrowOptions = {
3838
*/
3939
const CStat = {
4040
name: 'CStat',
41-
extends: CBox,
42-
render (h) {
43-
const children = cleanChildren(this.$slots.default)
41+
functional: true,
42+
render (h, { props, slots, data, ...rest }) {
43+
const children = cleanChildren(slots().default)
4444
return h(CBox, {
45-
props: {
45+
...rest,
46+
props: { as: props.as },
47+
attrs: {
4648
flex: 1,
4749
pr: 4,
4850
position: 'relative',
49-
...forwardProps(this.$props)
50-
},
51-
attrs: {
51+
...(data.attrs || {}),
5252
'data-chakra-component': 'CStat'
5353
}
5454
}, children)
@@ -65,17 +65,20 @@ const CStat = {
6565
*/
6666
const CStatGroup = {
6767
name: 'CStatGroup',
68-
extends: CFlex,
69-
render (h) {
70-
const children = cleanChildren(this.$slots.default)
68+
functional: true,
69+
props: CFlex.props,
70+
render (h, { props, slots, data, ...rest }) {
71+
const children = cleanChildren(slots().default)
7172
return h(CFlex, {
73+
...rest,
7274
props: {
7375
flexWrap: 'wrap',
7476
justifyContent: 'space-around',
7577
alignItems: 'flex-start',
76-
...forwardProps(this.$props)
78+
...forwardProps(props)
7779
},
7880
attrs: {
81+
...(data.attrs || {}),
7982
'data-chakra-component': 'CStatGroup'
8083
}
8184
}, children)
@@ -92,23 +95,27 @@ const CStatGroup = {
9295
*/
9396
const CStatArrow = {
9497
name: 'CStatArrow',
95-
extends: CIcon,
98+
functional: true,
9699
props: {
100+
...CIcon.props,
97101
type: {
98102
type: String,
99103
default: 'increase'
100104
}
101105
},
102-
render (h) {
106+
render (h, { props, slots, data, ...rest }) {
103107
return h(CIcon, {
108+
...rest,
104109
props: {
105-
mr: 1,
106110
size: '14px',
107-
verticalAlign: 'middle',
108-
...arrowOptions[this.type],
109-
...forwardProps(this.$props)
111+
...arrowOptions[props.type],
112+
...forwardProps(props)
110113
},
111114
attrs: {
115+
mr: 1,
116+
verticalAlign: 'middle',
117+
...(data.attrs || {}),
118+
color: arrowOptions[props.type].color,
112119
'data-chakra-component': 'CStatArrow'
113120
}
114121
})
@@ -125,19 +132,20 @@ const CStatArrow = {
125132
*/
126133
const CStatNumber = {
127134
name: 'CStatNumber',
128-
extends: CText,
129-
render (h) {
135+
functional: true,
136+
props: CText.props,
137+
render (h, { props, slots, data, ...rest }) {
130138
return h(CText, {
131-
props: {
139+
...rest,
140+
props: forwardProps(props),
141+
attrs: {
132142
fontSize: '2xl',
133143
verticalAlign: 'baseline',
134144
fontWeight: 'semibold',
135-
...forwardProps(this.$props)
136-
},
137-
attrs: {
145+
...(data.attrs || {}),
138146
'data-chakra-component': 'CStatNumber'
139147
}
140-
}, this.$slots.default)
148+
}, slots().default)
141149
}
142150
}
143151

@@ -151,16 +159,20 @@ const CStatNumber = {
151159
*/
152160
const CStatHelperText = {
153161
name: 'CStatHelperText',
154-
extends: CText,
155-
render (h) {
162+
functional: true,
163+
props: CText.props,
164+
render (h, { props, slots, data, ...rest }) {
156165
return h(CText, {
157-
props: {
166+
...rest,
167+
props: forwardProps(props),
168+
attrs: {
158169
fontSize: 'sm',
159170
opacity: 0.8,
160171
mb: 2,
161-
...forwardProps(this.$props)
172+
...(data.attrs || {}),
173+
'data-chakra-component': 'CStatHelperText'
162174
}
163-
}, this.$slots.default)
175+
}, slots().default)
164176
}
165177
}
166178

@@ -174,18 +186,19 @@ const CStatHelperText = {
174186
*/
175187
const CStatLabel = {
176188
name: 'CStatLabel',
177-
extends: CText,
178-
render (h) {
189+
functional: true,
190+
props: CText.props,
191+
render (h, { props, slots, data, ...rest }) {
179192
return h(CText, {
180-
props: {
193+
...rest,
194+
props: forwardProps(props),
195+
attrs: {
181196
fontWeight: 'medium',
182197
fontSize: 'sm',
183-
...forwardProps(this.$props)
184-
},
185-
attrs: {
198+
...(data.attrs || {}),
186199
'data-chakra-component': 'CStatLabel'
187200
}
188-
}, this.$slots.default)
201+
}, slots().default)
189202
}
190203
}
191204

0 commit comments

Comments
 (0)