@haiilo/catalyst 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ const patchBrowser = () => {
15
15
  };
16
16
 
17
17
  patchBrowser().then(options => {
18
- return index.bootstrapLazy([["cat-alert_23.cjs",[[1,"cat-select-demo"],[1,"cat-input",{"autoComplete":[1,"auto-complete"],"clearable":[4],"disabled":[4],"hint":[1],"icon":[1],"iconRight":[4,"icon-right"],"label":[1],"labelHidden":[4,"label-hidden"],"max":[8],"maxLength":[2,"max-length"],"min":[8],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"textPrefix":[1,"text-prefix"],"textSuffix":[1,"text-suffix"],"readonly":[4],"required":[4],"round":[4],"type":[1],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64],"clear":[64]}],[1,"cat-modal",{"size":[1],"isVisible":[32],"show":[64]}],[1,"cat-tabs",{"activeTab":[1,"active-tab"],"tabsAlign":[1,"tabs-align"],"tabs":[32],"activeTabId":[32]},[[0,"keydown","onKeydown"]]],[0,"cat-toast-demo"],[1,"cat-alert",{"color":[1],"icon":[1],"noIcon":[4,"no-icon"]}],[1,"cat-badge",{"variant":[1],"color":[1],"size":[1],"round":[4],"pulse":[4]}],[1,"cat-card"],[1,"cat-menu",{"placement":[1]},[[0,"catClick","clickHandler"]]],[1,"cat-radio",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-radio-group",{"name":[1],"value":[1025],"disabled":[4],"a11yLabel":[1,"a11y-label"],"labelLeft":[4,"label-left"]},[[0,"keydown","onKeydown"],[0,"input","onInput"],[2,"blur","onBlur"]]],[1,"cat-tab",{"label":[513],"icon":[513],"iconOnly":[520,"icon-only"],"iconRight":[516,"icon-right"],"url":[513],"urlTarget":[513,"url-target"],"deactivated":[516]},[[0,"click","onClick"]]],[1,"cat-textarea",{"disabled":[4],"hint":[1],"label":[1],"labelHidden":[4,"label-hidden"],"maxLength":[2,"max-length"],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"readonly":[4],"required":[4],"rows":[2],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-toggle",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-tooltip",{"content":[1],"disabled":[4],"placement":[1],"round":[4],"size":[1],"showDelay":[2,"show-delay"],"hideDelay":[2,"hide-delay"],"longTouchDuration":[2,"long-touch-duration"]},[[0,"keydown","handleKeyDown"]]],[1,"cat-select",{"multiple":[4],"debounce":[2],"placement":[1],"value":[1025],"disabled":[4],"placeholder":[1],"hint":[1],"label":[1],"name":[1],"labelHidden":[4,"label-hidden"],"required":[4],"clearable":[4],"tags":[4],"tagHint":[1,"tag-hint"],"connector":[32],"state":[32],"hasSlottedLabel":[32],"connect":[64]},[[0,"blur","onBlur"],[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"]]],[1,"cat-avatar",{"size":[1],"round":[4],"label":[1],"initials":[1],"src":[1],"icon":[1],"url":[1],"urlTarget":[1,"url-target"],"backgroundImage":[32]}],[1,"cat-checkbox",{"checked":[1028],"disabled":[4],"indeterminate":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-scrollable",{"noShadowX":[4,"no-shadow-x"],"noShadowY":[4,"no-shadow-y"],"noOverflowX":[4,"no-overflow-x"],"noOverflowY":[4,"no-overflow-y"],"noOverscroll":[4,"no-overscroll"],"noScrolledInit":[4,"no-scrolled-init"],"scrolledBuffer":[2,"scrolled-buffer"]}],[1,"cat-skeleton",{"effect":[1],"variant":[1],"size":[1],"lines":[2]}],[1,"cat-button",{"variant":[1],"color":[1],"active":[4],"size":[1],"name":[1],"value":[1],"disabled":[4],"loading":[4],"submit":[4],"noEllipsis":[4,"no-ellipsis"],"round":[4],"url":[1],"urlTarget":[1,"url-target"],"icon":[1],"iconOnly":[8,"icon-only"],"iconRight":[4,"icon-right"],"buttonId":[1,"button-id"],"a11yLabel":[1,"a11y-label"],"_iconOnly":[32],"setFocus":[64]},[[0,"click","haltDisabledEvents"]]],[1,"cat-spinner",{"size":[1],"a11yLabel":[1,"a11y-label"]}],[1,"cat-icon",{"icon":[1],"size":[1],"a11yLabel":[1,"a11y-label"]}]]]], options);
18
+ return index.bootstrapLazy([["cat-alert_23.cjs",[[1,"cat-select-demo"],[1,"cat-input",{"autoComplete":[1,"auto-complete"],"clearable":[4],"disabled":[4],"hint":[1],"icon":[1],"iconRight":[4,"icon-right"],"label":[1],"labelHidden":[4,"label-hidden"],"max":[8],"maxLength":[2,"max-length"],"min":[8],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"textPrefix":[1,"text-prefix"],"textSuffix":[1,"text-suffix"],"readonly":[4],"required":[4],"round":[4],"type":[1],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64],"clear":[64]}],[1,"cat-modal",{"size":[1],"isVisible":[32],"show":[64]}],[1,"cat-tabs",{"activeTab":[1,"active-tab"],"tabsAlign":[1,"tabs-align"],"tabs":[32],"activeTabId":[32]},[[0,"keydown","onKeydown"]]],[0,"cat-toast-demo"],[1,"cat-alert",{"color":[1],"icon":[1],"noIcon":[4,"no-icon"]}],[1,"cat-badge",{"variant":[1],"color":[1],"size":[1],"round":[4],"pulse":[4]}],[1,"cat-card"],[1,"cat-menu",{"placement":[1],"close":[64]},[[0,"catClick","clickHandler"]]],[1,"cat-radio",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-radio-group",{"name":[1],"value":[1025],"disabled":[4],"a11yLabel":[1,"a11y-label"],"labelLeft":[4,"label-left"]},[[0,"keydown","onKeydown"],[0,"input","onInput"],[2,"blur","onBlur"]]],[1,"cat-tab",{"label":[513],"icon":[513],"iconOnly":[520,"icon-only"],"iconRight":[516,"icon-right"],"url":[513],"urlTarget":[513,"url-target"],"deactivated":[516]},[[0,"click","onClick"]]],[1,"cat-textarea",{"disabled":[4],"hint":[1],"label":[1],"labelHidden":[4,"label-hidden"],"maxLength":[2,"max-length"],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"readonly":[4],"required":[4],"rows":[2],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-toggle",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-tooltip",{"content":[1],"disabled":[4],"placement":[1],"round":[4],"size":[1],"showDelay":[2,"show-delay"],"hideDelay":[2,"hide-delay"],"longTouchDuration":[2,"long-touch-duration"]},[[0,"keydown","handleKeyDown"]]],[1,"cat-select",{"multiple":[4],"debounce":[2],"placement":[1],"value":[1025],"disabled":[4],"placeholder":[1],"hint":[1],"label":[1],"name":[1],"labelHidden":[4,"label-hidden"],"required":[4],"clearable":[4],"tags":[4],"tagHint":[1,"tag-hint"],"connector":[32],"state":[32],"hasSlottedLabel":[32],"connect":[64]},[[0,"blur","onBlur"],[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"]]],[1,"cat-avatar",{"size":[1],"round":[4],"label":[1],"initials":[1],"src":[1],"icon":[1],"url":[1],"urlTarget":[1,"url-target"],"backgroundImage":[32]}],[1,"cat-checkbox",{"checked":[1028],"disabled":[4],"indeterminate":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-scrollable",{"noShadowX":[4,"no-shadow-x"],"noShadowY":[4,"no-shadow-y"],"noOverflowX":[4,"no-overflow-x"],"noOverflowY":[4,"no-overflow-y"],"noOverscroll":[4,"no-overscroll"],"noScrolledInit":[4,"no-scrolled-init"],"scrolledBuffer":[2,"scrolled-buffer"]}],[1,"cat-skeleton",{"effect":[1],"variant":[1],"size":[1],"lines":[2]}],[1,"cat-button",{"variant":[1],"color":[1],"active":[4],"size":[1],"name":[1],"value":[1],"disabled":[4],"loading":[4],"submit":[4],"noEllipsis":[4,"no-ellipsis"],"round":[4],"url":[1],"urlTarget":[1,"url-target"],"icon":[1],"iconOnly":[8,"icon-only"],"iconRight":[4,"icon-right"],"buttonId":[1,"button-id"],"a11yLabel":[1,"a11y-label"],"_iconOnly":[32],"setFocus":[64]},[[0,"click","haltDisabledEvents"]]],[1,"cat-spinner",{"size":[1],"a11yLabel":[1,"a11y-label"]}],[1,"cat-icon",{"icon":[1],"size":[1],"a11yLabel":[1,"a11y-label"]}]]]], options);
19
19
  });
20
20
 
21
21
  //# sourceMappingURL=catalyst.cjs.js.map
@@ -14,7 +14,7 @@ const patchEsm = () => {
14
14
  const defineCustomElements = (win, options) => {
15
15
  if (typeof window === 'undefined') return Promise.resolve();
16
16
  return patchEsm().then(() => {
17
- return index.bootstrapLazy([["cat-alert_23.cjs",[[1,"cat-select-demo"],[1,"cat-input",{"autoComplete":[1,"auto-complete"],"clearable":[4],"disabled":[4],"hint":[1],"icon":[1],"iconRight":[4,"icon-right"],"label":[1],"labelHidden":[4,"label-hidden"],"max":[8],"maxLength":[2,"max-length"],"min":[8],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"textPrefix":[1,"text-prefix"],"textSuffix":[1,"text-suffix"],"readonly":[4],"required":[4],"round":[4],"type":[1],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64],"clear":[64]}],[1,"cat-modal",{"size":[1],"isVisible":[32],"show":[64]}],[1,"cat-tabs",{"activeTab":[1,"active-tab"],"tabsAlign":[1,"tabs-align"],"tabs":[32],"activeTabId":[32]},[[0,"keydown","onKeydown"]]],[0,"cat-toast-demo"],[1,"cat-alert",{"color":[1],"icon":[1],"noIcon":[4,"no-icon"]}],[1,"cat-badge",{"variant":[1],"color":[1],"size":[1],"round":[4],"pulse":[4]}],[1,"cat-card"],[1,"cat-menu",{"placement":[1]},[[0,"catClick","clickHandler"]]],[1,"cat-radio",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-radio-group",{"name":[1],"value":[1025],"disabled":[4],"a11yLabel":[1,"a11y-label"],"labelLeft":[4,"label-left"]},[[0,"keydown","onKeydown"],[0,"input","onInput"],[2,"blur","onBlur"]]],[1,"cat-tab",{"label":[513],"icon":[513],"iconOnly":[520,"icon-only"],"iconRight":[516,"icon-right"],"url":[513],"urlTarget":[513,"url-target"],"deactivated":[516]},[[0,"click","onClick"]]],[1,"cat-textarea",{"disabled":[4],"hint":[1],"label":[1],"labelHidden":[4,"label-hidden"],"maxLength":[2,"max-length"],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"readonly":[4],"required":[4],"rows":[2],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-toggle",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-tooltip",{"content":[1],"disabled":[4],"placement":[1],"round":[4],"size":[1],"showDelay":[2,"show-delay"],"hideDelay":[2,"hide-delay"],"longTouchDuration":[2,"long-touch-duration"]},[[0,"keydown","handleKeyDown"]]],[1,"cat-select",{"multiple":[4],"debounce":[2],"placement":[1],"value":[1025],"disabled":[4],"placeholder":[1],"hint":[1],"label":[1],"name":[1],"labelHidden":[4,"label-hidden"],"required":[4],"clearable":[4],"tags":[4],"tagHint":[1,"tag-hint"],"connector":[32],"state":[32],"hasSlottedLabel":[32],"connect":[64]},[[0,"blur","onBlur"],[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"]]],[1,"cat-avatar",{"size":[1],"round":[4],"label":[1],"initials":[1],"src":[1],"icon":[1],"url":[1],"urlTarget":[1,"url-target"],"backgroundImage":[32]}],[1,"cat-checkbox",{"checked":[1028],"disabled":[4],"indeterminate":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-scrollable",{"noShadowX":[4,"no-shadow-x"],"noShadowY":[4,"no-shadow-y"],"noOverflowX":[4,"no-overflow-x"],"noOverflowY":[4,"no-overflow-y"],"noOverscroll":[4,"no-overscroll"],"noScrolledInit":[4,"no-scrolled-init"],"scrolledBuffer":[2,"scrolled-buffer"]}],[1,"cat-skeleton",{"effect":[1],"variant":[1],"size":[1],"lines":[2]}],[1,"cat-button",{"variant":[1],"color":[1],"active":[4],"size":[1],"name":[1],"value":[1],"disabled":[4],"loading":[4],"submit":[4],"noEllipsis":[4,"no-ellipsis"],"round":[4],"url":[1],"urlTarget":[1,"url-target"],"icon":[1],"iconOnly":[8,"icon-only"],"iconRight":[4,"icon-right"],"buttonId":[1,"button-id"],"a11yLabel":[1,"a11y-label"],"_iconOnly":[32],"setFocus":[64]},[[0,"click","haltDisabledEvents"]]],[1,"cat-spinner",{"size":[1],"a11yLabel":[1,"a11y-label"]}],[1,"cat-icon",{"icon":[1],"size":[1],"a11yLabel":[1,"a11y-label"]}]]]], options);
17
+ return index.bootstrapLazy([["cat-alert_23.cjs",[[1,"cat-select-demo"],[1,"cat-input",{"autoComplete":[1,"auto-complete"],"clearable":[4],"disabled":[4],"hint":[1],"icon":[1],"iconRight":[4,"icon-right"],"label":[1],"labelHidden":[4,"label-hidden"],"max":[8],"maxLength":[2,"max-length"],"min":[8],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"textPrefix":[1,"text-prefix"],"textSuffix":[1,"text-suffix"],"readonly":[4],"required":[4],"round":[4],"type":[1],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64],"clear":[64]}],[1,"cat-modal",{"size":[1],"isVisible":[32],"show":[64]}],[1,"cat-tabs",{"activeTab":[1,"active-tab"],"tabsAlign":[1,"tabs-align"],"tabs":[32],"activeTabId":[32]},[[0,"keydown","onKeydown"]]],[0,"cat-toast-demo"],[1,"cat-alert",{"color":[1],"icon":[1],"noIcon":[4,"no-icon"]}],[1,"cat-badge",{"variant":[1],"color":[1],"size":[1],"round":[4],"pulse":[4]}],[1,"cat-card"],[1,"cat-menu",{"placement":[1],"close":[64]},[[0,"catClick","clickHandler"]]],[1,"cat-radio",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-radio-group",{"name":[1],"value":[1025],"disabled":[4],"a11yLabel":[1,"a11y-label"],"labelLeft":[4,"label-left"]},[[0,"keydown","onKeydown"],[0,"input","onInput"],[2,"blur","onBlur"]]],[1,"cat-tab",{"label":[513],"icon":[513],"iconOnly":[520,"icon-only"],"iconRight":[516,"icon-right"],"url":[513],"urlTarget":[513,"url-target"],"deactivated":[516]},[[0,"click","onClick"]]],[1,"cat-textarea",{"disabled":[4],"hint":[1],"label":[1],"labelHidden":[4,"label-hidden"],"maxLength":[2,"max-length"],"minLength":[2,"min-length"],"name":[1],"placeholder":[1],"readonly":[4],"required":[4],"rows":[2],"value":[1032],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-toggle",{"checked":[1028],"disabled":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-tooltip",{"content":[1],"disabled":[4],"placement":[1],"round":[4],"size":[1],"showDelay":[2,"show-delay"],"hideDelay":[2,"hide-delay"],"longTouchDuration":[2,"long-touch-duration"]},[[0,"keydown","handleKeyDown"]]],[1,"cat-select",{"multiple":[4],"debounce":[2],"placement":[1],"value":[1025],"disabled":[4],"placeholder":[1],"hint":[1],"label":[1],"name":[1],"labelHidden":[4,"label-hidden"],"required":[4],"clearable":[4],"tags":[4],"tagHint":[1,"tag-hint"],"connector":[32],"state":[32],"hasSlottedLabel":[32],"connect":[64]},[[0,"blur","onBlur"],[0,"keydown","onKeyDown"],[0,"keyup","onKeyUp"]]],[1,"cat-avatar",{"size":[1],"round":[4],"label":[1],"initials":[1],"src":[1],"icon":[1],"url":[1],"urlTarget":[1,"url-target"],"backgroundImage":[32]}],[1,"cat-checkbox",{"checked":[1028],"disabled":[4],"indeterminate":[4],"label":[1],"labelHidden":[4,"label-hidden"],"name":[1],"required":[4],"value":[1032],"hint":[1],"labelLeft":[4,"label-left"],"hasSlottedLabel":[32],"setFocus":[64]}],[1,"cat-scrollable",{"noShadowX":[4,"no-shadow-x"],"noShadowY":[4,"no-shadow-y"],"noOverflowX":[4,"no-overflow-x"],"noOverflowY":[4,"no-overflow-y"],"noOverscroll":[4,"no-overscroll"],"noScrolledInit":[4,"no-scrolled-init"],"scrolledBuffer":[2,"scrolled-buffer"]}],[1,"cat-skeleton",{"effect":[1],"variant":[1],"size":[1],"lines":[2]}],[1,"cat-button",{"variant":[1],"color":[1],"active":[4],"size":[1],"name":[1],"value":[1],"disabled":[4],"loading":[4],"submit":[4],"noEllipsis":[4,"no-ellipsis"],"round":[4],"url":[1],"urlTarget":[1,"url-target"],"icon":[1],"iconOnly":[8,"icon-only"],"iconRight":[4,"icon-right"],"buttonId":[1,"button-id"],"a11yLabel":[1,"a11y-label"],"_iconOnly":[32],"setFocus":[64]},[[0,"click","haltDisabledEvents"]]],[1,"cat-spinner",{"size":[1],"a11yLabel":[1,"a11y-label"]}],[1,"cat-icon",{"icon":[1],"size":[1],"a11yLabel":[1,"a11y-label"]}]]]], options);
18
18
  });
19
19
  };
20
20
 
@@ -16,16 +16,19 @@
16
16
  display: none;
17
17
  }
18
18
 
19
- .content {
19
+ ::slotted(nav) {
20
20
  padding-top: 0.5rem;
21
21
  padding-bottom: 0.5rem;
22
+ min-width: 8rem;
23
+ max-width: 16rem;
24
+ }
25
+
26
+ .content {
22
27
  position: absolute;
23
28
  background: white;
24
29
  display: none;
25
30
  overflow: auto;
26
31
  -webkit-overflow-scrolling: touch;
27
- min-width: 8rem;
28
- max-width: 16rem;
29
32
  min-height: 2rem;
30
33
  max-height: calc(100vh - 48px);
31
34
  box-shadow: 0 1px 4px 0 rgba(16, 29, 48, 0.2);
@@ -1,5 +1,5 @@
1
1
  import { autoUpdate, computePosition, flip, offset } from '@floating-ui/dom';
2
- import { Component, Event, h, Host, Listen, Prop } from '@stencil/core';
2
+ import { Component, Event, h, Host, Listen, Method, Prop } from '@stencil/core';
3
3
  import * as focusTrap from 'focus-trap';
4
4
  import { tabbable } from 'tabbable';
5
5
  import firstTabbable from '../../utils/first-tabbable';
@@ -13,13 +13,19 @@ export class CatMenu {
13
13
  this.placement = 'bottom-start';
14
14
  }
15
15
  clickHandler(event) {
16
- var _a;
17
16
  // hide menu on button click
18
17
  if (this.content && event.composedPath().includes(this.content)) {
19
- (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
20
- this.hide();
18
+ this.close();
21
19
  }
22
20
  }
21
+ /**
22
+ * Closes the menu.
23
+ */
24
+ async close() {
25
+ var _a;
26
+ (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
27
+ this.hide();
28
+ }
23
29
  componentDidLoad() {
24
30
  var _a, _b, _c, _d, _e;
25
31
  this.trigger = firstTabbable(this.triggerSlot);
@@ -172,6 +178,24 @@ export class CatMenu {
172
178
  }
173
179
  }
174
180
  }]; }
181
+ static get methods() { return {
182
+ "close": {
183
+ "complexType": {
184
+ "signature": "() => Promise<void>",
185
+ "parameters": [],
186
+ "references": {
187
+ "Promise": {
188
+ "location": "global"
189
+ }
190
+ },
191
+ "return": "Promise<void>"
192
+ },
193
+ "docs": {
194
+ "text": "Closes the menu.",
195
+ "tags": []
196
+ }
197
+ }
198
+ }; }
175
199
  static get listeners() { return [{
176
200
  "name": "catClick",
177
201
  "method": "clickHandler",
@@ -1 +1 @@
1
- {"version":3,"file":"cat-menu.js","sourceRoot":"","sources":["../../../src/components/cat-menu/cat-menu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAa,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAgB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAoB,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,aAAa,MAAM,4BAA4B,CAAC;AAEvD,IAAI,YAAY,GAAG,CAAC,CAAC;AAOrB,MAAM,OAAO,OAAO;EALpB;IAOmB,OAAE,GAAG,YAAY,EAAE,CAAC;IAOrC;;OAEG;IACK,cAAS,GAAc,cAAc,CAAC;GA6G/C;EAhGC,YAAY,CAAC,KAA8B;;IACzC,4BAA4B;IAC5B,IAAI,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;MAC/D,MAAA,IAAI,CAAC,IAAI,0CAAE,UAAU,EAAE,CAAC;MACxB,IAAI,CAAC,IAAI,EAAE,CAAC;KACb;EACH,CAAC;EAED,gBAAgB;;IACd,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC,eAA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C,IAAI;WACd,CAAC,CAAC;SACJ;MACH,CAAC,CAAC,CAAC;KACJ;EACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAvHuB,cAAM,GAAG,CAAE,CAAA","sourcesContent":["import { autoUpdate, computePosition, flip, offset, Placement } from '@floating-ui/dom';\nimport { Component, Event, EventEmitter, h, Host, Listen, Prop } from '@stencil/core';\nimport * as focusTrap from 'focus-trap';\nimport { FocusableElement, tabbable } from 'tabbable';\nimport firstTabbable from '../../utils/first-tabbable';\n\nlet nextUniqueId = 0;\n\n@Component({\n tag: 'cat-menu',\n styleUrl: 'cat-menu.scss',\n shadow: true\n})\nexport class CatMenu {\n private static readonly OFFSET = 4;\n private readonly id = nextUniqueId++;\n private triggerSlot?: Element;\n private trigger?: FocusableElement;\n private content?: HTMLElement;\n private trap?: focusTrap.FocusTrap;\n private keyListener?: (event: KeyboardEvent) => void;\n\n /**\n * The placement of the menu.\n */\n @Prop() placement: Placement = 'bottom-start';\n\n /**\n * Emitted when the menu is opened.\n */\n @Event() catOpen!: EventEmitter<FocusEvent>;\n\n /**\n * Emitted when the menu is closed.\n */\n @Event() catClose!: EventEmitter<FocusEvent>;\n\n @Listen('catClick')\n clickHandler(event: CustomEvent<MouseEvent>) {\n // hide menu on button click\n if (this.content && event.composedPath().includes(this.content)) {\n this.trap?.deactivate();\n this.hide();\n }\n }\n\n componentDidLoad(): void {\n this.trigger = firstTabbable(this.triggerSlot);\n this.trigger?.setAttribute('aria-haspopup', 'true');\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.trigger?.setAttribute('aria-controls', this.contentId);\n this.content?.setAttribute('id', this.contentId);\n if (this.trigger && this.content) {\n this.trigger?.addEventListener('click', () => this.show());\n autoUpdate(this.trigger, this.content, () => this.update());\n }\n\n this.keyListener = event => {\n if (this.content && ['ArrowDown', 'ArrowUp'].includes(event.key)) {\n const targetElements = tabbable(this.content, { includeContainer: false, getShadowRoot: true });\n const activeElement = firstTabbable(document.activeElement);\n const activeIdx = activeElement ? targetElements.indexOf(activeElement) : -1;\n const activeOff = event.key === 'ArrowDown' ? 1 : -1;\n const targetIdx = activeIdx < 0 ? 0 : (activeIdx + activeOff + targetElements.length) % targetElements.length;\n targetElements[targetIdx].focus();\n event.preventDefault();\n }\n };\n document.addEventListener('keydown', this.keyListener);\n }\n\n disconnectedCallback(): void {\n if (this.keyListener) {\n document.removeEventListener('keydown', this.keyListener);\n }\n }\n\n render() {\n return (\n <Host>\n <slot name=\"trigger\" ref={el => (this.triggerSlot = el)}></slot>\n <div class=\"content\" ref={el => (this.content = el)}>\n <slot name=\"content\"></slot>\n </div>\n </Host>\n );\n }\n\n private get contentId() {\n return `cat-menu-${this.id}`;\n }\n\n private show() {\n if (this.content) {\n this.content.style.display = 'block';\n this.trigger?.setAttribute('aria-expanded', 'true');\n this.catOpen.emit();\n this.trap = this.trap\n ? this.trap.updateContainerElements(this.content)\n : focusTrap.createFocusTrap(this.content, {\n tabbableOptions: {\n getShadowRoot: true\n },\n allowOutsideClick: true,\n clickOutsideDeactivates: event => !this.content || !event.composedPath().includes(this.content),\n onPostDeactivate: () => this.hide()\n });\n this.trap.activate();\n }\n }\n\n private hide() {\n if (this.content) {\n this.content.style.display = '';\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.catClose.emit();\n }\n }\n\n private update() {\n if (this.trigger && this.content) {\n computePosition(this.trigger, this.content, {\n placement: this.placement,\n middleware: [offset(CatMenu.OFFSET), flip()]\n }).then(({ x, y }) => {\n if (this.content) {\n Object.assign(this.content.style, {\n left: `${x}px`,\n top: `${y}px`\n });\n }\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"cat-menu.js","sourceRoot":"","sources":["../../../src/components/cat-menu/cat-menu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAa,MAAM,kBAAkB,CA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B,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;SACpC,CAAC,CAAC;MACP,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;KACtB;EACH,CAAC;EAEO,IAAI;;IACV,IAAI,IAAI,CAAC,OAAO,EAAE;MAChB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;MAChC,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;MACrD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;KACtB;EACH,CAAC;EAEO,MAAM;IACZ,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE;MAChC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QAC1C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,UAAU,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;OAC7C,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE;QACnB,IAAI,IAAI,CAAC,OAAO,EAAE;UAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YAChC,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,GAAG,EAAE,GAAG,CAAC,IAAI;WACd,CAAC,CAAC;SACJ;MACH,CAAC,CAAC,CAAC;KACJ;EACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA/HuB,cAAM,GAAG,CAAE,CAAA","sourcesContent":["import { autoUpdate, computePosition, flip, offset, Placement } from '@floating-ui/dom';\nimport { Component, Event, EventEmitter, h, Host, Listen, Method, Prop } from '@stencil/core';\nimport * as focusTrap from 'focus-trap';\nimport { FocusableElement, tabbable } from 'tabbable';\nimport firstTabbable from '../../utils/first-tabbable';\n\nlet nextUniqueId = 0;\n\n@Component({\n tag: 'cat-menu',\n styleUrl: 'cat-menu.scss',\n shadow: true\n})\nexport class CatMenu {\n private static readonly OFFSET = 4;\n private readonly id = nextUniqueId++;\n private triggerSlot?: Element;\n private trigger?: FocusableElement;\n private content?: HTMLElement;\n private trap?: focusTrap.FocusTrap;\n private keyListener?: (event: KeyboardEvent) => void;\n\n /**\n * The placement of the menu.\n */\n @Prop() placement: Placement = 'bottom-start';\n\n /**\n * Emitted when the menu is opened.\n */\n @Event() catOpen!: EventEmitter<FocusEvent>;\n\n /**\n * Emitted when the menu is closed.\n */\n @Event() catClose!: EventEmitter<FocusEvent>;\n\n @Listen('catClick')\n clickHandler(event: CustomEvent<MouseEvent>) {\n // hide menu on button click\n if (this.content && event.composedPath().includes(this.content)) {\n this.close();\n }\n }\n\n /**\n * Closes the menu.\n */\n @Method()\n async close(): Promise<void> {\n this.trap?.deactivate();\n this.hide();\n }\n\n componentDidLoad(): void {\n this.trigger = firstTabbable(this.triggerSlot);\n this.trigger?.setAttribute('aria-haspopup', 'true');\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.trigger?.setAttribute('aria-controls', this.contentId);\n this.content?.setAttribute('id', this.contentId);\n if (this.trigger && this.content) {\n this.trigger?.addEventListener('click', () => this.show());\n autoUpdate(this.trigger, this.content, () => this.update());\n }\n\n this.keyListener = event => {\n if (this.content && ['ArrowDown', 'ArrowUp'].includes(event.key)) {\n const targetElements = tabbable(this.content, { includeContainer: false, getShadowRoot: true });\n const activeElement = firstTabbable(document.activeElement);\n const activeIdx = activeElement ? targetElements.indexOf(activeElement) : -1;\n const activeOff = event.key === 'ArrowDown' ? 1 : -1;\n const targetIdx = activeIdx < 0 ? 0 : (activeIdx + activeOff + targetElements.length) % targetElements.length;\n targetElements[targetIdx].focus();\n event.preventDefault();\n }\n };\n document.addEventListener('keydown', this.keyListener);\n }\n\n disconnectedCallback(): void {\n if (this.keyListener) {\n document.removeEventListener('keydown', this.keyListener);\n }\n }\n\n render() {\n return (\n <Host>\n <slot name=\"trigger\" ref={el => (this.triggerSlot = el)}></slot>\n <div class=\"content\" ref={el => (this.content = el)}>\n <slot name=\"content\"></slot>\n </div>\n </Host>\n );\n }\n\n private get contentId() {\n return `cat-menu-${this.id}`;\n }\n\n private show() {\n if (this.content) {\n this.content.style.display = 'block';\n this.trigger?.setAttribute('aria-expanded', 'true');\n this.catOpen.emit();\n this.trap = this.trap\n ? this.trap.updateContainerElements(this.content)\n : focusTrap.createFocusTrap(this.content, {\n tabbableOptions: {\n getShadowRoot: true\n },\n allowOutsideClick: true,\n clickOutsideDeactivates: event => !this.content || !event.composedPath().includes(this.content),\n onPostDeactivate: () => this.hide()\n });\n this.trap.activate();\n }\n }\n\n private hide() {\n if (this.content) {\n this.content.style.display = '';\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.catClose.emit();\n }\n }\n\n private update() {\n if (this.trigger && this.content) {\n computePosition(this.trigger, this.content, {\n placement: this.placement,\n middleware: [offset(CatMenu.OFFSET), flip()]\n }).then(({ x, y }) => {\n if (this.content) {\n Object.assign(this.content.style, {\n left: `${x}px`,\n top: `${y}px`\n });\n }\n });\n }\n }\n}\n"]}
@@ -3,7 +3,7 @@ import { a as autoUpdate, c as computePosition, o as offset, f as flip } from '.
3
3
  import { c as createFocusTrap } from './focus-trap.esm.js';
4
4
  import { f as firstTabbable, t as tabbable } from './first-tabbable.js';
5
5
 
6
- const catMenuCss = ":host{display:contents}:host([hidden]){display:none}.content{padding-top:0.5rem;padding-bottom:0.5rem;position:absolute;background:white;display:none;overflow:auto;-webkit-overflow-scrolling:touch;min-width:8rem;max-width:16rem;min-height:2rem;max-height:calc(100vh - 48px);box-shadow:0 1px 4px 0 rgba(16, 29, 48, 0.2);border-radius:0.25rem;z-index:100}";
6
+ const catMenuCss = ":host{display:contents}:host([hidden]){display:none}::slotted(nav){padding-top:0.5rem;padding-bottom:0.5rem;min-width:8rem;max-width:16rem}.content{position:absolute;background:white;display:none;overflow:auto;-webkit-overflow-scrolling:touch;min-height:2rem;max-height:calc(100vh - 48px);box-shadow:0 1px 4px 0 rgba(16, 29, 48, 0.2);border-radius:0.25rem;z-index:100}";
7
7
 
8
8
  let nextUniqueId = 0;
9
9
  const CatMenu$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
@@ -20,13 +20,19 @@ const CatMenu$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
20
20
  this.placement = 'bottom-start';
21
21
  }
22
22
  clickHandler(event) {
23
- var _a;
24
23
  // hide menu on button click
25
24
  if (this.content && event.composedPath().includes(this.content)) {
26
- (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
27
- this.hide();
25
+ this.close();
28
26
  }
29
27
  }
28
+ /**
29
+ * Closes the menu.
30
+ */
31
+ async close() {
32
+ var _a;
33
+ (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
34
+ this.hide();
35
+ }
30
36
  componentDidLoad() {
31
37
  var _a, _b, _c, _d, _e;
32
38
  this.trigger = firstTabbable(this.triggerSlot);
@@ -106,7 +112,8 @@ const CatMenu$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
106
112
  }
107
113
  static get style() { return catMenuCss; }
108
114
  }, [1, "cat-menu", {
109
- "placement": [1]
115
+ "placement": [1],
116
+ "close": [64]
110
117
  }, [[0, "catClick", "clickHandler"]]]);
111
118
  CatMenu$1.OFFSET = 4;
112
119
  function defineCustomElement$1() {
@@ -1 +1 @@
1
- {"file":"cat-menu.js","mappings":";;;;;AAAA,MAAM,UAAU,GAAG,mWAAmW;;ACMtX,IAAI,YAAY,GAAG,CAAC,CAAC;MAORA,SAAO;EALpB;;;;;;IAOmB,OAAE,GAAG,YAAY,EAAE,CAAC;;;;IAU7B,cAAS,GAAc,cAAc,CAAC;GA6G/C;EAhGC,YAAY,CAAC,KAA8B;;;IAE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AAK,EAAE;YAChC,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,GAAG,EAAE,GAAG,CAAC,IAAI;WACd,CAAC,CAAC;SACJ;OACF,CAAC,CAAC;KACJ;GACF;;;;;AAvHuBA,gBAAM,GAAG,CAAE,CAAA;;;;;;;;;;;;;;;;;;;;","names":["CatMenu","focusTrap.createFocusTrap"],"sources":["./src/components/cat-menu/cat-menu.scss?tag=cat-menu&encapsulation=shadow","./src/components/cat-menu/cat-menu.tsx"],"sourcesContent":["@import 'variables';\n@import 'mixins';\n\n$-min-width: 8rem;\n$-max-width: 16rem;\n$-min-height: 2rem;\n$-max-height: calc(100vh - 48px);\n\n:host {\n display: contents;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.content {\n padding-top: $cat-body-margin-bottom * 0.5;\n padding-bottom: $cat-body-margin-bottom * 0.5;\n position: absolute;\n background: cat-token('color.ui.background.body');\n display: none;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n min-width: $-min-width;\n max-width: $-max-width;\n min-height: $-min-height;\n max-height: $-max-height;\n @include cat-elevation(1);\n border-radius: cat-border-radius('m');\n z-index: $cat-menu-z-index;\n}\n","import { autoUpdate, computePosition, flip, offset, Placement } from '@floating-ui/dom';\nimport { Component, Event, EventEmitter, h, Host, Listen, Prop } from '@stencil/core';\nimport * as focusTrap from 'focus-trap';\nimport { FocusableElement, tabbable } from 'tabbable';\nimport firstTabbable from '../../utils/first-tabbable';\n\nlet nextUniqueId = 0;\n\n@Component({\n tag: 'cat-menu',\n styleUrl: 'cat-menu.scss',\n shadow: true\n})\nexport class CatMenu {\n private static readonly OFFSET = 4;\n private readonly id = nextUniqueId++;\n private triggerSlot?: Element;\n private trigger?: FocusableElement;\n private content?: HTMLElement;\n private trap?: focusTrap.FocusTrap;\n private keyListener?: (event: KeyboardEvent) => void;\n\n /**\n * The placement of the menu.\n */\n @Prop() placement: Placement = 'bottom-start';\n\n /**\n * Emitted when the menu is opened.\n */\n @Event() catOpen!: EventEmitter<FocusEvent>;\n\n /**\n * Emitted when the menu is closed.\n */\n @Event() catClose!: EventEmitter<FocusEvent>;\n\n @Listen('catClick')\n clickHandler(event: CustomEvent<MouseEvent>) {\n // hide menu on button click\n if (this.content && event.composedPath().includes(this.content)) {\n this.trap?.deactivate();\n this.hide();\n }\n }\n\n componentDidLoad(): void {\n this.trigger = firstTabbable(this.triggerSlot);\n this.trigger?.setAttribute('aria-haspopup', 'true');\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.trigger?.setAttribute('aria-controls', this.contentId);\n this.content?.setAttribute('id', this.contentId);\n if (this.trigger && this.content) {\n this.trigger?.addEventListener('click', () => this.show());\n autoUpdate(this.trigger, this.content, () => this.update());\n }\n\n this.keyListener = event => {\n if (this.content && ['ArrowDown', 'ArrowUp'].includes(event.key)) {\n const targetElements = tabbable(this.content, { includeContainer: false, getShadowRoot: true });\n const activeElement = firstTabbable(document.activeElement);\n const activeIdx = activeElement ? targetElements.indexOf(activeElement) : -1;\n const activeOff = event.key === 'ArrowDown' ? 1 : -1;\n const targetIdx = activeIdx < 0 ? 0 : (activeIdx + activeOff + targetElements.length) % targetElements.length;\n targetElements[targetIdx].focus();\n event.preventDefault();\n }\n };\n document.addEventListener('keydown', this.keyListener);\n }\n\n disconnectedCallback(): void {\n if (this.keyListener) {\n document.removeEventListener('keydown', this.keyListener);\n }\n }\n\n render() {\n return (\n <Host>\n <slot name=\"trigger\" ref={el => (this.triggerSlot = el)}></slot>\n <div class=\"content\" ref={el => (this.content = el)}>\n <slot name=\"content\"></slot>\n </div>\n </Host>\n );\n }\n\n private get contentId() {\n return `cat-menu-${this.id}`;\n }\n\n private show() {\n if (this.content) {\n this.content.style.display = 'block';\n this.trigger?.setAttribute('aria-expanded', 'true');\n this.catOpen.emit();\n this.trap = this.trap\n ? this.trap.updateContainerElements(this.content)\n : focusTrap.createFocusTrap(this.content, {\n tabbableOptions: {\n getShadowRoot: true\n },\n allowOutsideClick: true,\n clickOutsideDeactivates: event => !this.content || !event.composedPath().includes(this.content),\n onPostDeactivate: () => this.hide()\n });\n this.trap.activate();\n }\n }\n\n private hide() {\n if (this.content) {\n this.content.style.display = '';\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.catClose.emit();\n }\n }\n\n private update() {\n if (this.trigger && this.content) {\n computePosition(this.trigger, this.content, {\n placement: this.placement,\n middleware: [offset(CatMenu.OFFSET), flip()]\n }).then(({ x, y }) => {\n if (this.content) {\n Object.assign(this.content.style, {\n left: `${x}px`,\n top: `${y}px`\n });\n }\n });\n }\n }\n}\n"],"version":3}
1
+ {"file":"cat-menu.js","mappings":";;;;;AAAA,MAAM,UAAU,GAAG,kXAAkX;;ACMrY,IAAI,YAAY,GAAG,CAAC,CAAC;MAORA,SAAO;EALpB;;;;;;IAOmB,OAAE,GAAG,YAAY,EAAE,CAAC;;;;IAU7B,cAAS,GAAc,cAAc,CAAC;GAqH/C;EAxGC,YAAY,CAAC,KAA8B;;IAEzC,IAAI,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;MAC/D,IAAI,CAAC,KAAK,EAAE,CAAC;KACd;GACF;;;;EAMD,MAAM,KAAK;;IACT,MAAA,IAAI,CAAC,IAAI,0CAAE,UAAU,EAAE,CAAC;IACxB,IAAI,CAAC,IAAI,EAAE,CAAC;GACb;EAED,gBAAgB;;IACd,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACpD,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IACrD,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5D,MAAA,IAAI,CAAC,OAAO,0CAAE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,IAAI,CAAC,OAAO,EAAE;MAChB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;MAChC,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;MACrD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;KACtB;GACF;EAEO,MAAM;IACZ,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE;MAChC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QAC1C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,UAAU,EAAE,CAAC,MAAM,CAACD,SAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;OAC7C,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QACf,IAAI,IAAI,CAAC,OAAO,EAAE;UAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YAChC,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,GAAG,EAAE,GAAG,CAAC,IAAI;WACd,CAAC,CAAC;SACJ;OACF,CAAC,CAAC;KACJ;GACF;;;;;;AA/HuBA,gBAAM,GAAG,CAAE,CAAA;;;;;;;;;;;;;;;;;;;;","names":["CatMenu","focusTrap.createFocusTrap"],"sources":["./src/components/cat-menu/cat-menu.scss?tag=cat-menu&encapsulation=shadow","./src/components/cat-menu/cat-menu.tsx"],"sourcesContent":["@import 'variables';\n@import 'mixins';\n\n$-min-width: 8rem;\n$-max-width: 16rem;\n$-min-height: 2rem;\n$-max-height: calc(100vh - 48px);\n\n:host {\n display: contents;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n::slotted(nav) {\n padding-top: $cat-body-margin-bottom * 0.5;\n padding-bottom: $cat-body-margin-bottom * 0.5;\n min-width: $-min-width;\n max-width: $-max-width;\n}\n\n.content {\n position: absolute;\n background: cat-token('color.ui.background.body');\n display: none;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n min-height: $-min-height;\n max-height: $-max-height;\n @include cat-elevation(1);\n border-radius: cat-border-radius('m');\n z-index: $cat-menu-z-index;\n}\n","import { autoUpdate, computePosition, flip, offset, Placement } from '@floating-ui/dom';\nimport { Component, Event, EventEmitter, h, Host, Listen, Method, Prop } from '@stencil/core';\nimport * as focusTrap from 'focus-trap';\nimport { FocusableElement, tabbable } from 'tabbable';\nimport firstTabbable from '../../utils/first-tabbable';\n\nlet nextUniqueId = 0;\n\n@Component({\n tag: 'cat-menu',\n styleUrl: 'cat-menu.scss',\n shadow: true\n})\nexport class CatMenu {\n private static readonly OFFSET = 4;\n private readonly id = nextUniqueId++;\n private triggerSlot?: Element;\n private trigger?: FocusableElement;\n private content?: HTMLElement;\n private trap?: focusTrap.FocusTrap;\n private keyListener?: (event: KeyboardEvent) => void;\n\n /**\n * The placement of the menu.\n */\n @Prop() placement: Placement = 'bottom-start';\n\n /**\n * Emitted when the menu is opened.\n */\n @Event() catOpen!: EventEmitter<FocusEvent>;\n\n /**\n * Emitted when the menu is closed.\n */\n @Event() catClose!: EventEmitter<FocusEvent>;\n\n @Listen('catClick')\n clickHandler(event: CustomEvent<MouseEvent>) {\n // hide menu on button click\n if (this.content && event.composedPath().includes(this.content)) {\n this.close();\n }\n }\n\n /**\n * Closes the menu.\n */\n @Method()\n async close(): Promise<void> {\n this.trap?.deactivate();\n this.hide();\n }\n\n componentDidLoad(): void {\n this.trigger = firstTabbable(this.triggerSlot);\n this.trigger?.setAttribute('aria-haspopup', 'true');\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.trigger?.setAttribute('aria-controls', this.contentId);\n this.content?.setAttribute('id', this.contentId);\n if (this.trigger && this.content) {\n this.trigger?.addEventListener('click', () => this.show());\n autoUpdate(this.trigger, this.content, () => this.update());\n }\n\n this.keyListener = event => {\n if (this.content && ['ArrowDown', 'ArrowUp'].includes(event.key)) {\n const targetElements = tabbable(this.content, { includeContainer: false, getShadowRoot: true });\n const activeElement = firstTabbable(document.activeElement);\n const activeIdx = activeElement ? targetElements.indexOf(activeElement) : -1;\n const activeOff = event.key === 'ArrowDown' ? 1 : -1;\n const targetIdx = activeIdx < 0 ? 0 : (activeIdx + activeOff + targetElements.length) % targetElements.length;\n targetElements[targetIdx].focus();\n event.preventDefault();\n }\n };\n document.addEventListener('keydown', this.keyListener);\n }\n\n disconnectedCallback(): void {\n if (this.keyListener) {\n document.removeEventListener('keydown', this.keyListener);\n }\n }\n\n render() {\n return (\n <Host>\n <slot name=\"trigger\" ref={el => (this.triggerSlot = el)}></slot>\n <div class=\"content\" ref={el => (this.content = el)}>\n <slot name=\"content\"></slot>\n </div>\n </Host>\n );\n }\n\n private get contentId() {\n return `cat-menu-${this.id}`;\n }\n\n private show() {\n if (this.content) {\n this.content.style.display = 'block';\n this.trigger?.setAttribute('aria-expanded', 'true');\n this.catOpen.emit();\n this.trap = this.trap\n ? this.trap.updateContainerElements(this.content)\n : focusTrap.createFocusTrap(this.content, {\n tabbableOptions: {\n getShadowRoot: true\n },\n allowOutsideClick: true,\n clickOutsideDeactivates: event => !this.content || !event.composedPath().includes(this.content),\n onPostDeactivate: () => this.hide()\n });\n this.trap.activate();\n }\n }\n\n private hide() {\n if (this.content) {\n this.content.style.display = '';\n this.trigger?.setAttribute('aria-expanded', 'false');\n this.catClose.emit();\n }\n }\n\n private update() {\n if (this.trigger && this.content) {\n computePosition(this.trigger, this.content, {\n placement: this.placement,\n middleware: [offset(CatMenu.OFFSET), flip()]\n }).then(({ x, y }) => {\n if (this.content) {\n Object.assign(this.content.style, {\n left: `${x}px`,\n top: `${y}px`\n });\n }\n });\n }\n }\n}\n"],"version":3}
@@ -3049,7 +3049,7 @@ const firstTabbable = (container) => {
3049
3049
  return (container ? tabbable(container, { includeContainer: true, getShadowRoot: true }) : []).shift();
3050
3050
  };
3051
3051
 
3052
- const catMenuCss = ":host{display:contents}:host([hidden]){display:none}.content{padding-top:0.5rem;padding-bottom:0.5rem;position:absolute;background:white;display:none;overflow:auto;-webkit-overflow-scrolling:touch;min-width:8rem;max-width:16rem;min-height:2rem;max-height:calc(100vh - 48px);box-shadow:0 1px 4px 0 rgba(16, 29, 48, 0.2);border-radius:0.25rem;z-index:100}";
3052
+ const catMenuCss = ":host{display:contents}:host([hidden]){display:none}::slotted(nav){padding-top:0.5rem;padding-bottom:0.5rem;min-width:8rem;max-width:16rem}.content{position:absolute;background:white;display:none;overflow:auto;-webkit-overflow-scrolling:touch;min-height:2rem;max-height:calc(100vh - 48px);box-shadow:0 1px 4px 0 rgba(16, 29, 48, 0.2);border-radius:0.25rem;z-index:100}";
3053
3053
 
3054
3054
  let nextUniqueId$6 = 0;
3055
3055
  const CatMenu = class {
@@ -3064,13 +3064,19 @@ const CatMenu = class {
3064
3064
  this.placement = 'bottom-start';
3065
3065
  }
3066
3066
  clickHandler(event) {
3067
- var _a;
3068
3067
  // hide menu on button click
3069
3068
  if (this.content && event.composedPath().includes(this.content)) {
3070
- (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
3071
- this.hide();
3069
+ this.close();
3072
3070
  }
3073
3071
  }
3072
+ /**
3073
+ * Closes the menu.
3074
+ */
3075
+ async close() {
3076
+ var _a;
3077
+ (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
3078
+ this.hide();
3079
+ }
3074
3080
  componentDidLoad() {
3075
3081
  var _a, _b, _c, _d, _e;
3076
3082
  this.trigger = firstTabbable(this.triggerSlot);