From fcf8599cfae67b6bb17d2bb77df5945179c0864e Mon Sep 17 00:00:00 2001 From: tugcekucukoglu Date: Thu, 18 Apr 2024 17:19:35 +0300 Subject: [PATCH] Refactor #5612 - Sidebar / Drawer --- .../BaseSidebar.vue => drawer/BaseDrawer.vue} | 6 +- components/lib/drawer/Drawer.d.ts | 285 ++++++++++++++++++ .../Sidebar.spec.js => drawer/Drawer.spec.js} | 19 +- components/lib/drawer/Drawer.vue | 225 ++++++++++++++ components/lib/drawer/package.json | 9 + components/lib/drawer/style/DrawerStyle.d.ts | 3 + components/lib/drawer/style/DrawerStyle.js | 48 +++ components/lib/drawer/style/package.json | 6 + components/lib/sidebar/Sidebar.d.ts | 239 +-------------- components/lib/sidebar/Sidebar.vue | 222 +------------- .../lib/sidebar/style/SidebarStyle.d.ts | 4 +- components/lib/sidebar/style/SidebarStyle.js | 45 +-- .../base/{sidebar => drawer}/index.js | 6 +- .../base/{sidebar => drawer}/package.json | 0 .../presets/aura/{sidebar => drawer}/index.js | 0 .../aura/{sidebar => drawer}/package.json | 0 16 files changed, 614 insertions(+), 503 deletions(-) rename components/lib/{sidebar/BaseSidebar.vue => drawer/BaseDrawer.vue} (92%) create mode 100755 components/lib/drawer/Drawer.d.ts rename components/lib/{sidebar/Sidebar.spec.js => drawer/Drawer.spec.js} (87%) create mode 100755 components/lib/drawer/Drawer.vue create mode 100644 components/lib/drawer/package.json create mode 100644 components/lib/drawer/style/DrawerStyle.d.ts create mode 100644 components/lib/drawer/style/DrawerStyle.js create mode 100644 components/lib/drawer/style/package.json mode change 100755 => 100644 components/lib/sidebar/Sidebar.vue rename components/lib/themes/primeone/base/{sidebar => drawer}/index.js (95%) rename components/lib/themes/primeone/base/{sidebar => drawer}/package.json (100%) rename components/lib/themes/primeone/presets/aura/{sidebar => drawer}/index.js (100%) rename components/lib/themes/primeone/presets/aura/{sidebar => drawer}/package.json (100%) diff --git a/components/lib/sidebar/BaseSidebar.vue b/components/lib/drawer/BaseDrawer.vue similarity index 92% rename from components/lib/sidebar/BaseSidebar.vue rename to components/lib/drawer/BaseDrawer.vue index f36650cba..db63751bf 100644 --- a/components/lib/sidebar/BaseSidebar.vue +++ b/components/lib/drawer/BaseDrawer.vue @@ -1,9 +1,9 @@ diff --git a/components/lib/drawer/package.json b/components/lib/drawer/package.json new file mode 100644 index 000000000..4207f23ab --- /dev/null +++ b/components/lib/drawer/package.json @@ -0,0 +1,9 @@ +{ + "main": "./drawer.cjs.js", + "module": "./drawer.esm.js", + "unpkg": "./drawer.min.js", + "types": "./Drawer.d.ts", + "browser": { + "./sfc": "./Drawer.vue" + } +} diff --git a/components/lib/drawer/style/DrawerStyle.d.ts b/components/lib/drawer/style/DrawerStyle.d.ts new file mode 100644 index 000000000..90c0e7732 --- /dev/null +++ b/components/lib/drawer/style/DrawerStyle.d.ts @@ -0,0 +1,3 @@ +import { BaseStyle } from '../../base/style'; + +export interface DrawerStyle extends BaseStyle {} diff --git a/components/lib/drawer/style/DrawerStyle.js b/components/lib/drawer/style/DrawerStyle.js new file mode 100644 index 000000000..c8c54202f --- /dev/null +++ b/components/lib/drawer/style/DrawerStyle.js @@ -0,0 +1,48 @@ +import BaseStyle from 'primevue/base/style'; + +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 }) => { + const positions = ['left', 'right', 'top', 'bottom']; + const pos = positions.find((item) => item === props.position); + + return [ + 'p-drawer-mask', + { + 'p-component-overlay p-component-overlay-enter': props.modal, + 'p-drawer-open': instance.containerVisible, + 'p-drawer-full': instance.fullScreen + }, + pos ? `p-drawer-${pos}` : '' + ]; + }, + root: ({ instance }) => [ + 'p-drawer p-component', + { + 'p-ripple-disabled': instance.$primevue.config.ripple === false, + 'p-drawer-full': instance.fullScreen + } + ], + header: 'p-drawer-header', + title: 'p-drawer-title', + closeButton: 'p-drawer-close-button', + content: 'p-drawer-content' +}; + +export default BaseStyle.extend({ + name: 'drawer', + classes, + inlineStyles +}); diff --git a/components/lib/drawer/style/package.json b/components/lib/drawer/style/package.json new file mode 100644 index 000000000..d8d50d065 --- /dev/null +++ b/components/lib/drawer/style/package.json @@ -0,0 +1,6 @@ +{ + "main": "./drawerstyle.cjs.js", + "module": "./drawerstyle.esm.js", + "unpkg": "./drawerstyle.min.js", + "types": "./DrawerStyle.d.ts" +} diff --git a/components/lib/sidebar/Sidebar.d.ts b/components/lib/sidebar/Sidebar.d.ts index 7b4a110b2..627ed3f01 100755 --- a/components/lib/sidebar/Sidebar.d.ts +++ b/components/lib/sidebar/Sidebar.d.ts @@ -2,273 +2,64 @@ * * Sidebar is a panel component displayed as an overlay at the edges of the screen. * - * [Live Demo](https://primevue.org/sidebar) + * [Live Demo](https://primevue.org/drawer) * * @module sidebar * */ -import { TransitionProps, VNode } from 'vue'; -import { ComponentHooks } from '../basecomponent'; -import { ButtonPassThroughOptions } from '../button'; -import { PassThroughOptions } from '../passthrough'; -import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers'; - -export declare type SidebarPassThroughOptionType = SidebarPassThroughAttributes | ((options: SidebarPassThroughMethodOptions) => SidebarPassThroughAttributes | string) | string | null | undefined; - -export declare type SidebarPassThroughTransitionType = TransitionProps | ((options: SidebarPassThroughMethodOptions) => TransitionProps) | undefined; +import 'vue'; +import * as Drawer from '../drawer'; +import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; /** * Custom passthrough(pt) option method. */ -export interface SidebarPassThroughMethodOptions { - /** - * Defines instance. - */ - instance: any; - /** - * Defines valid properties. - */ - props: SidebarProps; - /** - * Defines current inline state. - */ - state: SidebarState; - /** - * Defines valid attributes. - */ - attrs: any; - /** - * Defines parent options. - */ - parent: any; - /** - * Defines passthrough(pt) options in global config. - */ - global: object | undefined; -} +export interface SidebarPassThroughMethodOptions extends Drawer.DrawerPassThroughMethodOptions {} /** * Custom shared passthrough(pt) option method. */ -export interface SidebarSharedPassThroughMethodOptions { - /** - * Defines valid properties. - */ - props: SidebarProps; - /** - * Defines current inline state. - */ - state: SidebarState; -} +export interface SidebarSharedPassThroughMethodOptions extends Drawer.DrawerSharedPassThroughMethodOptions {} /** * Custom passthrough(pt) options. * @see {@link SidebarProps.pt} */ -export interface SidebarPassThroughOptions { - /** - * Used to pass attributes to the root's DOM element. - */ - root?: SidebarPassThroughOptionType; - /** - * Used to pass attributes to the header's DOM element. - */ - header?: SidebarPassThroughOptionType; - /** - * Used to pass attributes to the header content's DOM element. - */ - title?: SidebarPassThroughOptionType; - /** - * Used to pass attributes to the previous button's DOM element. - * @see {@link ButtonPassThroughOptions} - */ - toggler?: ButtonPassThroughOptions; - /** - * Used to pass attributes to the content's DOM element. - */ - content?: SidebarPassThroughOptionType; - /** - * Used to pass attributes to the mask's DOM element. - */ - mask?: SidebarPassThroughOptionType; - /** - * Used to manage all lifecycle hooks. - * @see {@link BaseComponent.ComponentHooks} - */ - hooks?: ComponentHooks; - /** - * Used to control Vue Transition API. - */ - transition?: SidebarPassThroughTransitionType; -} +export interface SidebarPassThroughOptions extends Drawer.DrawerPassThroughOptions {} /** * Custom passthrough attributes for each DOM elements */ -export interface SidebarPassThroughAttributes { - [key: string]: any; -} +export interface SidebarPassThroughAttributes extends Drawer.DrawerPassThroughAttributes {} /** * Defines current inline state in Sidebar component. */ -export interface SidebarState { - /** - * Current container visible state as a boolean. - * @defaultValue false - */ - containerVisible: boolean; -} +export interface SidebarState extends Drawer.DrawerState {} /** * Defines valid properties in Sidebar component. */ -export interface SidebarProps { - /** - * Specifies the visibility of the dialog. - * @defaultValue false - */ - visible?: boolean | undefined; - /** - * Specifies the position of the sidebar. - * @defaultValue left - */ - position?: 'left' | 'right' | 'top' | 'bottom' | 'full' | undefined; - /** - * Title content of the dialog. - */ - header?: string | undefined; - /** - * Base zIndex value to use in layering. - * @defaultValue 0 - */ - baseZIndex?: number | undefined; - /** - * Whether to automatically manage layering. - * @defaultValue true - */ - autoZIndex?: boolean | undefined; - /** - * Whether clicking outside closes the panel. - * @defaultValue true - */ - dismissable?: boolean | undefined; - /** - * Whether to display a close icon inside the panel. - * @defaultValue true - */ - showCloseIcon?: boolean | undefined; - /** - * Used to pass the custom value to read for the button inside the component. - * @defaultValue { severity: 'secondary', text: true, rounded: true } - */ - closeButtonProps?: object | undefined; - /** - * Icon to display in the sidebar close button. - * @deprecated since v3.27.0. Use 'closeicon' slot. - */ - closeIcon?: string | undefined; - /** - * Whether to a modal layer behind the sidebar. - * @defaultValue true - */ - modal?: boolean | undefined; - /** - * Whether background scroll should be blocked when sidebar is visible. - * @defaultValue false - */ - blockScroll?: boolean | undefined; - /** - * It generates scoped CSS variables using design tokens for the component. - */ - dt?: DesignToken; - /** - * Used to pass attributes to DOM elements inside the component. - * @type {SidebarPassThroughOptions} - */ - pt?: PassThrough; - /** - * Used to configure passthrough(pt) options of the component. - * @type {PassThroughOptions} - */ - ptOptions?: PassThroughOptions; - /** - * When enabled, it removes component related styles in the core. - * @defaultValue false - */ - unstyled?: boolean; -} +export interface SidebarProps extends Drawer.DrawerProps {} /** * Defines valid slots in Sidebar component. */ -export interface SidebarSlots { - /** - * Custom content template. - */ - default(): VNode[]; - /** - * Custom header template. - * @param {Object} scope - header slot's params. - */ - header(scope: { - /** - * Style class of the header title - */ - class: any; - }): VNode[]; - /** - * Custom close icon template. - * @param {Object} scope - close icon slot's params. - */ - closeicon(scope: { - /** - * Style class of the close icon - */ - class: any; - }): VNode[]; - /** - * Custom container slot. - * @param {Object} scope - container slot's params. - */ - container(scope: { - /** - * Close sidebar function. - * @deprecated since v3.39.0. Use 'closeCallback' property instead. - */ - onClose: () => void; - /** - * Close sidebar function. - */ - closeCallback: () => void; - }): VNode[]; -} +export interface SidebarSlots extends Drawer.DrawerSlots {} /** * Defines valid emits in Sidebar component. */ -export interface SidebarEmits { - /** - * Emitted when the value changes. - * @param {boolean} value - New value. - */ - 'update:modelValue'(value: boolean): void; - /** - * Callback to invoke when sidebar gets shown. - */ - show(): void; - /** - * Callback to invoke when sidebar gets hidden. - */ - hide(): void; -} +export interface SidebarEmits extends Drawer.DrawerEmits {} /** + * @deprecated Deprecated since v4. Use Drawer component instead. + * * **PrimeVue - Sidebar** * * _Sidebar is a panel component displayed as an overlay._ * - * [Live Demo](https://www.primevue.org/sidebar/) + * [Live Demo](https://www.primevue.org/drawer/) * --- --- * ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png) * diff --git a/components/lib/sidebar/Sidebar.vue b/components/lib/sidebar/Sidebar.vue old mode 100755 new mode 100644 index 5a6e2edac..eaa658f8d --- a/components/lib/sidebar/Sidebar.vue +++ b/components/lib/sidebar/Sidebar.vue @@ -1,225 +1,11 @@ - - diff --git a/components/lib/sidebar/style/SidebarStyle.d.ts b/components/lib/sidebar/style/SidebarStyle.d.ts index 20bd1c2bf..8c10b3b40 100644 --- a/components/lib/sidebar/style/SidebarStyle.d.ts +++ b/components/lib/sidebar/style/SidebarStyle.d.ts @@ -1,3 +1,3 @@ -import { BaseStyle } from '../../base/style'; +import { DrawerStyle } from '../../drawer/style/DrawerStyle'; -export interface SidebarStyle extends BaseStyle {} +export interface SidebarStyle extends DrawerStyle {} diff --git a/components/lib/sidebar/style/SidebarStyle.js b/components/lib/sidebar/style/SidebarStyle.js index f997688a8..c998bcddf 100644 --- a/components/lib/sidebar/style/SidebarStyle.js +++ b/components/lib/sidebar/style/SidebarStyle.js @@ -1,48 +1,5 @@ import BaseStyle from 'primevue/base/style'; -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 }) => { - const positions = ['left', 'right', 'top', 'bottom']; - const pos = positions.find((item) => item === props.position); - - return [ - 'p-drawer-mask', - { - 'p-component-overlay p-component-overlay-enter': props.modal, - 'p-drawer-open': instance.containerVisible, - 'p-drawer-full': instance.fullScreen - }, - pos ? `p-drawer-${pos}` : '' - ]; - }, - root: ({ instance }) => [ - 'p-drawer p-component', - { - 'p-ripple-disabled': instance.$primevue.config.ripple === false, - 'p-drawer-full': instance.fullScreen - } - ], - header: 'p-drawer-header', - title: 'p-drawer-title', - closeButton: 'p-drawer-close-button', - content: 'p-drawer-content' -}; - export default BaseStyle.extend({ - name: 'sidebar', - classes, - inlineStyles + name: 'sidebar' }); diff --git a/components/lib/themes/primeone/base/sidebar/index.js b/components/lib/themes/primeone/base/drawer/index.js similarity index 95% rename from components/lib/themes/primeone/base/sidebar/index.js rename to components/lib/themes/primeone/base/drawer/index.js index f6c748161..b5cf974d7 100644 --- a/components/lib/themes/primeone/base/sidebar/index.js +++ b/components/lib/themes/primeone/base/drawer/index.js @@ -7,9 +7,9 @@ export default { transform: translate3d(0px, 0px, 0px); position: relative; transition: transform 0.3s; - background: ${dt('sidebar.background')}; - color: ${dt('sidebar.color')}; - border: 1px solid ${dt('sidebar.border.color')}; + background: ${dt('drawer.background')}; + color: ${dt('drawer.color')}; + border: 1px solid ${dt('drawer.border.color')}; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1); } diff --git a/components/lib/themes/primeone/base/sidebar/package.json b/components/lib/themes/primeone/base/drawer/package.json similarity index 100% rename from components/lib/themes/primeone/base/sidebar/package.json rename to components/lib/themes/primeone/base/drawer/package.json diff --git a/components/lib/themes/primeone/presets/aura/sidebar/index.js b/components/lib/themes/primeone/presets/aura/drawer/index.js similarity index 100% rename from components/lib/themes/primeone/presets/aura/sidebar/index.js rename to components/lib/themes/primeone/presets/aura/drawer/index.js diff --git a/components/lib/themes/primeone/presets/aura/sidebar/package.json b/components/lib/themes/primeone/presets/aura/drawer/package.json similarity index 100% rename from components/lib/themes/primeone/presets/aura/sidebar/package.json rename to components/lib/themes/primeone/presets/aura/drawer/package.json