Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack component #48

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
12 changes: 12 additions & 0 deletions components/content/examples/stack/BasicStack.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<CStack :spacing="5">
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</CHeading>
<CText :mt="4">Vue makes front-end development a breeze.</CText>
</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</CHeading>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>
</CBox>
</CStack>
</template>
12 changes: 12 additions & 0 deletions components/content/examples/stack/HorizontalStack.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<CStack :spacing="5" is-inline>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</CHeading>
<CText :mt="4">Vue makes front-end development a breeze.</CText>
</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</CHeading>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>
</CBox>
</CStack>
</template>
12 changes: 12 additions & 0 deletions components/content/examples/stack/HorizontalStackTwo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<CHStack :spacing="5">
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</CHeading>
<CText :mt="4">Vue makes front-end development a breeze.</CText>
</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</CHeading>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>
</CBox>
</CHStack>
</template>
8 changes: 8 additions & 0 deletions components/content/examples/stack/HtmlStack.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<CStack :spacing="4">
<CText>Chakra component 1</CText>
<p>HTML paragraph element</p>
<h3>HTML heading element</h3>
<CText>Chakra component 2</CText>
</CStack>
</template>
12 changes: 12 additions & 0 deletions components/content/examples/stack/ReverseStack.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<CStack :spacing="5" direction="column-reverse">
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</CHeading>
<CText :mt="4">Vue makes front-end development a breeze.</CText>
</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</CHeading>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>
</CBox>
</CStack>
</template>
141 changes: 141 additions & 0 deletions content/4.components/stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: Stack
description: Stack Component
version: 2.0+
---

# Stack

Stack is a layout utility component that makes it easy to stack elements together and apply a space between them. It composes the `Flex` component.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could Flex be changed into CFlex?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Stack is a layout utility component that makes it easy to stack elements together and apply a space between them. It composes the `Flex` component.
Stack is a layout utility component that makes it easy to stack elements together and apply a space between them. It composes the `CFlex` component.


## Import

By default, each item is stacked vertically. `CStack` clones its children and passes the spacing to them using `margin-bottom` or `margin-right`.

```js
import { CStack } from '@chakra-ui/vue-next';
```

In addition, Chakra-UI Vue exports two additional `CStack` components
- `CVStack`: used to stack elements in the vertical direction
- `CHStack`: used to stack elements in the horizontal direction

```js
import { CStack, CHStack, CVStack } from '@chakra-ui/vue-next';
```

## Usage

::showcase
::basic-stack
::
::

```html
<CStack :spacing="5">
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</c-heading>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CHeading>See the Vue</c-heading>
<CHeading>See the Vue</CHeading>

<CText :mt="4">Vue makes front-end development a breeze.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Vue makes front-end development a breeze.</c-text>
<CText :mt="4">Vue makes front-end development a breeze.</CText>

</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</c-heading>
D-Lite marked this conversation as resolved.
Show resolved Hide resolved
<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>

</CBox>
</CStack>
```

## Stack items horizontally

You can stack the items horizontally either:

- By passing the `is-inline` prop or `direction` and set it to `row` to the `CStack` component.

::showcase
::horizontal-stack
::
::

```html
<CStack :spacing="5" is-inline>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</c-heading>
D-Lite marked this conversation as resolved.
Show resolved Hide resolved
<CText :mt="4">Vue makes front-end development a breeze.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Vue makes front-end development a breeze.</c-text>
<CText :mt="4">Vue makes front-end development a breeze.</CText>

</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</c-heading>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CHeading>Go Nuxt!</c-heading>
<CHeading>Go Nuxt!</CHeading>

<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>

</CBox>
</CStack>
```

- Using the `CHStack` component.

::showcase
::horizontal-stack-two
::
::

```html
<CHStack :spacing="5">
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</c-heading>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CHeading>See the Vue</c-heading>
<CHeading>See the Vue</CHeading>

<CText :mt="4">Vue makes front-end development a breeze.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Vue makes front-end development a breeze.</c-text>
<CText :mt="4">Vue makes front-end development a breeze.</CText>

</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</c-heading>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CHeading>Go Nuxt!</c-heading>
<CHeading>Go Nuxt!</CHeading>

<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>

</CBox>
</CHStack>
```

Optionally, you can use align and justify to adjust the alignment and distribution of the items.

## Reverse display order of items

Set `direction` to `row-reverse` or `column-reverse`.

::showcase
::reverse-stack
::
::

```html
<CStack :spacing="5" is-reversed>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>See the Vue</c-heading>
D-Lite marked this conversation as resolved.
Show resolved Hide resolved
<CText :mt="4">Vue makes front-end development a breeze.</c-text>
D-Lite marked this conversation as resolved.
Show resolved Hide resolved
</CBox>
<CBox :p="5" shadow="md" border-width="1px">
<CHeading>Go Nuxt!</c-heading>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CHeading>Go Nuxt!</c-heading>
<CHeading>Go Nuxt!</CHeading>

<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<CText :mt="4">Nuxt makes writing Vue even easier.</c-text>
<CText :mt="4">Nuxt makes writing Vue even easier.</CText>

</CBox>
</CStack>
```

### Stacking HTML elements

::showcase
::html-stack
::
::

```html
<CStack :spacing="4">
<CText>Chakra component 1</CText>
<p>HTML paragraph element</p>
<h3>HTML heading element</h3>
<CText>Chakra component 2</c-text>
D-Lite marked this conversation as resolved.
Show resolved Hide resolved
</CStack>
```

## Props

| Name | Type | Default | Description |
|------------------|-----------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------|
| `isInline` | `boolean` | false | If `true` the items will be stacked horizontally. |
| `direction` | `FlexProps["flexDirection"]` | | The direction to stack the items. |
| `spacing` | `StyledSystem.MarginProps` | | The space between each stack item |
| `align` | `FlexProps["alignItems"]` | | The alignment of the stack item. Similar to `align-items` |
| `justify` | `FlexProps["justifyContent"]` | | The distribution of the stack item. Similar to `justify-content` |
| `shouldWrapChildren` | `boolean` | false | If `true`, the children will be wrapped in a `Box` with `display: inline-block`, and the Box will take the spacing props |
| `divider` | `boolean` | false | If `true`, the stack items will be divided by a straight line |