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

feat(Slideover): handle top and bottom side #1834

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 46 additions & 7 deletions src/runtime/components/overlays/Slideover.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<TransitionRoot as="template" :appear="appear" :show="isOpen" @after-leave="onAfterLeave">
<HDialog :class="[ui.wrapper, { 'justify-end': side === 'right' }]" v-bind="attrs" @close="close">
<HDialog :class="[ui.wrapper, { 'justify-end': side === 'right' }, { 'items-end': side === 'bottom' }]" v-bind="attrs" @close="close">
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
<div :class="[ui.overlay.base, ui.overlay.background]" />
</TransitionChild>

<TransitionChild as="template" :appear="appear" v-bind="transitionClass">
<HDialogPanel :class="[ui.base, ui.width, ui.background, ui.ring, ui.padding]">
<HDialogPanel :class="[ui.base, sideType === 'horizontal' ? [ui.width, 'h-full'] : [ui.height, 'w-full'], ui.background, ui.ring, ui.padding]">
<slot />
</HDialogPanel>
</TransitionChild>
Expand Down Expand Up @@ -46,9 +46,9 @@ export default defineComponent({
default: false
},
side: {
type: String as PropType<'left' | 'right'>,
type: String as PropType<'left' | 'right' | 'top' | 'bottom'>,
default: 'right',
validator: (value: string) => ['left', 'right'].includes(value)
validator: (value: string) => ['left', 'right', 'top', 'bottom'].includes(value)
},
overlay: {
type: Boolean,
Expand Down Expand Up @@ -89,14 +89,52 @@ export default defineComponent({
return {}
}

let enterFrom, leaveTo
switch (props.side) {
case 'left':
enterFrom = ui.value.translate.left
leaveTo = ui.value.translate.left
break
case 'right':
enterFrom = ui.value.translate.right
leaveTo = ui.value.translate.right
break
case 'top':
enterFrom = ui.value.translate.top
leaveTo = ui.value.translate.top
break
case 'bottom':
enterFrom = ui.value.translate.bottom
leaveTo = ui.value.translate.bottom
break
default:
enterFrom = ui.value.translate.right
leaveTo = ui.value.translate.right
}

return {
...ui.value.transition,
enterFrom: props.side === 'left' ? ui.value.translate.left : ui.value.translate.right,
enterFrom,
enterTo: ui.value.translate.base,
leaveFrom: ui.value.translate.base,
leaveTo: props.side === 'left' ? ui.value.translate.left : ui.value.translate.right
leaveTo
}
})
const sideType = computed(() => {
switch (props.side) {
case 'left':
return 'horizontal'
case 'right':
return 'horizontal'
case 'top':
return 'vertical'
case 'bottom':
return 'vertical'
default:
return 'right'
}
})


function close (value: boolean) {
if (props.preventClose) {
Expand All @@ -121,9 +159,10 @@ export default defineComponent({
attrs,
isOpen,
transitionClass,
sideType,
onAfterLeave,
close
}
}
})
</script>
</script>
5 changes: 4 additions & 1 deletion src/runtime/ui.config/overlays/slideover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ export default {
padding: '',
shadow: 'shadow-xl',
width: 'w-screen max-w-md',
height: 'h-screen max-h-96',
translate: {
base: 'translate-x-0',
left: '-translate-x-full rtl:translate-x-full',
right: 'translate-x-full rtl:-translate-x-full'
right: 'translate-x-full rtl:-translate-x-full',
top: '-translate-y-full',
bottom: 'translate-y-full'
},
// Syntax for `<TransitionRoot>` component https://headlessui.com/vue/transition#basic-example
transition: {
Expand Down
Loading