-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: layer add accordion component
- Loading branch information
1 parent
556ae59
commit fc039c5
Showing
4 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
const props = defineProps({ | ||
modelValue: { | ||
type: [String, Number], | ||
default: '' | ||
}, | ||
value: { | ||
type: [String, Number], | ||
default: '' | ||
}, | ||
activeClass: { | ||
type: String, | ||
default: '' | ||
} | ||
}) | ||
const emit = defineEmits<{ | ||
'update:modelValue': [value: string | number] | ||
}>() | ||
const isActive = computed(() => props.modelValue === props.value) | ||
function onClick() { | ||
if (props.value === props.modelValue) { | ||
emit('update:modelValue', '') | ||
return | ||
} | ||
emit('update:modelValue', props.value) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="accordion" :class="[isActive ? activeClass : '']"> | ||
<div class="header" @click="onClick"> | ||
<slot name="header" v-bind="{ isActive }" /> | ||
</div> | ||
<div class="content" :class="[isActive ? 'open' : 'closed']"> | ||
<div> | ||
<slot name="content" v-bind="{ isActive }" /> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.accordion { | ||
.header { | ||
user-select: none; | ||
} | ||
.content { | ||
display: grid; | ||
transition: all 0.3s; | ||
} | ||
.content > div { | ||
overflow: hidden; | ||
} | ||
.open { | ||
grid-template-rows: 1fr; | ||
} | ||
.closed { | ||
grid-template-rows: 0fr; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<svg | ||
width="16" | ||
height="17" | ||
viewBox="0 0 16 17" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
fill-rule="evenodd" | ||
clip-rule="evenodd" | ||
d="M8 3.49992C5.23858 3.49992 3 5.7385 3 8.49992C3 11.2613 5.23858 13.4999 8 13.4999C10.7614 13.4999 13 11.2613 13 8.49992C13 7.75449 12.8372 7.04845 12.5457 6.41426C12.4304 6.16335 12.5403 5.86646 12.7912 5.75113C13.0421 5.6358 13.339 5.74571 13.4543 5.99661C13.8048 6.75915 14 7.60742 14 8.49992C14 11.8136 11.3137 14.4999 8 14.4999C4.68629 14.4999 2 11.8136 2 8.49992C2 5.18621 4.68629 2.49992 8 2.49992V3.49992Z" | ||
fill="currentColor" | ||
/> | ||
<path | ||
d="M8 4.96616V1.03368C8 0.821722 8.24721 0.705932 8.41005 0.841626L10.7695 2.80787C10.8895 2.90781 10.8895 3.09203 10.7695 3.19198L8.41005 5.15822C8.24721 5.29391 8 5.17812 8 4.96616Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters