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(disable-animation): migrate disable-animation mechanism #2507

Merged
merged 34 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3194500
refactor(disable-animation): disable animation con chromatic and test…
TomMenga Mar 19, 2024
e953ff1
refactor(disable-animation): migrate disable-animation mechanism
TomMenga Mar 19, 2024
ac8176a
fix(laoding-indicator): fix disable-animation
TomMenga Mar 20, 2024
9db73f4
docs(disable-animation): add docs to readmes
TomMenga Mar 20, 2024
9dd5d05
Revert "refactor(timetable, journey): migrate disable-animation mecha…
TomMenga Mar 21, 2024
0577bf1
feat(disable-animation): add disable-animation-specific class
TomMenga Mar 21, 2024
1259dd9
feat(alert): disable fade-in animation by default
TomMenga Mar 21, 2024
8b8ff1b
feat(notification): disable open animation by default
TomMenga Mar 27, 2024
6b1aa21
chore: integrity
TomMenga Mar 27, 2024
2c05ede
fix: feedbacks
TomMenga Apr 8, 2024
057b4bd
Merge branch 'main' into refactor/disable-animation
TomMenga Apr 8, 2024
5bc2d3a
Merge branch 'main' into refactor/disable-animation
TomMenga Apr 16, 2024
95eed41
refactor(dialog): adapt to the new disable-animation system
TomMenga Apr 16, 2024
db843a9
chore: integrity
TomMenga Apr 16, 2024
9474a74
refactor(alert): add 'animation' property
TomMenga Apr 16, 2024
fa4611b
refactor(notification): add 'animation' property
TomMenga Apr 16, 2024
3413d6c
docs: remove 'disable-animation' entry from readmes
TomMenga Apr 16, 2024
a815fac
style: move animation mixins to a different file
TomMenga Apr 16, 2024
15a8786
fix: fix animation mixin inclusion
jeripeierSBB Apr 17, 2024
05aee7a
fix: pr feedbacks
TomMenga Apr 17, 2024
b28b9a4
Merge branch 'main' into refactor/disable-animation
TomMenga Apr 17, 2024
ff7b5c6
docs(alert, notification): change 'animation' default
TomMenga Apr 17, 2024
0800a30
style(loading-indicator): use token for anim duration
TomMenga Apr 17, 2024
7e216f8
Merge branch 'main' into refactor/disable-animation
TomMenga Apr 17, 2024
27572b0
feat(alert, notification): change 'animation' default
TomMenga Apr 18, 2024
26d73e4
test: update snapshots
TomMenga Apr 18, 2024
20c8ed5
docs(alert, notification): update animation docs
TomMenga Apr 22, 2024
3a47c07
Merge branch 'refs/heads/main' into refactor/disable-animation
jeripeierSBB Apr 23, 2024
4085975
fix: readme of image
jeripeierSBB Apr 23, 2024
29ff187
fix: refactor remaining components
jeripeierSBB Apr 23, 2024
3a9b49c
fix: formatting
jeripeierSBB Apr 23, 2024
51e746c
fix: formatting 2
jeripeierSBB Apr 23, 2024
5bf8ca6
Merge branch 'refs/heads/main' into refactor/disable-animation
jeripeierSBB Apr 23, 2024
884f611
fix: linting
jeripeierSBB Apr 23, 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
1 change: 1 addition & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ export const decorators: Decorator[] = [
? html`<div style="padding: 2rem;min-height: 100vh">${story()}</div>`
: story(),
withBackgroundDecorator,
(story) => (isChromatic() ? html`<div class="sbb-disable-animation">${story()}</div>` : story()),
];
6 changes: 3 additions & 3 deletions src/components/accordion/accordion.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ describe(`sbb-accordion ${fixture.name}`, () => {
element = await fixture(
html`
<sbb-accordion title-level="4">
<sbb-expansion-panel id="panel-1" disable-animation title-level=${ssrTitleLevel}>
<sbb-expansion-panel id="panel-1" title-level=${ssrTitleLevel}>
<sbb-expansion-panel-header id="header-1">Header 1</sbb-expansion-panel-header>
<sbb-expansion-panel-content>Content 1</sbb-expansion-panel-content>
</sbb-expansion-panel>
<sbb-expansion-panel id="panel-2" disable-animation title-level=${ssrTitleLevel}>
<sbb-expansion-panel id="panel-2" title-level=${ssrTitleLevel}>
<sbb-expansion-panel-header id="header-2">Header 2</sbb-expansion-panel-header>
<sbb-expansion-panel-content>Content 2</sbb-expansion-panel-content>
</sbb-expansion-panel>
<sbb-expansion-panel id="panel-3" disable-animation title-level=${ssrTitleLevel}>
<sbb-expansion-panel id="panel-3" title-level=${ssrTitleLevel}>
<sbb-expansion-panel-header id="header-3">Header 3</sbb-expansion-panel-header>
<sbb-expansion-panel-content>Content 3</sbb-expansion-panel-content>
</sbb-expansion-panel>
Expand Down
17 changes: 0 additions & 17 deletions src/components/accordion/accordion.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ const multi: InputType = {
},
};

const disableAnimation: InputType = {
control: {
type: 'boolean',
},
table: {
category: 'Accordion',
},
};

const titleLevel: InputType = {
control: {
type: 'inline-radio',
Expand Down Expand Up @@ -119,7 +110,6 @@ const contentText: InputType = {
const defaultArgTypes: ArgTypes = {
numberOfPanels,
multi,
'disable-animation': disableAnimation,
'title-level': titleLevel,
color,
expanded,
Expand All @@ -133,7 +123,6 @@ const defaultArgTypes: ArgTypes = {
const defaultArgs: Args = {
numberOfPanels: 3,
multi: false,
'disable-animation': false,
'title-level': titleLevel.options![2],
color: color.options![0],
expanded: false,
Expand Down Expand Up @@ -226,12 +215,6 @@ export const Multi: StoryObj = {
args: { ...defaultArgs, multi: true },
};

export const NoAnimation: StoryObj = {
render: Template,
argTypes: defaultArgTypes,
args: { ...defaultArgs, 'disable-animation': true },
};

const meta: Meta = {
decorators: [withActions as Decorator],
parameters: {
Expand Down
8 changes: 0 additions & 8 deletions src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ export class SbbAccordionElement extends SbbHydrationMixin(LitElement) {
}
private _titleLevel: SbbTitleLevel | null = null;

/**
* Whether the animation should be disabled.
* @controls SbbExpansionPanelElement.disableAnimation
*/
@property({ attribute: 'disable-animation', reflect: true, type: Boolean })
public disableAnimation = false;

/** Whether more than one sbb-expansion-panel can be open at the same time. */
@property({ type: Boolean })
public set multi(value: boolean) {
Expand Down Expand Up @@ -98,7 +91,6 @@ export class SbbAccordionElement extends SbbHydrationMixin(LitElement) {
this._expansionPanels.forEach(
(panel: SbbExpansionPanelElement, index: number, array: SbbExpansionPanelElement[]) => {
panel.titleLevel = this.titleLevel;
panel.disableAnimation = this.disableAnimation;
panel.toggleAttribute('data-accordion-first', index === 0);
panel.toggleAttribute('data-accordion-last', index === array.length - 1);
},
Expand Down
9 changes: 4 additions & 5 deletions src/components/accordion/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ In the following example, all the `sbb-expansion-panel-header` would be wrapped

## Properties

| Name | Attribute | Privacy | Type | Default | Description |
| ------------------ | ------------------- | ------- | ----------------------- | ------- | --------------------------------------------------------------------------- |
| `titleLevel` | `title-level` | public | `SbbTitleLevel \| null` | `null` | The heading level for the sbb-expansion-panel-headers within the component. |
| `disableAnimation` | `disable-animation` | public | `boolean` | `false` | Whether the animation should be disabled. |
| `multi` | `multi` | public | `boolean` | `false` | Whether more than one sbb-expansion-panel can be open at the same time. |
| Name | Attribute | Privacy | Type | Default | Description |
| ------------ | ------------- | ------- | ----------------------- | ------- | --------------------------------------------------------------------------- |
| `titleLevel` | `title-level` | public | `SbbTitleLevel \| null` | `null` | The heading level for the sbb-expansion-panel-headers within the component. |
| `multi` | `multi` | public | `boolean` | `false` | Whether more than one sbb-expansion-panel can be open at the same time. |

## Slots

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ snapshots["sbb-alert-group should render Dom"] =
role="status"
>
<sbb-alert
animation="open"
data-state="opening"
href="https://www.sbb.ch"
size="m"
Expand Down Expand Up @@ -113,3 +114,24 @@ snapshots["sbb-alert-group should render A11y tree Firefox"] =
`;
/* end snapshot sbb-alert-group should render A11y tree Firefox */

snapshots["sbb-alert-group should render with slots"] =
`<sbb-alert-group
accessibility-title-level="3"
role="status"
>
<span slot="accessibility-title">
Interruptions
</span>
<sbb-alert
animation="open"
data-state="opening"
href="https://www.sbb.ch"
size="m"
title-content="Interruption between Genève and Lausanne"
>
The rail traffic between Allaman and Morges is interrupted. All trains are cancelled.
</sbb-alert>
</sbb-alert-group>
`;
/* end snapshot sbb-alert-group should render with slots */

13 changes: 1 addition & 12 deletions src/components/alert/alert-group/alert-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,7 @@ describe(`sbb-alert-group`, () => {
</sbb-alert-group>
`);

expect(root).dom.to.be.equal(
`
<sbb-alert-group accessibility-title-level='3' role='status'>
<span slot="accessibility-title">
Interruptions
</span>
<sbb-alert title-content='Interruption between Genève and Lausanne' href='https://www.sbb.ch' size="m" data-state="opening">
The rail traffic between Allaman and Morges is interrupted. All trains are cancelled.
</sbb-alert>
</sbb-alert-group>
`,
);
await expect(root).dom.to.be.equalSnapshot();
expect(root).shadowDom.to.be.equal(
`
<div class="sbb-alert-group">
Expand Down
10 changes: 6 additions & 4 deletions src/components/alert/alert/alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ $open-anim-opacity-to: 1;
--sbb-alert-close-icon-size: var(--sbb-size-icon-ui-small);
--sbb-alert-close-icon-margin: var(--sbb-spacing-responsive-xxs);
--sbb-alert-gap: var(--sbb-spacing-fixed-2x) var(--sbb-spacing-responsive-xs);
--sbb-alert-animation-duration: var(--sbb-animation-duration-6x);
--sbb-alert-animation-duration: var(
--sbb-disable-animation-zero-time,
var(--sbb-animation-duration-6x)
);

@include sbb.mq($from: medium) {
--sbb-alert-icon-size: #{sbb.px-to-rem-build(28)};
Expand All @@ -35,9 +38,8 @@ $open-anim-opacity-to: 1;
display: block;
}

:host([disable-animation]) {
// To avoid flickering, we need 0 instead of 0.1ms here.
--sbb-alert-animation-duration: 0ms;
:host([animation='none']) {
@include sbb.disable-animation;
}

:host([size='s']) {
Expand Down
8 changes: 3 additions & 5 deletions src/components/alert/alert/alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ describe(`sbb-alert`, () => {

it('should render default properties', async () => {
element = await fixture(
html`<sbb-alert disable-animation title-content="Interruption">Alert content</sbb-alert>`,
html`<sbb-alert title-content="Interruption">Alert content</sbb-alert>`,
);

expect(element).dom.to.be.equal(
`
<sbb-alert disable-animation title-content="Interruption" size="m" data-state="opening">
<sbb-alert title-content="Interruption" size="m" data-state="opening" animation="open">
Alert content
</sbb-alert>
`,
Expand All @@ -32,7 +32,6 @@ describe(`sbb-alert`, () => {
title-content="Interruption"
title-level="2"
size="l"
disable-animation
icon-name="disruption"
accessibility-label="label"
href="https://www.sbb.ch"
Expand All @@ -49,12 +48,12 @@ describe(`sbb-alert`, () => {
title-content="Interruption"
title-level="2"
size="l"
disable-animation
icon-name="disruption"
accessibility-label="label"
href="https://www.sbb.ch"
rel="noopener" target="_blank"
link-content="Show much more"
animation="open"
data-state="opening"
>
Alert content
Expand All @@ -66,7 +65,6 @@ describe(`sbb-alert`, () => {

testA11yTreeSnapshot(html`
<sbb-alert
disable-animation
title-content="Interruption"
href="https://www.sbb.ch"
accessibility-label="test-a11y-label"
Expand Down
23 changes: 9 additions & 14 deletions src/components/alert/alert/alert.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ const readonly: InputType = {
},
};

const disableAnimation: InputType = {
control: {
type: 'boolean',
},
};

const iconName: InputType = {
control: {
type: 'text',
Expand Down Expand Up @@ -136,27 +130,33 @@ const accessibilityLabel: InputType = {
},
};

const animation: InputType = {
control: {
type: 'inline-radio',
},
options: ['open', 'none'],
};

const defaultArgTypes: ArgTypes = {
'title-content': titleContent,
'title-level': titleLevel,
size,
readonly,
'disable-animation': disableAnimation,
'icon-name': iconName,
'content-slot-text': contentSlotText,
'link-content': linkContent,
href,
target,
rel,
'accessibility-label': accessibilityLabel,
animation: animation,
};

const defaultArgs: Args = {
'title-content': 'Interruption between Berne and Olten',
'title-level': 3,
size: size.options![0],
readonly: false,
'disable-animation': false,
'icon-name': 'info',
'content-slot-text':
"Between Berne and Olten from 03.11.2021 to 05.12.2022 each time from 22:30 to 06:00 o'clock construction work will take place. You have to expect changed travel times and changed connections.",
Expand All @@ -165,6 +165,7 @@ const defaultArgs: Args = {
target: undefined,
rel: undefined,
'accessibility-label': undefined,
animation: animation.options![0],
};

export const defaultAlert: StoryObj = {
Expand All @@ -191,12 +192,6 @@ export const withoutCloseButton: StoryObj = {
args: { ...defaultArgs, readonly: true },
};

export const withDisabledAnimation: StoryObj = {
render: Default,
argTypes: defaultArgTypes,
args: { ...defaultArgs, 'disable-animation': true },
};

export const withoutLink: StoryObj = {
render: Default,
argTypes: defaultArgTypes,
Expand Down
6 changes: 3 additions & 3 deletions src/components/alert/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export class SbbAlertElement extends SbbIconNameMixin(LitElement) {
/** You can choose between `m` or `l` size. */
@property({ reflect: true }) public size: 's' | 'm' | 'l' = 'm';

/** Whether the fade in animation should be disabled. */
@property({ attribute: 'disable-animation', type: Boolean }) public disableAnimation = false;

/**
* Name of the icon which will be forward to the nested `sbb-icon`.
* Choose the icons from https://icons.app.sbb.ch.
Expand Down Expand Up @@ -77,6 +74,9 @@ export class SbbAlertElement extends SbbIconNameMixin(LitElement) {
/** This will be forwarded as aria-label to the relevant nested element. */
@property({ attribute: 'accessibility-label' }) public accessibilityLabel: string | undefined;

/** The enabled animations. */
@property({ reflect: true }) public animation: 'open' | 'none' = 'open';

/** The state of the alert. */
private get _state(): SbbAlertState {
return (this.getAttribute('data-state') as SbbAlertState | null) ?? 'closed';
Expand Down
7 changes: 6 additions & 1 deletion src/components/alert/alert/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ The description text is wrapped into an `<p>` element to guarantee the semantic

Avoid slotting block elements (e.g. `<div>`) as this violates semantic rules and can have negative effects on screen readers.

## Animation

Set the `animation` property to manage which animations are enabled.
As a base rule, opening animations should be active if an alert arrives after the initial page load.

<!-- Auto Generated Below -->

## Properties
Expand All @@ -81,7 +86,6 @@ Avoid slotting block elements (e.g. `<div>`) as this violates semantic rules and
| -------------------- | --------------------- | ------- | --------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `readonly` | `readonly` | public | `boolean` | `false` | Whether the alert is readonly. In readonly mode, there is no dismiss button offered to the user. |
| `size` | `size` | public | `'s' \| 'm' \| 'l'` | `'m'` | You can choose between `m` or `l` size. |
| `disableAnimation` | `disable-animation` | public | `boolean` | `false` | Whether the fade in animation should be disabled. |
| `iconName` | `icon-name` | public | `string \| undefined` | `'info'` | Name of the icon which will be forward to the nested `sbb-icon`. Choose the icons from https://icons.app.sbb.ch. Styling is optimized for icons of type HIM-CUS. |
| `titleContent` | `title-content` | public | `string \| undefined` | | Content of title. |
| `titleLevel` | `title-level` | public | `SbbTitleLevel` | `'3'` | Level of title, will be rendered as heading tag (e.g. h3). Defaults to level 3. |
Expand All @@ -90,6 +94,7 @@ Avoid slotting block elements (e.g. `<div>`) as this violates semantic rules and
| `target` | `target` | public | `LinkTargetType \| string \| undefined` | | Where to display the linked URL. |
| `rel` | `rel` | public | `string \| undefined` | | The relationship of the linked URL as space-separated link types. |
| `accessibilityLabel` | `accessibility-label` | public | `string \| undefined` | | This will be forwarded as aria-label to the relevant nested element. |
| `animation` | `animation` | public | `'open' \| 'none'` | `'open'` | The enabled animations. |

## Methods

Expand Down
2 changes: 1 addition & 1 deletion src/components/autocomplete/autocomplete.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe(`sbb-autocomplete with ${fixture.name}`, () => {
html`
<sbb-form-field>
<input />
<sbb-autocomplete id="myAutocomplete" disable-animation>
<sbb-autocomplete id="myAutocomplete">
<sbb-option id="option-1" value="1">1</sbb-option>
<sbb-option id="option-2" value="2">2</sbb-option>
<sbb-option id="option-3" value="3">3</sbb-option>
Expand Down
4 changes: 0 additions & 4 deletions src/components/autocomplete/autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
);
}

:host([disable-animation]) {
--sbb-options-panel-animation-duration: 0.1ms;
}

:host([preserve-icon-space]) {
--sbb-option-icon-container-display: block;
}
Expand Down
Loading
Loading