chunk.6UEDCTIJ.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import {
  2. focusVisible
  3. } from "./chunk.XAZSQ3AT.js";
  4. import {
  5. animateTo,
  6. shimKeyframesHeightAuto,
  7. stopAnimations,
  8. waitForEvent
  9. } from "./chunk.CTCDC263.js";
  10. import {
  11. getAnimation,
  12. setDefaultAnimation
  13. } from "./chunk.NC36RJW4.js";
  14. import {
  15. event,
  16. watch
  17. } from "./chunk.XX234VRK.js";
  18. import {
  19. e as e2
  20. } from "./chunk.YXKHB4AC.js";
  21. import {
  22. T,
  23. e,
  24. h,
  25. n,
  26. o,
  27. r
  28. } from "./chunk.5PIDMFOE.js";
  29. import {
  30. __decorateClass
  31. } from "./chunk.IHGPZX35.js";
  32. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/details/details.scss
  33. var details_default = ":host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n:host {\n display: block;\n}\n\n.details {\n border: solid 1px var(--sl-color-gray-200);\n border-radius: var(--sl-border-radius-medium);\n overflow-anchor: none;\n}\n\n.details--disabled {\n opacity: 0.5;\n}\n\n.details__header {\n display: flex;\n align-items: center;\n border-radius: inherit;\n padding: var(--sl-spacing-medium);\n user-select: none;\n cursor: pointer;\n}\n.details__header:focus {\n outline: none;\n}\n\n.focus-visible .details__header:focus {\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n\n.details--disabled .details__header {\n cursor: not-allowed;\n}\n.details--disabled .details__header:focus {\n outline: none;\n box-shadow: none;\n}\n\n.details__summary {\n flex: 1 1 auto;\n display: flex;\n align-items: center;\n}\n\n.details__summary-icon {\n flex: 0 0 auto;\n display: flex;\n align-items: center;\n transition: var(--sl-transition-medium) transform ease;\n}\n\n.details--open .details__summary-icon {\n transform: rotate(90deg);\n}\n\n.details__body {\n overflow: hidden;\n}\n\n.details__content {\n padding: var(--sl-spacing-medium);\n}";
  34. // src/components/details/details.ts
  35. var id = 0;
  36. var SlDetails = class extends h {
  37. constructor() {
  38. super(...arguments);
  39. this.componentId = `details-${++id}`;
  40. this.hasInitialized = false;
  41. this.open = false;
  42. this.disabled = false;
  43. }
  44. connectedCallback() {
  45. super.connectedCallback();
  46. this.updateComplete.then(() => focusVisible.observe(this.details));
  47. }
  48. firstUpdated() {
  49. this.body.hidden = !this.open;
  50. this.body.style.height = this.open ? "auto" : "0";
  51. this.updateComplete.then(() => this.hasInitialized = true);
  52. }
  53. disconnectedCallback() {
  54. super.disconnectedCallback();
  55. focusVisible.unobserve(this.details);
  56. }
  57. async show() {
  58. if (this.open) {
  59. return;
  60. }
  61. this.open = true;
  62. return waitForEvent(this, "sl-after-show");
  63. }
  64. async hide() {
  65. if (!this.open) {
  66. return;
  67. }
  68. this.open = false;
  69. return waitForEvent(this, "sl-after-hide");
  70. }
  71. handleSummaryClick() {
  72. if (!this.disabled) {
  73. this.open ? this.hide() : this.show();
  74. this.header.focus();
  75. }
  76. }
  77. handleSummaryKeyDown(event2) {
  78. if (event2.key === "Enter" || event2.key === " ") {
  79. event2.preventDefault();
  80. this.open ? this.hide() : this.show();
  81. }
  82. if (event2.key === "ArrowUp" || event2.key === "ArrowLeft") {
  83. event2.preventDefault();
  84. this.hide();
  85. }
  86. if (event2.key === "ArrowDown" || event2.key === "ArrowRight") {
  87. event2.preventDefault();
  88. this.show();
  89. }
  90. }
  91. async handleOpenChange() {
  92. if (!this.hasInitialized) {
  93. return;
  94. }
  95. if (this.open) {
  96. this.slShow.emit();
  97. await stopAnimations(this);
  98. this.body.hidden = false;
  99. const { keyframes, options } = getAnimation(this, "details.show");
  100. await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
  101. this.body.style.height = "auto";
  102. this.slAfterShow.emit();
  103. } else {
  104. this.slHide.emit();
  105. await stopAnimations(this);
  106. const { keyframes, options } = getAnimation(this, "details.hide");
  107. await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
  108. this.body.hidden = true;
  109. this.body.style.height = "auto";
  110. this.slAfterHide.emit();
  111. }
  112. }
  113. render() {
  114. return T`
  115. <div
  116. part="base"
  117. class=${e2({
  118. details: true,
  119. "details--open": this.open,
  120. "details--disabled": this.disabled
  121. })}
  122. >
  123. <header
  124. part="header"
  125. id=${`${this.componentId}-header`}
  126. class="details__header"
  127. role="button"
  128. aria-expanded=${this.open ? "true" : "false"}
  129. aria-controls=${`${this.componentId}-content`}
  130. aria-disabled=${this.disabled ? "true" : "false"}
  131. tabindex=${this.disabled ? "-1" : "0"}
  132. @click=${this.handleSummaryClick}
  133. @keydown=${this.handleSummaryKeyDown}
  134. >
  135. <div part="summary" class="details__summary">
  136. <slot name="summary">${this.summary}</slot>
  137. </div>
  138. <span part="summary-icon" class="details__summary-icon">
  139. <sl-icon name="chevron-right" library="system"></sl-icon>
  140. </span>
  141. </header>
  142. <div class="details__body">
  143. <div
  144. part="content"
  145. id=${`${this.componentId}-content`}
  146. class="details__content"
  147. role="region"
  148. aria-labelledby=${`${this.componentId}-header`}
  149. >
  150. <slot></slot>
  151. </div>
  152. </div>
  153. </div>
  154. `;
  155. }
  156. };
  157. SlDetails.styles = r(details_default);
  158. __decorateClass([
  159. o(".details")
  160. ], SlDetails.prototype, "details", 2);
  161. __decorateClass([
  162. o(".details__header")
  163. ], SlDetails.prototype, "header", 2);
  164. __decorateClass([
  165. o(".details__body")
  166. ], SlDetails.prototype, "body", 2);
  167. __decorateClass([
  168. e({ type: Boolean, reflect: true })
  169. ], SlDetails.prototype, "open", 2);
  170. __decorateClass([
  171. e()
  172. ], SlDetails.prototype, "summary", 2);
  173. __decorateClass([
  174. e({ type: Boolean, reflect: true })
  175. ], SlDetails.prototype, "disabled", 2);
  176. __decorateClass([
  177. event("sl-show")
  178. ], SlDetails.prototype, "slShow", 2);
  179. __decorateClass([
  180. event("sl-after-show")
  181. ], SlDetails.prototype, "slAfterShow", 2);
  182. __decorateClass([
  183. event("sl-hide")
  184. ], SlDetails.prototype, "slHide", 2);
  185. __decorateClass([
  186. event("sl-after-hide")
  187. ], SlDetails.prototype, "slAfterHide", 2);
  188. __decorateClass([
  189. watch("open")
  190. ], SlDetails.prototype, "handleOpenChange", 1);
  191. SlDetails = __decorateClass([
  192. n("sl-details")
  193. ], SlDetails);
  194. var details_default2 = SlDetails;
  195. setDefaultAnimation("details.show", {
  196. keyframes: [
  197. { height: "0", opacity: "0" },
  198. { height: "auto", opacity: "1" }
  199. ],
  200. options: { duration: 250, easing: "linear" }
  201. });
  202. setDefaultAnimation("details.hide", {
  203. keyframes: [
  204. { height: "auto", opacity: "1" },
  205. { height: "0", opacity: "0" }
  206. ],
  207. options: { duration: 250, easing: "linear" }
  208. });
  209. export {
  210. details_default2 as details_default
  211. };