Skip to content

Commit 33e40be

Browse files
Implementing new shapes for ion-toast
1 parent ab61c12 commit 33e40be

File tree

7 files changed

+74
-6
lines changed

7 files changed

+74
-6
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,7 @@ ion-toast,prop,message,IonicSafeString | string | undefined,undefined,false,fals
23762376
ion-toast,prop,mode,"ios" | "md",undefined,false,false
23772377
ion-toast,prop,position,"bottom" | "middle" | "top",'bottom',false,false
23782378
ion-toast,prop,positionAnchor,HTMLElement | string | undefined,undefined,false,false
2379+
ion-toast,prop,shape,"rectangular" | "round" | "soft" | undefined,undefined,false,false
23792380
ion-toast,prop,swipeGesture,"vertical" | undefined,undefined,false,false
23802381
ion-toast,prop,theme,"ios" | "md" | "ionic",undefined,false,false
23812382
ion-toast,prop,translucent,boolean,false,false,false

core/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,6 +3771,10 @@ export namespace Components {
37713771
* Present the toast overlay after it has been created.
37723772
*/
37733773
"present": () => Promise<void>;
3774+
/**
3775+
* Set to `"soft"` for a toast with slightly rounded corners, `"round"` for a toast with fully rounded corners, or `"rectangular"` for a toast without rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
3776+
*/
3777+
"shape"?: 'soft' | 'round' | 'rectangular';
37743778
/**
37753779
* If set to 'vertical', the Toast can be dismissed with a swipe gesture. The swipe direction is determined by the value of the `position` property: `top`: The Toast can be swiped up to dismiss. `bottom`: The Toast can be swiped down to dismiss. `middle`: The Toast can be swiped up or down to dismiss.
37763780
*/
@@ -9161,6 +9165,10 @@ declare namespace LocalJSX {
91619165
* The element to anchor the toast's position to. Can be set as a direct reference or the ID of the element. With `position="bottom"`, the toast will sit above the chosen element. With `position="top"`, the toast will sit below the chosen element. With `position="middle"`, the value of `positionAnchor` is ignored.
91629166
*/
91639167
"positionAnchor"?: HTMLElement | string;
9168+
/**
9169+
* Set to `"soft"` for a toast with slightly rounded corners, `"round"` for a toast with fully rounded corners, or `"rectangular"` for a toast without rounded corners. Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
9170+
*/
9171+
"shape"?: 'soft' | 'round' | 'rectangular';
91649172
/**
91659173
* If set to 'vertical', the Toast can be dismissed with a swipe gesture. The swipe direction is determined by the value of the `position` property: `top`: The Toast can be swiped up to dismiss. `bottom`: The Toast can be swiped down to dismiss. `middle`: The Toast can be swiped up or down to dismiss.
91669174
*/

core/src/components/toast/test/basic/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,30 @@
169169
Toast with Icon 3
170170
</button>
171171

172+
<button
173+
class="expand"
174+
id="soft-shape-toast"
175+
onclick="openToast({ message: 'click to close', duration: 2000, shape: 'soft' })"
176+
>
177+
Soft Toast
178+
</button>
179+
180+
<button
181+
class="expand"
182+
id="round-shape-toast"
183+
onclick="openToast({ message: 'click to close', duration: 2000, shape: 'round' })"
184+
>
185+
Round Toast
186+
</button>
187+
188+
<button
189+
class="expand"
190+
id="rect-shape-toast"
191+
onclick="openToast({ message: 'click to close', duration: 2000, shape: 'rectangular' })"
192+
>
193+
Rectangular Toast
194+
</button>
195+
172196
<ion-grid>
173197
<ion-row>
174198
<ion-col size="6">

core/src/components/toast/toast.ionic.scss

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
:host {
88
--background: #{globals.$ionic-color-neutral-1200};
9-
--border-radius: #{globals.$ionic-border-radius-400};
109
--box-shadow: #{globals.$ionic-elevation-400};
1110
--button-color: #{globals.$ionic-color-base-white};
1211
--color: #{globals.$ionic-color-base-white};
@@ -36,6 +35,21 @@
3635
@include globals.padding(globals.$ionic-space-300, globals.$ionic-space-400);
3736
}
3837

38+
// Toast Shapes
39+
// --------------------------------------------------
40+
41+
:host(.toast-shape-soft) {
42+
--border-radius: #{globals.$ionic-border-radius-200};
43+
}
44+
45+
:host(.toast-shape-round) {
46+
--border-radius: #{globals.$ionic-border-radius-400};
47+
}
48+
49+
:host(.toast-shape-rectangular) {
50+
--border-radius: #{globals.$ionic-border-radius-0};
51+
}
52+
3953
// Toast Header
4054
// --------------------------------------------------
4155

core/src/components/toast/toast.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { createColorClasses, getClassMap } from '@utils/theme';
2222

2323
import { config } from '../../global/config';
2424
import { getIonMode, getIonTheme } from '../../global/ionic-global';
25-
import type { AnimationBuilder, Color, CssClassMap, OverlayInterface, FrameworkDelegate } from '../../interface';
25+
import type { AnimationBuilder, Color, CssClassMap, OverlayInterface, FrameworkDelegate, Theme } from '../../interface';
2626
import type { OverlayEventDetail } from '../../utils/overlays-interface';
2727
import type { IonicSafeString } from '../../utils/sanitization';
2828

@@ -172,6 +172,15 @@ export class Toast implements ComponentInterface, OverlayInterface {
172172
*/
173173
@Prop() positionAnchor?: HTMLElement | string;
174174

175+
/**
176+
* Set to `"soft"` for a toast with slightly rounded corners,
177+
* `"round"` for a toast with fully rounded corners, or `"rectangular"`
178+
* for a toast without rounded corners.
179+
*
180+
* Defaults to `"round"` for the `ionic` theme, undefined for all other themes.
181+
*/
182+
@Prop() shape?: 'soft' | 'round' | 'rectangular';
183+
175184
/**
176185
* An array of buttons for the toast.
177186
*/
@@ -484,6 +493,16 @@ export class Toast implements ComponentInterface, OverlayInterface {
484493
return buttons;
485494
}
486495

496+
private getShape(theme: Theme): string | undefined {
497+
const { shape } = this;
498+
499+
if (theme === 'ionic' && shape === undefined) {
500+
return 'round';
501+
}
502+
503+
return shape;
504+
}
505+
487506
/**
488507
* Returns the element specified by the positionAnchor prop,
489508
* or undefined if prop's value is an ID string and the element
@@ -696,6 +715,7 @@ export class Toast implements ComponentInterface, OverlayInterface {
696715
const startButtons = allButtons.filter((b) => b.side === 'start');
697716
const endButtons = allButtons.filter((b) => b.side !== 'start');
698717
const theme = getIonTheme(this);
718+
const shape = this.getShape(theme);
699719
const wrapperClass = {
700720
'toast-wrapper': true,
701721
[`toast-${this.position}`]: true,
@@ -725,6 +745,7 @@ export class Toast implements ComponentInterface, OverlayInterface {
725745
...getClassMap(this.cssClass),
726746
'overlay-hidden': true,
727747
'toast-translucent': this.translucent,
748+
[`toast-shape-${shape}`]: shape !== undefined,
728749
})}
729750
onIonToastWillDismiss={this.dispatchCancelHandler}
730751
>

packages/angular/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,15 +2341,15 @@ export declare interface IonTitle extends Components.IonTitle {}
23412341

23422342

23432343
@ProxyCmp({
2344-
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'swipeGesture', 'theme', 'translucent', 'trigger'],
2344+
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'shape', 'swipeGesture', 'theme', 'translucent', 'trigger'],
23452345
methods: ['present', 'dismiss', 'onDidDismiss', 'onWillDismiss']
23462346
})
23472347
@Component({
23482348
selector: 'ion-toast',
23492349
changeDetection: ChangeDetectionStrategy.OnPush,
23502350
template: '<ng-content></ng-content>',
23512351
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
2352-
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'swipeGesture', 'theme', 'translucent', 'trigger'],
2352+
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'shape', 'swipeGesture', 'theme', 'translucent', 'trigger'],
23532353
})
23542354
export class IonToast {
23552355
protected el: HTMLElement;

packages/angular/standalone/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,15 +2092,15 @@ export declare interface IonTitle extends Components.IonTitle {}
20922092

20932093
@ProxyCmp({
20942094
defineCustomElementFn: defineIonToast,
2095-
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'swipeGesture', 'theme', 'translucent', 'trigger'],
2095+
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'shape', 'swipeGesture', 'theme', 'translucent', 'trigger'],
20962096
methods: ['present', 'dismiss', 'onDidDismiss', 'onWillDismiss']
20972097
})
20982098
@Component({
20992099
selector: 'ion-toast',
21002100
changeDetection: ChangeDetectionStrategy.OnPush,
21012101
template: '<ng-content></ng-content>',
21022102
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
2103-
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'swipeGesture', 'theme', 'translucent', 'trigger'],
2103+
inputs: ['animated', 'buttons', 'color', 'cssClass', 'duration', 'enterAnimation', 'header', 'htmlAttributes', 'icon', 'isOpen', 'keyboardClose', 'layout', 'leaveAnimation', 'message', 'mode', 'position', 'positionAnchor', 'shape', 'swipeGesture', 'theme', 'translucent', 'trigger'],
21042104
standalone: true
21052105
})
21062106
export class IonToast {

0 commit comments

Comments
 (0)