shell.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { h, Fragment } from "@stencil/core";
  7. import { CSS, SLOTS } from "./resources";
  8. import { getSlotted } from "../../utils/dom";
  9. import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
  10. /**
  11. * @slot - A slot for adding content to the component. This content will appear between any leading and trailing panels added to the component, such as a map.
  12. * @slot header - A slot for adding header content. This content will be positioned at the top of the component.
  13. * @slot footer - A slot for adding footer content. This content will be positioned at the bottom of the component.
  14. * @slot panel-start - A slot for adding the starting `calcite-shell-panel`.
  15. * @slot panel-end - A slot for adding the ending `calcite-shell-panel`.
  16. * @slot primary-panel - [DEPRECATED] A slot for adding the leading `calcite-shell-panel`.
  17. * @slot contextual-panel - [DEPRECATED] A slot for adding the trailing `calcite-shell-panel`.
  18. * @slot center-row - A slot for adding content to the center row.
  19. */
  20. export class Shell {
  21. constructor() {
  22. // --------------------------------------------------------------------------
  23. //
  24. // Properties
  25. //
  26. // --------------------------------------------------------------------------
  27. /**
  28. * Positions the center content behind any `calcite-shell-panel`s.
  29. */
  30. this.contentBehind = false;
  31. }
  32. // --------------------------------------------------------------------------
  33. //
  34. // Lifecycle
  35. //
  36. // --------------------------------------------------------------------------
  37. connectedCallback() {
  38. connectConditionalSlotComponent(this);
  39. }
  40. disconnectedCallback() {
  41. disconnectConditionalSlotComponent(this);
  42. }
  43. // --------------------------------------------------------------------------
  44. //
  45. // Render Methods
  46. //
  47. // --------------------------------------------------------------------------
  48. renderHeader() {
  49. const hasHeader = !!getSlotted(this.el, SLOTS.header);
  50. return hasHeader ? h("slot", { key: "header", name: SLOTS.header }) : null;
  51. }
  52. renderContent() {
  53. const defaultSlotNode = h("slot", { key: "default-slot" });
  54. const centerRowSlotNode = h("slot", { key: "center-row-slot", name: SLOTS.centerRow });
  55. const contentContainerKey = "content-container";
  56. const content = !!this.contentBehind
  57. ? [
  58. h("div", { class: {
  59. [CSS.content]: true,
  60. [CSS.contentBehind]: true
  61. }, key: contentContainerKey }, defaultSlotNode),
  62. centerRowSlotNode
  63. ]
  64. : [
  65. h("div", { class: CSS.content, key: contentContainerKey }, defaultSlotNode, centerRowSlotNode)
  66. ];
  67. return content;
  68. }
  69. renderFooter() {
  70. const hasFooter = !!getSlotted(this.el, SLOTS.footer);
  71. return hasFooter ? (h("div", { class: CSS.footer, key: "footer" }, h("slot", { name: SLOTS.footer }))) : null;
  72. }
  73. renderMain() {
  74. const primaryPanel = getSlotted(this.el, SLOTS.primaryPanel);
  75. const mainClasses = {
  76. [CSS.main]: true,
  77. [CSS.mainReversed]: (primaryPanel === null || primaryPanel === void 0 ? void 0 : primaryPanel.position) === "end"
  78. };
  79. return (h("div", { class: mainClasses }, h("slot", { name: SLOTS.primaryPanel }), h("slot", { name: SLOTS.panelStart }), this.renderContent(), h("slot", { name: SLOTS.panelEnd }), h("slot", { name: SLOTS.contextualPanel })));
  80. }
  81. render() {
  82. return (h(Fragment, null, this.renderHeader(), this.renderMain(), this.renderFooter()));
  83. }
  84. static get is() { return "calcite-shell"; }
  85. static get encapsulation() { return "shadow"; }
  86. static get originalStyleUrls() {
  87. return {
  88. "$": ["shell.scss"]
  89. };
  90. }
  91. static get styleUrls() {
  92. return {
  93. "$": ["shell.css"]
  94. };
  95. }
  96. static get properties() {
  97. return {
  98. "contentBehind": {
  99. "type": "boolean",
  100. "mutable": false,
  101. "complexType": {
  102. "original": "boolean",
  103. "resolved": "boolean",
  104. "references": {}
  105. },
  106. "required": false,
  107. "optional": false,
  108. "docs": {
  109. "tags": [],
  110. "text": "Positions the center content behind any `calcite-shell-panel`s."
  111. },
  112. "attribute": "content-behind",
  113. "reflect": true,
  114. "defaultValue": "false"
  115. }
  116. };
  117. }
  118. static get elementRef() { return "el"; }
  119. }