Skip to content

Commit

Permalink
feat: add collapsible component
Browse files Browse the repository at this point in the history
  • Loading branch information
phojie committed Oct 29, 2024
1 parent fe03bf2 commit 51717ae
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/common/accordion/AccordionTrigger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const delegatedProps = computed(() => {
v-bind="delegatedProps"
:class="
cn(
'flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180',
'flex flex-1 items-center bg-transparent justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180',
props.class,
)
"
Expand All @@ -31,7 +31,7 @@ const delegatedProps = computed(() => {
<slot name="icon">
<Icon
name="lucide:chevron-down"
class="flex shrink-0 transition-transform duration-200 square-4"
class="flex shrink-0 transition-transform duration-200 size-4"
/>
</slot>
</AccordionTrigger>
Expand Down
15 changes: 15 additions & 0 deletions components/common/collapsible/Collapsible.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script setup lang="ts">
import type { CollapsibleRootEmits, CollapsibleRootProps } from 'radix-vue'
import { CollapsibleRoot, useForwardPropsEmits } from 'radix-vue'
const props = defineProps<CollapsibleRootProps>()
const emits = defineEmits<CollapsibleRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>

<template>
<CollapsibleRoot v-slot="{ open }" v-bind="forwarded">
<slot :open="open" />
</CollapsibleRoot>
</template>
11 changes: 11 additions & 0 deletions components/common/collapsible/CollapsibleContent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { CollapsibleContent, type CollapsibleContentProps } from 'radix-vue'
const props = defineProps<CollapsibleContentProps>()
</script>

<template>
<CollapsibleContent v-bind="props" class="overflow-hidden transition-all data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down">
<slot />
</CollapsibleContent>
</template>
11 changes: 11 additions & 0 deletions components/common/collapsible/CollapsibleTrigger.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { CollapsibleTrigger, type CollapsibleTriggerProps } from 'radix-vue'
const props = defineProps<CollapsibleTriggerProps>()
</script>

<template>
<CollapsibleTrigger v-bind="props">
<slot />
</CollapsibleTrigger>
</template>
3 changes: 3 additions & 0 deletions components/common/collapsible/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as Collapsible } from './Collapsible.vue'
export { default as CollapsibleContent } from './CollapsibleContent.vue'
export { default as CollapsibleTrigger } from './CollapsibleTrigger.vue'

0 comments on commit 51717ae

Please sign in to comment.