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

Commit 9152bd8

Browse files
committed
feat(layout): add Spacer component, test, example
1 parent 2438b3f commit 9152bd8

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<c-flex>
3+
<c-box p="4" bg="red.400"> Box 1 </c-box>
4+
<c-spacer />
5+
<c-box p="4" bg="green.400"> Box 2 </c-box>
6+
</c-flex>
7+
</template>

packages/layout/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export * from './link-box'
1111
export * from './list'
1212
export * from './kbd'
1313
export * from './simple-grid'
14+
export * from './spacer'
1415
export * from './stack'

packages/layout/src/spacer.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { chakra, HTMLChakraProps } from '@chakra-ui/vue-system'
2+
import { defineComponent, h } from '@vue/runtime-core'
3+
4+
export interface SpacerProps extends HTMLChakraProps<'div'> {}
5+
6+
/**
7+
* A flexible flex spacer that expands along the major axis of its containing flex layout.
8+
* It renders a `div` by default, and takes up any available space.
9+
*
10+
* @see Docs https://chakra-ui.com/docs/layout/flex#using-the-spacer
11+
*/
12+
export const CSpacer = defineComponent({
13+
setup(propss, { slots }) {
14+
return () => {
15+
return h(
16+
chakra('div', {
17+
label: 'spacer',
18+
baseStyle: {
19+
flex: 1,
20+
justifySelf: 'stretch',
21+
alignSelf: 'stretch',
22+
},
23+
}),
24+
{},
25+
slots
26+
)
27+
}
28+
},
29+
})

packages/layout/tests/__snapshots__/layout.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,28 @@ exports[`<CSimpleGrid /> should render properly 1`] = `
397397
</DocumentFragment>
398398
`;
399399

400+
exports[`<CSpacer /> should render properly 1`] = `
401+
<DocumentFragment>
402+
<div
403+
class="css-1xhj18k"
404+
>
405+
<div
406+
class="chakra-box css-zzdd9b"
407+
>
408+
Box 1
409+
</div>
410+
<div
411+
class="chakra-spacer css-17xejub"
412+
/>
413+
<div
414+
class="chakra-box css-pp1cg2"
415+
>
416+
Box 2
417+
</div>
418+
</div>
419+
</DocumentFragment>
420+
`;
421+
400422
exports[`<CSquare /> & <CCircle /> should render properly 1`] = `
401423
<DocumentFragment>
402424
<div

packages/layout/tests/layout.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
CStack,
1616
CSimpleGrid,
1717
CVStack,
18+
CSpacer,
1819
CHStack,
1920
CGridItem,
2021
CKbd,
@@ -24,6 +25,7 @@ import {
2425
CUnorderedList,
2526
CListIcon,
2627
} from '../src'
28+
import { CFlex } from '@chakra-ui/vue-next'
2729
import { render, testA11y } from '../../test-utils/src'
2830

2931
describe('<CLink />', () => {
@@ -355,3 +357,22 @@ describe('<CSimpleGrid />', () => {
355357
expect(asFragment()).toMatchSnapshot()
356358
})
357359
})
360+
361+
describe('<CSpacer />', () => {
362+
const renderComponent = () =>
363+
render({
364+
components: { CFlex, CSpacer, CBox },
365+
template: `
366+
<c-flex>
367+
<c-box p="4" bg="red.400"> Box 1 </c-box>
368+
<c-spacer />
369+
<c-box p="4" bg="green.400"> Box 2 </c-box>
370+
</c-flex>
371+
`,
372+
})
373+
374+
it('should render properly', async () => {
375+
const { asFragment } = renderComponent()
376+
expect(asFragment()).toMatchSnapshot()
377+
})
378+
})

0 commit comments

Comments
 (0)