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

chore: release candidate for v0.9.0 🎉 #438

Merged
merged 21 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8dc4127
Add srcset support to CImage
MWFIAE Apr 26, 2021
4c4be7d
fix: make CPopper's modifiers to be correctly merged
MaySoMusician Apr 29, 2021
c56d785
chore(tests): Added test for srcset in CImage
MWFIAE May 4, 2021
1eddbe1
feat(image): added srcset to the imageProps
MWFIAE May 5, 2021
47ed88c
Start adding CGridItem
IHIutch Mar 14, 2021
0ee84a9
Fix import
IHIutch Mar 14, 2021
6d30004
Add tests
IHIutch Jun 5, 2021
b072690
Update docs
IHIutch Jun 5, 2021
ace19f2
Merge pull request #423 from MWFIAE/patch-1
codebender828 Jun 8, 2021
cd16a51
Merge branch 'develop' into feature/fix-cpopper-modifier-merging
codebender828 Jun 8, 2021
fb111fd
Merge branch 'develop' into feat/grid-item
codebender828 Jun 8, 2021
5a4f228
Merge pull request #424 from MaySoMusician/feature/fix-cpopper-modifi…
codebender828 Jun 9, 2021
8a0b375
Merge branch 'develop' into feat/grid-item
codebender828 Jun 9, 2021
00343a3
Merge pull request #407 from IHIutch/feat/grid-item
codebender828 Jun 10, 2021
30b08d1
Fix grid item example
IHIutch Jun 10, 2021
18054d6
Merge pull request #437 from IHIutch/fix/grid-item-docs
codebender828 Jun 12, 2021
93a6ebd
Merge branch 'master' of github.com:chakra-ui/chakra-ui-vue into develop
codebender828 Jun 12, 2021
5552440
chore: release 1.9.0 changeset
codebender828 Jun 12, 2021
00000ca
Merge branch 'develop' of github.com:chakra-ui/chakra-ui-vue into dev…
codebender828 Jun 12, 2021
c0d609c
fix: update CBox storybook
codebender828 Jun 12, 2021
8a1569d
chore: update changes set documentation
codebender828 Jun 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/small-bikes-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@chakra-ui/vue': minor
'chakra-ui-docs': minor
---

- This changeset adds a srcset support to the CImage component.
- Fixes merging of Popper.js modifiers
- Adds CGridItems components to the core 👏🏾
23 changes: 18 additions & 5 deletions packages/chakra-ui-core/src/CBox/CBox.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storiesOf } from '@storybook/vue'
import { CBox } from '..'
import CBox from '../CBox'

