Skip to content

Commit 33f523a

Browse files
author
Maks Wolkowinski
committed
feat(UI): Overflow menu (Switch from scroll button to dropdown)
Signed-off-by: Maks Wolkowinski <[email protected]> Change-Id: I80c76c9511ceec9d3e46a261ce8ffefc1d5aa477
1 parent e8eef98 commit 33f523a

File tree

5 files changed

+269
-8
lines changed

5 files changed

+269
-8
lines changed

browser/css/jsdialogs.css

-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@
152152
vertical-align: middle;
153153
}
154154

155-
.jsdialog.vertical:not(.sidebar):not(.ui-separator) {
156-
width: 100%;
157-
}
158-
159155
th.jsdialog:not(:first-child) {
160156
padding-inline-end: 24px;
161157
}

browser/css/toolbar.css

+16
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@
6060
margin: 0px;
6161
}
6262

63+
/* overflow menu */
64+
.menu-overflow-wrapper {
65+
position: absolute;
66+
height: var(--header-height);
67+
top: var(--header-height);
68+
display: flex;
69+
background-color: var(--color-background-lighter);
70+
border: 1px solid var(--color-toolbar-border);
71+
align-items: center;
72+
border-radius: 4px;
73+
padding: 0 4px;
74+
box-shadow: 0 2px 6px 2px rgba(60, 64, 67, .15);
75+
opacity: 0;
76+
pointer-events: none;
77+
}
78+
6379
/* status bar / mobile bottom bar */
6480

6581
#toolbar-down .ui-badge {
+70
Loading

browser/images/lc_menuoverflow.svg

+70
Loading

browser/src/control/Control.TopToolbar.js

+113-4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class TopToolbar extends JSDialog.Toolbar {
188188
{type: 'customtoolitem', id: 'insertannotation', text: _UNO('.uno:InsertAnnotation', '', true), visible: false, lockUno: '.uno:InsertAnnotation'},
189189
{type: 'customtoolitem', id: 'inserthyperlink', command: 'inserthyperlink', text: _UNO('.uno:HyperlinkDialog', '', true), lockUno: '.uno:HyperlinkDialog'},
190190
{type: 'toolitem', id: 'insertsymbol', text: _UNO('.uno:InsertSymbol', '', true), command: '.uno:InsertSymbol'},
191+
{type: 'customtoolitem', id: 'menuoverflow', text: _('More'), desktop: true, mobile: false, visible: true},
191192
{type: 'spacer', id: 'topspacer'},
192193
{type: 'separator', orientation: 'vertical', id: 'breaksidebar', visible: false},
193194
{type: 'toolitem', id: 'sidebar', text: _UNO('.uno:Sidebar', '', true), command: '.uno:SidebarDeck.PropertyDeck', visible: false},
@@ -226,14 +227,123 @@ class TopToolbar extends JSDialog.Toolbar {
226227
}
227228
}
228229

230+
createOverflowMenu() {
231+
const topBarMenu = this.parentContainer.querySelector(
232+
'.root-container .vertical',
233+
);
234+
235+
const overflowMenu = L.DomUtil.create(
236+
'div',
237+
'menu-overflow-wrapper',
238+
this.parentContainer,
239+
);
240+
241+
const overflowMenuButton =
242+
this.parentContainer.querySelector('#menuoverflow');
243+
244+
const showOverflowMenu = () => {
245+
overflowMenu.style.opacity = 1;
246+
overflowMenu.style.pointerEvents = 'revert';
247+
L.DomUtil.addClass(overflowMenuButton, 'selected');
248+
};
249+
250+
const hideOverflowMenu = () => {
251+
overflowMenu.style.opacity = 0;
252+
overflowMenu.style.pointerEvents = 'none';
253+
L.DomUtil.removeClass(overflowMenuButton, 'selected');
254+
};
255+
256+
overflowMenuButton.addEventListener('click', () => {
257+
if (
258+
overflowMenu.style.opacity === '0' ||
259+
overflowMenu.style.opacity === ''
260+
) {
261+
showOverflowMenu();
262+
} else {
263+
hideOverflowMenu();
264+
}
265+
});
266+
267+
const breakSidebar = this.parentContainer.querySelector('#breaksidebar');
268+
const foldButton = this.parentContainer.querySelector('#fold');
269+
270+
const getMenuWidth = () => {
271+
const splitPosition =
272+
foldButton.offsetLeft +
273+
foldButton.offsetWidth * 2 -
274+
breakSidebar.offsetLeft;
275+
return window.innerWidth - splitPosition;
276+
};
277+
278+
let overflowMenuDebounced = 0;
279+
const originalTopbar = topBarMenu.querySelectorAll('.jsdialog');
280+
281+
const overflowMenuHandler = () => {
282+
overflowMenuDebounced && clearTimeout(overflowMenuDebounced);
283+
284+
hideOverflowMenu();
285+
286+
overflowMenuDebounced = setTimeout(() => {
287+
topBarMenu.replaceChildren(...originalTopbar);
288+
289+
const topBarButtons = topBarMenu.querySelectorAll('.jsdialog:not(.hidden)');
290+
const menuWidth = getMenuWidth();
291+
292+
const overflowMenuOffscreen = document.createElement('div');
293+
overflowMenuOffscreen.className = 'menu-overfow-vertical';
294+
295+
let section = [];
296+
let overflow = false;
297+
298+
const appendSection = () => {
299+
for (const element of section) {
300+
overflowMenuOffscreen.appendChild(element);
301+
}
302+
section.length = 0;
303+
};
304+
305+
for (const button of topBarButtons) {
306+
if (button.id === 'topspacer' || button.id === 'menuoverflow') {
307+
break;
308+
}
309+
310+
if (button.offsetLeft > menuWidth || overflow) {
311+
overflow = true;
312+
appendSection();
313+
overflowMenuOffscreen.appendChild(button);
314+
} else if (button.className.includes('vertical')) {
315+
section = [button];
316+
} else {
317+
section.push(button);
318+
}
319+
}
320+
321+
overflowMenu.replaceChildren(overflowMenuOffscreen);
322+
323+
if (overflowMenuOffscreen.children.length <= 0) {
324+
overflowMenuButton.style.display = 'none';
325+
} else {
326+
overflowMenuButton.style.display = 'revert';
327+
}
328+
329+
overflowMenu.style.left =
330+
overflowMenuButton.offsetLeft -
331+
overflowMenu.clientWidth +
332+
overflowMenuButton.offsetWidth +
333+
'px';
334+
}, 250);
335+
};
336+
337+
window.addEventListener('resize', overflowMenuHandler);
338+
}
339+
229340
create() {
230341
this.reset();
231342

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

235-
JSDialog.MakeScrollable(this.parentContainer, this.parentContainer.querySelector('div'));
236-
JSDialog.RefreshScrollables();
346+
this.createOverflowMenu();
237347

238348
if (this.map.isRestrictedUser()) {
239349
for (var i = 0; i < items.length; i++) {
@@ -254,8 +364,7 @@ class TopToolbar extends JSDialog.Toolbar {
254364
this.map.createFontSelector('#fontnamecombobox-input');
255365

256366
// on mode switch NB -> Compact
257-
if (this.map._docLoadedOnce)
258-
this.onDocLayerInit();
367+
if (this.map._docLoadedOnce) this.onDocLayerInit();
259368
}
260369

261370
onDocLayerInit() {

0 commit comments

Comments
 (0)