Skip to content

Commit

Permalink
feat: add toggle slot visibility component
Browse files Browse the repository at this point in the history
  • Loading branch information
bastyen committed Oct 4, 2024
1 parent 9e2ff25 commit df9a10b
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 56 deletions.
23 changes: 23 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export namespace Components {
"checked": boolean;
"fontFamily": string;
}
interface GrwToggleSlotVisibility {
"fabBackgroundColor": string;
"fabColor": string;
"fontFamily": string;
"largeViewSize": number;
"slotEndHeight": string;
}
interface GrwTouristicContentCard {
"fontFamily": string;
"isInsideHorizontalList": boolean;
Expand Down Expand Up @@ -756,6 +763,12 @@ declare global {
prototype: HTMLGrwSwitchElement;
new (): HTMLGrwSwitchElement;
};
interface HTMLGrwToggleSlotVisibilityElement extends Components.GrwToggleSlotVisibility, HTMLStencilElement {
}
var HTMLGrwToggleSlotVisibilityElement: {
prototype: HTMLGrwToggleSlotVisibilityElement;
new (): HTMLGrwToggleSlotVisibilityElement;
};
interface HTMLGrwTouristicContentCardElementEventMap {
"touristicContentCardPress": number;
"cardTouristicContentMouseOver": number;
Expand Down Expand Up @@ -935,6 +948,7 @@ declare global {
"grw-select-language": HTMLGrwSelectLanguageElement;
"grw-sensitive-area-detail": HTMLGrwSensitiveAreaDetailElement;
"grw-switch": HTMLGrwSwitchElement;
"grw-toggle-slot-visibility": HTMLGrwToggleSlotVisibilityElement;
"grw-touristic-content-card": HTMLGrwTouristicContentCardElement;
"grw-touristic-content-detail": HTMLGrwTouristicContentDetailElement;
"grw-touristic-content-provider": HTMLGrwTouristicContentProviderElement;
Expand Down Expand Up @@ -1239,6 +1253,13 @@ declare namespace LocalJSX {
"checked"?: boolean;
"fontFamily"?: string;
}
interface GrwToggleSlotVisibility {
"fabBackgroundColor"?: string;
"fabColor"?: string;
"fontFamily"?: string;
"largeViewSize"?: number;
"slotEndHeight"?: string;
}
interface GrwTouristicContentCard {
"fontFamily"?: string;
"isInsideHorizontalList"?: boolean;
Expand Down Expand Up @@ -1450,6 +1471,7 @@ declare namespace LocalJSX {
"grw-select-language": GrwSelectLanguage;
"grw-sensitive-area-detail": GrwSensitiveAreaDetail;
"grw-switch": GrwSwitch;
"grw-toggle-slot-visibility": GrwToggleSlotVisibility;
"grw-touristic-content-card": GrwTouristicContentCard;
"grw-touristic-content-detail": GrwTouristicContentDetail;
"grw-touristic-content-provider": GrwTouristicContentProvider;
Expand Down Expand Up @@ -1497,6 +1519,7 @@ declare module "@stencil/core" {
"grw-select-language": LocalJSX.GrwSelectLanguage & JSXBase.HTMLAttributes<HTMLGrwSelectLanguageElement>;
"grw-sensitive-area-detail": LocalJSX.GrwSensitiveAreaDetail & JSXBase.HTMLAttributes<HTMLGrwSensitiveAreaDetailElement>;
"grw-switch": LocalJSX.GrwSwitch & JSXBase.HTMLAttributes<HTMLGrwSwitchElement>;
"grw-toggle-slot-visibility": LocalJSX.GrwToggleSlotVisibility & JSXBase.HTMLAttributes<HTMLGrwToggleSlotVisibilityElement>;
"grw-touristic-content-card": LocalJSX.GrwTouristicContentCard & JSXBase.HTMLAttributes<HTMLGrwTouristicContentCardElement>;
"grw-touristic-content-detail": LocalJSX.GrwTouristicContentDetail & JSXBase.HTMLAttributes<HTMLGrwTouristicContentDetailElement>;
"grw-touristic-content-provider": LocalJSX.GrwTouristicContentProvider & JSXBase.HTMLAttributes<HTMLGrwTouristicContentProviderElement>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/grw-app/grw-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ export class GrwApp {
tiles-max-zoom-offline={this.tilesMaxZoomOffline}
grw-app={true}
main-marker-size={this.mainMarkerSize}
selected-main-markerSize={this.selectedMainMarkerSize}
selected-main-marker-size={this.selectedMainMarkerSize}
main-cluster-size={this.mainClusterSize}
common-marker-size={this.commonMarkerSize}
departure-arrival-marker-size={this.departureArrivalMarkerSize}
Expand Down
8 changes: 4 additions & 4 deletions src/components/grw-app/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
| `touristicEvents` | `touristic-events` | | `boolean` | `false` |
| `treks` | `treks` | | `boolean` | `true` |
| `urlLayer` | `url-layer` | | `string` | `undefined` |
| `useGradient` | `use-gradient` | | `boolean` | `false` |
| `weather` | `weather` | | `boolean` | `false` |


Expand Down Expand Up @@ -148,16 +147,16 @@ graph TD;
grw-touristic-contents-list --> grw-touristic-content-card
grw-touristic-events-list --> grw-touristic-event-card
grw-outdoor-sites-list --> grw-outdoor-site-card
grw-trek-detail --> grw-details-modal
grw-trek-detail --> grw-touristic-event-detail
grw-trek-detail --> grw-touristic-content-detail
grw-trek-detail --> grw-trek-card
grw-trek-detail --> grw-poi
grw-trek-detail --> grw-sensitive-area-detail
grw-trek-detail --> grw-information-desk
grw-trek-detail --> grw-touristic-content-card
grw-trek-detail --> grw-touristic-event-card
grw-trek-detail --> grw-details-modal
grw-trek-detail --> grw-touristic-content-detail
grw-trek-detail --> grw-touristic-content-provider
grw-trek-detail --> grw-touristic-event-detail
grw-trek-detail --> grw-touristic-event-provider
grw-outdoor-site-detail --> grw-poi
grw-outdoor-site-detail --> grw-outdoor-site-card
Expand All @@ -168,6 +167,7 @@ graph TD;
grw-outdoor-course-detail --> grw-touristic-content-card
grw-outdoor-course-detail --> grw-touristic-event-card
grw-outdoor-course-detail --> grw-poi
grw-map --> grw-fab
grw-filters --> grw-filter
style grw-app fill:#f9f,stroke:#333,stroke-width:4px
```
Expand Down
2 changes: 1 addition & 1 deletion src/components/grw-details-modal/grw-details-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CloseIcon from '../../assets/close.svg';
@Component({
tag: 'grw-details-modal',
styleUrl: 'grw-details-modal.scss',
shadow: true,
shadow: false,
})
export class GrwDetailsModal {
@Event() closeDetailsModal: EventEmitter<number>;
Expand Down
2 changes: 2 additions & 0 deletions src/components/grw-extended-fab/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
### Used by

- [grw-app](../grw-app)
- [grw-toggle-slot-visibility](../grw-toggle-slot-visibility)

### Graph
```mermaid
graph TD;
grw-app --> grw-extended-fab
grw-toggle-slot-visibility --> grw-extended-fab
style grw-extended-fab fill:#f9f,stroke:#333,stroke-width:4px
```

Expand Down
42 changes: 42 additions & 0 deletions src/components/grw-fab/readme.md
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/)*
4 changes: 3 additions & 1 deletion src/components/grw-map/grw-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,9 @@ export class GrwMap {
(this.elevationControl.options as any).height = elevationHeight;
(this.elevationControl as any).redraw();
}
this.map.invalidateSize();
if (this.map) {
this.map.invalidateSize();
}
forceUpdate(this.hostElement);
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/grw-map/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
| `colorTrekLine` | `color-trek-line` | | `string` | `'#6b0030'` |
| `commonMarkerSize` | `common-marker-size` | | `number` | `48` |
| `departureArrivalMarkerSize` | `departure-arrival-marker-size` | | `number` | `14` |
| `elevationDefaultState` | `elevation-default-state` | | `string` | `'visible'` |
| `elevationHeight` | `elevation-height` | | `number` | `280` |
| `fontFamily` | `font-family` | | `string` | `'Roboto'` |
| `grwApp` | `grw-app` | | `boolean` | `false` |
| `isLargeView` | `is-large-view` | | `boolean` | `false` |
| `largeViewSize` | `large-view-size` | | `number` | `1024` |
| `mainClusterSize` | `main-cluster-size` | | `number` | `48` |
| `mainMarkerSize` | `main-marker-size` | | `number` | `32` |
Expand All @@ -34,7 +36,6 @@
| `selectedMainMarkerSize` | `selected-main-marker-size` | | `number` | `48` |
| `tilesMaxZoomOffline` | `tiles-max-zoom-offline` | | `number` | `16` |
| `urlLayer` | `url-layer` | | `string` | `undefined` |
| `useGradient` | `use-gradient` | | `boolean` | `false` |


## Events
Expand Down Expand Up @@ -63,9 +64,14 @@

- [grw-app](../grw-app)

### Depends on

- [grw-fab](../grw-fab)

### Graph
```mermaid
graph TD;
grw-map --> grw-fab
grw-app --> grw-map
style grw-map fill:#f9f,stroke:#333,stroke-width:4px
```
Expand Down
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;
}
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>
);
}
}
Loading

0 comments on commit df9a10b

Please sign in to comment.