storiesOf('UI | Box', module)
.add('Box', () => ({
Expand Down Expand Up @@ -28,13 +28,26 @@ storiesOf('UI | Box', module)
template: `
<div>
<CBox
position="relative"
w="300px"
h="200px"
font-family="body"
objectFit="contain"
bgImg="url(https://lh3.googleusercontent.com/proxy/vG0O53R9-vPA2WpuC5lXWCHIVuIQiQ1R7bpQ1UcDsHnHVlz2BJMeSeJx1I1n4huq_SeB39iegxgQl1zXcnNqpq2IJfCgQwwWXpdRG9pNdA)"
overflow="hidden"
rounded="20px"
>
<CBox h="full" bg="red.200" :w="1/2" />
<CBox
as="img"
font-family="body"
objectFit="contain"
src="https://images.unsplash.com/photo-1600002415506-dd06090d3480?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1650&q=80"
/>
<CBox px="5" display="flex" flex-direction="column" justify-content="center" py="3" h="full" pos="absolute" top="0" left="0" bg="pink.200" w="50%">
<CBox as="h1" font-size="xl" font-weight="bold">
Tempations
</CBox>
<CBox as="p" font-size="md">
Spacial cakes for special moments.
</CBox>
</CBox>
</CBox>
</div>
`
Expand Down
77 changes: 71 additions & 6 deletions packages/chakra-ui-core/src/CGrid/CGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,65 @@
*/

import { createStyledAttrsMixin } from '../utils'
import { SNA } from '../config/props/props.types'
import { SNA, StringArray } from '../config/props/props.types'

/**
* @description Map "span" values to accommodate breakpoint values
* @param {Array} value
* @returns {(String|Array)} String or Array of breakpoint values
*/
const spanFn = (value) => {
if (Array.isArray(value)) {
return value.map(v =>
v === 'auto' ? 'auto' : `span ${v}/span ${v}`
)
} else {
return value === 'auto' ? 'auto' : `span ${value}/span ${value}`
}
}

/**
* CGridItem component
*
* A primitive component useful for grid layouts.
*
* @extends CBox
* @see Docs https://vue.chakra-ui.com/grid
*/

const CGridItem = {
name: 'CGridItem',
mixins: [createStyledAttrsMixin('CGridItem')],
props: {
colSpan: { type: StringArray },
rowSpan: { type: StringArray },
colStart: { type: StringArray },
colEnd: { type: StringArray },
rowStart: { type: StringArray },
rowEnd: { type: StringArray }
},
computed: {
componentStyles () {
return {
gridColumn: this.colSpan ? spanFn(this.colSpan) : null,
gridRow: this.rowSpan ? spanFn(this.rowSpan) : null,
gridColumnStart: this.colStart,
gridColumnEnd: this.colEnd,
gridRowStart: this.rowStart,
gridRowEnd: this.rowEnd
}
}
},
render (h) {
return h('div',
{
class: this.className,
attrs: this.computedAttrs
},
this.$slots.default
)
}
}

/**
* CGrid component
Expand Down Expand Up @@ -61,11 +119,18 @@ const CGrid = {
}
},
render (h) {
return h(this.as, {
class: this.className,
attrs: this.computedAttrs
}, this.$slots.default)
return h(
this.as,
{
class: this.className,
attrs: this.computedAttrs
},
this.$slots.default
)
}
}

export default CGrid
export {
CGrid,
CGridItem
}
16 changes: 15 additions & 1 deletion packages/chakra-ui-core/src/CGrid/CGrid.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { storiesOf } from '@storybook/vue'
import { CReset, CGrid, CBox } from '..'
import { CReset, CGrid, CGridItem, CBox } from '..'

storiesOf('UI | Grid', module)
.add('Default Grid', () => ({
Expand All @@ -17,3 +17,17 @@ storiesOf('UI | Grid', module)
</div>
`
}))

storiesOf('UI | Grid', module)
.add('Grid Items', () => ({
components: { CReset, CGrid, CGridItem },
template: `
<div>
<CReset />
<CGrid w="600px" template-columns="repeat(5, 1fr)" gap="6">
<CGridItem col-span="2" h="10" bg="blue.500" />
<CGridItem col-start="4" col-end="6" h="10" bg="red.500" />
</CGrid>
</div>
`
}))
3 changes: 1 addition & 2 deletions packages/chakra-ui-core/src/CGrid/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import CGrid from './CGrid'
export default CGrid
export * from './CGrid'
26 changes: 24 additions & 2 deletions packages/chakra-ui-core/src/CGrid/test/CGrid.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import CGrid from '..'
import { CGrid, CGridItem } from '..'
import { render } from '@/tests/test-utils'

const renderComponent = (props) => {
const inlineAttrs = (props && props.inlineAttrs) || ''
const base = {
components: { CGrid },
components: { CGrid, CGridItem },
template: `<CGrid ${inlineAttrs}>Grid Me</CGrid>`,
...props
}
Expand All @@ -23,3 +23,25 @@ it('should change gap', () => {

expect(asFragment()).toMatchSnapshot()
})

it('should offset columns', () => {
const inlineAttrs = 'col-start="4" col-end="6"'
const { asFragment } = renderComponent({
template: `
<CGrid w="600px" template-columns="repeat(5, 1fr)" gap="6">
<CGridItem ${inlineAttrs}>I'm in a grid item</CGridItem>
</CGrid>`
})
expect(asFragment()).toMatchSnapshot()
})

it('should span columns', () => {
const inlineAttrs = 'col-span="2"'
const { asFragment } = renderComponent({
template: `
<CGrid w="600px" template-columns="repeat(5, 1fr)" gap="6">
<CGridItem ${inlineAttrs}>I'm in a grid item</CGridItem>
</CGrid>`
})
expect(asFragment()).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ exports[`should change gap 1`] = `
</DocumentFragment>
`;

exports[`should offset columns 1`] = `
<DocumentFragment>
<div
class="css-12kxrxg"
data-chakra-component="CGrid"
>
<div
class="css-1i8ejg0"
data-chakra-component="CGridItem"
>
I'm in a grid item
</div>
</div>
</DocumentFragment>
`;

exports[`should render correctly 1`] = `
<DocumentFragment>
<div
Expand All @@ -21,3 +37,19 @@ exports[`should render correctly 1`] = `
</div>
</DocumentFragment>
`;

exports[`should span columns 1`] = `
<DocumentFragment>
<div
class="css-12kxrxg"
data-chakra-component="CGrid"
>
<div
class="css-tuh9u2"
data-chakra-component="CGridItem"
>
I'm in a grid item
</div>
</div>
</DocumentFragment>
`;
10 changes: 6 additions & 4 deletions packages/chakra-ui-core/src/CImage/CImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CImage = {
mixins: [createStyledAttrsMixin('CImage')],
props: {
src: String,
srcset: String,
fallbackSrc: String,
ignoreFalback: Boolean,
htmlWidth: String,
Expand All @@ -48,12 +49,13 @@ const CImage = {
created () {
// Should only invoke window.Image in the browser.
if (process.browser) {
this.loadImage(this.src)
this.loadImage(this.src, this.srcset)
}
},
methods: {
loadImage (src) {
loadImage (src, srcset) {
const image = new window.Image()
image.srcset = srcset
image.src = src

image.onload = (event) => {
Expand All @@ -70,9 +72,9 @@ const CImage = {
render (h) {
let imageProps
if (this.ignoreFallback) {
imageProps = { src: this.src }
imageProps = { src: this.src, srcset: this.srcset }
} else {
imageProps = { src: this.hasLoaded ? this.src : this.fallbackSrc }
imageProps = { src: this.hasLoaded ? this.src : this.fallbackSrc, srcset: this.srcset }
}
return h(CNoSsr, [
h('img', {
Expand Down
7 changes: 7 additions & 0 deletions packages/chakra-ui-core/src/CImage/tests/CImage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ it('fallback src works', async () => {
expect(screen.getByAltText(/Mesut Koca/i)).toHaveAttribute('src', 'LOAD_FALLBACK_SRC')
})
})

it('srcset works', async () => {
renderComponent({ template: '<CImage alt="My Image Description" src="LOAD_SUCCESS_SRC" srcset="LOAD_SUCCESS_SRC 400w" />' })
await wait(() => {
expect(screen.getByAltText(/My Image Description/i)).toHaveAttribute('srcset', 'LOAD_SUCCESS_SRC 400w')
})
})
23 changes: 22 additions & 1 deletion packages/chakra-ui-core/src/CPopper/CPopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ function flipPlacement (placement) {
}
}

/**
* Call _.merge() for each item of `object` array with the corresponding
* item of `source` array
* @param {*} object The destination Modifiers array.
* @param {*} source The source array.
* @returns Returns merged `array`
*/
function mergeModifiers (object, source) {
if (!Array.isArray(object)) throw new Error('`object` must be an array')

const _source = Array.isArray(source) ? source : [source]

object.forEach((o) => {
const { name } = o
const _s = _source.find(s => s.name === name)
if (_s) merge(o, _s)
})

return object
}

/**
* CPopper component
*
Expand Down Expand Up @@ -153,7 +174,7 @@ const CPopper = {
return ref
},
computedModifiers () {
return merge([
return mergeModifiers([
this.usePortal && {
name: 'preventOverflow',
options: {
Expand Down
2 changes: 1 addition & 1 deletion packages/chakra-ui-core/src/CSimpleGrid/CSimpleGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @see Source https://github.com/chakra-ui/chakra-ui-vue/blob/master/packages/chakra-ui-core/src/CSimpleGrid/CSimpleGrid.js
*/

import CGrid from '../CGrid'
import { CGrid } from '../CGrid'
import { SNA } from '../config/props/props.types'
import { createStyledAttrsMixin } from '../utils'
import { countToColumns, widthToColumns } from './utils/grid.styles'
Expand Down
2 changes: 1 addition & 1 deletion packages/chakra-ui-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export { default as CFormHelperText } from './CFormHelperText'
export { default as CFragment } from './CFragment'

// G
export { default as CGrid } from './CGrid'
export * from './CGrid'

// H
export { default as CHeading } from './CHeading'
Expand Down
Loading