Skip to content

Commit

Permalink
Origo master feature more option button - ui component (#1496)
Browse files Browse the repository at this point in the history
* New button for reaching layer info

* Layer info menu

* Only show remove layer option when layer can be removed

* Add focus to icon-smallest

* Move close button into legend component

* Add box shadow

* Popup menu created on demand in layer.js

* Toggle popup menu on more info button click

* align layer check buttons

* Change popupmenu to ui component

* Smaller padding right on legend layer rows

Co-authored-by: Markus Polleryd <markus.polleryd@decerno.se>
  • Loading branch information
Polleryd and Markus Polleryd authored Mar 31, 2022
1 parent ffb99dd commit 560b85a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/controls/legend/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ const Group = function Group(options = {}, viewer) {
});
},
render() {
return `<div class="flex row align-center padding-left padding-right text-smaller pointer collapse-header" style="width: 100%;">
return `<div class="flex row align-center padding-left text-smaller pointer collapse-header" style="width: 100%; padding-right: 1.875rem">
<div id="${this.getId()}" class="flex row align-center grow">
${expandButton.render()}
<span class="grow padding-x-small">${title}</span>
<span class="grow padding-x-small" style="word-break: break-all;">${title}</span>
</div>
${tickButton ? tickButton.render() : ''}
</div>`;
Expand Down
7 changes: 4 additions & 3 deletions src/controls/legend/overlay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Button, dom } from '../../ui';
import { HeaderIcon } from '../../utils/legendmaker';
import PopupMenu from '../../popupmenu';
import PopupMenu from '../../ui/popupmenu';

const OverlayLayer = function OverlayLayer(options) {
let {
Expand All @@ -20,7 +20,7 @@ const OverlayLayer = function OverlayLayer(options) {
const popupMenuItems = [];
let layerList;

const cls = `${clsSettings} flex row align-center padding-left padding-right item`.trim();
const cls = `${clsSettings} flex row align-center padding-left padding-right-smaller item`.trim();
const title = layer.get('title') || 'Titel saknas';
const name = layer.get('name');
const secure = layer.get('secure');
Expand Down Expand Up @@ -193,7 +193,8 @@ const OverlayLayer = function OverlayLayer(options) {
const { top, left } = getElementOffset(moreInfoButtonEl, viewerEl);
const right = viewerEl.offsetWidth - left - moreInfoButtonEl.offsetWidth;
const targetRect = moreInfoButtonEl.getBoundingClientRect();
popupMenu = PopupMenu({ target: viewer.getId(), onUnfocus });
popupMenu = PopupMenu({ onUnfocus });
document.getElementById(viewer.getId()).appendChild(dom.html(popupMenu.render()));
popupMenu.setContent(popupMenuList.render());
popupMenuList.dispatch('render');
popupMenu.setPosition({ right: `${right}px`, top: `${top + targetRect.height}px` });
Expand Down
42 changes: 18 additions & 24 deletions src/popupmenu.js → src/ui/popupmenu.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import Cuid from 'cuid';
import { dom } from './ui';
import { Component } from '.';

export default function popup(options = {}) {
const {
target,
onUnfocus = () => {}
} = options;

const id = Cuid();
let id;
let isVisible = true;

function render(targetId) {
const pop = `<div id="${id}" class="popup-menu z-index-ontop-high"></div>`;
document.getElementById(targetId).appendChild(dom.html(pop));
}

function getEl() {
return document.getElementById(id);
}
Expand Down Expand Up @@ -45,23 +38,24 @@ export default function popup(options = {}) {
if (content) getEl().innerHTML = content;
}

function bindUIActions() {
window.addEventListener('click', (e) => {
const popupMenuEl = document.getElementById(id);
if (!popupMenuEl.contains(e.target)) {
onUnfocus(e);
e.preventDefault();
}
});
}

render(target);
bindUIActions();
return {
return Component({
onInit() {
id = this.getId();
window.addEventListener('click', (e) => {
const popupMenuEl = document.getElementById(id);
if (!popupMenuEl.contains(e.target)) {
onUnfocus(e);
e.preventDefault();
}
});
},
getEl,
setPosition,
setVisibility,
toggleVisibility,
setContent
};
setContent,
render() {
return `<div id="${this.getId()}" class="popup-menu z-index-ontop-high"></div>`;
}
});
}

0 comments on commit 560b85a

Please sign in to comment.