shell.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.82
  5. */
  6. import { Component, Element, Prop, 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 shell. This content will appear between any leading and trailing panels added to the shell. (eg. a map)
  12. * @slot header - A slot for adding header content. This content will be positioned at the top of the shell.
  13. * @slot footer - A slot for adding footer content. This content will be positioned at the bottom of the shell.
  14. * @slot primary-panel - A slot for adding the leading `calcite-shell-panel`.
  15. * @slot contextual-panel - A slot for adding the trailing `calcite-shell-panel`.
  16. * @slot center-row - A slot for adding custom content in the center row.
  17. */
  18. export class Shell {
  19. constructor() {
  20. // --------------------------------------------------------------------------
  21. //
  22. // Properties
  23. //
  24. // --------------------------------------------------------------------------
  25. /**
  26. * Positions the center content behind any calcite-shell-panels.
  27. */
  28. this.contentBehind = false;
  29. }
  30. // --------------------------------------------------------------------------
  31. //
  32. // Lifecycle
  33. //
  34. // --------------------------------------------------------------------------
  35. connectedCallback() {
  36. connectConditionalSlotComponent(this);
  37. }
  38. disconnectedCallback() {
  39. disconnectConditionalSlotComponent(this);
  40. }
  41. // --------------------------------------------------------------------------
  42. //
  43. // Render Methods
  44. //
  45. // --------------------------------------------------------------------------
  46. renderHeader() {
  47. const hasHeader = !!getSlotted(this.el, SLOTS.header);
  48. return hasHeader ? h("slot", { key: "header", name: SLOTS.header }) : null;
  49. }
  50. renderContent() {
  51. const defaultSlotNode = h("slot", { key: "default-slot" });
  52. const centerRowSlotNode = h("slot", { key: "center-row-slot", name: SLOTS.centerRow });
  53. const contentContainerKey = "content-container";
  54. const content = !!this.contentBehind
  55. ? [
  56. h("div", { class: {
  57. [CSS.content]: true,
  58. [CSS.contentBehind]: true
  59. }, key: contentContainerKey }, defaultSlotNode),
  60. centerRowSlotNode
  61. ]
  62. : [
  63. h("div", { class: CSS.content, key: contentContainerKey },
  64. defaultSlotNode,
  65. 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" },
  72. h("slot", { name: SLOTS.footer }))) : null;
  73. }
  74. renderMain() {
  75. const primaryPanel = getSlotted(this.el, SLOTS.primaryPanel);
  76. const mainClasses = {
  77. [CSS.main]: true,
  78. [CSS.mainReversed]: (primaryPanel === null || primaryPanel === void 0 ? void 0 : primaryPanel.position) === "end"
  79. };
  80. return (h("div", { class: mainClasses },
  81. h("slot", { name: SLOTS.primaryPanel }),
  82. this.renderContent(),
  83. h("slot", { name: SLOTS.contextualPanel })));
  84. }
  85. render() {
  86. return (h(Fragment, null,
  87. this.renderHeader(),
  88. this.renderMain(),
  89. this.renderFooter()));
  90. }
  91. static get is() { return "calcite-shell"; }
  92. static get encapsulation() { return "shadow"; }
  93. static get originalStyleUrls() { return {
  94. "$": ["shell.scss"]
  95. }; }
  96. static get styleUrls() { return {
  97. "$": ["shell.css"]
  98. }; }
  99. static get properties() { return {
  100. "contentBehind": {
  101. "type": "boolean",
  102. "mutable": false,
  103. "complexType": {
  104. "original": "boolean",
  105. "resolved": "boolean",
  106. "references": {}
  107. },
  108. "required": false,
  109. "optional": false,
  110. "docs": {
  111. "tags": [],
  112. "text": "Positions the center content behind any calcite-shell-panels."
  113. },
  114. "attribute": "content-behind",
  115. "reflect": true,
  116. "defaultValue": "false"
  117. }
  118. }; }
  119. static get elementRef() { return "el"; }
  120. }