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

Commit 47ed88c

Browse files
committed
Start adding CGridItem
1 parent 782fecd commit 47ed88c

File tree

5 files changed

+89
-11
lines changed

5 files changed

+89
-11
lines changed

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

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,65 @@
1010
*/
1111

1212
import { createStyledAttrsMixin } from '../utils'
13-
import { SNA } from '../config/props/props.types'
13+
import { SNA, StringArray } from '../config/props/props.types'
14+
15+
/**
16+
* @description Map "span" values to accommodate breakpoint values
17+
* @param {Array} value
18+
* @returns {(String|Array)} String or Array of breakpoint values
19+
*/
20+
const spanFn = (value) => {
21+
if (Array.isArray(value)) {
22+
return value.map(v =>
23+
v === 'auto' ? 'auto' : `span ${v}/span ${v}`
24+
)
25+
} else {
26+
return value === 'auto' ? 'auto' : `span ${value}/span ${value}`
27+
}
28+
}
29+
30+
/**
31+
* CGridItem component
32+
*
33+
* A primitive component useful for grid layouts.
34+
*
35+
* @extends CBox
36+
* @see Docs https://vue.chakra-ui.com/grid
37+
*/
38+
39+
const CGridItem = {
40+
name: 'CGridItem',
41+
mixins: [createStyledAttrsMixin('CGridItem')],
42+
props: {
43+
colSpan: { type: StringArray },
44+
rowSpan: { type: StringArray },
45+
colStart: { type: StringArray },
46+
colEnd: { type: StringArray },
47+
rowStart: { type: StringArray },
48+
rowEnd: { type: StringArray }
49+
},
50+
computed: {
51+
componentStyles () {
52+
return {
53+
gridColumn: this.colSpan ? spanFn(this.colSpan) : null,
54+
gridRow: this.rowSpan ? spanFn(this.rowSpan) : null,
55+
gridColumnStart: this.colStart,
56+
gridColumnEnd: this.colEnd,
57+
gridRowStart: this.rowStart,
58+
gridRowEnd: this.rowEnd
59+
}
60+
}
61+
},
62+
render (h) {
63+
return h('div',
64+
{
65+
class: this.className,
66+
attrs: this.computedAttrs
67+
},
68+
this.$slots.default
69+
)
70+
}
71+
}
1472

1573
/**
1674
* CGrid component
@@ -61,11 +119,18 @@ const CGrid = {
61119
}
62120
},
63121
render (h) {
64-
return h(this.as, {
65-
class: this.className,
66-
attrs: this.computedAttrs
67-
}, this.$slots.default)
122+
return h(
123+
this.as,
124+
{
125+
class: this.className,
126+
attrs: this.computedAttrs
127+
},
128+
this.$slots.default
129+
)
68130
}
69131
}
70132

71-
export default CGrid
133+
export {
134+
CGrid,
135+
CGridItem
136+
}

packages/chakra-ui-core/src/CGrid/CGrid.stories.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { storiesOf } from '@storybook/vue'
2-
import { CReset, CGrid, CBox } from '..'
2+
import { CReset, CGrid, CGridItem, CBox } from '..'
33

44
storiesOf('UI | Grid', module)
55
.add('Default Grid', () => ({
@@ -17,3 +17,17 @@ storiesOf('UI | Grid', module)
1717
</div>
1818
`
1919
}))
20+
21+
storiesOf('UI | Grid', module)
22+
.add('Grid Items', () => ({
23+
components: { CReset, CGrid, CGridItem },
24+
template: `
25+
<div>
26+
<CReset />
27+
<CGrid w="600px" template-columns="repeat(5, 1fr)" gap="6">
28+
<CGridItem col-span="2" h="10" bg="blue.500" />
29+
<CGridItem col-start="4" col-end="6" h="10" bg="red.500" />
30+
</CGrid>
31+
</div>
32+
`
33+
}))
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import CGrid from './CGrid'
2-
export default CGrid
1+
export * from './CGrid'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @see Source https://github.com/chakra-ui/chakra-ui-vue/blob/master/packages/chakra-ui-core/src/CSimpleGrid/CSimpleGrid.js
99
*/
1010

11-
import CGrid from '../CGrid'
11+
import { CGrid } from '../CGrid'
1212
import { SNA } from '../config/props/props.types'
1313
import { createStyledAttrsMixin } from '../utils'
1414
import { countToColumns, widthToColumns } from './utils/grid.styles'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export { default as CFormHelperText } from './CFormHelperText'
5555
export { default as CFragment } from './CFragment'
5656

5757
// G
58-
export { default as CGrid } from './CGrid'
58+
export * from './CGrid'
5959

6060
// H
6161
export { default as CHeading } from './CHeading'

0 commit comments

Comments
 (0)