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

Commit f4d7b0a

Browse files
committed
refactor(layout): refactor Grid component
1 parent efc2a80 commit f4d7b0a

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

packages/layout/src/grid.ts

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { BoxProps } from './box'
2-
import { h, defineComponent, PropType } from 'vue'
2+
import { h, defineComponent, PropType, computed, watchEffect } from 'vue'
33
import {
44
chakra,
55
HTMLChakraProps,
66
SystemProps,
77
ResponsiveValue,
88
} from '@chakra-ui/vue-system'
99
import { filterUndefined, mapResponsive } from '@chakra-ui/utils'
10+
import { SNAO } from '@chakra-ui/vue-utils'
1011

1112
export interface GridProps extends HTMLChakraProps<'div'>, GridOptions {}
1213

@@ -112,30 +113,22 @@ export interface GridItemProps extends BoxProps {
112113
*/
113114
export const CGrid = defineComponent({
114115
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']>,
135128
},
136129
setup(props, { slots, attrs }) {
137-
return () => {
138-
const styles = filterUndefined({
130+
const styles = computed(() =>
131+
filterUndefined({
139132
display: 'grid',
140133
gridArea: props.area,
141134
gridTemplateAreas: props.templateAreas,
@@ -150,13 +143,14 @@ export const CGrid = defineComponent({
150143
gridTemplateRows: props.templateRows,
151144
gridTemplateColumns: props.templateColumns,
152145
})
153-
146+
)
147+
watchEffect(() => {
148+
console.log(styles.value)
149+
})
150+
return () => {
154151
return h(
155-
chakra('div', { label: 'grid' }),
156-
{
157-
__css: styles,
158-
...attrs,
159-
},
152+
chakra('div', { label: 'grid', __css: styles.value, ...attrs }),
153+
{},
160154
slots
161155
)
162156
}
@@ -171,28 +165,30 @@ function spanFn(span?: ResponsiveValue<number | 'auto'>) {
171165

172166
export const CGridItem = defineComponent({
173167
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']>,
180174
},
181175
setup(props, { slots, attrs }) {
182-
return () => {
183-
const styles = filterUndefined({
176+
const styles = computed(() =>
177+
filterUndefined({
184178
gridColumn: spanFn(props.colSpan),
185179
gridRow: spanFn(props.rowSpan),
186180
gridColumnStart: props.colStart,
187181
gridColumnEnd: props.colEnd,
188182
gridRowStart: props.rowStart,
189183
gridRowEnd: props.rowEnd,
190184
})
185+
)
191186

187+
return () => {
192188
return h(
193189
chakra('div', { label: 'grid__item' }),
194190
{
195-
__css: styles,
191+
__css: styles.value,
196192
...attrs,
197193
},
198194
slots

0 commit comments

Comments
 (0)