Skip to content

Replace width to translate #908

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions src/scss/component/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
.sidebarAnimation { transition: width $transitionSidebarTime linear; }

#sidebarToggle {
width: 28px; height: 28px; background-size: 20px; border-radius: 6px; position: fixed; left: 84px; top: 12px; backdrop-filter: blur(20px);
width: 28px; height: 28px; background-size: 20px; border-radius: 6px; position: fixed; top: 12px; backdrop-filter: blur(20px);
background-image: url('~img/icon/widget/toggle0.svg'); z-index: 22; -webkit-app-region: no-drag; transition: none;
}
#sidebarToggle.sidebarAnimation { transition: left $transitionSidebarTime linear; }
#sidebarToggle.sidebarAnimation { transition: transform $transitionSidebarTime linear; }
#sidebarToggle:hover, #sidebarToggle.hover { background-color: var(--color-shape-highlight-medium); background-image: url('~img/icon/widget/toggle1.svg'); }

.sidebar { position: fixed; z-index: 21; user-select: none; transition: none; top: 0px; left: 0px; height: 100%; }
.sidebar.anim { transition-property: width; transition-duration: $transitionSidebarTime; transition-timing-function: linear; }
.sidebar.anim { transition-property: transform; transition-duration: $transitionSidebarTime; transition-timing-function: linear; }
.sidebar.withVault { left: $vaultWidthCollapsed; }
.sidebar.isClosed { left: 0px !important; }

.sidebar {
> .inner { width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden; position: relative; z-index: 1; background-color: var(--color-shape-tertiary); }
Expand Down
4 changes: 2 additions & 2 deletions src/scss/component/vault.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
background-color: var(--color-shape-primary); z-index: 30; width: $vaultWidthCollapsed; height: 100%; display: flex; flex-direction: column;
flex-shrink: 0; position: fixed; left: 0px; top: 0px; overflow: hidden; transform: translate3d(0px, 0px, 0px); transition: none;
}
.vault.isClosed, .vault.isHidden { width: 0px; }
.vault.anim { transition-property: width; transition-timing-function: linear; }
.vault.isClosed, .vault.isHidden { transform: translateX(-100%); }
.vault.anim { transition-property: transform; transition-timing-function: linear; }
.vault {
.head {
height: 50px; display: flex; flex-direction: row; align-items: center; justify-content: flex-end; gap: 0px 8px; padding: 0px 14px; flex-shrink: 0;
Expand Down
44 changes: 20 additions & 24 deletions src/ts/lib/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface SidebarData {
};

class Sidebar {

data: SidebarData = {
width: 0,
isClosed: false,
Expand Down Expand Up @@ -72,9 +71,10 @@ class Sidebar {
};

this.obj.addClass('anim');
this.setElementsWidth(width);

this.setAnimating(true);
this.setStyle({ width: 0 });

this.obj.css({ transform: `translateX(${-width}px)` });
this.set({ isClosed: true });
this.resizePage(0, true);
this.vaultHide();
Expand Down Expand Up @@ -105,7 +105,6 @@ class Sidebar {
this.obj.removeClass('isClosed');
this.obj.addClass('anim');

this.setStyle({ width });
this.set({ isClosed: false });
this.resizePage(width, true);

Expand All @@ -121,9 +120,9 @@ class Sidebar {
if (this.isAnimating) {
return;
};

const { width, isClosed } = this.data;

isClosed ? this.open(width) : this.close();
};

Expand Down Expand Up @@ -172,7 +171,7 @@ class Sidebar {
const { x } = keyboard.mouse.page;
const { width, isClosed } = this.data;
const vw = isClosed || !showVault ? 0 : J.Size.vault.width;
const menuOpen = S.Menu.isOpenList([ 'dataviewContext', 'widget', 'selectSidebarToggle' ]);
const menuOpen = S.Menu.isOpenList(['dataviewContext', 'widget', 'selectSidebarToggle']);
const popupOpen = S.Popup.isOpen();

let show = false;
Expand Down Expand Up @@ -216,18 +215,18 @@ class Sidebar {
const { showVault, isFullScreen } = S.Common;
const { ww } = U.Common.getWindowDimensions();
const vw = isClosed || !showVault || !keyboard.isMain() ? 0 : J.Size.vault.width;
const pageWidth = ww - width - vw;
const pageWidth = ww - (isClosed ? 0 : (width + vw));
const ho = keyboard.isMainHistory() ? J.Size.history.panel : 0;
const navigation = S.Common.getRef('navigation');
let toggleX = width ? width - 40 + (showVault ? vw : 0) : 84;

let toggleX = width && !isClosed ? width - 40 + (showVault ? vw : 0) : 84;
if (!width && (isFullScreen || !U.Common.isPlatformMac())) {
toggleX -= 68;
};

this.header.css({ width: '' }).removeClass('withSidebar');
this.footer.css({ width: '' });
this.dummy.css({ width: width + vw });
this.dummy.css({ width: isClosed ? 0 : width + vw });

if (animate) {
this.header.addClass('sidebarAnimation');
Expand All @@ -244,13 +243,13 @@ class Sidebar {
};

navigation?.setX(width + vw, animate);
width ? this.header.addClass('withSidebar') : this.header.removeClass('withSidebar');
width && !isClosed ? this.header.addClass('withSidebar') : this.header.removeClass('withSidebar');

this.page.css({ width: pageWidth });
this.loader.css({ width: pageWidth, right: 0 });
this.header.css({ width: pageWidth - ho });
this.footer.css({ width: pageWidth - ho });
this.toggleButton.css({ left: toggleX });
this.toggleButton.css({ transform: `translateX(${toggleX}px)` });

$(window).trigger('sidebarResize');
};
Expand All @@ -264,7 +263,7 @@ class Sidebar {

const { width } = v;

this.data = Object.assign<SidebarData, Partial<SidebarData>>(this.data, {
this.data = Object.assign<SidebarData, Partial<SidebarData>>(this.data, {
width: this.limitWidth(width),
});

Expand All @@ -280,8 +279,9 @@ class Sidebar {
if (!this.obj || !this.obj.length) {
return;
};

this.obj.css({ width: v.isClosed ? 0 : v.width });
const { showVault } = S.Common;
let transX = v.isClosed ? -v.width - (showVault ? J.Size.vault.width : 0) : 0;
this.obj.css({ width: v.width, transform: `translateX(${transX}px)` });
};

/**
Expand All @@ -298,22 +298,18 @@ class Sidebar {

vaultHide () {
this.vault.addClass('anim');
this.setVaultAnimationParam(this.data.width, true);
this.setVaultAnimationParam(this.data.width);
this.vault.addClass('isClosed');
};

vaultShow (width: number) {
this.vault.addClass('anim');
this.setVaultAnimationParam(width, false);
this.setVaultAnimationParam(width);
this.vault.removeClass('isClosed');
};

setVaultAnimationParam (width: number, withDelay: boolean) {
const css: any = { transitionDuration: `${this.getVaultDuration(width)}ms`, transitionDelay: '' };

if (withDelay) {
css.transitionDelay = `${J.Constant.delay.sidebar}ms`;
};
setVaultAnimationParam (width: number) {
const css: any = { transitionDuration: `${this.getVaultDuration(width)}ms`, transitionDelay: `${J.Constant.delay.sidebar}ms` };

this.vault.css(css);
};
Expand Down
Loading