Skip to content

Commit

Permalink
fix(toast): add initial opacity based on mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thetaPC committed Nov 26, 2024
1 parent ff93af7 commit ea17631
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 21 deletions.
46 changes: 27 additions & 19 deletions core/src/components/toast/test/basic/toast.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,34 @@ class ToastFixture {
/**
* This behavior does not vary across directions.
*/
configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('toast: position rendering'), () => {
let toastFixture: ToastFixture;
test.beforeEach(async ({ page }) => {
toastFixture = new ToastFixture(page);
await toastFixture.goto(config);
});
test('should render toast at the top', async () => {
await toastFixture.openToast('#show-top-toast');
await toastFixture.screenshot('top', screenshot);
});
test('should render toast at the middle', async () => {
await toastFixture.openToast('#show-middle-toast');
await toastFixture.screenshot('middle', screenshot);
});
test('should render toast at the bottom', async () => {
await toastFixture.openToast('#show-bottom-toast');
await toastFixture.screenshot('bottom', screenshot);
configs({ modes: ['ios', 'md', 'ionic-md', 'ionic-ios'], directions: ['ltr'] }).forEach(
({ title, screenshot, config }) => {
test.describe(title('toast: position rendering'), () => {
let toastFixture: ToastFixture;
test.beforeEach(async ({ page }) => {
toastFixture = new ToastFixture(page);
await toastFixture.goto(config);
});
test('should render toast at the top', async () => {
await toastFixture.openToast('#show-top-toast');
await toastFixture.screenshot('top', screenshot);
});
test('should render toast at the middle', async () => {
await toastFixture.openToast('#show-middle-toast');
await toastFixture.screenshot('middle', screenshot);
});
test('should render toast at the bottom', async () => {
await toastFixture.openToast('#show-bottom-toast');
await toastFixture.screenshot('bottom', screenshot);
});
});
});
}
);

/**
* This behavior does not vary across directions.
*/
configs({ modes: ['ios', 'md', 'ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('toast: color rendering'), () => {
test('should set color correctly', async ({ page }) => {
const toastFixture = new ToastFixture(page);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 26 additions & 2 deletions core/src/components/toast/toast.ionic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,42 @@
z-index: 1001;
}

// Toast Wrapper
// --------------------------------------------------

.toast-wrapper {
@include globals.margin(auto);

display: block;
position: absolute;

opacity: 0.01;

// TODO(ROU-10853): replace this value with a layer token.
z-index: 10;
}

/*
* In `md` mode, the toast fades in when presented.
* To achieve the fade-in effect, the initial opacity must be set
* to a value less than 1.
*/
:host(.md) .toast-wrapper {
opacity: 0.01;
}

/*
* In `ios` mode, the toast will move into the screen based
* on the `position`. If the `position` is `middle`, the toast
* will fade in from the middle of the screen.
* To achieve the fade-in effect, the initial opacity must be set
* to a value less than 1.
*/
:host(.ios) .toast-wrapper.toast-middle {
opacity: 0.01;
}

// Toast Container
// --------------------------------------------------

.toast-container {
@include globals.padding(globals.$ion-space-300, globals.$ion-space-400);
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/components/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ export class Toast implements ComponentInterface, OverlayInterface {
const startButtons = allButtons.filter((b) => b.side === 'start');
const endButtons = allButtons.filter((b) => b.side !== 'start');
const theme = getIonTheme(this);
const mode = getIonMode(this);
const shape = this.getShape();
const wrapperClass = {
'toast-wrapper': true,
Expand All @@ -746,6 +747,7 @@ export class Toast implements ComponentInterface, OverlayInterface {
zIndex: `${60000 + this.overlayIndex}`,
}}
class={createColorClasses(this.color, {
[mode]: true,
[theme]: true,
...getClassMap(this.cssClass),
'overlay-hidden': true,
Expand Down

0 comments on commit ea17631

Please sign in to comment.