action-sheet.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, createEvent, readTask, h, Host } from '@stencil/core/internal/client';
  5. import { c as createButtonActiveGesture } from './button-active.js';
  6. import { r as raf } from './helpers.js';
  7. import { c as createLockController } from './lock-controller.js';
  8. import { d as createDelegateController, e as createTriggerController, B as BACKDROP, i as isCancel, f as present, g as dismiss, h as eventMethod, s as safeCall, j as prepareOverlay, k as setOverlayId } from './overlays.js';
  9. import { g as getClassMap } from './theme.js';
  10. import { b as getIonMode } from './ionic-global.js';
  11. import { c as createAnimation } from './animation.js';
  12. import { d as defineCustomElement$3 } from './backdrop.js';
  13. import { d as defineCustomElement$2 } from './icon.js';
  14. import { d as defineCustomElement$1 } from './ripple-effect.js';
  15. /**
  16. * iOS Action Sheet Enter Animation
  17. */
  18. const iosEnterAnimation = (baseEl) => {
  19. const baseAnimation = createAnimation();
  20. const backdropAnimation = createAnimation();
  21. const wrapperAnimation = createAnimation();
  22. backdropAnimation
  23. .addElement(baseEl.querySelector('ion-backdrop'))
  24. .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
  25. .beforeStyles({
  26. 'pointer-events': 'none',
  27. })
  28. .afterClearStyles(['pointer-events']);
  29. wrapperAnimation
  30. .addElement(baseEl.querySelector('.action-sheet-wrapper'))
  31. .fromTo('transform', 'translateY(100%)', 'translateY(0%)');
  32. return baseAnimation
  33. .addElement(baseEl)
  34. .easing('cubic-bezier(.36,.66,.04,1)')
  35. .duration(400)
  36. .addAnimation([backdropAnimation, wrapperAnimation]);
  37. };
  38. /**
  39. * iOS Action Sheet Leave Animation
  40. */
  41. const iosLeaveAnimation = (baseEl) => {
  42. const baseAnimation = createAnimation();
  43. const backdropAnimation = createAnimation();
  44. const wrapperAnimation = createAnimation();
  45. backdropAnimation.addElement(baseEl.querySelector('ion-backdrop')).fromTo('opacity', 'var(--backdrop-opacity)', 0);
  46. wrapperAnimation
  47. .addElement(baseEl.querySelector('.action-sheet-wrapper'))
  48. .fromTo('transform', 'translateY(0%)', 'translateY(100%)');
  49. return baseAnimation
  50. .addElement(baseEl)
  51. .easing('cubic-bezier(.36,.66,.04,1)')
  52. .duration(450)
  53. .addAnimation([backdropAnimation, wrapperAnimation]);
  54. };
  55. /**
  56. * MD Action Sheet Enter Animation
  57. */
  58. const mdEnterAnimation = (baseEl) => {
  59. const baseAnimation = createAnimation();
  60. const backdropAnimation = createAnimation();
  61. const wrapperAnimation = createAnimation();
  62. backdropAnimation
  63. .addElement(baseEl.querySelector('ion-backdrop'))
  64. .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
  65. .beforeStyles({
  66. 'pointer-events': 'none',
  67. })
  68. .afterClearStyles(['pointer-events']);
  69. wrapperAnimation
  70. .addElement(baseEl.querySelector('.action-sheet-wrapper'))
  71. .fromTo('transform', 'translateY(100%)', 'translateY(0%)');
  72. return baseAnimation
  73. .addElement(baseEl)
  74. .easing('cubic-bezier(.36,.66,.04,1)')
  75. .duration(400)
  76. .addAnimation([backdropAnimation, wrapperAnimation]);
  77. };
  78. /**
  79. * MD Action Sheet Leave Animation
  80. */
  81. const mdLeaveAnimation = (baseEl) => {
  82. const baseAnimation = createAnimation();
  83. const backdropAnimation = createAnimation();
  84. const wrapperAnimation = createAnimation();
  85. backdropAnimation.addElement(baseEl.querySelector('ion-backdrop')).fromTo('opacity', 'var(--backdrop-opacity)', 0);
  86. wrapperAnimation
  87. .addElement(baseEl.querySelector('.action-sheet-wrapper'))
  88. .fromTo('transform', 'translateY(0%)', 'translateY(100%)');
  89. return baseAnimation
  90. .addElement(baseEl)
  91. .easing('cubic-bezier(.36,.66,.04,1)')
  92. .duration(450)
  93. .addAnimation([backdropAnimation, wrapperAnimation]);
  94. };
  95. const 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:auto;--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.sc-ion-action-sheet-ios:disabled{color:var(--button-color-disabled);opacity:0.4}.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:calc(100vh - (var(--ion-safe-area-top, 0) + var(--ion-safe-area-bottom, 0)));max-height:calc(100dvh - (var(--ion-safe-area-top, 0) + var(--ion-safe-area-bottom, 0)))}.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)}@media (any-pointer: coarse){.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:not(:disabled):hover{color:var(--button-color-hover)}.action-sheet-button.sc-ion-action-sheet-ios:not(:disabled):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, var(--ion-background-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-step-150, var(--ion-background-color, #fff)));--button-background-selected-opacity:1;--button-color:var(--ion-color-primary, #0054e9);--button-color-disabled:var(--ion-color-step-850, var(--ion-text-color-step-150, #262626));--color:var(--ion-color-step-400, var(--ion-text-color-step-600, #999999));text-align:center}.action-sheet-wrapper.sc-ion-action-sheet-ios{-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto;margin-top:var(--ion-safe-area-top, 0);padding-bottom:var(--ion-safe-area-bottom, 0);-webkit-box-sizing:content-box;box-sizing:content-box}.action-sheet-container.sc-ion-action-sheet-ios{-webkit-padding-start:8px;padding-inline-start:8px;-webkit-padding-end:8px;padding-inline-end:8px;padding-top:0;padding-bottom:0}.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{-webkit-padding-start:10px;padding-inline-start:10px;-webkit-padding-end:10px;padding-inline-end:10px;padding-top:14px;padding-bottom:13px;color:var(--color, var(--ion-color-step-400, var(--ion-text-color-step-600, #999999)));font-size:max(13px, 0.8125rem);font-weight:400;text-align:center}.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:max(13px, 0.8125rem);font-weight:400}.action-sheet-button.sc-ion-action-sheet-ios{-webkit-padding-start:14px;padding-inline-start:14px;-webkit-padding-end:14px;padding-inline-end:14px;padding-top:14px;padding-bottom:14px;min-height:56px;font-size:max(20px, 1.25rem);contain:content}.action-sheet-button.sc-ion-action-sheet-ios .action-sheet-icon.sc-ion-action-sheet-ios{-webkit-margin-end:0.3em;margin-inline-end:0.3em;font-size:max(28px, 1.75rem);pointer-events:none}.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, #c5000f)}@media (any-hover: hover){.action-sheet-destructive.sc-ion-action-sheet-ios:hover{color:var(--ion-color-danger, #c5000f)}}";
  96. const IonActionSheetIosStyle0 = actionSheetIosCss;
  97. const 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:auto;--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.sc-ion-action-sheet-md:disabled{color:var(--button-color-disabled);opacity:0.4}.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:calc(100vh - (var(--ion-safe-area-top, 0) + var(--ion-safe-area-bottom, 0)));max-height:calc(100dvh - (var(--ion-safe-area-top, 0) + var(--ion-safe-area-bottom, 0)))}.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)}@media (any-pointer: coarse){.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:not(:disabled):hover{color:var(--button-color-hover)}.action-sheet-button.sc-ion-action-sheet-md:not(:disabled):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, var(--ion-text-color-step-150, #262626));--button-color-disabled:var(--button-color);--color:rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.54)}.action-sheet-wrapper.sc-ion-action-sheet-md{-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto;margin-top:var(--ion-safe-area-top, 0);margin-bottom:0}.action-sheet-title.sc-ion-action-sheet-md{-webkit-padding-start:16px;padding-inline-start:16px;-webkit-padding-end:16px;padding-inline-end: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:1rem;text-align:start}.action-sheet-sub-title.sc-ion-action-sheet-md{padding-left:0;padding-right:0;padding-top:16px;padding-bottom:0;font-size:0.875rem}.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{-webkit-padding-start:16px;padding-inline-start:16px;-webkit-padding-end:16px;padding-inline-end:16px;padding-top:12px;padding-bottom:12px;position:relative;min-height:52px;font-size:1rem;text-align:start;contain:content;overflow:hidden}.action-sheet-icon.sc-ion-action-sheet-md{-webkit-margin-start:0;margin-inline-start:0;-webkit-margin-end:32px;margin-inline-end:32px;margin-top:0;margin-bottom:0;color:var(--color);font-size:1.5rem}.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}";
  98. const IonActionSheetMdStyle0 = actionSheetMdCss;
  99. const ActionSheet = /*@__PURE__*/ proxyCustomElement(class ActionSheet extends HTMLElement {
  100. constructor() {
  101. super();
  102. this.__registerHost();
  103. this.didPresent = createEvent(this, "ionActionSheetDidPresent", 7);
  104. this.willPresent = createEvent(this, "ionActionSheetWillPresent", 7);
  105. this.willDismiss = createEvent(this, "ionActionSheetWillDismiss", 7);
  106. this.didDismiss = createEvent(this, "ionActionSheetDidDismiss", 7);
  107. this.didPresentShorthand = createEvent(this, "didPresent", 7);
  108. this.willPresentShorthand = createEvent(this, "willPresent", 7);
  109. this.willDismissShorthand = createEvent(this, "willDismiss", 7);
  110. this.didDismissShorthand = createEvent(this, "didDismiss", 7);
  111. this.delegateController = createDelegateController(this);
  112. this.lockController = createLockController();
  113. this.triggerController = createTriggerController();
  114. this.presented = false;
  115. this.onBackdropTap = () => {
  116. this.dismiss(undefined, BACKDROP);
  117. };
  118. this.dispatchCancelHandler = (ev) => {
  119. const role = ev.detail.role;
  120. if (isCancel(role)) {
  121. const cancelButton = this.getButtons().find((b) => b.role === 'cancel');
  122. this.callButtonHandler(cancelButton);
  123. }
  124. };
  125. this.overlayIndex = undefined;
  126. this.delegate = undefined;
  127. this.hasController = false;
  128. this.keyboardClose = true;
  129. this.enterAnimation = undefined;
  130. this.leaveAnimation = undefined;
  131. this.buttons = [];
  132. this.cssClass = undefined;
  133. this.backdropDismiss = true;
  134. this.header = undefined;
  135. this.subHeader = undefined;
  136. this.translucent = false;
  137. this.animated = true;
  138. this.htmlAttributes = undefined;
  139. this.isOpen = false;
  140. this.trigger = undefined;
  141. }
  142. onIsOpenChange(newValue, oldValue) {
  143. if (newValue === true && oldValue === false) {
  144. this.present();
  145. }
  146. else if (newValue === false && oldValue === true) {
  147. this.dismiss();
  148. }
  149. }
  150. triggerChanged() {
  151. const { trigger, el, triggerController } = this;
  152. if (trigger) {
  153. triggerController.addClickListener(el, trigger);
  154. }
  155. }
  156. /**
  157. * Present the action sheet overlay after it has been created.
  158. */
  159. async present() {
  160. const unlock = await this.lockController.lock();
  161. await this.delegateController.attachViewToDom();
  162. await present(this, 'actionSheetEnter', iosEnterAnimation, mdEnterAnimation);
  163. unlock();
  164. }
  165. /**
  166. * Dismiss the action sheet overlay after it has been presented.
  167. *
  168. * @param data Any data to emit in the dismiss events.
  169. * @param role The role of the element that is dismissing the action sheet.
  170. * This can be useful in a button handler for determining which button was
  171. * clicked to dismiss the action sheet.
  172. * Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
  173. *
  174. * This is a no-op if the overlay has not been presented yet. If you want
  175. * to remove an overlay from the DOM that was never presented, use the
  176. * [remove](https://developer.mozilla.org/en-US/docs/Web/API/Element/remove) method.
  177. */
  178. async dismiss(data, role) {
  179. const unlock = await this.lockController.lock();
  180. const dismissed = await dismiss(this, data, role, 'actionSheetLeave', iosLeaveAnimation, mdLeaveAnimation);
  181. if (dismissed) {
  182. this.delegateController.removeViewFromDom();
  183. }
  184. unlock();
  185. return dismissed;
  186. }
  187. /**
  188. * Returns a promise that resolves when the action sheet did dismiss.
  189. */
  190. onDidDismiss() {
  191. return eventMethod(this.el, 'ionActionSheetDidDismiss');
  192. }
  193. /**
  194. * Returns a promise that resolves when the action sheet will dismiss.
  195. *
  196. */
  197. onWillDismiss() {
  198. return eventMethod(this.el, 'ionActionSheetWillDismiss');
  199. }
  200. async buttonClick(button) {
  201. const role = button.role;
  202. if (isCancel(role)) {
  203. return this.dismiss(button.data, role);
  204. }
  205. const shouldDismiss = await this.callButtonHandler(button);
  206. if (shouldDismiss) {
  207. return this.dismiss(button.data, button.role);
  208. }
  209. return Promise.resolve();
  210. }
  211. async callButtonHandler(button) {
  212. if (button) {
  213. // a handler has been provided, execute it
  214. // pass the handler the values from the inputs
  215. const rtn = await safeCall(button.handler);
  216. if (rtn === false) {
  217. // if the return value of the handler is false then do not dismiss
  218. return false;
  219. }
  220. }
  221. return true;
  222. }
  223. getButtons() {
  224. return this.buttons.map((b) => {
  225. return typeof b === 'string' ? { text: b } : b;
  226. });
  227. }
  228. connectedCallback() {
  229. prepareOverlay(this.el);
  230. this.triggerChanged();
  231. }
  232. disconnectedCallback() {
  233. if (this.gesture) {
  234. this.gesture.destroy();
  235. this.gesture = undefined;
  236. }
  237. this.triggerController.removeClickListener();
  238. }
  239. componentWillLoad() {
  240. var _a;
  241. if (!((_a = this.htmlAttributes) === null || _a === void 0 ? void 0 : _a.id)) {
  242. setOverlayId(this.el);
  243. }
  244. }
  245. componentDidLoad() {
  246. /**
  247. * Only create gesture if:
  248. * 1. A gesture does not already exist
  249. * 2. App is running in iOS mode
  250. * 3. A wrapper ref exists
  251. * 4. A group ref exists
  252. */
  253. const { groupEl, wrapperEl } = this;
  254. if (!this.gesture && getIonMode(this) === 'ios' && wrapperEl && groupEl) {
  255. readTask(() => {
  256. const isScrollable = groupEl.scrollHeight > groupEl.clientHeight;
  257. if (!isScrollable) {
  258. this.gesture = createButtonActiveGesture(wrapperEl, (refEl) => refEl.classList.contains('action-sheet-button'));
  259. this.gesture.enable(true);
  260. }
  261. });
  262. }
  263. /**
  264. * If action sheet was rendered with isOpen="true"
  265. * then we should open action sheet immediately.
  266. */
  267. if (this.isOpen === true) {
  268. raf(() => this.present());
  269. }
  270. /**
  271. * When binding values in frameworks such as Angular
  272. * it is possible for the value to be set after the Web Component
  273. * initializes but before the value watcher is set up in Stencil.
  274. * As a result, the watcher callback may not be fired.
  275. * We work around this by manually calling the watcher
  276. * callback when the component has loaded and the watcher
  277. * is configured.
  278. */
  279. this.triggerChanged();
  280. }
  281. render() {
  282. const { header, htmlAttributes, overlayIndex } = this;
  283. const mode = getIonMode(this);
  284. const allButtons = this.getButtons();
  285. const cancelButton = allButtons.find((b) => b.role === 'cancel');
  286. const buttons = allButtons.filter((b) => b.role !== 'cancel');
  287. const headerID = `action-sheet-${overlayIndex}-header`;
  288. return (h(Host, Object.assign({ key: '7bbd202ca9e19727e7514abbe073687d982f80c3', role: "dialog", "aria-modal": "true", "aria-labelledby": header !== undefined ? headerID : null, tabindex: "-1" }, htmlAttributes, { style: {
  289. zIndex: `${20000 + this.overlayIndex}`,
  290. }, 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", { key: '23344a9221a2e6720d7b9de5249dc37256cafa7b', tappable: this.backdropDismiss }), h("div", { key: 'fbc2ba15549c2ab04e759e82df6e177fd80cc0a6', tabindex: "0", "aria-hidden": "true" }), h("div", { key: '748ee5235d0b4cb26d6f1b7589f77af2e37ad28a', class: "action-sheet-wrapper ion-overlay-wrapper", ref: (el) => (this.wrapperEl = el) }, h("div", { key: '7ce5fa236cf75e9b1e49c4725c9a811078706554', class: "action-sheet-container" }, h("div", { key: 'dc2251f3bcee4a93e3449f09621cbd2b65d329e9', class: "action-sheet-group", ref: (el) => (this.groupEl = el) }, header !== undefined && (h("div", { key: '48d325c8a852f56ed57a9ada1a6709d05ba32ee2', id: headerID, class: {
  291. 'action-sheet-title': true,
  292. 'action-sheet-has-sub-title': this.subHeader !== undefined,
  293. } }, header, this.subHeader && h("div", { key: '66093728052eb67f37a35f3232761ce4a08896f3', class: "action-sheet-sub-title" }, this.subHeader))), buttons.map((b) => (h("button", Object.assign({}, b.htmlAttributes, { type: "button", id: b.id, class: buttonClass(b), onClick: () => this.buttonClick(b), disabled: b.disabled }), h("span", { class: "action-sheet-button-inner" }, b.icon && h("ion-icon", { icon: b.icon, "aria-hidden": "true", lazy: false, class: "action-sheet-icon" }), b.text), mode === 'md' && h("ion-ripple-effect", null))))), cancelButton && (h("div", { key: 'f4eb8e3e2885b85af5080df18d0de0bdd1d719de', class: "action-sheet-group action-sheet-group-cancel" }, h("button", Object.assign({ key: '169f4eb09255aba85062baad49ceb151239fbfb7' }, cancelButton.htmlAttributes, { type: "button", class: buttonClass(cancelButton), onClick: () => this.buttonClick(cancelButton) }), h("span", { key: '25fb8a466dd67ea94c79cfb4f9965527e1ce6d42', class: "action-sheet-button-inner" }, cancelButton.icon && (h("ion-icon", { key: 'eb5b071e120a2c86afdf967af6a763a43044d1ca', icon: cancelButton.icon, "aria-hidden": "true", lazy: false, class: "action-sheet-icon" })), cancelButton.text), mode === 'md' && h("ion-ripple-effect", { key: '452ad7e1052b2c681e2d98de8193949755ad4d54' })))))), h("div", { key: 'e1cecf280c987c050d9445e2c458b903f153089b', tabindex: "0", "aria-hidden": "true" })));
  294. }
  295. get el() { return this; }
  296. static get watchers() { return {
  297. "isOpen": ["onIsOpenChange"],
  298. "trigger": ["triggerChanged"]
  299. }; }
  300. static get style() { return {
  301. ios: IonActionSheetIosStyle0,
  302. md: IonActionSheetMdStyle0
  303. }; }
  304. }, [34, "ion-action-sheet", {
  305. "overlayIndex": [2, "overlay-index"],
  306. "delegate": [16],
  307. "hasController": [4, "has-controller"],
  308. "keyboardClose": [4, "keyboard-close"],
  309. "enterAnimation": [16],
  310. "leaveAnimation": [16],
  311. "buttons": [16],
  312. "cssClass": [1, "css-class"],
  313. "backdropDismiss": [4, "backdrop-dismiss"],
  314. "header": [1],
  315. "subHeader": [1, "sub-header"],
  316. "translucent": [4],
  317. "animated": [4],
  318. "htmlAttributes": [16],
  319. "isOpen": [4, "is-open"],
  320. "trigger": [1],
  321. "present": [64],
  322. "dismiss": [64],
  323. "onDidDismiss": [64],
  324. "onWillDismiss": [64]
  325. }, undefined, {
  326. "isOpen": ["onIsOpenChange"],
  327. "trigger": ["triggerChanged"]
  328. }]);
  329. const buttonClass = (button) => {
  330. return Object.assign({ 'action-sheet-button': true, 'ion-activatable': !button.disabled, 'ion-focusable': !button.disabled, [`action-sheet-${button.role}`]: button.role !== undefined }, getClassMap(button.cssClass));
  331. };
  332. function defineCustomElement() {
  333. if (typeof customElements === "undefined") {
  334. return;
  335. }
  336. const components = ["ion-action-sheet", "ion-backdrop", "ion-icon", "ion-ripple-effect"];
  337. components.forEach(tagName => { switch (tagName) {
  338. case "ion-action-sheet":
  339. if (!customElements.get(tagName)) {
  340. customElements.define(tagName, ActionSheet);
  341. }
  342. break;
  343. case "ion-backdrop":
  344. if (!customElements.get(tagName)) {
  345. defineCustomElement$3();
  346. }
  347. break;
  348. case "ion-icon":
  349. if (!customElements.get(tagName)) {
  350. defineCustomElement$2();
  351. }
  352. break;
  353. case "ion-ripple-effect":
  354. if (!customElements.get(tagName)) {
  355. defineCustomElement$1();
  356. }
  357. break;
  358. } });
  359. }
  360. export { ActionSheet as A, defineCustomElement as d };