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

refactor(sbb-dialog): introduce inner components and header animation #2231

Merged
merged 67 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7ff0358
feat: add show/hide animation for dialog header
dauriamarco Nov 24, 2023
e18c5f5
feat: make mobile animation smoother
dauriamarco Nov 25, 2023
a1c4e28
fix: stabilize dialog header animation
dauriamarco Nov 25, 2023
206249b
feat: improve header animation
dauriamarco Nov 27, 2023
bfa914b
test: add e2e tests
dauriamarco Nov 27, 2023
497209f
refactor: rename data attr
dauriamarco Nov 28, 2023
bfa4107
fix: review
dauriamarco Dec 12, 2023
3109862
fix: attr ref remove
dauriamarco Dec 13, 2023
5e0cd7e
fix: temp tests fix
dauriamarco Dec 15, 2023
b1dec9e
fix: use setTimeout for RO callback
dauriamarco Dec 18, 2023
e9ef23f
fix: chromatic
dauriamarco Dec 20, 2023
34e865d
fix: rebase
dauriamarco Jan 17, 2024
81e7398
refactor: dialog initial refactoring
dauriamarco Jan 31, 2024
2b230eb
feat: add dialog actions
dauriamarco Feb 2, 2024
6de6568
fix: rebase
dauriamarco Feb 2, 2024
ac2e2ad
fix: integrity
dauriamarco Feb 5, 2024
bb721ad
fix: lint
dauriamarco Feb 5, 2024
3901c35
feat: handle negative state
dauriamarco Feb 7, 2024
4f78ca9
fix: dialog stories
dauriamarco Feb 7, 2024
e05e98c
fix: dialog title stories
dauriamarco Feb 7, 2024
1972457
fix: dialog content stories
dauriamarco Feb 7, 2024
ccb5284
fix: dialog actions stories
dauriamarco Feb 7, 2024
6da8a9d
fix: integrity
dauriamarco Feb 7, 2024
0adc70b
fix: remove fullscreen mode
dauriamarco Feb 7, 2024
fd7b956
fix: tests
dauriamarco Feb 8, 2024
29b3285
refactor: re-organize folders
dauriamarco Feb 8, 2024
3168915
fix: dialog snapshot
dauriamarco Feb 8, 2024
fd40340
fix: nested dialogs closing
dauriamarco Feb 8, 2024
f7dc8f1
refactor: remove e2e tests
dauriamarco Feb 8, 2024
7c12cc5
fix: hideOnScroll setter
dauriamarco Feb 8, 2024
6d71170
feat: implement type converter for hideOnScroll
dauriamarco Feb 8, 2024
37716d1
feat: show dialog title with focus visible within
dauriamarco Feb 8, 2024
504fe07
fix: sync negative state earlier
dauriamarco Feb 8, 2024
aa0fc55
docs: add documentation
dauriamarco Feb 8, 2024
49ee579
fix: review
dauriamarco Feb 20, 2024
5ba4f48
fix: rebase
dauriamarco Feb 20, 2024
a864bbc
docs: improve documentation
dauriamarco Feb 20, 2024
ca63fb3
fix: chromatic interactions
dauriamarco Feb 20, 2024
43e8ec4
fix: review
dauriamarco Feb 28, 2024
cf7b291
fix: use sbb-screenreader-only component
dauriamarco Feb 28, 2024
d82e33f
docs: improve documentation
dauriamarco Feb 28, 2024
b397420
fix: include testA11yTreeSnapshot
dauriamarco Feb 28, 2024
e11bab8
fix: testA11yTreeSnapshot
dauriamarco Feb 28, 2024
9ae7c22
fix: dialog hide title story
dauriamarco Feb 28, 2024
93b33b6
feat: improve hideOnScroll
dauriamarco Feb 29, 2024
21847f5
fix: rebase
dauriamarco Mar 5, 2024
602e565
fix: rebase
dauriamarco Mar 11, 2024
dd58c3c
fix: remove useless tests
dauriamarco Mar 11, 2024
944fd54
fix: optimize high contrast mode
dauriamarco Mar 13, 2024
a641c07
fix: use hostAttributes
dauriamarco Mar 16, 2024
7fcbc29
fix: high contrast mode
dauriamarco Mar 17, 2024
90b83c8
fix: review
dauriamarco Mar 17, 2024
a8e0f37
fix: add didClose event details type
dauriamarco Mar 18, 2024
98ef7b4
feat: show back button if an accessibilityBackLabel is provided
dauriamarco Mar 18, 2024
db9eb94
fix: tests
dauriamarco Mar 18, 2024
3c628e2
fix: rebase
dauriamarco Mar 19, 2024
bd7a960
fix: chromatic scroll
dauriamarco Mar 19, 2024
e37dea0
fix: rebase
dauriamarco Apr 4, 2024
bff75f2
fix: integrity
dauriamarco Apr 4, 2024
59392b7
Merge remote-tracking branch 'origin/main' into feat/dialog-header-hi…
dauriamarco Apr 8, 2024
93fabd4
fix: lint
dauriamarco Apr 8, 2024
50538cb
Merge remote-tracking branch 'origin/main' into feat/dialog-header-hi…
dauriamarco Apr 10, 2024
d9fb43b
fix: lint
dauriamarco Apr 10, 2024
d841ff9
fix: review
dauriamarco Apr 10, 2024
0775047
fix: cssprop documentation
dauriamarco Apr 10, 2024
a88d2f8
fix: remove hideHeader play story
dauriamarco Apr 10, 2024
20c7604
fix: remove named slots
dauriamarco Apr 10, 2024
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
17 changes: 14 additions & 3 deletions src/components/core/dom/breakpoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isBrowser } from './platform.js';

