Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sbb-map-container): allow config of sticky offset on mobile #3092

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/elements/map-container/map-container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
--sbb-map-container-map-height: calc(
var(--sbb-map-container-map-height-zero) + var(--sbb-map-container-border-radius)
);
--sbb-map-container-mobile-sticky-block-start: 0;

@include sbb.mq($from: small) {
--sbb-map-container-map-height: calc(
Expand Down Expand Up @@ -106,6 +107,7 @@

// We use "to: medium" to avoid resetting the styles
@include sbb.mq($to: medium) {
inset-block-start: var(--sbb-map-container-mobile-sticky-block-start);
height: var(--sbb-map-container-map-height);
}

Expand Down
14 changes: 6 additions & 8 deletions src/elements/map-container/map-container.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ export const MapContainer: StoryObj = {
const meta: Meta = {
decorators: [
(story) => html`
<div>
<sbb-header expanded hide-on-scroll>
<sbb-header-button icon-name="hamburger-menu-small" expand-from="small">
Menu
</sbb-header-button>
</sbb-header>
${story()}
</div>
<sbb-header expanded>
<sbb-header-button icon-name="hamburger-menu-small" expand-from="small">
Menu
</sbb-header-button>
</sbb-header>
${story()}
`,
],
parameters: {
Expand Down
4 changes: 4 additions & 0 deletions src/elements/map-container/map-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import '../button/tertiary-button.js';
* For specific use cases, this variable can be used to modify the preset height.
* @cssprop [--sbb-map-container-sidebar-width=zero-large:400px;wide-ultra:480px] - Can be used
* to modify the width of the left sidebar.
* @cssprop [--sbb-map-container-mobile-sticky-block-start=0] - If e.g. a header with a fixed height
* is placed before the map-container, the map should be sticky respecting
* this offset from the document's top. Only applied on mobile views.
* Most commonly it can be set to `var(--sbb-header-height)`.
*/
@customElement('sbb-map-container')
export class SbbMapContainerElement extends LitElement {
Expand Down
124 changes: 77 additions & 47 deletions src/elements/map-container/map-container.visual.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html } from 'lit';
import { html, nothing, type TemplateResult } from 'lit';
import { styleMap } from 'lit/directives/style-map.js';

import { describeViewports, visualDiffDefault } from '../core/testing/private.js';
Expand All @@ -8,57 +8,87 @@ import '../header.js';
import '../title.js';

describe(`sbb-map-container`, () => {
const template = (stickyOffset = false): TemplateResult => html`
<sbb-header expanded>
<sbb-header-button icon-name="hamburger-menu-small" expand-from="small">
Menu
</sbb-header-button>
</sbb-header>
<sbb-map-container
style=${stickyOffset
? `--sbb-map-container-mobile-sticky-block-start: var(--sbb-header-height);`
: nothing}
>
<!-- Content slot -->
<div style="padding: var(--sbb-spacing-fixed-4x)">
<sbb-title level="4">Operations & Disruptions</sbb-title>
${[...Array(5).keys()].map(
(value) => html`
<div
style=${styleMap({
'background-color': 'var(--sbb-color-milk)',
height: '116px',
display: 'flex',
'align-items': 'center',
'justify-content': 'center',
'border-radius': 'var(--sbb-border-radius-4x)',
'margin-block-end': 'var(--sbb-spacing-fixed-4x)',
})}
>
<p>Situation ${value}</p>
</div>
`,
)}
</div>

<div slot="map" style="height: 100%">
<div
style=${styleMap({
'background-color': 'grey',
height: '100%',
display: 'flex',
'align-items': 'center',
'justify-content': 'center',
})}
>
map
</div>
</div>
</sbb-map-container>
`;

beforeEach(() => {
// Reset page scrolling
window.scrollTo(0, 0);
});

describeViewports({ viewports: ['zero', 'medium'], viewportHeight: 500 }, () => {
it(
visualDiffDefault.name,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`
<sbb-header expanded>
<sbb-header-button icon-name="hamburger-menu-small" expand-from="small">
Menu
</sbb-header-button>
</sbb-header>
<sbb-map-container>
<!-- Content slot -->
<div style="padding: var(--sbb-spacing-fixed-4x)">
<sbb-title level="4">Operations & Disruptions</sbb-title>
${[...Array(5).keys()].map(
(value) => html`
<div
style=${styleMap({
'background-color': 'var(--sbb-color-milk)',
height: '116px',
display: 'flex',
'align-items': 'center',
'justify-content': 'center',
'border-radius': 'var(--sbb-border-radius-4x)',
'margin-block-end': 'var(--sbb-spacing-fixed-4x)',
})}
>
<p>Situation ${value}</p>
</div>
`,
)}
</div>
await setup.withFixture(template(), { padding: '0' });
}),
);
});

describeViewports({ viewports: ['zero'], viewportHeight: 500 }, () => {
it(
'scrolled without sticky offset',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template(), { padding: '0' });
setup.withPostSetupAction(() => {
window.scrollTo(0, 100);
});
}),
);

<div slot="map" style="height: 100%">
<div
style=${styleMap({
'background-color': 'grey',
height: '100%',
display: 'flex',
'align-items': 'center',
'justify-content': 'center',
})}
>
map
</div>
</div>
</sbb-map-container>
`,
{ padding: '0' },
);
it(
'scrolled with sticky offset',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(template(true), { padding: '0' });
setup.withPostSetupAction(() => {
window.scrollTo(0, 100);
});
}),
);
});
Expand Down
9 changes: 5 additions & 4 deletions src/elements/map-container/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ On desktop, the sidebar and the map are shown in a two column layout side by sid

## CSS Properties

| Name | Default | Description |
| ----------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--sbb-map-container-margin-start` | `var(--sbb-header-height)` | The component comes along with a height calculation that subtracts the height of the header. For specific use cases, this variable can be used to modify the preset height. |
| `--sbb-map-container-sidebar-width` | `zero-large:400px;wide-ultra:480px` | Can be used to modify the width of the left sidebar. |
| Name | Default | Description |
| ----------------------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--sbb-map-container-margin-start` | `var(--sbb-header-height)` | The component comes along with a height calculation that subtracts the height of the header. For specific use cases, this variable can be used to modify the preset height. |
| `--sbb-map-container-mobile-sticky-block-start` | `0` | If e.g. a header with a fixed height is placed before the map-container, the map should be sticky respecting this offset from the document's top. Only applied on mobile views. Most commonly it can be set to `var(--sbb-header-height)`. |
| `--sbb-map-container-sidebar-width` | `zero-large:400px;wide-ultra:480px` | Can be used to modify the width of the left sidebar. |

## Slots

Expand Down
Loading