-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Angular: Fix issue if BrowserAnimationsModule is imported
- Loading branch information
1 parent
bcca0cc
commit c550dbb
Showing
9 changed files
with
439 additions
and
394 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
13 changes: 13 additions & 0 deletions
13
...ate/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css
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,13 @@ | ||
:host { | ||
display: block; | ||
margin-top: 1rem; | ||
} | ||
|
||
.open-close-container { | ||
border: 1px solid #dddddd; | ||
margin-top: 1em; | ||
padding: 20px 20px 0px 20px; | ||
color: #000000; | ||
font-weight: bold; | ||
font-size: 20px; | ||
} |
7 changes: 7 additions & 0 deletions
7
...te/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html
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,7 @@ | ||
<nav> | ||
<button type="button" (click)="toggle()">Toggle Open/Close</button> | ||
</nav> | ||
|
||
<div [@openClose]="isOpen ? 'open' : 'closed'" class="open-close-container"> | ||
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p> | ||
</div> |
39 changes: 39 additions & 0 deletions
39
...late/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts
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,39 @@ | ||
import { Component } from '@angular/core'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { trigger, state, style, transition, animate } from '@angular/animations'; | ||
|
||
@Component({ | ||
selector: 'app-open-close', | ||
animations: [ | ||
trigger('openClose', [ | ||
// ... | ||
state( | ||
'open', | ||
style({ | ||
height: '200px', | ||
opacity: 1, | ||
backgroundColor: 'yellow', | ||
}) | ||
), | ||
state( | ||
'closed', | ||
style({ | ||
height: '100px', | ||
opacity: 0.8, | ||
backgroundColor: 'blue', | ||
}) | ||
), | ||
transition('open => closed', [animate('0.1s')]), | ||
transition('closed => open', [animate('0.1s')]), | ||
]), | ||
], | ||
templateUrl: 'open-close.component.html', | ||
styleUrls: ['open-close.component.css'], | ||
}) | ||
export class OpenCloseComponent { | ||
isOpen = true; | ||
|
||
toggle() { | ||
this.isOpen = !this.isOpen; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...rameworks/angular/template/stories/core/moduleMetadata/with-browser-animations.stories.ts
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,30 @@ | ||
import { Meta, StoryFn } from '@storybook/angular'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { within, userEvent } from '@storybook/testing-library'; | ||
import { expect } from '@storybook/jest'; | ||
import { OpenCloseComponent } from './angular-src/open-close-component/open-close.component'; | ||
|
||
export default { | ||
component: OpenCloseComponent, | ||
parameters: { | ||
chromatic: { delay: 100 }, | ||
}, | ||
} as Meta; | ||
|
||
export const WithBrowserAnimations: StoryFn = () => ({ | ||
template: `<app-open-close></app-open-close>`, | ||
moduleMetadata: { | ||
declarations: [OpenCloseComponent], | ||
imports: [BrowserAnimationsModule], | ||
}, | ||
}); | ||
|
||
WithBrowserAnimations.play = async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const opened = canvas.getByText('The box is now Open!'); | ||
expect(opened).toBeDefined(); | ||
const submitButton = canvas.getByRole('button'); | ||
await userEvent.click(submitButton); | ||
const closed = canvas.getByText('The box is now Closed!'); | ||
expect(closed).toBeDefined(); | ||
}; |
Oops, something went wrong.