-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67c12df
commit 7408207
Showing
9 changed files
with
316 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.mappable--default-popup { | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: 8px; | ||
} | ||
|
||
.mappable--default-popup_header { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
gap: 8px; | ||
|
||
.mappable--default-popup_header_title { | ||
font-size: 16px; | ||
font-weight: 400; | ||
line-height: 22px; | ||
color: #050d33; | ||
} | ||
.mappable--default-popup_header_close { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 32px; | ||
height: 32px; | ||
border: none; | ||
background: none; | ||
color: #c8c9cc; | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
.mappable--default-popup_description { | ||
font-size: 14px; | ||
font-weight: 400; | ||
line-height: 20px; | ||
color: #7b7d85; | ||
} | ||
|
||
.mappable--default-popup_action { | ||
width: max-content; | ||
padding: 12px 16px; | ||
border-radius: 8px; | ||
border: none; | ||
background-color: #eefd7d; | ||
transition: background-color 0.1s ease-out; | ||
color: #050d33; | ||
text-align: center; | ||
cursor: pointer; | ||
white-space: normal; | ||
|
||
font-size: 14px; | ||
font-style: normal; | ||
font-weight: 500; | ||
line-height: 16px; | ||
} | ||
|
||
.mappable--default-popup_action:hover { | ||
background-color: #e5fd30; | ||
} | ||
|
||
.mappable--default-popup__dark { | ||
.header_title { | ||
color: #f2f5fa; | ||
} | ||
.header_close { | ||
color: #46464d; | ||
} | ||
.mappable--default-popup_description { | ||
color: #7b7d85; | ||
} | ||
.mappable--default-popup_action { | ||
background-color: #d6fd63; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import {MMapBalloonMarker, MMapBalloonMarkerProps, MMapBalloonContentProps} from '../MMapBalloonMarker'; | ||
import './index.css'; | ||
import closeSVG from './close.svg'; | ||
|
||
export type MMapDefaultPopupMarkerProps = Omit<MMapBalloonMarkerProps, 'content'> & { | ||
/** Displayed title in popup header */ | ||
title?: string; | ||
/** Displayed description */ | ||
description?: string; | ||
/** The inscription on the action button */ | ||
action?: string; | ||
/** Callback of click the action button */ | ||
onAction?: () => void; | ||
}; | ||
/** | ||
* `MMapDefaultPopupMarker` is a default popup that contains a title, a description, and an action button. | ||
* @example | ||
* ```js | ||
* const defaultPopup = new MMapDefaultPopupMarker({ | ||
* title: 'Default title', | ||
* description: 'Default description', | ||
* action: 'Make action', | ||
* // support MMapMarker props | ||
* coordinates: POPUP_COORD, | ||
* draggable: true, | ||
* // support MMapBalloonMarker props | ||
* position: 'top', | ||
* }); | ||
* map.addChild(defaultPopup); | ||
* ``` | ||
*/ | ||
export class MMapDefaultPopupMarker extends mappable.MMapComplexEntity<MMapDefaultPopupMarkerProps> { | ||
private _balloon: MMapBalloonMarker; | ||
private _element: HTMLElement; | ||
|
||
public get isOpen() { | ||
return this._balloon.isOpen; | ||
} | ||
|
||
protected _onAttach(): void { | ||
const {title, description, action} = this._props; | ||
|
||
if (title === undefined && description === undefined && action === undefined) { | ||
throw new Error( | ||
'There is no content to display. Specify one of the parameters: title, description, action' | ||
); | ||
} | ||
|
||
this._balloon = new MMapBalloonMarker({ | ||
...this._props, | ||
content: this.__createDefaultPopup, | ||
onClose: () => (this._props.show = false), | ||
onOpen: () => (this._props.show = true) | ||
}); | ||
this.addChild(this._balloon); | ||
|
||
this._watchContext(mappable.ThemeContext, () => this._updateTheme(), {immediate: true}); | ||
} | ||
|
||
protected _onUpdate(propsDiff: Partial<MMapDefaultPopupMarkerProps>, oldProps: MMapDefaultPopupMarkerProps): void { | ||
const {title, description, action} = this._props; | ||
|
||
const isTitleChange = oldProps.title !== title; | ||
const isDescriptionChange = oldProps.description !== description; | ||
const isActionChange = oldProps.action !== action; | ||
|
||
if (isTitleChange || isDescriptionChange || isActionChange) { | ||
this._balloon.update({content: (close) => this.__createDefaultPopup(close)}); | ||
} | ||
|
||
this._balloon.update(this._props); | ||
} | ||
|
||
private _updateTheme() { | ||
const themeCtx = this._consumeContext(mappable.ThemeContext); | ||
this._element.classList.toggle('mappable--default-popup__dark', themeCtx.theme === 'dark'); | ||
} | ||
|
||
private __createDefaultPopup: MMapBalloonContentProps = (close) => { | ||
const {title, description, action} = this._props; | ||
this._element = document.createElement('mappable'); | ||
this._element.classList.add('mappable--default-popup'); | ||
|
||
const popupHeaderElement = document.createElement('mappable'); | ||
popupHeaderElement.classList.add('mappable--default-popup_header'); | ||
this._element.appendChild(popupHeaderElement); | ||
|
||
if (title) { | ||
const titleElement = document.createElement('mappable'); | ||
titleElement.classList.add('mappable--default-popup_header_title'); | ||
titleElement.textContent = title; | ||
popupHeaderElement.appendChild(titleElement); | ||
} | ||
|
||
const closeButton = document.createElement('button'); | ||
closeButton.classList.add('mappable--default-popup_header_close'); | ||
closeButton.innerHTML = closeSVG; | ||
closeButton.addEventListener('click', () => close()); | ||
popupHeaderElement.appendChild(closeButton); | ||
|
||
if (description) { | ||
const descriptionElement = document.createElement('mappable'); | ||
descriptionElement.classList.add('mappable--default-popup_description'); | ||
descriptionElement.textContent = description; | ||
this._element.appendChild(descriptionElement); | ||
} | ||
if (action) { | ||
const actionButton = document.createElement('button'); | ||
actionButton.classList.add('mappable--default-popup_action'); | ||
actionButton.textContent = action; | ||
actionButton.addEventListener('click', () => { | ||
this._props.onAction?.(); | ||
}); | ||
this._element.appendChild(actionButton); | ||
} | ||
|
||
return this._element; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.mappable--default-tooltip { | ||
display: block; | ||
max-width: inherit; | ||
max-height: inherit; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} |
Oops, something went wrong.