|
10 | 10 | */ |
11 | 11 |
|
12 | 12 | 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 | +} |
14 | 72 |
|
15 | 73 | /** |
16 | 74 | * CGrid component |
@@ -61,11 +119,18 @@ const CGrid = { |
61 | 119 | } |
62 | 120 | }, |
63 | 121 | 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 | + ) |
68 | 130 | } |
69 | 131 | } |
70 | 132 |
|
71 | | -export default CGrid |
| 133 | +export { |
| 134 | + CGrid, |
| 135 | + CGridItem |
| 136 | +} |
0 commit comments