@neuravision/ng-construct 0.3.2 → 0.3.3

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.
@@ -2521,15 +2521,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
2521
2521
  */
2522
2522
  class AfDropdownComponent {
2523
2523
  static nextId = 0;
2524
+ hostRef = inject(ElementRef);
2524
2525
  /** Dropdown button label. */
2525
2526
  label = input('Actions', ...(ngDevMode ? [{ debugName: "label" }] : []));
2527
+ /** Trigger button size. */
2528
+ size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : []));
2526
2529
  /** Menu items. */
2527
2530
  items = input([], ...(ngDevMode ? [{ debugName: "items" }] : []));
2528
2531
  /** Emits the selected item's value. */
2529
2532
  itemSelected = output();
2533
+ /** Computed CSS classes for the trigger button. */
2534
+ triggerClasses = computed(() => {
2535
+ const classes = ['ct-button', 'ct-button--secondary', 'ct-dropdown__trigger'];
2536
+ if (this.size() !== 'md') {
2537
+ classes.push(`ct-button--${this.size()}`);
2538
+ }
2539
+ return classes.join(' ');
2540
+ }, ...(ngDevMode ? [{ debugName: "triggerClasses" }] : []));
2530
2541
  triggerRef = viewChild('trigger', ...(ngDevMode ? [{ debugName: "triggerRef" }] : []));
2531
2542
  menuRef = viewChild('menu', ...(ngDevMode ? [{ debugName: "menuRef" }] : []));
2532
2543
  itemButtons = viewChildren('itemButton', ...(ngDevMode ? [{ debugName: "itemButtons" }] : []));
2544
+ /** Non-separator items that can receive focus and be selected. */
2545
+ actionableItems = computed(() => this.items().filter((item) => !item.separator), ...(ngDevMode ? [{ debugName: "actionableItems" }] : []));
2533
2546
  isOpen = signal(false, ...(ngDevMode ? [{ debugName: "isOpen" }] : []));
2534
2547
  focusedItemIndex = signal(0, ...(ngDevMode ? [{ debugName: "focusedItemIndex" }] : []));
2535
2548
  instanceId = AfDropdownComponent.nextId++;
@@ -2572,7 +2585,7 @@ class AfDropdownComponent {
2572
2585
  }
2573
2586
  /** Handles keyboard events within the open menu. */
