-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(toast): add wrapper and content parts #30737
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
Merged
+142
−5
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ee6d8c
feat(toast): Add attribute part='content'
Hurubon 8bdb27a
feat(toast): add wrapper and content parts
brandyscarney b694e24
Merge branch 'feature-8.8' into feat-30735
brandyscarney 239232c
test(toast): add e2e test for customizing via parts
brandyscarney 0a55ebb
bad copy paste
brandyscarney e6df0ca
Merge branch 'feature-8.8' into feat-30735
brandyscarney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,133 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * This behavior does not vary across directions | ||
| */ | ||
| configs({ directions: ['ltr'] }).forEach(({ config, title }) => { | ||
| test.describe(title('toast: custom'), () => { | ||
| test('should be able to customize toast wrapper, container, and content using css parts', async ({ page }) => { | ||
| await page.setContent( | ||
| ` | ||
| <ion-toast is-open="true" header="Header" message="Hello World"></ion-toast> | ||
|
|
||
| <style> | ||
| ion-toast::part(wrapper) { | ||
| background-color: red; | ||
| } | ||
| ion-toast::part(container) { | ||
| background-color: green; | ||
| } | ||
| ion-toast::part(content) { | ||
| background-color: blue; | ||
| } | ||
| </style> | ||
| `, | ||
| config | ||
| ); | ||
|
|
||
| const wrapperColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="wrapper"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).backgroundColor : null; | ||
| }); | ||
|
|
||
| expect(wrapperColor).toBe('rgb(255, 0, 0)'); | ||
|
|
||
| const containerColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="container"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).backgroundColor : null; | ||
| }); | ||
|
|
||
| expect(containerColor).toBe('rgb(0, 128, 0)'); | ||
|
|
||
| const contentColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="content"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).backgroundColor : null; | ||
| }); | ||
|
|
||
| expect(contentColor).toBe('rgb(0, 0, 255)'); | ||
| }); | ||
|
|
||
| test('should be able to customize toast header and message using css parts', async ({ page }) => { | ||
| await page.setContent( | ||
| ` | ||
| <ion-toast is-open="true" header="Header" message="Hello World"></ion-toast> | ||
|
|
||
| <style> | ||
| ion-toast::part(header) { | ||
| color: red; | ||
| } | ||
| ion-toast::part(message) { | ||
| color: green; | ||
| } | ||
| </style> | ||
| `, | ||
| config | ||
| ); | ||
|
|
||
| const headerColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="header"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).color : null; | ||
| }); | ||
|
|
||
| expect(headerColor).toBe('rgb(255, 0, 0)'); | ||
|
|
||
| const messageColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="message"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).color : null; | ||
| }); | ||
|
|
||
| expect(messageColor).toBe('rgb(0, 128, 0)'); | ||
| }); | ||
|
|
||
| test('should be able to customize toast icon, button, and button cancel using css parts', async ({ page }) => { | ||
| await page.setContent( | ||
| ` | ||
| <ion-toast is-open="true" header="Header" message="Hello World" icon="alert"></ion-toast> | ||
|
|
||
| <style> | ||
| ion-toast::part(icon) { | ||
| color: red; | ||
| } | ||
| ion-toast::part(button) { | ||
| color: green; | ||
| } | ||
| ion-toast::part(button cancel) { | ||
| color: blue; | ||
| } | ||
| </style> | ||
|
|
||
| <script> | ||
| const toast = document.querySelector('ion-toast'); | ||
| toast.buttons = [ | ||
| { text: 'Cancel', role: 'cancel' }, | ||
| { text: 'OK' } | ||
| ]; | ||
| </script> | ||
| `, | ||
| config | ||
| ); | ||
|
|
||
| const iconColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="icon"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).color : null; | ||
| }); | ||
|
|
||
| expect(iconColor).toBe('rgb(255, 0, 0)'); | ||
|
|
||
| const buttonColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="button"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).color : null; | ||
| }); | ||
|
|
||
| expect(buttonColor).toBe('rgb(0, 128, 0)'); | ||
|
|
||
| const buttonCancelColor = await page.locator('ion-toast').evaluate((el: any) => { | ||
| const partEl = el.shadowRoot?.querySelector('[part="button cancel"]') as HTMLElement | null; | ||
| return partEl ? getComputedStyle(partEl).color : null; | ||
| }); | ||
|
|
||
| expect(buttonCancelColor).toBe('rgb(0, 0, 255)'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.