1
1
import { BoxProps } from './box'
2
- import { h , defineComponent , PropType } from 'vue'
2
+ import { h , defineComponent , PropType , computed , watchEffect } from 'vue'
3
3
import {
4
4
chakra ,
5
5
HTMLChakraProps ,
6
6
SystemProps ,
7
7
ResponsiveValue ,
8
8
} from '@chakra-ui/vue-system'
9
9
import { filterUndefined , mapResponsive } from '@chakra-ui/utils'
10
+ import { SNAO } from '@chakra-ui/vue-utils'
10
11
11
12
export interface GridProps extends HTMLChakraProps < 'div' > , GridOptions { }
12
13
@@ -112,30 +113,22 @@ export interface GridItemProps extends BoxProps {
112
113
*/
113
114
export const CGrid = defineComponent ( {
114
115
props : {
115
- templateColumns : [ Object , String , Array ] as PropType <
116
- GridProps [ 'gridTemplateColumns' ]
117
- > ,
118
- gap : [ Object , String , Array ] as PropType < GridProps [ 'gridGap' ] > ,
119
- rowGap : [ Object , String , Array ] as PropType < GridProps [ 'gridRowGap' ] > ,
120
- columnGap : [ Object , String , Array ] as PropType < GridProps [ 'gridColumnGap' ] > ,
121
- autoFlow : [ Object , String , Array ] as PropType < GridProps [ 'gridAutoFlow' ] > ,
122
- autoRows : [ Object , String , Array ] as PropType < GridProps [ 'gridAutoRows' ] > ,
123
- autoColumns : [ Object , String , Array ] as PropType <
124
- GridProps [ 'gridAutoColumns' ]
125
- > ,
126
- templateRows : [ Object , String , Array ] as PropType <
127
- GridProps [ 'gridTemplateRows' ]
128
- > ,
129
- templateAreas : [ Object , String , Array ] as PropType <
130
- GridProps [ 'gridTemplateAreas' ]
131
- > ,
132
- area : [ Object , String , Array ] as PropType < GridProps [ 'gridArea' ] > ,
133
- column : [ Object , String , Array ] as PropType < GridProps [ 'gridColumn' ] > ,
134
- row : [ Object , String , Array ] as PropType < GridProps [ 'gridRow' ] > ,
116
+ templateColumns : SNAO as PropType < GridProps [ 'gridTemplateColumns' ] > ,
117
+ gap : SNAO as PropType < GridProps [ 'gridGap' ] > ,
118
+ rowGap : SNAO as PropType < GridProps [ 'gridRowGap' ] > ,
119
+ columnGap : SNAO as PropType < GridProps [ 'gridColumnGap' ] > ,
120
+ autoFlow : SNAO as PropType < GridProps [ 'gridAutoFlow' ] > ,
121
+ autoRows : SNAO as PropType < GridProps [ 'gridAutoRows' ] > ,
122
+ autoColumns : SNAO as PropType < GridProps [ 'gridAutoColumns' ] > ,
123
+ templateRows : SNAO as PropType < GridProps [ 'gridTemplateRows' ] > ,
124
+ templateAreas : SNAO as PropType < GridProps [ 'gridTemplateAreas' ] > ,
125
+ area : SNAO as PropType < GridProps [ 'gridArea' ] > ,
126
+ column : SNAO as PropType < GridProps [ 'gridColumn' ] > ,
127
+ row : SNAO as PropType < GridProps [ 'gridRow' ] > ,
135
128
} ,
136
129
setup ( props , { slots, attrs } ) {
137
- return ( ) => {
138
- const styles = filterUndefined ( {
130
+ const styles = computed ( ( ) =>
131
+ filterUndefined ( {
139
132
display : 'grid' ,
140
133
gridArea : props . area ,
141
134
gridTemplateAreas : props . templateAreas ,
@@ -150,13 +143,14 @@ export const CGrid = defineComponent({
150
143
gridTemplateRows : props . templateRows ,
151
144
gridTemplateColumns : props . templateColumns ,
152
145
} )
153
-
146
+ )
147
+ watchEffect ( ( ) => {
148
+ console . log ( styles . value )
149
+ } )
150
+ return ( ) => {
154
151
return h (
155
- chakra ( 'div' , { label : 'grid' } ) ,
156
- {
157
- __css : styles ,
158
- ...attrs ,
159
- } ,
152
+ chakra ( 'div' , { label : 'grid' , __css : styles . value , ...attrs } ) ,
153
+ { } ,
160
154
slots
161
155
)
162
156
}
@@ -171,28 +165,30 @@ function spanFn(span?: ResponsiveValue<number | 'auto'>) {
171
165
172
166
export const CGridItem = defineComponent ( {
173
167
props : {
174
- colSpan : [ Object , String , Array ] as PropType < GridItemProps [ 'colSpan' ] > ,
175
- colStart : [ Object , String , Array ] as PropType < GridItemProps [ 'colStart' ] > ,
176
- colEnd : [ Object , String , Array ] as PropType < GridItemProps [ 'colEnd' ] > ,
177
- rowStart : [ Object , String , Array ] as PropType < GridItemProps [ 'rowStart' ] > ,
178
- rowEnd : [ Object , String , Array ] as PropType < GridItemProps [ 'rowEnd' ] > ,
179
- rowSpan : [ Object , String , Array ] as PropType < GridItemProps [ 'rowSpan' ] > ,
168
+ colSpan : SNAO as PropType < GridItemProps [ 'colSpan' ] > ,
169
+ colStart : SNAO as PropType < GridItemProps [ 'colStart' ] > ,
170
+ colEnd : SNAO as PropType < GridItemProps [ 'colEnd' ] > ,
171
+ rowStart : SNAO as PropType < GridItemProps [ 'rowStart' ] > ,
172
+ rowEnd : SNAO as PropType < GridItemProps [ 'rowEnd' ] > ,
173
+ rowSpan : SNAO as PropType < GridItemProps [ 'rowSpan' ] > ,
180
174
} ,
181
175
setup ( props , { slots, attrs } ) {
182
- return ( ) => {
183
- const styles = filterUndefined ( {
176
+ const styles = computed ( ( ) =>
177
+ filterUndefined ( {
184
178
gridColumn : spanFn ( props . colSpan ) ,
185
179
gridRow : spanFn ( props . rowSpan ) ,
186
180
gridColumnStart : props . colStart ,
187
181
gridColumnEnd : props . colEnd ,
188
182
gridRowStart : props . rowStart ,
189
183
gridRowEnd : props . rowEnd ,
190
184
} )
185
+ )
191
186
187
+ return ( ) => {
192
188
return h (
193
189
chakra ( 'div' , { label : 'grid__item' } ) ,
194
190
{
195
- __css : styles ,
191
+ __css : styles . value ,
196
192
...attrs ,
197
193
} ,
198
194
slots
0 commit comments