Skip to content

Commit

Permalink
Refactor #3965 - Refactor on Sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jul 5, 2023
1 parent e65a1ee commit 22498f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
64 changes: 30 additions & 34 deletions components/lib/sidebar/BaseSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import { useStyle } from 'primevue/usestyle';
const styles = `
.p-sidebar-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
justify-content: center;
align-items: center;
pointer-events: none;
background-color: transparent;
transition-property: background-color;
Expand Down Expand Up @@ -91,23 +84,6 @@ const styles = `
transition: opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1);
}
/* Position */
.p-sidebar-left {
justify-content: flex-start;
}
.p-sidebar-right {
justify-content: flex-end;
}
.p-sidebar-top {
align-items: flex-start;
}
.p-sidebar-bottom {
align-items: flex-end;
}
/* Size */
.p-sidebar-left .p-sidebar {
width: 20rem;
Expand Down Expand Up @@ -177,17 +153,36 @@ const styles = `
}
`;
/* Position */
const inlineStyles = {
mask: ({ position }) => ({
position: 'fixed',
height: '100%',
width: '100%',
left: 0,
top: 0,
display: 'flex',
justifyContent: position === 'left' ? 'flex-start' : position === 'right' ? 'flex-end' : 'center',
alignItems: position === 'top' ? 'flex-start' : position === 'bottom' ? 'flex-end' : 'center'
})
};
const classes = {
mask: ({ instance, props }) => [
'p-sidebar-mask',
instance.getPositionClass(),
{
'p-component-overlay p-component-overlay-enter': props.modal,
'p-sidebar-mask-scrollblocker': props.blockScroll,
'p-sidebar-visible': instance.containerVisible,
'p-sidebar-full': instance.fullScreen
}
],
mask: ({ instance, props }) => {
const positions = ['left', 'right', 'top', 'bottom'];
const pos = positions.find((item) => item === props.position);
return [
'p-sidebar-mask',
{
'p-component-overlay p-component-overlay-enter': props.modal,
'p-sidebar-mask-scrollblocker': props.blockScroll,
'p-sidebar-visible': instance.containerVisible,
'p-sidebar-full': instance.fullScreen
},
pos ? `p-sidebar-${pos}` : ''
];
},
root: ({ instance }) => [
'p-sidebar p-component',
{
Expand Down Expand Up @@ -248,6 +243,7 @@ export default {
},
css: {
classes,
inlineStyles,
loadStyle
},
provide() {
Expand Down
8 changes: 1 addition & 7 deletions components/lib/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Portal>
<div v-if="containerVisible" :ref="maskRef" @mousedown="onMaskClick" :class="cx('mask')" v-bind="ptm('mask')">
<div v-if="containerVisible" :ref="maskRef" @mousedown="onMaskClick" :class="cx('mask')" :style="sx('mask', true, { position })" v-bind="ptm('mask')">
<transition name="p-sidebar" @enter="onEnter" @after-enter="onAfterEnter" @before-leave="onBeforeLeave" @leave="onLeave" @after-leave="onAfterLeave" appear>
<div v-if="visible" :ref="containerRef" v-focustrap :class="cx('root')" role="complementary" :aria-modal="modal" @keydown="onKeydown" v-bind="{ ...$attrs, ...ptm('root') }">
<div :ref="headerContainerRef" :class="cx('header')" v-bind="ptm('header')">
Expand Down Expand Up @@ -151,12 +151,6 @@ export default {
closeButtonRef(el) {
this.closeButton = el;
},
getPositionClass() {
const positions = ['left', 'right', 'top', 'bottom'];
const pos = positions.find((item) => item === this.position);
return pos ? `p-sidebar-${pos}` : '';
},
bindOutsideClickListener() {
if (!this.outsideClickListener) {
this.outsideClickListener = (event) => {
Expand Down

0 comments on commit 22498f1

Please sign in to comment.