mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 17:00:36 +01:00
chore(Accordion): transition on height
This commit is contained in:
@@ -267,12 +267,8 @@ const accordion = {
|
|||||||
padding: 'py-2'
|
padding: 'py-2'
|
||||||
},
|
},
|
||||||
transition: {
|
transition: {
|
||||||
enterActiveClass: 'transition duration-100 ease-in',
|
enterActiveClass: 'overflow-hidden transition-[height] duration-200 ease-out',
|
||||||
enterFromClass: 'transform opacity-0',
|
leaveActiveClass: 'overflow-hidden transition-[height] duration-200 ease-out'
|
||||||
enterToClass: 'transform opacity-100',
|
|
||||||
leaveActiveClass: 'transition duration-75 ease-out',
|
|
||||||
leaveFromClass: 'transform opacity-100',
|
|
||||||
leaveToClass: 'transform opacity-0'
|
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
openIcon: 'i-heroicons-chevron-down-20-solid',
|
openIcon: 'i-heroicons-chevron-down-20-solid',
|
||||||
|
|||||||
@@ -18,12 +18,20 @@
|
|||||||
</slot>
|
</slot>
|
||||||
</HDisclosureButton>
|
</HDisclosureButton>
|
||||||
|
|
||||||
<Transition v-bind="ui.transition">
|
<Transition
|
||||||
<HDisclosurePanel :class="[ui.item.base, ui.item.size, ui.item.color, ui.item.padding]">
|
v-bind="ui.transition"
|
||||||
<slot :name="item.slot || 'item'" :item="item" :index="index" :open="open" :close="close">
|
@enter="onEnter"
|
||||||
{{ item.content }}
|
@after-enter="onAfterEnter"
|
||||||
</slot>
|
@before-leave="onBeforeLeave"
|
||||||
</HDisclosurePanel>
|
@leave="onLeave"
|
||||||
|
>
|
||||||
|
<div v-show="open">
|
||||||
|
<HDisclosurePanel :class="[ui.item.base, ui.item.size, ui.item.color, ui.item.padding]" static>
|
||||||
|
<slot :name="item.slot || 'item'" :item="item" :index="index" :open="open" :close="close">
|
||||||
|
{{ item.content }}
|
||||||
|
</slot>
|
||||||
|
</HDisclosurePanel>
|
||||||
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</HDisclosure>
|
</HDisclosure>
|
||||||
</div>
|
</div>
|
||||||
@@ -82,10 +90,37 @@ export default defineComponent({
|
|||||||
|
|
||||||
const uiButton = computed<Partial<typeof appConfig.ui.button>>(() => appConfig.ui.button)
|
const uiButton = computed<Partial<typeof appConfig.ui.button>>(() => appConfig.ui.button)
|
||||||
|
|
||||||
|
function onEnter (el: HTMLElement, done) {
|
||||||
|
el.style.height = '0'
|
||||||
|
el.offsetHeight // Trigger a reflow, flushing the CSS changes
|
||||||
|
el.style.height = el.scrollHeight + 'px'
|
||||||
|
|
||||||
|
el.addEventListener('transitionend', done, { once: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
function onBeforeLeave (el: HTMLElement) {
|
||||||
|
el.style.height = el.scrollHeight + 'px'
|
||||||
|
el.offsetHeight // Trigger a reflow, flushing the CSS changes
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAfterEnter (el: HTMLElement) {
|
||||||
|
el.style.height = 'auto'
|
||||||
|
}
|
||||||
|
|
||||||
|
function onLeave (el: HTMLElement, done) {
|
||||||
|
el.style.height = '0';
|
||||||
|
|
||||||
|
(el as HTMLElement).addEventListener('transitionend', done, { once: true })
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// eslint-disable-next-line vue/no-dupe-keys
|
// eslint-disable-next-line vue/no-dupe-keys
|
||||||
ui,
|
ui,
|
||||||
uiButton,
|
uiButton,
|
||||||
|
onEnter,
|
||||||
|
onBeforeLeave,
|
||||||
|
onAfterEnter,
|
||||||
|
onLeave,
|
||||||
omit
|
omit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user