Feat/layer popup (#1520)

* fix: 1.修复 Popup 换行和事件穿透问题

* chore: 重新触发 Github CI

Co-authored-by: yanxiong <oujinhui.ojh@antgroup.com>
This commit is contained in:
heiyexing 2022-12-01 18:37:09 +08:00 committed by GitHub
parent 6f3d043a7b
commit 50b6c2c227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 15 deletions

View File

@ -30,15 +30,17 @@ const Demo: FunctionComponent = () => {
newScene.on('loaded', () => { newScene.on('loaded', () => {
const newPopup = new Popup({ const newPopup = new Popup({
closeOnClick: true, // closeOnClick: true,
closeOnEsc: true, closeOnEsc: true,
lngLat: { lngLat: {
lng: 120.104697, lng: 120.104697,
lat: 30.260704, lat: 30.260704,
}, },
anchor: 'bottom-right', anchor: 'bottom-right',
title: 'Popup Title', // followCursor: true,
html: 'Popup Content', title:
'算啦就是老地方上的分萨迪克浪费撒东方巨龙凯撒付款流水阿帆十多分数据福克斯阿道夫阿斯蒂芬',
html: '算啦就是老地方上的分萨迪克浪费撒东方巨龙凯撒付款流水阿帆十多分数据福克斯阿道夫阿斯蒂芬',
}); });
newScene.addPopup(newPopup); newScene.addPopup(newPopup);
@ -199,9 +201,16 @@ const Demo: FunctionComponent = () => {
<button <button
onClick={() => { onClick={() => {
popup?.setOptions({ popup?.setOptions({
html: 'html', html: 'html byOptions',
}); });
}} }}
>
htmlByOptions
</button>
<button
onClick={() => {
popup?.setHTML('html');
}}
> >
html html
</button> </button>
@ -224,7 +233,7 @@ const Demo: FunctionComponent = () => {
}); });
}} }}
> >
title toggleTitle
</button> </button>
<button <button
onClick={() => { onClick={() => {

View File

@ -423,6 +423,7 @@
display: -webkit-flex; display: -webkit-flex;
display: flex; display: flex;
will-change: transform; will-change: transform;
pointer-events: none;
} }
.l7-popup.l7-popup-hide { .l7-popup.l7-popup-hide {
display: none; display: none;
@ -439,9 +440,12 @@
margin-bottom: 8px; margin-bottom: 8px;
font-weight: bold; font-weight: bold;
} }
.l7-popup .l7-popup-content .l7-popup-close-button,
.l7-popup .l7-popup-content .l7-popup-content__title, .l7-popup .l7-popup-content .l7-popup-content__title,
.l7-popup .l7-popup-content .l7-popup-content__panel { .l7-popup .l7-popup-content .l7-popup-content__panel {
white-space: break-spaces; white-space: normal;
user-select: text;
pointer-events: initial;
} }
.l7-popup .l7-popup-content .l7-popup-close-button { .l7-popup .l7-popup-content .l7-popup-close-button {
position: absolute; position: absolute;

View File

@ -8,6 +8,7 @@
display: -webkit-flex; display: -webkit-flex;
display: flex; display: flex;
will-change: transform; will-change: transform;
pointer-events: none;
&.l7-popup-hide { &.l7-popup-hide {
display: none; display: none;
} }
@ -25,9 +26,12 @@
font-weight: bold; font-weight: bold;
} }
.l7-popup-close-button,
.l7-popup-content__title, .l7-popup-content__title,
.l7-popup-content__panel { .l7-popup-content__panel {
white-space: break-spaces; white-space: normal;
user-select: text;
pointer-events: initial;
} }
.l7-popup-close-button { .l7-popup-close-button {

View File

@ -176,6 +176,9 @@ export default class Popup<O extends IPopupOption = IPopupOption>
}; };
if ( if (
this.checkUpdateOption(option, [ this.checkUpdateOption(option, [
'html',
'text',
'title',
'closeButton', 'closeButton',
'closeButtonOffsets', 'closeButtonOffsets',
'maxWidth', 'maxWidth',
@ -215,9 +218,6 @@ export default class Popup<O extends IPopupOption = IPopupOption>
} else if (this.checkUpdateOption(option, ['text']) && option.text) { } else if (this.checkUpdateOption(option, ['text']) && option.text) {
this.setText(option.text); this.setText(option.text);
} }
if (this.checkUpdateOption(option, ['title'])) {
this.setTitle(option.title);
}
if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) { if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
this.setLnglat(option.lngLat); this.setLnglat(option.lngLat);
} }
@ -278,6 +278,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>
public setTitle(title?: ElementType) { public setTitle(title?: ElementType) {
this.show(); this.show();
this.popupOption.title = title;
if (title) { if (title) {
if (!this.contentTitle) { if (!this.contentTitle) {
this.contentTitle = DOM.create('div', 'l7-popup-content__title'); this.contentTitle = DOM.create('div', 'l7-popup-content__title');
@ -461,6 +462,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>
} }
this.contentTitle = undefined; this.contentTitle = undefined;
this.content = DOM.create('div', 'l7-popup-content', this.container); this.content = DOM.create('div', 'l7-popup-content', this.container);
this.setTitle(this.popupOption.title);
if (this.popupOption.closeButton) { if (this.popupOption.closeButton) {
const closeButton = createL7Icon('l7-icon-guanbi'); const closeButton = createL7Icon('l7-icon-guanbi');
@ -535,14 +537,18 @@ export default class Popup<O extends IPopupOption = IPopupOption>
this.container.style.whiteSpace = 'nowrap'; this.container.style.whiteSpace = 'nowrap';
} }
// 设置 Popup 的最大宽度
if (maxWidth && this.container.style.maxWidth !== maxWidth) {
this.container.style.maxWidth = maxWidth;
}
this.updateLngLatPosition(); this.updateLngLatPosition();
DOM.setTransform(this.container, `${anchorTranslate[anchor]}`); DOM.setTransform(this.container, `${anchorTranslate[anchor]}`);
applyAnchorClass(this.container, anchor, 'popup'); applyAnchorClass(this.container, anchor, 'popup');
if (maxWidth) {
const { width } = this.container.getBoundingClientRect();
if (width > parseFloat(maxWidth)) {
this.container.style.width = maxWidth;
}
} else {
this.container.style.removeProperty('width');
}
}; };
/** /**