mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-10 09:22:34 +00:00
Refactor #3965 - Refactor on Sidebar
This commit is contained in:
parent
e65a1ee1d4
commit
22498f1e61
2 changed files with 31 additions and 41 deletions
|
@ -4,14 +4,7 @@ import { useStyle } from 'primevue/usestyle';
|
||||||
|
|
||||||
const styles = `
|
const styles = `
|
||||||
.p-sidebar-mask {
|
.p-sidebar-mask {
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: none;
|
display: none;
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
transition-property: background-color;
|
transition-property: background-color;
|
||||||
|
@ -91,23 +84,6 @@ const styles = `
|
||||||
transition: opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1);
|
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 */
|
/* Size */
|
||||||
.p-sidebar-left .p-sidebar {
|
.p-sidebar-left .p-sidebar {
|
||||||
width: 20rem;
|
width: 20rem;
|
||||||
|
@ -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 = {
|
const classes = {
|
||||||
mask: ({ instance, props }) => [
|
mask: ({ instance, props }) => {
|
||||||
'p-sidebar-mask',
|
const positions = ['left', 'right', 'top', 'bottom'];
|
||||||
instance.getPositionClass(),
|
const pos = positions.find((item) => item === props.position);
|
||||||
{
|
|
||||||
'p-component-overlay p-component-overlay-enter': props.modal,
|
return [
|
||||||
'p-sidebar-mask-scrollblocker': props.blockScroll,
|
'p-sidebar-mask',
|
||||||
'p-sidebar-visible': instance.containerVisible,
|
{
|
||||||
'p-sidebar-full': instance.fullScreen
|
'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 }) => [
|
root: ({ instance }) => [
|
||||||
'p-sidebar p-component',
|
'p-sidebar p-component',
|
||||||
{
|
{
|
||||||
|
@ -248,6 +243,7 @@ export default {
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
classes,
|
classes,
|
||||||
|
inlineStyles,
|
||||||
loadStyle
|
loadStyle
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<Portal>
|
<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>
|
<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 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')">
|
<div :ref="headerContainerRef" :class="cx('header')" v-bind="ptm('header')">
|
||||||
|
@ -151,12 +151,6 @@ export default {
|
||||||
closeButtonRef(el) {
|
closeButtonRef(el) {
|
||||||
this.closeButton = 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() {
|
bindOutsideClickListener() {
|
||||||
if (!this.outsideClickListener) {
|
if (!this.outsideClickListener) {
|
||||||
this.outsideClickListener = (event) => {
|
this.outsideClickListener = (event) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue