UNPKG

27.7 kBJavaScriptView Raw
1/*!
2 * (C) Ionic http://ionicframework.com - MIT License
3 */
4import { proxyCustomElement, HTMLElement, createEvent, readTask, h, Host } from '@stencil/core/internal/client';
5import { b as getIonMode } from './ionic-global.js';
6import { c as createButtonActiveGesture } from './button-active.js';
7import { B as BACKDROP, i as isCancel, d as present, e as prepareOverlay, f as dismiss, g as eventMethod, s as safeCall } from './overlays.js';
8import { g as getClassMap } from './theme.js';
9import { c as createAnimation } from './animation.js';
10import { d as defineCustomElement$3 } from './backdrop.js';
11import { d as defineCustomElement$2 } from './icon.js';
12import { d as defineCustomElement$1 } from './ripple-effect.js';
13
14/**
15 * iOS Action Sheet Enter Animation
16 */
17const iosEnterAnimation = (baseEl) => {
18 const baseAnimation = createAnimation();
19 const backdropAnimation = createAnimation();
20 const wrapperAnimation = createAnimation();
21 backdropAnimation
22 .addElement(baseEl.querySelector('ion-backdrop'))
23 .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
24 .beforeStyles({
25 'pointer-events': 'none'
26 })
27 .afterClearStyles(['pointer-events']);
28 wrapperAnimation
29 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
30 .fromTo('transform', 'translateY(100%)', 'translateY(0%)');
31 return baseAnimation
32 .addElement(baseEl)
33 .easing('cubic-bezier(.36,.66,.04,1)')
34 .duration(400)
35 .addAnimation([backdropAnimation, wrapperAnimation]);
36};
37
38/**
39 * iOS Action Sheet Leave Animation
40 */
41const iosLeaveAnimation = (baseEl) => {
42 const baseAnimation = createAnimation();
43 const backdropAnimation = createAnimation();
44 const wrapperAnimation = createAnimation();
45 backdropAnimation
46 .addElement(baseEl.querySelector('ion-backdrop'))
47 .fromTo('opacity', 'var(--backdrop-opacity)', 0);
48 wrapperAnimation
49 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
50 .fromTo('transform', 'translateY(0%)', 'translateY(100%)');
51 return baseAnimation
52 .addElement(baseEl)
53 .easing('cubic-bezier(.36,.66,.04,1)')
54 .duration(450)
55 .addAnimation([backdropAnimation, wrapperAnimation]);
56};
57
58/**
59 * MD Action Sheet Enter Animation
60 */
61const mdEnterAnimation = (baseEl) => {
62 const baseAnimation = createAnimation();
63 const backdropAnimation = createAnimation();
64 const wrapperAnimation = createAnimation();
65 backdropAnimation
66 .addElement(baseEl.querySelector('ion-backdrop'))
67 .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
68 .beforeStyles({
69 'pointer-events': 'none'
70 })
71 .afterClearStyles(['pointer-events']);
72 wrapperAnimation
73 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
74 .fromTo('transform', 'translateY(100%)', 'translateY(0%)');
75 return baseAnimation
76 .addElement(baseEl)
77 .easing('cubic-bezier(.36,.66,.04,1)')
78 .duration(400)
79 .addAnimation([backdropAnimation, wrapperAnimation]);
80};
81
82/**
83 * MD Action Sheet Leave Animation
84 */
85const mdLeaveAnimation = (baseEl) => {
86 const baseAnimation = createAnimation();
87 const backdropAnimation = createAnimation();
88 const wrapperAnimation = createAnimation();
89 backdropAnimation
90 .addElement(baseEl.querySelector('ion-backdrop'))
91 .fromTo('opacity', 'var(--backdrop-opacity)', 0);
92 wrapperAnimation
93 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
94 .fromTo('transform', 'translateY(0%)', 'translateY(100%)');
95 return baseAnimation
96 .addElement(baseEl)
97 .easing('cubic-bezier(.36,.66,.04,1)')
98 .duration(450)
99 .addAnimation([backdropAnimation, wrapperAnimation]);
100};
101
102const actionSheetIosCss = ".sc-ion-action-sheet-ios-h{--color:initial;--button-color-activated:var(--button-color);--button-color-focused:var(--button-color);--button-color-hover:var(--button-color);--button-color-selected:var(--button-color);--min-width:auto;--width:100%;--max-width:500px;--min-height:auto;--height:100%;--max-height:calc(100% - (var(--ion-safe-area-top) + var(--ion-safe-area-bottom)));-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;left:0;right:0;top:0;bottom:0;display:block;position:fixed;outline:none;font-family:var(--ion-font-family, inherit);-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:1001}.overlay-hidden.sc-ion-action-sheet-ios-h{display:none}.action-sheet-wrapper.sc-ion-action-sheet-ios{left:0;right:0;bottom:0;-webkit-transform:translate3d(0, 100%, 0);transform:translate3d(0, 100%, 0);display:block;position:absolute;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);height:var(--height);min-height:var(--min-height);max-height:var(--max-height);z-index:10;pointer-events:none}.action-sheet-button.sc-ion-action-sheet-ios{display:block;position:relative;width:100%;border:0;outline:none;background:var(--button-background);color:var(--button-color);font-family:inherit;overflow:hidden}.action-sheet-button-inner.sc-ion-action-sheet-ios{display:-ms-flexbox;display:flex;position:relative;-ms-flex-flow:row nowrap;flex-flow:row nowrap;-ms-flex-negative:0;flex-shrink:0;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;pointer-events:none;width:100%;height:100%;z-index:1}.action-sheet-container.sc-ion-action-sheet-ios{display:-ms-flexbox;display:flex;-ms-flex-flow:column;flex-flow:column;-ms-flex-pack:end;justify-content:flex-end;height:100%;max-height:100%}.action-sheet-group.sc-ion-action-sheet-ios{-ms-flex-negative:2;flex-shrink:2;overscroll-behavior-y:contain;overflow-y:auto;-webkit-overflow-scrolling:touch;pointer-events:all;background:var(--background)}.action-sheet-group.sc-ion-action-sheet-ios::-webkit-scrollbar{display:none}.action-sheet-group-cancel.sc-ion-action-sheet-ios{-ms-flex-negative:0;flex-shrink:0;overflow:hidden}.action-sheet-button.sc-ion-action-sheet-ios::after{left:0;right:0;top:0;bottom:0;position:absolute;content:\"\";opacity:0}.action-sheet-selected.sc-ion-action-sheet-ios{color:var(--button-color-selected)}.action-sheet-selected.sc-ion-action-sheet-ios::after{background:var(--button-background-selected);opacity:var(--button-background-selected-opacity)}.action-sheet-button.ion-activated.sc-ion-action-sheet-ios{color:var(--button-color-activated)}.action-sheet-button.ion-activated.sc-ion-action-sheet-ios::after{background:var(--button-background-activated);opacity:var(--button-background-activated-opacity)}.action-sheet-button.ion-focused.sc-ion-action-sheet-ios{color:var(--button-color-focused)}.action-sheet-button.ion-focused.sc-ion-action-sheet-ios::after{background:var(--button-background-focused);opacity:var(--button-background-focused-opacity)}@media (any-hover: hover){.action-sheet-button.sc-ion-action-sheet-ios:hover{color:var(--button-color-hover)}.action-sheet-button.sc-ion-action-sheet-ios:hover::after{background:var(--button-background-hover);opacity:var(--button-background-hover-opacity)}}.sc-ion-action-sheet-ios-h{--background:var(--ion-overlay-background-color, var(--ion-color-step-100, #f9f9f9));--backdrop-opacity:var(--ion-backdrop-opacity, 0.4);--button-background:linear-gradient(0deg, rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.08), rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.08) 50%, transparent 50%) bottom/100% 1px no-repeat transparent;--button-background-activated:var(--ion-text-color, #000);--button-background-activated-opacity:.08;--button-background-hover:currentColor;--button-background-hover-opacity:.04;--button-background-focused:currentColor;--button-background-focused-opacity:.12;--button-background-selected:var(--ion-color-step-150, var(--ion-background-color, #fff));--button-background-selected-opacity:1;--button-color:var(--ion-color-primary, #3880ff);--color:var(--ion-color-step-400, #999999);text-align:center}.action-sheet-wrapper.sc-ion-action-sheet-ios{margin-left:auto;margin-right:auto;margin-top:var(--ion-safe-area-top, 0);margin-bottom:var(--ion-safe-area-bottom, 0)}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-wrapper.sc-ion-action-sheet-ios{margin-left:unset;margin-right:unset;-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto}}.action-sheet-container.sc-ion-action-sheet-ios{padding-left:8px;padding-right:8px;padding-top:0;padding-bottom:0}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-container.sc-ion-action-sheet-ios{padding-left:unset;padding-right:unset;-webkit-padding-start:8px;padding-inline-start:8px;-webkit-padding-end:8px;padding-inline-end:8px}}.action-sheet-group.sc-ion-action-sheet-ios{border-radius:13px;margin-bottom:8px}.action-sheet-group.sc-ion-action-sheet-ios:first-child{margin-top:10px}.action-sheet-group.sc-ion-action-sheet-ios:last-child{margin-bottom:10px}@supports ((-webkit-backdrop-filter: blur(0)) or (backdrop-filter: blur(0))){.action-sheet-translucent.sc-ion-action-sheet-ios-h .action-sheet-group.sc-ion-action-sheet-ios{background-color:transparent;-webkit-backdrop-filter:saturate(280%) blur(20px);backdrop-filter:saturate(280%) blur(20px)}.action-sheet-translucent.sc-ion-action-sheet-ios-h .action-sheet-title.sc-ion-action-sheet-ios,.action-sheet-translucent.sc-ion-action-sheet-ios-h .action-sheet-button.sc-ion-action-sheet-ios{background-color:transparent;background-image:-webkit-gradient(linear, left bottom, left top, from(rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8)), to(rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8))), -webkit-gradient(linear, left bottom, left top, from(rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.4)), color-stop(50%, rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.4)), color-stop(50%, rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8)));background-image:linear-gradient(0deg, rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8), rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8) 100%), linear-gradient(0deg, rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.4), rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.4) 50%, rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8) 50%);background-repeat:no-repeat;background-position:top, bottom;background-size:100% calc(100% - 1px), 100% 1px;-webkit-backdrop-filter:saturate(120%);backdrop-filter:saturate(120%)}.action-sheet-translucent.sc-ion-action-sheet-ios-h .action-sheet-button.ion-activated.sc-ion-action-sheet-ios{background-color:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.7);background-image:none}.action-sheet-translucent.sc-ion-action-sheet-ios-h .action-sheet-cancel.sc-ion-action-sheet-ios{background:var(--button-background-selected)}}.action-sheet-title.sc-ion-action-sheet-ios{background:-webkit-gradient(linear, left bottom, left top, from(rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.08)), color-stop(50%, rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.08)), color-stop(50%, transparent)) bottom/100% 1px no-repeat transparent;background:linear-gradient(0deg, rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.08), rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.08) 50%, transparent 50%) bottom/100% 1px no-repeat transparent}.action-sheet-title.sc-ion-action-sheet-ios{padding-left:10px;padding-right:10px;padding-top:14px;padding-bottom:13px;color:var(--color, var(--ion-color-step-400, #999999));font-size:13px;font-weight:400;text-align:center}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-title.sc-ion-action-sheet-ios{padding-left:unset;padding-right:unset;-webkit-padding-start:10px;padding-inline-start:10px;-webkit-padding-end:10px;padding-inline-end:10px}}.action-sheet-title.action-sheet-has-sub-title.sc-ion-action-sheet-ios{font-weight:600}.action-sheet-sub-title.sc-ion-action-sheet-ios{padding-left:0;padding-right:0;padding-top:6px;padding-bottom:0;font-size:13px;font-weight:400}.action-sheet-button.sc-ion-action-sheet-ios{padding-left:18px;padding-right:18px;padding-top:18px;padding-bottom:18px;height:56px;font-size:20px;contain:strict}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-button.sc-ion-action-sheet-ios{padding-left:unset;padding-right:unset;-webkit-padding-start:18px;padding-inline-start:18px;-webkit-padding-end:18px;padding-inline-end:18px}}.action-sheet-button.sc-ion-action-sheet-ios .action-sheet-icon.sc-ion-action-sheet-ios{margin-right:0.3em;font-size:28px;pointer-events:none}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-button.sc-ion-action-sheet-ios .action-sheet-icon.sc-ion-action-sheet-ios{margin-right:unset;-webkit-margin-end:0.3em;margin-inline-end:0.3em}}.action-sheet-button.sc-ion-action-sheet-ios:last-child{background-image:none}.action-sheet-selected.sc-ion-action-sheet-ios{font-weight:bold}.action-sheet-cancel.sc-ion-action-sheet-ios{font-weight:600}.action-sheet-cancel.sc-ion-action-sheet-ios::after{background:var(--button-background-selected);opacity:var(--button-background-selected-opacity)}.action-sheet-destructive.sc-ion-action-sheet-ios,.action-sheet-destructive.ion-activated.sc-ion-action-sheet-ios,.action-sheet-destructive.ion-focused.sc-ion-action-sheet-ios{color:var(--ion-color-danger, #eb445a)}@media (any-hover: hover){.action-sheet-destructive.sc-ion-action-sheet-ios:hover{color:var(--ion-color-danger, #eb445a)}}";
103
104const actionSheetMdCss = ".sc-ion-action-sheet-md-h{--color:initial;--button-color-activated:var(--button-color);--button-color-focused:var(--button-color);--button-color-hover:var(--button-color);--button-color-selected:var(--button-color);--min-width:auto;--width:100%;--max-width:500px;--min-height:auto;--height:100%;--max-height:calc(100% - (var(--ion-safe-area-top) + var(--ion-safe-area-bottom)));-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;left:0;right:0;top:0;bottom:0;display:block;position:fixed;outline:none;font-family:var(--ion-font-family, inherit);-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:1001}.overlay-hidden.sc-ion-action-sheet-md-h{display:none}.action-sheet-wrapper.sc-ion-action-sheet-md{left:0;right:0;bottom:0;-webkit-transform:translate3d(0, 100%, 0);transform:translate3d(0, 100%, 0);display:block;position:absolute;width:var(--width);min-width:var(--min-width);max-width:var(--max-width);height:var(--height);min-height:var(--min-height);max-height:var(--max-height);z-index:10;pointer-events:none}.action-sheet-button.sc-ion-action-sheet-md{display:block;position:relative;width:100%;border:0;outline:none;background:var(--button-background);color:var(--button-color);font-family:inherit;overflow:hidden}.action-sheet-button-inner.sc-ion-action-sheet-md{display:-ms-flexbox;display:flex;position:relative;-ms-flex-flow:row nowrap;flex-flow:row nowrap;-ms-flex-negative:0;flex-shrink:0;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;pointer-events:none;width:100%;height:100%;z-index:1}.action-sheet-container.sc-ion-action-sheet-md{display:-ms-flexbox;display:flex;-ms-flex-flow:column;flex-flow:column;-ms-flex-pack:end;justify-content:flex-end;height:100%;max-height:100%}.action-sheet-group.sc-ion-action-sheet-md{-ms-flex-negative:2;flex-shrink:2;overscroll-behavior-y:contain;overflow-y:auto;-webkit-overflow-scrolling:touch;pointer-events:all;background:var(--background)}.action-sheet-group.sc-ion-action-sheet-md::-webkit-scrollbar{display:none}.action-sheet-group-cancel.sc-ion-action-sheet-md{-ms-flex-negative:0;flex-shrink:0;overflow:hidden}.action-sheet-button.sc-ion-action-sheet-md::after{left:0;right:0;top:0;bottom:0;position:absolute;content:\"\";opacity:0}.action-sheet-selected.sc-ion-action-sheet-md{color:var(--button-color-selected)}.action-sheet-selected.sc-ion-action-sheet-md::after{background:var(--button-background-selected);opacity:var(--button-background-selected-opacity)}.action-sheet-button.ion-activated.sc-ion-action-sheet-md{color:var(--button-color-activated)}.action-sheet-button.ion-activated.sc-ion-action-sheet-md::after{background:var(--button-background-activated);opacity:var(--button-background-activated-opacity)}.action-sheet-button.ion-focused.sc-ion-action-sheet-md{color:var(--button-color-focused)}.action-sheet-button.ion-focused.sc-ion-action-sheet-md::after{background:var(--button-background-focused);opacity:var(--button-background-focused-opacity)}@media (any-hover: hover){.action-sheet-button.sc-ion-action-sheet-md:hover{color:var(--button-color-hover)}.action-sheet-button.sc-ion-action-sheet-md:hover::after{background:var(--button-background-hover);opacity:var(--button-background-hover-opacity)}}.sc-ion-action-sheet-md-h{--background:var(--ion-overlay-background-color, var(--ion-background-color, #fff));--backdrop-opacity:var(--ion-backdrop-opacity, 0.32);--button-background:transparent;--button-background-selected:currentColor;--button-background-selected-opacity:0;--button-background-activated:transparent;--button-background-activated-opacity:0;--button-background-hover:currentColor;--button-background-hover-opacity:.04;--button-background-focused:currentColor;--button-background-focused-opacity:.12;--button-color:var(--ion-color-step-850, #262626);--color:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.54)}.action-sheet-wrapper.sc-ion-action-sheet-md{margin-left:auto;margin-right:auto;margin-top:var(--ion-safe-area-top, 0);margin-bottom:0}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-wrapper.sc-ion-action-sheet-md{margin-left:unset;margin-right:unset;-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto}}.action-sheet-title.sc-ion-action-sheet-md{padding-left:16px;padding-right:16px;padding-top:20px;padding-bottom:17px;min-height:60px;color:var(--color, rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.54));font-size:16px;text-align:start}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-title.sc-ion-action-sheet-md{padding-left:unset;padding-right:unset;-webkit-padding-start:16px;padding-inline-start:16px;-webkit-padding-end:16px;padding-inline-end:16px}}.action-sheet-sub-title.sc-ion-action-sheet-md{padding-left:0;padding-right:0;padding-top:16px;padding-bottom:0;font-size:14px}.action-sheet-group.sc-ion-action-sheet-md:first-child{padding-top:0}.action-sheet-group.sc-ion-action-sheet-md:last-child{padding-bottom:var(--ion-safe-area-bottom)}.action-sheet-button.sc-ion-action-sheet-md{padding-left:16px;padding-right:16px;padding-top:0;padding-bottom:0;position:relative;height:52px;font-size:16px;text-align:start;contain:strict;overflow:hidden}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-button.sc-ion-action-sheet-md{padding-left:unset;padding-right:unset;-webkit-padding-start:16px;padding-inline-start:16px;-webkit-padding-end:16px;padding-inline-end:16px}}.action-sheet-icon.sc-ion-action-sheet-md{padding-bottom:4px;margin-left:0;margin-right:32px;margin-top:0;margin-bottom:0;color:var(--color);font-size:24px}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.action-sheet-icon.sc-ion-action-sheet-md{margin-left:unset;margin-right:unset;-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:32px;margin-inline-end:32px}}.action-sheet-button-inner.sc-ion-action-sheet-md{-ms-flex-pack:start;justify-content:flex-start}.action-sheet-selected.sc-ion-action-sheet-md{font-weight:bold}";
105
106const ActionSheet = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
107 constructor() {
108 super();
109 this.__registerHost();
110 this.didPresent = createEvent(this, "ionActionSheetDidPresent", 7);
111 this.willPresent = createEvent(this, "ionActionSheetWillPresent", 7);
112 this.willDismiss = createEvent(this, "ionActionSheetWillDismiss", 7);
113 this.didDismiss = createEvent(this, "ionActionSheetDidDismiss", 7);
114 this.presented = false;
115 /**
116 * If `true`, the keyboard will be automatically dismissed when the overlay is presented.
117 */
118 this.keyboardClose = true;
119 /**
120 * An array of buttons for the action sheet.
121 */
122 this.buttons = [];
123 /**
124 * If `true`, the action sheet will be dismissed when the backdrop is clicked.
125 */
126 this.backdropDismiss = true;
127 /**
128 * If `true`, the action sheet will be translucent.
129 * Only applies when the mode is `"ios"` and the device supports
130 * [`backdrop-filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter#Browser_compatibility).
131 */
132 this.translucent = false;
133 /**
134 * If `true`, the action sheet will animate.
135 */
136 this.animated = true;
137 this.onBackdropTap = () => {
138 this.dismiss(undefined, BACKDROP);
139 };
140 this.dispatchCancelHandler = (ev) => {
141 const role = ev.detail.role;
142 if (isCancel(role)) {
143 const cancelButton = this.getButtons().find(b => b.role === 'cancel');
144 this.callButtonHandler(cancelButton);
145 }
146 };
147 }
148 /**
149 * Present the action sheet overlay after it has been created.
150 */
151 present() {
152 return present(this, 'actionSheetEnter', iosEnterAnimation, mdEnterAnimation);
153 }
154 connectedCallback() {
155 prepareOverlay(this.el);
156 }
157 /**
158 * Dismiss the action sheet overlay after it has been presented.
159 *
160 * @param data Any data to emit in the dismiss events.
161 * @param role The role of the element that is dismissing the action sheet.
162 * This can be useful in a button handler for determining which button was
163 * clicked to dismiss the action sheet.
164 * Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
165 */
166 dismiss(data, role) {
167 return dismiss(this, data, role, 'actionSheetLeave', iosLeaveAnimation, mdLeaveAnimation);
168 }
169 /**
170 * Returns a promise that resolves when the action sheet did dismiss.
171 */
172 onDidDismiss() {
173 return eventMethod(this.el, 'ionActionSheetDidDismiss');
174 }
175 /**
176 * Returns a promise that resolves when the action sheet will dismiss.
177 *
178 */
179 onWillDismiss() {
180 return eventMethod(this.el, 'ionActionSheetWillDismiss');
181 }
182 async buttonClick(button) {
183 const role = button.role;
184 if (isCancel(role)) {
185 return this.dismiss(button.data, role);
186 }
187 const shouldDismiss = await this.callButtonHandler(button);
188 if (shouldDismiss) {
189 return this.dismiss(button.data, button.role);
190 }
191 return Promise.resolve();
192 }
193 async callButtonHandler(button) {
194 if (button) {
195 // a handler has been provided, execute it
196 // pass the handler the values from the inputs
197 const rtn = await safeCall(button.handler);
198 if (rtn === false) {
199 // if the return value of the handler is false then do not dismiss
200 return false;
201 }
202 }
203 return true;
204 }
205 getButtons() {
206 return this.buttons.map(b => {
207 return (typeof b === 'string')
208 ? { text: b }
209 : b;
210 });
211 }
212 disconnectedCallback() {
213 if (this.gesture) {
214 this.gesture.destroy();
215 this.gesture = undefined;
216 }
217 }
218 componentDidLoad() {
219 /**
220 * Do not create gesture if:
221 * 1. A gesture already exists
222 * 2. App is running in MD mode
223 * 3. A wrapper ref does not exist
224 */
225 const { groupEl, wrapperEl } = this;
226 if (this.gesture || getIonMode(this) === 'md' || !wrapperEl || !groupEl) {
227 return;
228 }
229 readTask(() => {
230 const isScrollable = groupEl.scrollHeight > groupEl.clientHeight;
231 if (!isScrollable) {
232 this.gesture = createButtonActiveGesture(wrapperEl, (refEl) => refEl.classList.contains('action-sheet-button'));
233 this.gesture.enable(true);
234 }
235 });
236 }
237 render() {
238 const { htmlAttributes } = this;
239 const mode = getIonMode(this);
240 const allButtons = this.getButtons();
241 const cancelButton = allButtons.find(b => b.role === 'cancel');
242 const buttons = allButtons.filter(b => b.role !== 'cancel');
243 return (h(Host, Object.assign({ role: "dialog", "aria-modal": "true", tabindex: "-1" }, htmlAttributes, { style: {
244 zIndex: `${20000 + this.overlayIndex}`,
245 }, class: Object.assign(Object.assign({ [mode]: true }, getClassMap(this.cssClass)), { 'overlay-hidden': true, 'action-sheet-translucent': this.translucent }), onIonActionSheetWillDismiss: this.dispatchCancelHandler, onIonBackdropTap: this.onBackdropTap }), h("ion-backdrop", { tappable: this.backdropDismiss }), h("div", { tabindex: "0" }), h("div", { class: "action-sheet-wrapper ion-overlay-wrapper", role: "dialog", ref: el => this.wrapperEl = el }, h("div", { class: "action-sheet-container" }, h("div", { class: "action-sheet-group", ref: el => this.groupEl = el }, this.header !== undefined &&
246 h("div", { class: {
247 'action-sheet-title': true,
248 'action-sheet-has-sub-title': this.subHeader !== undefined
249 } }, this.header, this.subHeader && h("div", { class: "action-sheet-sub-title" }, this.subHeader)), buttons.map(b => h("button", { type: "button", id: b.id, class: buttonClass(b), onClick: () => this.buttonClick(b) }, h("span", { class: "action-sheet-button-inner" }, b.icon && h("ion-icon", { icon: b.icon, lazy: false, class: "action-sheet-icon" }), b.text), mode === 'md' && h("ion-ripple-effect", null)))), cancelButton &&
250 h("div", { class: "action-sheet-group action-sheet-group-cancel" }, h("button", { type: "button", class: buttonClass(cancelButton), onClick: () => this.buttonClick(cancelButton) }, h("span", { class: "action-sheet-button-inner" }, cancelButton.icon &&
251 h("ion-icon", { icon: cancelButton.icon, lazy: false, class: "action-sheet-icon" }), cancelButton.text), mode === 'md' && h("ion-ripple-effect", null))))), h("div", { tabindex: "0" })));
252 }
253 get el() { return this; }
254 static get style() { return {
255 ios: actionSheetIosCss,
256 md: actionSheetMdCss
257 }; }
258}, [34, "ion-action-sheet", {
259 "overlayIndex": [2, "overlay-index"],
260 "keyboardClose": [4, "keyboard-close"],
261 "enterAnimation": [16],
262 "leaveAnimation": [16],
263 "buttons": [16],
264 "cssClass": [1, "css-class"],
265 "backdropDismiss": [4, "backdrop-dismiss"],
266 "header": [1],
267 "subHeader": [1, "sub-header"],
268 "translucent": [4],
269 "animated": [4],
270 "htmlAttributes": [16],
271 "present": [64],
272 "dismiss": [64],
273 "onDidDismiss": [64],
274 "onWillDismiss": [64]
275 }]);
276const buttonClass = (button) => {
277 return Object.assign({ 'action-sheet-button': true, 'ion-activatable': true, 'ion-focusable': true, [`action-sheet-${button.role}`]: button.role !== undefined }, getClassMap(button.cssClass));
278};
279function defineCustomElement() {
280 if (typeof customElements === "undefined") {
281 return;
282 }
283 const components = ["ion-action-sheet", "ion-backdrop", "ion-icon", "ion-ripple-effect"];
284 components.forEach(tagName => { switch (tagName) {
285 case "ion-action-sheet":
286 if (!customElements.get(tagName)) {
287 customElements.define(tagName, ActionSheet);
288 }
289 break;
290 case "ion-backdrop":
291 if (!customElements.get(tagName)) {
292 defineCustomElement$3();
293 }
294 break;
295 case "ion-icon":
296 if (!customElements.get(tagName)) {
297 defineCustomElement$2();
298 }
299 break;
300 case "ion-ripple-effect":
301 if (!customElements.get(tagName)) {
302 defineCustomElement$1();
303 }
304 break;
305 } });
306}
307
308export { ActionSheet as A, defineCustomElement as d };