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

Commit 1ad71ad

Browse files
committed
docs(collapse): create dcos for component
1 parent b3e8de8 commit 1ad71ad

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

docs/components/collapse.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Collapse
2+
3+
The Collapse component is used to create regions of content that can
4+
expand/collapse with a simple animation. It helps to hide content that's not
5+
immediately relevant to the user.
6+
7+
This component leverages [`@vueuse/motion`](https://motion.vueuse.org/)
8+
9+
## Import
10+
11+
```js
12+
import { CCollapse } from '@chakra-ui/vue-next';
13+
```
14+
15+
## Usage
16+
17+
### Basic Usage
18+
19+
```vue
20+
<template>
21+
<div>
22+
<c-button mb="4" variant-color="blue" @click="show = !show">
23+
Toggle
24+
</c-button>
25+
<c-collapse :is-open="show">
26+
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
27+
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
28+
labore wes anderson cred nesciunt sapiente ea proident.
29+
</c-collapse>
30+
</div>
31+
</template>
32+
33+
<script>
34+
export default {
35+
data () {
36+
return {
37+
show: false
38+
}
39+
}
40+
}
41+
</script>
42+
```
43+
44+
### Changing the startingHeight
45+
46+
```vue
47+
<template>
48+
<div>
49+
<c-button mb="4" variant-color="blue" @click="show = !show">
50+
Show {{ show ? 'Less' : 'More' }}
51+
</c-button>
52+
<c-collapse :starting-height="20" :is-open="show">
53+
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
54+
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
55+
labore wes anderson cred nesciunt sapiente ea proident.
56+
</c-collapse>
57+
</div>
58+
</template>
59+
60+
<script>
61+
export default {
62+
data () {
63+
return {
64+
show: false
65+
}
66+
}
67+
}
68+
</script>
69+
```
70+
71+
72+
## Props
73+
74+
This component doesn't have any custom props.
75+
76+
| Name | Type | Description |
77+
| ---------------- | --------- | ------------------------------------------------------------------------------------------------------------ |
78+
| isOpen | `boolean` | If `true`, the content will be visible |
79+
| animateOpacity | `boolean` | If `true`, the opacity of the content will be animated |
80+
| duration | `number` | The animation duration as it expands |
81+
| startingHeight | `number` | The height you want the content in it's collapsed state. Set to `0` by default |
82+
| endingHeight | `number` | The height you want the content in it's expanded state. Set to `auto` by default |
83+
84+
## Events
85+
86+
| Name | Payload | Description |
87+
| ---------- | --------- | ------------------------------------------------------------------------------------------------------------ |
88+
| `@entered` | `Event` | The event to be called when the collapse animation starts. |
89+
| `@left` | `Event` | The event to be called when the collapse animation ends. |

packages/c-motion/src/c-collapse.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const CCollapse = defineComponent({
6666
default: true
6767
},
6868
},
69+
emits: ['entered', 'left'],
6970
setup(props, { slots, attrs, emit }) {
7071
const [targetRef, targetNode] = useRef()
7172
const transitionId = useId('collapse-transition')
@@ -144,12 +145,19 @@ export const CCollapse = defineComponent({
144145

145146
watch(() => props.isOpen!, (newVal) => {
146147
if (!newVal && targetNode.value!) {
147-
leave(() => null)
148+
leave(onDoneLeft)
148149
} else {
149-
enter(() => null)
150+
enter(onDoneEnter)
150151
}
151152
})
152153

154+
const onDoneEnter = () => {
155+
emit('entered')
156+
}
157+
const onDoneLeft = () => {
158+
emit('left')
159+
}
160+
153161
/**
154162
* We first invoke
155163
* the transition to make sure it's registered
@@ -174,7 +182,7 @@ export const CCollapse = defineComponent({
174182

175183
return (
176184
withDirectives(
177-
<chakra.div ref={targetRef}>
185+
<chakra.div {...attrs} ref={targetRef}>
178186
{() => children}
179187
</chakra.div>,
180188
[

0 commit comments

Comments
 (0)