-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add key entry button toggle classlist
- Loading branch information
1 parent
4968f36
commit 889c3bf
Showing
3 changed files
with
228 additions
and
220 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
/** | ||
@function key | ||
@description | ||
mapp.ui.locations.entries.key(entry) | ||
The method returns the name of the `entry.location.layer` of the entry. | ||
This returns a styled div element with the name of the layer. | ||
This can be clicked to toggle the visibility of the layer. | ||
The entry method returns a button HTML element which will toggle the location.layer display. | ||
The button classList reflects whether the layer is displayed or not. | ||
@example | ||
```json | ||
{ | ||
"type":"key" | ||
} | ||
``` | ||
@function key | ||
@param {Object} entry | ||
@param {string} entry.type The type of the entry. | ||
@return {HTMLElement} The button key element, with an onclick event to toggle the visibility of the layer. | ||
@param {Object} entry.location.layer The Mapp location layer object. | ||
@return {HTMLElement} | ||
The button key element, with an onclick event to toggle the visibility of the layer. | ||
*/ | ||
|
||
export default function key(entry) { | ||
const node = mapp.utils.html.node` | ||
<div class="layer-key"> | ||
<button title="${mapp.dictionary.layer_visibility}" | ||
onclick="${() => { | ||
// If the layer is visible, hide it, otherwise show it. | ||
entry.location.layer.display === true ? entry.location.layer.hide() : entry.location.layer.show(); | ||
}}"> | ||
${entry.location.layer.name} | ||
</button> | ||
</div> | ||
`; | ||
|
||
const classList = `layer-key ${entry.location.layer.display ? 'active' : ''}` | ||
|
||
const node = mapp.utils.html.node`<div> | ||
<button | ||
class=${classList} | ||
title="${mapp.dictionary.layer_visibility}" | ||
onclick="${e => { | ||
if (e.target.classList.toggle('active')) { | ||
entry.location.layer.show(); | ||
} else { | ||
entry.location.layer.hide(); | ||
} | ||
}}">${entry.location.layer.name}`; | ||
|
||
return node; | ||
} |
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
Oops, something went wrong.