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(UI): Overflow menu (Switch from scroll button to dropdown) #10124

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 0 additions & 4 deletions browser/css/jsdialogs.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ div#autoFillPreviewTooltip .lokdialog.ui-dialog-content.ui-widget-content {
vertical-align: middle;
}

.jsdialog.vertical:not(.sidebar):not(.ui-separator) {
width: 100%;
}

th.jsdialog:not(:first-child) {
padding-inline-end: 24px;
}
Expand Down
16 changes: 16 additions & 0 deletions browser/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@
margin: 0px;
}

/* overflow menu */
.menu-overflow-wrapper {
position: absolute;
height: var(--header-height);
top: var(--header-height);
display: flex;
background-color: var(--color-background-lighter);
border: 1px solid var(--color-toolbar-border);
align-items: center;
border-radius: 4px;
padding: 0 4px;
box-shadow: 0 2px 6px 2px rgba(60, 64, 67, .15);
opacity: 0;
pointer-events: none;
}

/* status bar / mobile bottom bar */

#toolbar-down .ui-badge {
Expand Down
70 changes: 70 additions & 0 deletions browser/images/dark/lc_menuoverflow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions browser/images/lc_menuoverflow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 113 additions & 3 deletions browser/src/control/Control.TopToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class TopToolbar extends JSDialog.Toolbar {
{type: 'customtoolitem', id: 'insertannotation', text: _UNO('.uno:InsertAnnotation', '', true), visible: false, lockUno: '.uno:InsertAnnotation'},
{type: 'customtoolitem', id: 'inserthyperlink', command: 'inserthyperlink', text: _UNO('.uno:HyperlinkDialog', '', true), lockUno: '.uno:HyperlinkDialog'},
{type: 'toolitem', id: 'insertsymbol', text: _UNO('.uno:InsertSymbol', '', true), command: '.uno:InsertSymbol'},
{type: 'customtoolitem', id: 'menuoverflow', text: _('More'), desktop: true, mobile: false, visible: true},
{type: 'spacer', id: 'topspacer'},
{type: 'separator', orientation: 'vertical', id: 'breaksidebar', visible: false},
{type: 'toolitem', id: 'sidebar', text: _UNO('.uno:Sidebar', '', true), command: '.uno:SidebarDeck.PropertyDeck', visible: false},
Expand Down Expand Up @@ -228,14 +229,123 @@ class TopToolbar extends JSDialog.Toolbar {
}
}

createOverflowMenu() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, would be also good to use our helper for popups: https://github.com/CollaboraOnline/online/blob/master/browser/src/control/jsdialog/Util.Dropdown.js#L22

example usage:

JSDialog.OpenDropdown(

const topBarMenu = this.parentContainer.querySelector(
'.root-container .vertical',
);

const overflowMenu = L.DomUtil.create(
'div',
'menu-overflow-wrapper',
this.parentContainer,
);

const overflowMenuButton =
this.parentContainer.querySelector('#menuoverflow');

const showOverflowMenu = () => {
overflowMenu.style.opacity = 1;
overflowMenu.style.pointerEvents = 'revert';
L.DomUtil.addClass(overflowMenuButton, 'selected');
};

const hideOverflowMenu = () => {
overflowMenu.style.opacity = 0;
overflowMenu.style.pointerEvents = 'none';
L.DomUtil.removeClass(overflowMenuButton, 'selected');
};

overflowMenuButton.addEventListener('click', () => {
if (
overflowMenu.style.opacity === '0' ||
overflowMenu.style.opacity === ''
) {
showOverflowMenu();
} else {
hideOverflowMenu();
}
});

const breakSidebar = this.parentContainer.querySelector('#breaksidebar');
const foldButton = this.parentContainer.querySelector('#fold');

const getMenuWidth = () => {
const splitPosition =
foldButton.offsetLeft +
foldButton.offsetWidth * 2 -
breakSidebar.offsetLeft;
return window.innerWidth - splitPosition;
};

let overflowMenuDebounced = 0;
const originalTopbar = topBarMenu.querySelectorAll('.jsdialog');

const overflowMenuHandler = () => {
overflowMenuDebounced && clearTimeout(overflowMenuDebounced);

hideOverflowMenu();

overflowMenuDebounced = setTimeout(() => {
topBarMenu.replaceChildren(...originalTopbar);

const topBarButtons = topBarMenu.querySelectorAll('.jsdialog:not(.hidden)');
const menuWidth = getMenuWidth();

const overflowMenuOffscreen = document.createElement('div');
overflowMenuOffscreen.className = 'menu-overfow-vertical';

let section = [];
let overflow = false;

const appendSection = () => {
for (const element of section) {
overflowMenuOffscreen.appendChild(element);
}
section.length = 0;
};

for (const button of topBarButtons) {
if (button.id === 'topspacer' || button.id === 'menuoverflow') {
break;
}

if (button.offsetLeft > menuWidth || overflow) {
overflow = true;
appendSection();
overflowMenuOffscreen.appendChild(button);
} else if (button.className.includes('vertical')) {
section = [button];
} else {
section.push(button);
}
}

overflowMenu.replaceChildren(overflowMenuOffscreen);

if (overflowMenuOffscreen.children.length <= 0) {
overflowMenuButton.style.display = 'none';
} else {
overflowMenuButton.style.display = 'revert';
}

overflowMenu.style.left =
overflowMenuButton.offsetLeft -
overflowMenu.clientWidth +
overflowMenuButton.offsetWidth +
'px';
}, 250);
};

window.addEventListener('resize', overflowMenuHandler);
}

create() {
this.reset();

var items = this.getToolItems();
this.builder.build(this.parentContainer, items);

JSDialog.MakeScrollable(this.parentContainer, this.parentContainer.querySelector('div'));
JSDialog.RefreshScrollables();
this.createOverflowMenu();

if (this.map.isRestrictedUser()) {
for (var i = 0; i < items.length; i++) {
Expand All @@ -260,7 +370,7 @@ class TopToolbar extends JSDialog.Toolbar {
this.onDocLayerInit();

// if app opens direct in compact mode then we need to set the saveState first
this.map.saveState = new app.definitions.saveState(this.map);
this.map.saveState = new app.definitions.saveState(this.map);
}

onDocLayerInit() {
Expand Down
Loading