UNPKG

26.8 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5const index = require('./index-a0a08b2a.js');
6const ionicGlobal = require('./ionic-global-06f21c1a.js');
7const buttonActive = require('./button-active-59a73c71.js');
8const overlays = require('./overlays-59863ad4.js');
9const theme = require('./theme-30b7a575.js');
10const animation = require('./animation-13cbbb20.js');
11require('./haptic-9f199ada.js');
12require('./index-a1dd5c93.js');
13require('./gesture-controller-29adda71.js');
14require('./hardware-back-button-148ce546.js');
15require('./helpers-d381ec4d.js');
16
17/**
18 * iOS Action Sheet Enter Animation
19 */
20const iosEnterAnimation = (baseEl) => {
21 const baseAnimation = animation.createAnimation();
22 const backdropAnimation = animation.createAnimation();
23 const wrapperAnimation = animation.createAnimation();
24 backdropAnimation
25 .addElement(baseEl.querySelector('ion-backdrop'))
26 .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
27 .beforeStyles({
28 'pointer-events': 'none'
29 })
30 .afterClearStyles(['pointer-events']);
31 wrapperAnimation
32 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
33 .fromTo('transform', 'translateY(100%)', 'translateY(0%)');
34 return baseAnimation
35 .addElement(baseEl)
36 .easing('cubic-bezier(.36,.66,.04,1)')
37 .duration(400)
38 .addAnimation([backdropAnimation, wrapperAnimation]);
39};
40
41/**
42 * iOS Action Sheet Leave Animation
43 */
44const iosLeaveAnimation = (baseEl) => {
45 const baseAnimation = animation.createAnimation();
46 const backdropAnimation = animation.createAnimation();
47 const wrapperAnimation = animation.createAnimation();
48 backdropAnimation
49 .addElement(baseEl.querySelector('ion-backdrop'))
50 .fromTo('opacity', 'var(--backdrop-opacity)', 0);
51 wrapperAnimation
52 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
53 .fromTo('transform', 'translateY(0%)', 'translateY(100%)');
54 return baseAnimation
55 .addElement(baseEl)
56 .easing('cubic-bezier(.36,.66,.04,1)')
57 .duration(450)
58 .addAnimation([backdropAnimation, wrapperAnimation]);
59};
60
61/**
62 * MD Action Sheet Enter Animation
63 */
64const mdEnterAnimation = (baseEl) => {
65 const baseAnimation = animation.createAnimation();
66 const backdropAnimation = animation.createAnimation();
67 const wrapperAnimation = animation.createAnimation();
68 backdropAnimation
69 .addElement(baseEl.querySelector('ion-backdrop'))
70 .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
71 .beforeStyles({
72 'pointer-events': 'none'
73 })
74 .afterClearStyles(['pointer-events']);
75 wrapperAnimation
76 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
77 .fromTo('transform', 'translateY(100%)', 'translateY(0%)');
78 return baseAnimation
79 .addElement(baseEl)
80 .easing('cubic-bezier(.36,.66,.04,1)')
81 .duration(400)
82 .addAnimation([backdropAnimation, wrapperAnimation]);
83};
84
85/**
86 * MD Action Sheet Leave Animation
87 */
88const mdLeaveAnimation = (baseEl) => {
89 const baseAnimation = animation.createAnimation();
90 const backdropAnimation = animation.createAnimation();
91 const wrapperAnimation = animation.createAnimation();
92 backdropAnimation
93 .addElement(baseEl.querySelector('ion-backdrop'))
94 .fromTo('opacity', 'var(--backdrop-opacity)', 0);
95 wrapperAnimation
96 .addElement(baseEl.querySelector('.action-sheet-wrapper'))
97 .fromTo('transform', 'translateY(0%)', 'translateY(100%)');
98 return baseAnimation
99 .addElement(baseEl)
100 .easing('cubic-bezier(.36,.66,.04,1)')
101 .duration(450)
102 .addAnimation([backdropAnimation, wrapperAnimation]);
103};
104
105const 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;margin-left:auto;margin-right:auto;margin-top:auto;margin-bottom:auto;-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}@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-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)}}";
106
107const 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;margin-left:auto;margin-right:auto;margin-top:auto;margin-bottom:auto;-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}@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-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-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:0}.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}";
108
109const ActionSheet = class {
110 constructor(hostRef) {
111 index.registerInstance(this, hostRef);
112 this.didPresent = index.createEvent(this, "ionActionSheetDidPresent", 7);
113 this.willPresent = index.createEvent(this, "ionActionSheetWillPresent", 7);
114 this.willDismiss = index.createEvent(this, "ionActionSheetWillDismiss", 7);
115 this.didDismiss = index.createEvent(this, "ionActionSheetDidDismiss", 7);
116 this.presented = false;
117 /**
118 * If `true`, the keyboard will be automatically dismissed when the overlay is presented.
119 */
120 this.keyboardClose = true;
121 /**
122 * An array of buttons for the action sheet.
123 */
124 this.buttons = [];
125 /**
126 * If `true`, the action sheet will be dismissed when the backdrop is clicked.
127 */
128 this.backdropDismiss = true;
129 /**
130 * If `true`, the action sheet will be translucent.
131 * Only applies when the mode is `"ios"` and the device supports
132 * [`backdrop-filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter#Browser_compatibility).
133 */
134 this.translucent = false;
135 /**
136 * If `true`, the action sheet will animate.
137 */
138 this.animated = true;
139 this.onBackdropTap = () => {
140 this.dismiss(undefined, overlays.BACKDROP);
141 };
142 this.dispatchCancelHandler = (ev) => {
143 const role = ev.detail.role;
144 if (overlays.isCancel(role)) {
145 const cancelButton = this.getButtons().find(b => b.role === 'cancel');
146 this.callButtonHandler(cancelButton);
147 }
148 };
149 }
150 /**
151 * Present the action sheet overlay after it has been created.
152 */
153 present() {
154 return overlays.present(this, 'actionSheetEnter', iosEnterAnimation, mdEnterAnimation);
155 }
156 connectedCallback() {
157 overlays.prepareOverlay(this.el);
158 }
159 /**
160 * Dismiss the action sheet overlay after it has been presented.
161 *
162 * @param data Any data to emit in the dismiss events.
163 * @param role The role of the element that is dismissing the action sheet.
164 * This can be useful in a button handler for determining which button was
165 * clicked to dismiss the action sheet.
166 * Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
167 */
168 dismiss(data, role) {
169 return overlays.dismiss(this, data, role, 'actionSheetLeave', iosLeaveAnimation, mdLeaveAnimation);
170 }
171 /**
172 * Returns a promise that resolves when the action sheet did dismiss.
173 */
174 onDidDismiss() {
175 return overlays.eventMethod(this.el, 'ionActionSheetDidDismiss');
176 }
177 /**
178 * Returns a promise that resolves when the action sheet will dismiss.
179 *
180 */
181 onWillDismiss() {
182 return overlays.eventMethod(this.el, 'ionActionSheetWillDismiss');
183 }
184 async buttonClick(button) {
185 const role = button.role;
186 if (overlays.isCancel(role)) {
187 return this.dismiss(undefined, role);
188 }
189 const shouldDismiss = await this.callButtonHandler(button);
190 if (shouldDismiss) {
191 return this.dismiss(undefined, button.role);
192 }
193 return Promise.resolve();
194 }
195 async callButtonHandler(button) {
196 if (button) {
197 // a handler has been provided, execute it
198 // pass the handler the values from the inputs
199 const rtn = await overlays.safeCall(button.handler);
200 if (rtn === false) {
201 // if the return value of the handler is false then do not dismiss
202 return false;
203 }
204 }
205 return true;
206 }
207 getButtons() {
208 return this.buttons.map(b => {
209 return (typeof b === 'string')
210 ? { text: b }
211 : b;
212 });
213 }
214 disconnectedCallback() {
215 if (this.gesture) {
216 this.gesture.destroy();
217 this.gesture = undefined;
218 }
219 }
220 componentDidLoad() {
221 /**
222 * Do not create gesture if:
223 * 1. A gesture already exists
224 * 2. App is running in MD mode
225 * 3. A wrapper ref does not exist
226 */
227 const { groupEl, wrapperEl } = this;
228 if (this.gesture || ionicGlobal.getIonMode(this) === 'md' || !wrapperEl || !groupEl) {
229 return;
230 }
231 index.readTask(() => {
232 const isScrollable = groupEl.scrollHeight > groupEl.clientHeight;
233 if (!isScrollable) {
234 this.gesture = buttonActive.createButtonActiveGesture(wrapperEl, (refEl) => refEl.classList.contains('action-sheet-button'));
235 this.gesture.enable(true);
236 }
237 });
238 }
239 render() {
240 const mode = ionicGlobal.getIonMode(this);
241 const allButtons = this.getButtons();
242 const cancelButton = allButtons.find(b => b.role === 'cancel');
243 const buttons = allButtons.filter(b => b.role !== 'cancel');
244 return (index.h(index.Host, { role: "dialog", "aria-modal": "true", tabindex: "-1", style: {
245 zIndex: `${20000 + this.overlayIndex}`,
246 }, class: Object.assign(Object.assign({ [mode]: true }, theme.getClassMap(this.cssClass)), { 'action-sheet-translucent': this.translucent }), onIonActionSheetWillDismiss: this.dispatchCancelHandler, onIonBackdropTap: this.onBackdropTap }, index.h("ion-backdrop", { tappable: this.backdropDismiss }), index.h("div", { tabindex: "0" }), index.h("div", { class: "action-sheet-wrapper ion-overlay-wrapper", role: "dialog", ref: el => this.wrapperEl = el }, index.h("div", { class: "action-sheet-container" }, index.h("div", { class: "action-sheet-group", ref: el => this.groupEl = el }, this.header !== undefined &&
247 index.h("div", { class: {
248 'action-sheet-title': true,
249 'action-sheet-has-sub-title': this.subHeader !== undefined
250 } }, this.header, this.subHeader && index.h("div", { class: "action-sheet-sub-title" }, this.subHeader)), buttons.map(b => index.h("button", { type: "button", class: buttonClass(b), onClick: () => this.buttonClick(b) }, index.h("span", { class: "action-sheet-button-inner" }, b.icon && index.h("ion-icon", { icon: b.icon, lazy: false, class: "action-sheet-icon" }), b.text), mode === 'md' && index.h("ion-ripple-effect", null)))), cancelButton &&
251 index.h("div", { class: "action-sheet-group action-sheet-group-cancel" }, index.h("button", { type: "button", class: buttonClass(cancelButton), onClick: () => this.buttonClick(cancelButton) }, index.h("span", { class: "action-sheet-button-inner" }, cancelButton.icon &&
252 index.h("ion-icon", { icon: cancelButton.icon, lazy: false, class: "action-sheet-icon" }), cancelButton.text), mode === 'md' && index.h("ion-ripple-effect", null))))), index.h("div", { tabindex: "0" })));
253 }
254 get el() { return index.getElement(this); }
255};
256const buttonClass = (button) => {
257 return Object.assign({ 'action-sheet-button': true, 'ion-activatable': true, 'ion-focusable': true, [`action-sheet-${button.role}`]: button.role !== undefined }, theme.getClassMap(button.cssClass));
258};
259ActionSheet.style = {
260 ios: actionSheetIosCss,
261 md: actionSheetMdCss
262};
263
264exports.ion_action_sheet = ActionSheet;