-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add toggle slot visibility component
- Loading branch information
Showing
15 changed files
with
312 additions
and
56 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# grw-fab | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| ------------ | ------------- | ----------- | ---------- | ----------- | | ||
| `action` | -- | | `Function` | `undefined` | | ||
| `fontFamily` | `font-family` | | `string` | `'Roboto'` | | ||
| `hideTitle` | `hide-title` | | `string` | `undefined` | | ||
| `icon` | -- | | `Function` | `undefined` | | ||
| `showTitle` | `show-title` | | `string` | `undefined` | | ||
|
||
|
||
## Shadow Parts | ||
|
||
| Part | Description | | ||
| ------------------------------ | ----------- | | ||
| `"fab-visibility-button"` | | | ||
| `"fab-visibility-button-icon"` | | | ||
|
||
|
||
## Dependencies | ||
|
||
### Used by | ||
|
||
- [grw-map](../grw-map) | ||
|
||
### Graph | ||
```mermaid | ||
graph TD; | ||
grw-map --> grw-fab | ||
style grw-fab fill:#f9f,stroke:#333,stroke-width:4px | ||
``` | ||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
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
18 changes: 18 additions & 0 deletions
18
src/components/grw-toggle-slot-visibility/grw-toggle-slot-visibility.scss
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,18 @@ | ||
grw-toggle-slot-visibility { | ||
display: block; | ||
position: relative; | ||
width: 100%; | ||
overflow: hidden; | ||
max-width: 100dvw; | ||
} | ||
|
||
.grw-map-visibility-button-container { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
position: fixed; | ||
bottom: 24px; | ||
z-index: 4001; | ||
pointer-events: none; | ||
} |
135 changes: 135 additions & 0 deletions
135
src/components/grw-toggle-slot-visibility/grw-toggle-slot-visibility.tsx
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,135 @@ | ||
import { Component, Host, h, State, Prop, Listen, Element } from '@stencil/core'; | ||
import { translate } from 'i18n/i18n'; | ||
import state from 'store/store'; | ||
|
||
@Component({ | ||
tag: 'grw-toggle-slot-visibility', | ||
styleUrl: 'grw-toggle-slot-visibility.scss', | ||
shadow: false, | ||
}) | ||
export class GrwToggleSlotVisibility { | ||
@Element() toggleSlotElement: HTMLElement; | ||
@State() isLargeView = undefined; | ||
@State() showStartSlot = true; | ||
@State() showEndSlot = false; | ||
|
||
@Prop() largeViewSize = 1024; | ||
@Prop() fontFamily = 'Roboto'; | ||
@Prop() fabBackgroundColor = '#eaddff'; | ||
@Prop() fabColor = '#21005d'; | ||
@Prop() slotEndHeight = '100vh'; | ||
|
||
@Listen('resize', { target: 'window' }) | ||
onWindowResize() { | ||
this.handleView(); | ||
} | ||
|
||
handleView() { | ||
if (state.currentTrek && (typeof this.isLargeView === undefined || this.isLargeView !== this.toggleSlotElement.getBoundingClientRect().width >= this.largeViewSize)) { | ||
this.isLargeView = this.toggleSlotElement.getBoundingClientRect().width >= this.largeViewSize; | ||
this.showStartSlot = true; | ||
this.showEndSlot = this.isLargeView; | ||
if (!this.isLargeView) { | ||
const mapVisibilityButtonContainer = document.createElement('div'); | ||
mapVisibilityButtonContainer.className = 'grw-map-visibility-button-container'; | ||
const mapVisibilityButton = document.createElement('grw-extended-fab'); | ||
mapVisibilityButton.setAttribute('exportparts', 'map-visibility-button,map-visibility-button-icon,map-visibility-button-label'); | ||
mapVisibilityButton.setAttribute('font-family', this.fontFamily); | ||
mapVisibilityButton.action = () => this.toggleShowSlot(); | ||
mapVisibilityButton.icon = () => this.getMapVisibilityIconButton(); | ||
mapVisibilityButton.name = () => this.getMapVisibilityLabelButton(); | ||
mapVisibilityButton.setAttribute('display', this.isLargeView ? 'none' : 'flex'); | ||
mapVisibilityButtonContainer.append(mapVisibilityButton); | ||
document.body.append(mapVisibilityButtonContainer); | ||
|
||
const slotEnd: any = document.querySelector('#grw-slot-end-container'); | ||
|
||
const slotEndClone = slotEnd.cloneNode(true); | ||
slotEndClone.id = 'grw-slot-end-container-clone'; | ||
slotEndClone.style.visibility = 'hidden'; | ||
slotEndClone.style.position = 'fixed'; | ||
slotEndClone.style.top = '0px'; | ||
slotEndClone.style.left = '0px'; | ||
slotEndClone.style['z-index'] = '0'; | ||
slotEndClone.style.height = '100vh'; | ||
slotEndClone.style['background-color'] = '#ffffff'; | ||
document.body.append(slotEndClone); | ||
} else { | ||
const mapVisibilityButtonContainer = document.body.getElementsByClassName('grw-map-visibility-button-container')[0]; | ||
if (mapVisibilityButtonContainer) { | ||
mapVisibilityButtonContainer.remove(); | ||
} | ||
const slotEndClone = document.body.querySelector('#grw-slot-end-container-clone'); | ||
if (slotEndClone) { | ||
slotEndClone.remove(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
toggleShowSlot() { | ||
this.showStartSlot = !this.showStartSlot; | ||
this.showEndSlot = !this.showStartSlot; | ||
const grwSlotEndContainerClone: any = document.querySelector('#grw-slot-end-container-clone'); | ||
if (grwSlotEndContainerClone && this.showEndSlot) { | ||
grwSlotEndContainerClone.style.visibility = 'visible'; | ||
document.body.style.overflow = `hidden`; | ||
grwSlotEndContainerClone.style['z-index'] = '4000'; | ||
} else { | ||
grwSlotEndContainerClone.style.visibility = 'hidden'; | ||
document.body.style.overflow = `visible`; | ||
grwSlotEndContainerClone.style['z-index'] = '0'; | ||
} | ||
const grwExtendedFab: any = document.getElementsByTagName('grw-extended-fab')[0]; | ||
grwExtendedFab.icon = () => this.getMapVisibilityIconButton(); | ||
grwExtendedFab.name = () => this.getMapVisibilityLabelButton(); | ||
} | ||
|
||
componentDidRender() { | ||
this.handleView(); | ||
} | ||
|
||
getMapVisibilityIconButton() { | ||
let mapIconButton: string; | ||
mapIconButton = this.showStartSlot ? 'map' : 'summarize'; | ||
return mapIconButton; | ||
} | ||
|
||
getMapVisibilityLabelButton() { | ||
let mapLabelButton: string; | ||
mapLabelButton = this.showStartSlot ? translate[state.language].showMap : translate[state.language].showDetails; | ||
return mapLabelButton; | ||
} | ||
|
||
render() { | ||
return ( | ||
<Host styme={{ '--fab-background-color': this.fabBackgroundColor, '--fab-color': this.fabColor }}> | ||
{state.currentTrek && ( | ||
<div class="grw-toggle-slot-visibility-container"> | ||
<div | ||
class="grw-slot-start-container" | ||
style={{ height: this.showStartSlot ? '100%' : '100vh', visibility: this.showStartSlot ? 'visible' : 'hidden', zIndex: this.showStartSlot ? '1' : '0' }} | ||
> | ||
<slot name="start"> </slot> | ||
</div> | ||
|
||
<div | ||
id="grw-slot-end-container" | ||
style={{ | ||
width: '100%', | ||
height: this.slotEndHeight, | ||
visibility: !this.isLargeView ? 'hidden' : 'visible', | ||
position: !this.isLargeView ? 'absolute' : 'relative', | ||
top: !this.isLargeView ? '0px' : 'none', | ||
left: !this.isLargeView ? '0px' : 'none', | ||
zIndex: !this.isLargeView ? '0' : '1', | ||
}} | ||
> | ||
<slot name="end"> </slot> | ||
</div> | ||
</div> | ||
)} | ||
</Host> | ||
); | ||
} | ||
} |
Oops, something went wrong.