ion-split-pane.entry.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { r as registerInstance, c as createEvent, h, e as Host, f as getElement } from './index-527b9e34.js';
  5. import { p as printIonWarning } from './index-cfd9c1f2.js';
  6. import { b as getIonMode } from './ionic-global-b26f573e.js';
  7. const splitPaneIosCss = ":host{--side-width:100%;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:nowrap;flex-wrap:nowrap;contain:strict}:host(.split-pane-visible) ::slotted(.split-pane-main){left:0;right:0;top:0;bottom:0;position:relative;-ms-flex:1;flex:1;-webkit-box-shadow:none;box-shadow:none;overflow:hidden;z-index:0}::slotted(.split-pane-side:not(ion-menu)){display:none}:host{--border:0.55px solid var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-250, var(--ion-background-color-step-250, #c8c7cc))));--side-min-width:270px;--side-max-width:28%}";
  8. const IonSplitPaneIosStyle0 = splitPaneIosCss;
  9. const splitPaneMdCss = ":host{--side-width:100%;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:nowrap;flex-wrap:nowrap;contain:strict}:host(.split-pane-visible) ::slotted(.split-pane-main){left:0;right:0;top:0;bottom:0;position:relative;-ms-flex:1;flex:1;-webkit-box-shadow:none;box-shadow:none;overflow:hidden;z-index:0}::slotted(.split-pane-side:not(ion-menu)){display:none}:host{--border:1px solid var(--ion-item-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.13)))));--side-min-width:270px;--side-max-width:28%}";
  10. const IonSplitPaneMdStyle0 = splitPaneMdCss;
  11. // TODO(FW-2832): types
  12. const SPLIT_PANE_MAIN = 'split-pane-main';
  13. const SPLIT_PANE_SIDE = 'split-pane-side';
  14. const QUERY = {
  15. xs: '(min-width: 0px)',
  16. sm: '(min-width: 576px)',
  17. md: '(min-width: 768px)',
  18. lg: '(min-width: 992px)',
  19. xl: '(min-width: 1200px)',
  20. never: '',
  21. };
  22. const SplitPane = class {
  23. constructor(hostRef) {
  24. registerInstance(this, hostRef);
  25. this.ionSplitPaneVisible = createEvent(this, "ionSplitPaneVisible", 7);
  26. this.visible = false;
  27. this.contentId = undefined;
  28. this.disabled = false;
  29. this.when = QUERY['lg'];
  30. }
  31. visibleChanged(visible) {
  32. this.ionSplitPaneVisible.emit({ visible });
  33. }
  34. /**
  35. * @internal
  36. */
  37. async isVisible() {
  38. return Promise.resolve(this.visible);
  39. }
  40. async connectedCallback() {
  41. // TODO: connectedCallback is fired in CE build
  42. // before WC is defined. This needs to be fixed in Stencil.
  43. if (typeof customElements !== 'undefined' && customElements != null) {
  44. await customElements.whenDefined('ion-split-pane');
  45. }
  46. this.styleMainElement();
  47. this.updateState();
  48. }
  49. disconnectedCallback() {
  50. if (this.rmL) {
  51. this.rmL();
  52. this.rmL = undefined;
  53. }
  54. }
  55. updateState() {
  56. if (this.rmL) {
  57. this.rmL();
  58. this.rmL = undefined;
  59. }
  60. // Check if the split-pane is disabled
  61. if (this.disabled) {
  62. this.visible = false;
  63. return;
  64. }
  65. // When query is a boolean
  66. const query = this.when;
  67. if (typeof query === 'boolean') {
  68. this.visible = query;
  69. return;
  70. }
  71. // When query is a string, let's find first if it is a shortcut
  72. const mediaQuery = QUERY[query] || query;
  73. // Media query is empty or null, we hide it
  74. if (mediaQuery.length === 0) {
  75. this.visible = false;
  76. return;
  77. }
  78. // Listen on media query
  79. const callback = (q) => {
  80. this.visible = q.matches;
  81. };
  82. const mediaList = window.matchMedia(mediaQuery);
  83. // TODO FW-5869
  84. mediaList.addListener(callback);
  85. this.rmL = () => mediaList.removeListener(callback);
  86. this.visible = mediaList.matches;
  87. }
  88. /**
  89. * Attempt to find the main content
  90. * element inside of the split pane.
  91. * If found, set it as the main node.
  92. *
  93. * We assume that the main node
  94. * is available in the DOM on split
  95. * pane load.
  96. */
  97. styleMainElement() {
  98. const contentId = this.contentId;
  99. const children = this.el.children;
  100. const nu = this.el.childElementCount;
  101. let foundMain = false;
  102. for (let i = 0; i < nu; i++) {
  103. const child = children[i];
  104. const isMain = contentId !== undefined && child.id === contentId;
  105. if (isMain) {
  106. if (foundMain) {
  107. printIonWarning('[ion-split-pane] - Cannot have more than one main node.');
  108. return;
  109. }
  110. else {
  111. setPaneClass(child, isMain);
  112. foundMain = true;
  113. }
  114. }
  115. }
  116. if (!foundMain) {
  117. printIonWarning('[ion-split-pane] - Does not have a specified main node.');
  118. }
  119. }
  120. render() {
  121. const mode = getIonMode(this);
  122. return (h(Host, { key: '098801b5a318e2fc6913fb0d9079b1552927b99b', class: {
  123. [mode]: true,
  124. // Used internally for styling
  125. [`split-pane-${mode}`]: true,
  126. 'split-pane-visible': this.visible,
  127. } }, h("slot", { key: '8cbc6a942ecba54fc3c62027d46917db067b65c8' })));
  128. }
  129. get el() { return getElement(this); }
  130. static get watchers() { return {
  131. "visible": ["visibleChanged"],
  132. "disabled": ["updateState"],
  133. "when": ["updateState"]
  134. }; }
  135. };
  136. const setPaneClass = (el, isMain) => {
  137. let toAdd;
  138. let toRemove;
  139. if (isMain) {
  140. toAdd = SPLIT_PANE_MAIN;
  141. toRemove = SPLIT_PANE_SIDE;
  142. }
  143. else {
  144. toAdd = SPLIT_PANE_SIDE;
  145. toRemove = SPLIT_PANE_MAIN;
  146. }
  147. const classList = el.classList;
  148. classList.add(toAdd);
  149. classList.remove(toRemove);
  150. };
  151. SplitPane.style = {
  152. ios: IonSplitPaneIosStyle0,
  153. md: IonSplitPaneMdStyle0
  154. };
  155. export { SplitPane as ion_split_pane };