2574
2587
  onMenuKeydown(event) {
2575
- const actionableItems = this.getActionableItems();
2588
+ const actionableItems = this.actionableItems();
2576
2589
  if (actionableItems.length === 0)
2577
2590
  return;
2578
2591
  switch (event.key) {
@@ -2623,8 +2636,7 @@ class AfDropdownComponent {
2623
2636
  }
2624
2637
  }
2625
2638
  onDocumentClick(event) {
2626
- const target = event.target;
2627
- if (!target.closest('.ct-dropdown')) {
2639
+ if (!this.hostRef.nativeElement.contains(event.target)) {
2628
2640
  this.close(false);
2629
2641
  }
2630
2642
  }
@@ -2633,11 +2645,11 @@ class AfDropdownComponent {
2633
2645
  * actionable (non-separator) items.
2634
2646
  */
2635
2647
  getActionableIndex(item) {
2636
- return this.getActionableItems().indexOf(item);
2648
+ return this.actionableItems().indexOf(item);
2637
2649
  }
2638
2650
  open(focusLast = false) {
2639
2651
  this.isOpen.set(true);
2640
- const actionableItems = this.getActionableItems();
2652
+ const actionableItems = this.actionableItems();
2641
2653
  const startIndex = focusLast
2642
2654
  ? this.nextEnabledIndex(actionableItems.length, -1)
2643
2655
  : this.nextEnabledIndex(-1, 1);
@@ -2663,7 +2675,7 @@ class AfDropdownComponent {
2663
2675
  buttons[idx]?.nativeElement.focus();
2664
2676
  }
2665
2677
  nextEnabledIndex(from, direction) {
2666
- const actionableItems = this.getActionableItems();
2678
+ const actionableItems = this.actionableItems();
2667
2679
  const len = actionableItems.length;
2668
2680
  if (len === 0)
2669
2681
  return 0;
@@ -2679,9 +2691,6 @@ class AfDropdownComponent {
2679
2691
  }
2680
2692
  return from;
2681
2693
  }
2682
- getActionableItems() {
2683
- return this.items().filter((item) => !item.separator);
2684
- }
2685
2694
  handleTypeAhead(char) {
2686
2695
  if (this.typeAheadTimer) {
2687
2696
  clearTimeout(this.typeAheadTimer);
@@ -2691,7 +2700,7 @@ class AfDropdownComponent {
2691
2700
  this.typeAheadBuffer = '';
2692
2701
  this.typeAheadTimer = null;
2693
2702
  }, 500);
2694
- const actionableItems = this.getActionableItems();
2703
+ const actionableItems = this.actionableItems();
2695
2704
  const startIndex = this.focusedItemIndex() + 1;
2696
2705
  for (let i = 0; i < actionableItems.length; i++) {
2697
2706
  const idx = (startIndex + i) % actionableItems.length;
@@ -2703,11 +2712,12 @@ class AfDropdownComponent {
2703
2712
  }
2704
2713
  }
2705
2714
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: AfDropdownComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2706
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.2", type: AfDropdownComponent, isStandalone: true, selector: "af-dropdown", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemSelected: "itemSelected" }, host: { listeners: { "document:click": "onDocumentClick($event)" } }, viewQueries: [{ propertyName: "triggerRef", first: true, predicate: ["trigger"], descendants: true, isSignal: true }, { propertyName: "menuRef", first: true, predicate: ["menu"], descendants: true, isSignal: true }, { propertyName: "itemButtons", predicate: ["itemButton"], descendants: true, isSignal: true }], ngImport: i0, template: `
2715
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.2", type: AfDropdownComponent, isStandalone: true, selector: "af-dropdown", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { itemSelected: "itemSelected" }, host: { listeners: { "document:click": "onDocumentClick($event)" } }, viewQueries: [{ propertyName: "triggerRef", first: true, predicate: ["trigger"], descendants: true, isSignal: true }, { propertyName: "menuRef", first: true, predicate: ["menu"], descendants: true, isSignal: true }, { propertyName: "itemButtons", predicate: ["itemButton"], descendants: true, isSignal: true }], ngImport: i0, template: `
2707
2716
  <div class="ct-dropdown" [attr.data-state]="isOpen() ? 'open' : 'closed'">
2708
2717
  <button
2709
2718
  #trigger
2710
- class="ct-button ct-button--secondary ct-dropdown__trigger"
2719
+ [id]="triggerId"
2720
+ [class]="triggerClasses()"
2711
2721
  [attr.aria-expanded]="isOpen()"
2712
2722
  [attr.aria-controls]="menuId"
2713
2723
  aria-haspopup="menu"
@@ -2754,7 +2764,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
2754
2764
  <div class="ct-dropdown" [attr.data-state]="isOpen() ? 'open' : 'closed'">
2755
2765
  <button
2756
2766
  #trigger
2757
- class="ct-button ct-button--secondary ct-dropdown__trigger"
2767
+ [id]="triggerId"
2768
+ [class]="triggerClasses()"
2758
2769
  [attr.aria-expanded]="isOpen()"
2759
2770
  [attr.aria-controls]="menuId"
2760
2771
  aria-haspopup="menu"
@@ -2792,7 +2803,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
2792
2803
  }
2793
2804
  </div>
2794
2805
  `, styles: [":host{display:inline-block}\n"] }]
2795
- }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], itemSelected: [{ type: i0.Output, args: ["itemSelected"] }], triggerRef: [{ type: i0.ViewChild, args: ['trigger', { isSignal: true }] }], menuRef: [{ type: i0.ViewChild, args: ['menu', { isSignal: true }] }], itemButtons: [{ type: i0.ViewChildren, args: ['itemButton', { isSignal: true }] }] } });
2806
+ }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], itemSelected: [{ type: i0.Output, args: ["itemSelected"] }], triggerRef: [{ type: i0.ViewChild, args: ['trigger', { isSignal: true }] }], menuRef: [{ type: i0.ViewChild, args: ['menu', { isSignal: true }] }], itemButtons: [{ type: i0.ViewChildren, args: ['itemButton', { isSignal: true }] }] } });
2796
2807
 
2797
2808
  /**
2798
2809
  * Pagination component