export type Breakpoint = 'zero' | 'micro' | 'small' | 'medium' | 'wide' | 'large' | 'ultra';
export const breakpoints = ['zero', 'micro', 'small', 'medium', 'wide', 'large', 'ultra'] as const;
export type Breakpoint = (typeof breakpoints)[number];

/**
* Checks whether the document matches a particular media query.
Expand All @@ -10,7 +11,11 @@ export type Breakpoint = 'zero' | 'micro' | 'small' | 'medium' | 'wide' | 'large
* @param to The breakpoint corresponding to the `max-width` value of the media query (optional).
* @returns A boolean indicating whether the window matches the breakpoint.
*/
export function isBreakpoint(from?: Breakpoint, to?: Breakpoint): boolean {
export function isBreakpoint(
from?: Breakpoint,
to?: Breakpoint,
properties?: { includeMaxBreakpoint: boolean },
): boolean {
if (!isBrowser()) {
// TODO: Remove and decide case by case what should be done on consuming end
return false;
Expand All @@ -19,7 +24,13 @@ export function isBreakpoint(from?: Breakpoint, to?: Breakpoint): boolean {
const computedStyle = getComputedStyle(document.documentElement);
const breakpointMin = from ? computedStyle.getPropertyValue(`--sbb-breakpoint-${from}-min`) : '';
const breakpointMax = to
? `${parseFloat(computedStyle.getPropertyValue(`--sbb-breakpoint-${to}-min`)) - 0.0625}rem`
? `${
parseFloat(
computedStyle.getPropertyValue(
`--sbb-breakpoint-${to}-${properties?.includeMaxBreakpoint ? 'max' : 'min'}`,
),
) - (properties?.includeMaxBreakpoint ? 0 : 0.0625)
}rem`
: ''; // subtract 1px (0.0625rem) from the max-width breakpoint

const minWidth = breakpointMin && `(min-width: ${breakpointMin})`;
Expand Down
74 changes: 0 additions & 74 deletions src/components/dialog/__snapshots__/dialog.spec.snap.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["sbb-dialog-actions renders"] =
`<sbb-dialog-actions
align-group="start"
button-size="l"
horizontal-from="medium"
link-size="m"
orientation="horizontal"
>
</sbb-dialog-actions>
`;
/* end snapshot sbb-dialog-actions renders */

snapshots["sbb-dialog-actions A11y tree Chrome"] =
`<p>
{
"role": "WebArea",
"name": ""
}
</p>
`;
/* end snapshot sbb-dialog-actions A11y tree Chrome */

snapshots["sbb-dialog-actions A11y tree Firefox"] =
`<p>
{
"role": "document",
"name": ""
}
</p>
`;
/* end snapshot sbb-dialog-actions A11y tree Firefox */

snapshots["sbb-dialog-actions A11y tree Safari"] =
`<p>
{
"role": "WebArea",
"name": ""
}
</p>
`;
/* end snapshot sbb-dialog-actions A11y tree Safari */

21 changes: 21 additions & 0 deletions src/components/dialog/dialog-actions/dialog-actions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@use '../../core/styles' as sbb;

:host {
display: contents;

@include sbb.if-forced-colors {
--sbb-dialog-actions-border: var(--sbb-border-width-1x) solid CanvasText;
}
}

.sbb-dialog-actions {
padding-inline: var(--sbb-dialog-padding-inline);
padding-block: var(--sbb-spacing-responsive-s);
margin-block-start: auto;
background-color: var(--sbb-dialog-background-color);
border-block-start: var(--sbb-dialog-actions-border);

:host([data-overflows]:not([data-negative])) & {
@include sbb.shadow-level-9-soft;
}
}
24 changes: 24 additions & 0 deletions src/components/dialog/dialog-actions/dialog-actions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../../core/testing/private/index.js';
import './dialog-actions.js';

describe('sbb-dialog-actions', () => {
it('renders', async () => {
const root = await fixture(html`<sbb-dialog-actions></sbb-dialog-actions>`);

await expect(root).dom.to.equalSnapshot();

expect(root).shadowDom.to.be.equal(`
<div class="sbb-dialog-actions">
<div class="sbb-action-group">
<slot>
</slot>
</div>
</div>
`);
});

testA11yTreeSnapshot(html`<sbb-dialog-actions></sbb-dialog-actions>`);
});
45 changes: 45 additions & 0 deletions src/components/dialog/dialog-actions/dialog-actions.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { withActions } from '@storybook/addon-actions/decorator';
import type { Decorator, Meta, StoryObj } from '@storybook/web-components';
import type { TemplateResult } from 'lit';
import { html } from 'lit';

import './dialog-actions.js';
import readme from './readme.md?raw';

import '../../button/button/index.js';
import '../../button/secondary-button/index.js';
import '../../link/index.js';

const Template = (): TemplateResult =>
html`<sbb-dialog-actions align-group="stretch" orientation="vertical" horizontal-from="medium">
<sbb-block-link
align-self="start"
icon-name="chevron-small-left-small"
href="https://www.sbb.ch/en/"
sbb-dialog-close
>
Link
</sbb-block-link>
<sbb-secondary-button sbb-dialog-close> Cancel </sbb-secondary-button>
<sbb-button sbb-dialog-close> Confirm </sbb-button>
</sbb-dialog-actions>`;

export const Default: StoryObj = { render: Template };

const meta: Meta = {
decorators: [
(story) => html` <div style="padding: 2rem;">${story()}</div> `,
withActions as Decorator,
],
parameters: {
backgrounds: {
disable: true,
},
docs: {
extractComponentDescription: () => readme,
},
},
title: 'components/sbb-dialog/sbb-dialog-actions',
};

export default meta;
28 changes: 28 additions & 0 deletions src/components/dialog/dialog-actions/dialog-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { CSSResultGroup, TemplateResult } from 'lit';
import { html } from 'lit';
import { customElement } from 'lit/decorators.js';

import { SbbActionGroupElement } from '../../action-group/index.js';

import style from './dialog-actions.scss?lit&inline';

/**
* Use this component to display a footer into an `sbb-dialog` with an action group.
*
* @slot - Use the unnamed slot to add `sbb-block-link` or `sbb-button` elements to the `sbb-dialog-actions`.
*/
@customElement('sbb-dialog-actions')
export class SbbDialogActionsElement extends SbbActionGroupElement {
public static override styles: CSSResultGroup = [SbbActionGroupElement.styles, style];

protected override render(): TemplateResult {
return html` <div class="sbb-dialog-actions">${super.render()}</div> `;
}
}

declare global {
interface HTMLElementTagNameMap {
// eslint-disable-next-line @typescript-eslint/naming-convention
'sbb-dialog-actions': SbbDialogActionsElement;
}
}
1 change: 1 addition & 0 deletions src/components/dialog/dialog-actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dialog-actions.js';
29 changes: 29 additions & 0 deletions src/components/dialog/dialog-actions/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The `sbb-dialog-actions` component extends the [sbb-action-group](/docs/components-sbb-action-group--docs) component. Use it in combination with the [sbb-dialog](/docs/components-sbb-dialog--docs) to display a footer with an action group.

```html
<sbb-dialog>
<sbb-dialog-action>
<sbb-block-link sbb-dialog-close>Link</sbb-block-link>
<sbb-secondary-button sbb-dialog-close> Cancel </sbb-secondary-button>
<sbb-button sbb-dialog-close> Confirm </sbb-button>
</sbb-dialog-actions>
</sbb-dialog>
```

<!-- Auto Generated Below -->

## Properties

| Name | Attribute | Privacy | Type | Default | Description |
| ---------------- | ----------------- | ------- | ------------------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `alignGroup` | `align-group` | public | `'start' \| 'center' \| 'stretch' \| 'end'` | `'start'` | Set the slotted `<sbb-action-group>` children's alignment. |
| `horizontalFrom` | `horizontal-from` | public | `SbbHorizontalFrom` | `'medium'` | Overrides the behaviour of `orientation` property. |
| `orientation` | `orientation` | public | `SbbOrientation` | `'horizontal'` | Indicates the orientation of the components inside the `<sbb-action-group>`. |
| `buttonSize` | `button-size` | public | `SbbButtonSize` | `'l'` | Size of the nested sbb-button instances. This will overwrite the size attribute of nested sbb-button instances. |
| `linkSize` | `link-size` | public | `SbbLinkSize` | `'m'` | Size of the nested sbb-block-link instances. This will overwrite the size attribute of nested sbb-block-link instances. |

## Slots

| Name | Description |
| ---- | -------------------------------------------------------------------------------------------------- |
| | Use the unnamed slot to add `sbb-block-link` or `sbb-button` elements to the `sbb-dialog-actions`. |
26 changes: 26 additions & 0 deletions src/components/dialog/dialog-content/dialog-content.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@use '../../core/styles' as sbb;

:host {
display: contents;
}

.sbb-dialog-content {
@include sbb.scrollbar-rules;

padding-inline: var(--sbb-dialog-padding-inline);
padding-block: var(--sbb-dialog-padding-block);
overflow: auto;
transform: translateY(var(--sbb-dialog-header-margin-block-start));
margin-block: 0 calc(var(--sbb-dialog-header-height) * -1);
transition: var(--sbb-dialog-content-transition);
z-index: -1;

// In order to improve the header transition on mobile (especially iOS) we use
// a combination of the transform and margin properties on touch devices,
// while on desktop we use just the margin-block for a better transition of the visible scrollbar.
@include sbb.mq($from: medium) {
transform: unset;
margin-block: var(--sbb-dialog-header-margin-block-start) 0;
transition: margin var(--sbb-dialog-animation-duration) var(--sbb-dialog-animation-easing);
}
}
17 changes: 17 additions & 0 deletions src/components/dialog/dialog-content/dialog-content.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, fixture } from '@open-wc/testing';
import { html } from 'lit/static-html.js';
import './dialog-content.js';

describe('sbb-dialog-content', () => {
it('renders', async () => {
const root = await fixture(html`<sbb-dialog-content>Content</sbb-dialog-content>`);

expect(root).dom.to.be.equal(`<sbb-dialog-content>Content</sbb-dialog-content>`);

expect(root).shadowDom.to.be.equal(`
<div class="sbb-dialog-content">
<slot></slot>
</div>
`);
});
});
30 changes: 30 additions & 0 deletions src/components/dialog/dialog-content/dialog-content.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { withActions } from '@storybook/addon-actions/decorator';
import type { Decorator, Meta, StoryObj } from '@storybook/web-components';
import type { TemplateResult } from 'lit';
import { html } from 'lit';

import './dialog-content.js';
import readme from './readme.md?raw';

const Template = (): TemplateResult =>
html`<sbb-dialog-content>This is a dialog content.</sbb-dialog-content>`;

export const Default: StoryObj = { render: Template };

const meta: Meta = {
decorators: [
(story) => html` <div style="padding: 2rem;">${story()}</div> `,
withActions as Decorator,
],
parameters: {
backgrounds: {
disable: true,
},
docs: {
extractComponentDescription: () => readme,
},
},
title: 'components/sbb-dialog/sbb-dialog-content',
};

export default meta;
Loading
Loading