ng-primitives 0.90.0 → 0.91.0

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.
Files changed (93) hide show
  1. package/a11y/index.d.ts +38 -46
  2. package/accordion/index.d.ts +252 -104
  3. package/ai/index.d.ts +1 -1
  4. package/autofill/index.d.ts +49 -9
  5. package/avatar/index.d.ts +96 -61
  6. package/breadcrumbs/index.d.ts +156 -16
  7. package/button/index.d.ts +23 -28
  8. package/checkbox/index.d.ts +93 -14
  9. package/combobox/index.d.ts +1 -1
  10. package/date-picker/index.d.ts +12 -11
  11. package/fesm2022/ng-primitives-a11y.mjs +36 -52
  12. package/fesm2022/ng-primitives-a11y.mjs.map +1 -1
  13. package/fesm2022/ng-primitives-accordion.mjs +210 -189
  14. package/fesm2022/ng-primitives-accordion.mjs.map +1 -1
  15. package/fesm2022/ng-primitives-ai.mjs +4 -4
  16. package/fesm2022/ng-primitives-ai.mjs.map +1 -1
  17. package/fesm2022/ng-primitives-autofill.mjs +53 -36
  18. package/fesm2022/ng-primitives-autofill.mjs.map +1 -1
  19. package/fesm2022/ng-primitives-avatar.mjs +97 -138
  20. package/fesm2022/ng-primitives-avatar.mjs.map +1 -1
  21. package/fesm2022/ng-primitives-breadcrumbs.mjs +92 -35
  22. package/fesm2022/ng-primitives-breadcrumbs.mjs.map +1 -1
  23. package/fesm2022/ng-primitives-button.mjs +14 -36
  24. package/fesm2022/ng-primitives-button.mjs.map +1 -1
  25. package/fesm2022/ng-primitives-checkbox.mjs +87 -65
  26. package/fesm2022/ng-primitives-checkbox.mjs.map +1 -1
  27. package/fesm2022/ng-primitives-combobox.mjs +9 -9
  28. package/fesm2022/ng-primitives-combobox.mjs.map +1 -1
  29. package/fesm2022/ng-primitives-date-picker.mjs +5 -4
  30. package/fesm2022/ng-primitives-date-picker.mjs.map +1 -1
  31. package/fesm2022/ng-primitives-form-field.mjs +48 -16
  32. package/fesm2022/ng-primitives-form-field.mjs.map +1 -1
  33. package/fesm2022/ng-primitives-input.mjs +32 -48
  34. package/fesm2022/ng-primitives-input.mjs.map +1 -1
  35. package/fesm2022/ng-primitives-interactions.mjs +4 -4
  36. package/fesm2022/ng-primitives-interactions.mjs.map +1 -1
  37. package/fesm2022/ng-primitives-listbox.mjs.map +1 -1
  38. package/fesm2022/ng-primitives-menu.mjs +13 -6
  39. package/fesm2022/ng-primitives-menu.mjs.map +1 -1
  40. package/fesm2022/ng-primitives-pagination.mjs +6 -6
  41. package/fesm2022/ng-primitives-pagination.mjs.map +1 -1
  42. package/fesm2022/ng-primitives-progress.mjs +2 -2
  43. package/fesm2022/ng-primitives-progress.mjs.map +1 -1
  44. package/fesm2022/ng-primitives-radio.mjs +3 -3
  45. package/fesm2022/ng-primitives-radio.mjs.map +1 -1
  46. package/fesm2022/ng-primitives-roving-focus.mjs +259 -236
  47. package/fesm2022/ng-primitives-roving-focus.mjs.map +1 -1
  48. package/fesm2022/ng-primitives-search.mjs.map +1 -1
  49. package/fesm2022/ng-primitives-select.mjs +8 -8
  50. package/fesm2022/ng-primitives-select.mjs.map +1 -1
  51. package/fesm2022/ng-primitives-slider.mjs +195 -172
  52. package/fesm2022/ng-primitives-slider.mjs.map +1 -1
  53. package/fesm2022/ng-primitives-state.mjs +172 -2
  54. package/fesm2022/ng-primitives-state.mjs.map +1 -1
  55. package/fesm2022/ng-primitives-switch.mjs +90 -88
  56. package/fesm2022/ng-primitives-switch.mjs.map +1 -1
  57. package/fesm2022/ng-primitives-tabs.mjs +4 -1
  58. package/fesm2022/ng-primitives-tabs.mjs.map +1 -1
  59. package/fesm2022/ng-primitives-textarea.mjs +27 -35
  60. package/fesm2022/ng-primitives-textarea.mjs.map +1 -1
  61. package/fesm2022/ng-primitives-toggle-group.mjs +134 -136
  62. package/fesm2022/ng-primitives-toggle-group.mjs.map +1 -1
  63. package/fesm2022/ng-primitives-toggle.mjs +69 -58
  64. package/fesm2022/ng-primitives-toggle.mjs.map +1 -1
  65. package/fesm2022/ng-primitives-toolbar.mjs +26 -35
  66. package/fesm2022/ng-primitives-toolbar.mjs.map +1 -1
  67. package/fesm2022/ng-primitives-utils.mjs +48 -35
  68. package/fesm2022/ng-primitives-utils.mjs.map +1 -1
  69. package/form-field/index.d.ts +7 -3
  70. package/input/index.d.ts +61 -24
  71. package/interactions/index.d.ts +5 -5
  72. package/listbox/index.d.ts +1 -1
  73. package/menu/index.d.ts +3 -2
  74. package/package.json +1 -1
  75. package/pagination/index.d.ts +7 -7
  76. package/roving-focus/index.d.ts +77 -101
  77. package/schematics/ng-add/schema.d.ts +0 -1
  78. package/schematics/ng-generate/templates/checkbox/checkbox.__fileSuffix@dasherize__.ts.template +2 -2
  79. package/schematics/ng-generate/templates/slider/slider.__fileSuffix@dasherize__.ts.template +6 -3
  80. package/schematics/ng-generate/templates/switch/switch.__fileSuffix@dasherize__.ts.template +2 -2
  81. package/schematics/ng-generate/templates/toggle/toggle.__fileSuffix@dasherize__.ts.template +2 -2
  82. package/schematics/ng-generate/templates/toggle-group/toggle-group.__fileSuffix@dasherize__.ts.template +2 -2
  83. package/schematics/ng-generate/templates/toolbar/toolbar.__fileSuffix@dasherize__.ts.template +1 -1
  84. package/search/index.d.ts +1 -1
  85. package/select/index.d.ts +2 -2
  86. package/slider/index.d.ts +195 -56
  87. package/state/index.d.ts +57 -3
  88. package/switch/index.d.ts +103 -28
  89. package/textarea/index.d.ts +63 -8
  90. package/toggle/index.d.ts +65 -24
  91. package/toggle-group/index.d.ts +79 -54
  92. package/toolbar/index.d.ts +27 -17
  93. package/utils/index.d.ts +1 -0
@@ -1,123 +1,185 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, computed, afterRenderEffect, Directive, booleanAttribute, signal, inject, HOST_TAG_NAME, HostListener, InjectionToken, output } from '@angular/core';
2
+ import { signal, computed, afterRenderEffect, input, Directive, booleanAttribute, inject, HOST_TAG_NAME, InjectionToken, output } from '@angular/core';
3
+ import { safeTakeUntilDestroyed, uniqueId } from 'ng-primitives/utils';
3
4
  import { injectElementRef, injectDimensions, fromMutationObserver } from 'ng-primitives/internal';
4
- import { uniqueId, safeTakeUntilDestroyed } from 'ng-primitives/utils';
5
+ import { createPrimitive, controlled, attrBinding, deprecatedSetter, dataBinding, listener } from 'ng-primitives/state';
5
6
  import { debounceTime } from 'rxjs/operators';
6
- import { createStateToken, createStateProvider, createStateInjector, createState } from 'ng-primitives/state';
7
7
 
8
- /**
9
- * The state token for the AccordionItem primitive.
10
- */
11
- const NgpAccordionItemStateToken = createStateToken('AccordionItem');
12
- /**
13
- * Provides the AccordionItem state.
14
- */
15
- const provideAccordionItemState = createStateProvider(NgpAccordionItemStateToken);
16
- /**
17
- * Injects the AccordionItem state.
18
- */
19
- const injectAccordionItemState = createStateInjector(NgpAccordionItemStateToken);
20
- /**
21
- * The AccordionItem state registration function.
22
- */
23
- const accordionItemState = createState(NgpAccordionItemStateToken);
24
-
25
- /**
26
- * The state token for the Accordion primitive.
27
- */
28
- const NgpAccordionStateToken = createStateToken('Accordion');
29
- /**
30
- * Provides the Accordion state.
31
- */
32
- const provideAccordionState = createStateProvider(NgpAccordionStateToken);
33
- /**
34
- * Injects the Accordion state.
35
- */
36
- const injectAccordionState = createStateInjector(NgpAccordionStateToken);
37
- /**
38
- * The Accordion state registration function.
39
- */
40
- const accordionState = createState(NgpAccordionStateToken);
8
+ const [NgpAccordionStateToken, ngpAccordion, _injectAccordionState, provideAccordionState] = createPrimitive('NgpAccordion', ({ type, collapsible, value: _value = signal(null), disabled: _disabled = signal(false), orientation: _orientation = signal('vertical'), onValueChange, }) => {
9
+ const element = injectElementRef();
10
+ // Create controlled signals
11
+ const value = controlled(_value);
12
+ const disabled = controlled(_disabled);
13
+ const orientation = controlled(_orientation);
14
+ // Host bindings extracted from directive
15
+ attrBinding(element, 'data-orientation', orientation);
16
+ attrBinding(element, 'data-disabled', disabled);
17
+ // Setter methods
18
+ function setDisabled(value) {
19
+ disabled.set(value);
20
+ }
21
+ function setOrientation(value) {
22
+ orientation.set(value);
23
+ }
24
+ function setValue(newValue) {
25
+ value.set(newValue);
26
+ }
27
+ // Methods extracted from directive
28
+ /**
29
+ * @param value The value to check. @returns Whether the value is open. @internal
30
+ */
31
+ function isOpen(itemValue) {
32
+ if (type() === 'multiple') {
33
+ return value()?.includes(itemValue) ?? false;
34
+ }
35
+ return value() === itemValue;
36
+ }
37
+ function toggle(itemValue) {
38
+ const open = isOpen(itemValue);
39
+ // if we are in single mode and the itemValue is already open and the accordion is not collapsible, do nothing
40
+ if (type() === 'single' && open && !collapsible()) {
41
+ return;
42
+ }
43
+ // if we are in single mode then toggle the itemValue
44
+ if (type() === 'single') {
45
+ const newValue = open ? null : itemValue;
46
+ value.set(newValue);
47
+ onValueChange?.(newValue);
48
+ return;
49
+ }
50
+ // if we are in multiple mode then toggle the itemValue
51
+ let values = value() ?? [];
52
+ if (open) {
53
+ values = values.filter(v => v !== itemValue);
54
+ }
55
+ else {
56
+ values = [...values, itemValue];
57
+ }
58
+ value.set(values);
59
+ onValueChange?.(values);
60
+ }
61
+ return {
62
+ value: deprecatedSetter(value, 'setValue'),
63
+ disabled: deprecatedSetter(disabled, 'setDisabled'),
64
+ orientation: deprecatedSetter(orientation, 'setOrientation'),
65
+ setDisabled,
66
+ setOrientation,
67
+ setValue,
68
+ isOpen,
69
+ toggle,
70
+ };
71
+ });
72
+ function injectAccordionState() {
73
+ return _injectAccordionState();
74
+ }
41
75
 
42
- /**
43
- * Apply the `ngpAccordionContent` directive to an element that represents the content of an accordion item.
44
- */
45
- class NgpAccordionContent {
46
- constructor() {
47
- /**
48
- * Access the accordion content element reference
49
- */
50
- this.elementRef = injectElementRef();
51
- /**
52
- * Access the accordion
53
- */
54
- this.accordion = injectAccordionState();
55
- /**
56
- * Access the accordion item
57
- */
58
- this.accordionItem = injectAccordionItemState();
59
- /**
60
- * The id of the content region
61
- */
62
- this.id = input(uniqueId('ngp-accordion-content'), ...(ngDevMode ? [{ debugName: "id" }] : []));
63
- /**
64
- * The dimensions of the content
65
- */
66
- this.dimensions = injectDimensions();
67
- /**
68
- * The hidden until-found state of the content
69
- */
70
- this.hidden = computed(() => !this.accordionItem().open() && this.dimensions().height === 0 ? 'until-found' : null, ...(ngDevMode ? [{ debugName: "hidden" }] : []));
71
- this.accordionItem().content.set(this);
72
- // any time the open state of the accordion item changes, update the dimensions
73
- afterRenderEffect(() => this.updateDimensions());
74
- // update dimensions when the content changes
75
- fromMutationObserver(this.elementRef.nativeElement, {
76
- childList: true,
77
- subtree: true,
78
- disabled: computed(() => !this.accordionItem().open()),
79
- })
80
- .pipe(debounceTime(0), safeTakeUntilDestroyed())
81
- .subscribe(() => this.updateDimensions());
76
+ const [NgpAccordionItemStateToken, ngpAccordionItem, _injectAccordionItemState, provideAccordionItemState,] = createPrimitive('NgpAccordionItem', ({ value, disabled: _disabled = signal(false) }) => {
77
+ const accordion = injectAccordionState();
78
+ const element = injectElementRef();
79
+ const disabled = controlled(_disabled);
80
+ // Whether the accordion item is expanded.
81
+ const open = computed(() => accordion().isOpen(value()), ...(ngDevMode ? [{ debugName: "open" }] : []));
82
+ const trigger = signal(undefined, ...(ngDevMode ? [{ debugName: "trigger" }] : []));
83
+ const content = signal(undefined, ...(ngDevMode ? [{ debugName: "content" }] : []));
84
+ // Setup host data bindings
85
+ dataBinding(element, 'data-orientation', accordion().orientation);
86
+ dataBinding(element, 'data-open', open);
87
+ dataBinding(element, 'data-disabled', () => disabled() || accordion().disabled());
88
+ // Set the disabled state of the accordion item.
89
+ function setDisabled(value) {
90
+ disabled.set(value);
91
+ }
92
+ function setTrigger(id) {
93
+ trigger.set(id);
94
+ }
95
+ function setContent(id) {
96
+ content.set(id);
82
97
  }
98
+ return {
99
+ value,
100
+ open,
101
+ disabled: deprecatedSetter(disabled, 'setDisabled'),
102
+ triggerId: deprecatedSetter(trigger, 'setTrigger'),
103
+ contentId: deprecatedSetter(content, 'setContent'),
104
+ setDisabled,
105
+ setTrigger,
106
+ setContent,
107
+ };
108
+ });
109
+ function injectAccordionItemState() {
110
+ return _injectAccordionItemState();
111
+ }
112
+
113
+ const [NgpAccordionContentStateToken, ngpAccordionContent, injectAccordionContentState, provideAccordionContentState,] = createPrimitive('NgpAccordionContent', ({ id = signal(uniqueId('ngp-accordion-content')) }) => {
114
+ const element = injectElementRef();
115
+ const accordion = injectAccordionState();
116
+ const accordionItem = injectAccordionItemState();
117
+ const dimensions = injectDimensions();
118
+ const hidden = computed(() => !accordionItem().open() && dimensions().height === 0 ? 'until-found' : null, ...(ngDevMode ? [{ debugName: "hidden" }] : []));
119
+ // Host bindings
120
+ attrBinding(element, 'role', 'region');
121
+ attrBinding(element, 'id', id);
122
+ attrBinding(element, 'aria-labelledby', accordionItem().triggerId);
123
+ attrBinding(element, 'hidden', hidden);
124
+ dataBinding(element, 'data-orientation', accordion().orientation);
125
+ dataBinding(element, 'data-open', accordionItem().open);
126
+ dataBinding(element, 'data-closed', () => !accordionItem().open());
127
+ listener(element, 'beforematch', onBeforeMatch);
128
+ // Register the content with the accordion item state
129
+ accordionItem().setContent(id());
83
130
  /**
84
131
  * Handle the beforematch event to automatically open the accordion item
85
132
  * when the browser's find-in-page functionality tries to reveal hidden content.
86
133
  */
87
- onBeforeMatch() {
88
- const isDisabled = this.accordion().disabled() || this.accordionItem().disabled();
89
- if (isDisabled)
134
+ function onBeforeMatch() {
135
+ const isDisabled = accordion().disabled() || accordionItem().disabled();
136
+ if (isDisabled) {
90
137
  return;
91
- this.accordion().toggle(this.accordionItem().value());
138
+ }
139
+ accordion().toggle(accordionItem().value());
92
140
  }
93
- updateDimensions() {
94
- if (this.accordionItem().open()) {
141
+ function updateDimensions() {
142
+ if (accordionItem().open()) {
95
143
  // remove the inline styles to reset them
96
- this.elementRef.nativeElement.style.removeProperty('--ngp-accordion-content-width');
97
- this.elementRef.nativeElement.style.removeProperty('--ngp-accordion-content-height');
144
+ element.nativeElement.style.removeProperty('--ngp-accordion-content-width');
145
+ element.nativeElement.style.removeProperty('--ngp-accordion-content-height');
98
146
  // set the dimensions based on the content
99
- this.elementRef.nativeElement.style.setProperty('--ngp-accordion-content-width', `${this.elementRef.nativeElement.scrollWidth}px`);
100
- this.elementRef.nativeElement.style.setProperty('--ngp-accordion-content-height', `${this.elementRef.nativeElement.scrollHeight}px`);
147
+ element.nativeElement.style.setProperty('--ngp-accordion-content-width', `${element.nativeElement.scrollWidth}px`);
148
+ element.nativeElement.style.setProperty('--ngp-accordion-content-height', `${element.nativeElement.scrollHeight}px`);
101
149
  }
102
150
  }
151
+ // any time the open state of the accordion item changes, update the dimensions
152
+ afterRenderEffect(() => updateDimensions());
153
+ // update dimensions when the content changes
154
+ fromMutationObserver(element.nativeElement, {
155
+ childList: true,
156
+ subtree: true,
157
+ disabled: computed(() => !accordionItem().open()),
158
+ })
159
+ .pipe(debounceTime(0), safeTakeUntilDestroyed())
160
+ .subscribe(() => updateDimensions());
161
+ return {};
162
+ });
163
+
164
+ /**
165
+ * Apply the `ngpAccordionContent` directive to an element that represents the content of an accordion item.
166
+ */
167
+ class NgpAccordionContent {
168
+ constructor() {
169
+ /**
170
+ * The id of the content region
171
+ */
172
+ this.id = input(uniqueId('ngp-accordion-content'), ...(ngDevMode ? [{ debugName: "id" }] : []));
173
+ ngpAccordionContent({ id: this.id });
174
+ }
103
175
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordionContent, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
104
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordionContent, isStandalone: true, selector: "[ngpAccordionContent]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "region" }, listeners: { "beforematch": "onBeforeMatch()" }, properties: { "id": "id()", "attr.data-orientation": "accordion().orientation()", "attr.data-open": "accordionItem().open() ? \"\" : null", "attr.data-closed": "accordionItem().open() ? null : \"\"", "attr.aria-labelledby": "accordionItem().triggerId()", "attr.hidden": "hidden()" } }, exportAs: ["ngpAccordionContent"], ngImport: i0 }); }
176
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordionContent, isStandalone: true, selector: "[ngpAccordionContent]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["ngpAccordionContent"], ngImport: i0 }); }
105
177
  }
106
178
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordionContent, decorators: [{
107
179
  type: Directive,
108
180
  args: [{
109
181
  selector: '[ngpAccordionContent]',
110
182
  exportAs: 'ngpAccordionContent',
111
- host: {
112
- role: 'region',
113
- '[id]': 'id()',
114
- '[attr.data-orientation]': 'accordion().orientation()',
115
- '[attr.data-open]': 'accordionItem().open() ? "" : null',
116
- '[attr.data-closed]': 'accordionItem().open() ? null : ""',
117
- '[attr.aria-labelledby]': 'accordionItem().triggerId()',
118
- '(beforematch)': 'onBeforeMatch()',
119
- '[attr.hidden]': 'hidden()',
120
- },
121
183
  }]
122
184
  }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }] } });
123
185
 
@@ -145,34 +207,19 @@ class NgpAccordionItem {
145
207
  transform: booleanAttribute,
146
208
  }]));
147
209
  /**
148
- * Access the accordion trigger
149
- * @internal
150
- */
151
- this.trigger = signal(undefined, ...(ngDevMode ? [{ debugName: "trigger" }] : []));
152
- /**
153
- * Access the accordion content
154
- * @internal
155
- */
156
- this.content = signal(undefined, ...(ngDevMode ? [{ debugName: "content" }] : []));
157
- /**
158
- * Whether the accordion item is expanded.
159
- */
160
- this.open = computed(() => this.accordion().isOpen(this.state.value()), ...(ngDevMode ? [{ debugName: "open" }] : []));
161
- /**
162
- * The trigger id.
163
- */
164
- this.triggerId = computed(() => this.trigger()?.id(), ...(ngDevMode ? [{ debugName: "triggerId" }] : []));
165
- /**
166
- * The content id.
210
+ * The accordion item state.
167
211
  */
168
- this.contentId = computed(() => this.content()?.id(), ...(ngDevMode ? [{ debugName: "contentId" }] : []));
212
+ this.state = ngpAccordionItem({
213
+ value: this.value,
214
+ disabled: this.disabled,
215
+ });
169
216
  /**
170
- * The accordion item state.
217
+ * The open state of the accordion item.
171
218
  */
172
- this.state = accordionItemState(this);
219
+ this.open = this.state.open;
173
220
  }
174
221
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordionItem, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
175
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordionItem, isStandalone: true, selector: "[ngpAccordionItem]", inputs: { value: { classPropertyName: "value", publicName: "ngpAccordionItemValue", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpAccordionItemDisabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-orientation": "accordion().orientation()", "attr.data-open": "state.open() ? \"\" : null", "attr.data-disabled": "state.disabled() || accordion().disabled() ? \"\" : null" } }, providers: [provideAccordionItemState()], exportAs: ["ngpAccordionItem"], ngImport: i0 }); }
222
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordionItem, isStandalone: true, selector: "[ngpAccordionItem]", inputs: { value: { classPropertyName: "value", publicName: "ngpAccordionItemValue", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpAccordionItemDisabled", isSignal: true, isRequired: false, transformFunction: null } }, providers: [provideAccordionItemState()], exportAs: ["ngpAccordionItem"], ngImport: i0 }); }
176
223
  }
177
224
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordionItem, decorators: [{
178
225
  type: Directive,
@@ -180,68 +227,63 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
180
227
  selector: '[ngpAccordionItem]',
181
228
  exportAs: 'ngpAccordionItem',
182
229
  providers: [provideAccordionItemState()],
183
- host: {
184
- '[attr.data-orientation]': 'accordion().orientation()',
185
- '[attr.data-open]': 'state.open() ? "" : null',
186
- '[attr.data-disabled]': 'state.disabled() || accordion().disabled() ? "" : null',
187
- },
188
230
  }]
189
231
  }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionItemValue", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionItemDisabled", required: false }] }] } });
190
232
 
233
+ const [NgpAccordionTriggerStateToken, ngpAccordionTrigger, injectAccordionTriggerState, provideAccordionTriggerState,] = createPrimitive('NgpAccordionTrigger', ({ id = signal(uniqueId('ngp-accordion-trigger')) }) => {
234
+ const element = injectElementRef();
235
+ const tagName = inject(HOST_TAG_NAME);
236
+ const accordion = injectAccordionState();
237
+ const accordionItem = injectAccordionItemState();
238
+ // Host bindings
239
+ attrBinding(element, 'id', id);
240
+ attrBinding(element, 'type', tagName === 'button' ? 'button' : null);
241
+ attrBinding(element, 'aria-controls', accordionItem().contentId);
242
+ attrBinding(element, 'aria-expanded', accordionItem().open);
243
+ dataBinding(element, 'data-orientation', accordion().orientation);
244
+ dataBinding(element, 'data-open', accordionItem().open);
245
+ dataBinding(element, 'data-disabled', () => accordionItem().disabled() || accordion().disabled());
246
+ // register the trigger with the accordion item
247
+ accordionItem().setTrigger(id());
248
+ // Methods
249
+ function toggle() {
250
+ if (accordionItem().disabled() || accordion().disabled()) {
251
+ return;
252
+ }
253
+ accordion().toggle(accordionItem().value());
254
+ }
255
+ // Event listeners
256
+ listener(element, 'click', toggle);
257
+ return { id, toggle };
258
+ });
259
+
191
260
  /**
192
261
  * Apply the `ngpAccordionTrigger` directive to an element that represents the trigger for an accordion item, such as a button.
193
262
  */
194
263
  class NgpAccordionTrigger {
195
264
  constructor() {
196
- /**
197
- * The tag name of the element.
198
- */
199
- this.tagName = inject(HOST_TAG_NAME);
200
- /**
201
- * Access the parent accordion.
202
- */
203
- this.accordion = injectAccordionState();
204
- /**
205
- * The item instance.
206
- */
207
- this.accordionItem = injectAccordionItemState();
208
265
  /**
209
266
  * The id of the trigger.
210
267
  */
211
268
  this.id = input(uniqueId('ngp-accordion-trigger'), ...(ngDevMode ? [{ debugName: "id" }] : []));
212
- this.accordionItem().trigger.set(this);
269
+ this.state = ngpAccordionTrigger({ id: this.id });
213
270
  }
214
271
  /**
215
272
  * Toggle the accordion item.
216
273
  */
217
274
  toggle() {
218
- if (this.accordionItem().disabled() || this.accordion().disabled()) {
219
- return;
220
- }
221
- this.accordion().toggle(this.accordionItem().value());
275
+ this.state.toggle();
222
276
  }
223
277
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordionTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
224
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordionTrigger, isStandalone: true, selector: "[ngpAccordionTrigger]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "toggle()" }, properties: { "id": "id()", "attr.type": "tagName === \"button\" ? \"button\" : null", "attr.data-orientation": "accordion().orientation()", "attr.data-open": "accordionItem().open() ? \"\" : null", "attr.data-disabled": "accordionItem().disabled() || accordion().disabled() ? \"\" : null", "attr.aria-controls": "accordionItem().contentId()", "attr.aria-expanded": "accordionItem().open()" } }, exportAs: ["ngpAccordionTrigger"], ngImport: i0 }); }
278
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordionTrigger, isStandalone: true, selector: "[ngpAccordionTrigger]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["ngpAccordionTrigger"], ngImport: i0 }); }
225
279
  }
226
280
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordionTrigger, decorators: [{
227
281
  type: Directive,
228
282
  args: [{
229
283
  selector: '[ngpAccordionTrigger]',
230
284
  exportAs: 'ngpAccordionTrigger',
231
- host: {
232
- '[id]': 'id()',
233
- '[attr.type]': 'tagName === "button" ? "button" : null',
234
- '[attr.data-orientation]': 'accordion().orientation()',
235
- '[attr.data-open]': 'accordionItem().open() ? "" : null',
236
- '[attr.data-disabled]': 'accordionItem().disabled() || accordion().disabled() ? "" : null',
237
- '[attr.aria-controls]': 'accordionItem().contentId()',
238
- '[attr.aria-expanded]': 'accordionItem().open()',
239
- },
240
285
  }]
241
- }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], toggle: [{
242
- type: HostListener,
243
- args: ['click']
244
- }] } });
286
+ }], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }] } });
245
287
 
246
288
  const defaultAccordionConfig = {
247
289
  type: 'single',
@@ -322,7 +364,14 @@ class NgpAccordion {
322
364
  /**
323
365
  * The accordion state.
324
366
  */
325
- this.state = accordionState(this);
367
+ this.state = ngpAccordion({
368
+ type: this.type,
369
+ collapsible: this.collapsible,
370
+ value: this.value,
371
+ disabled: this.disabled,
372
+ orientation: this.orientation,
373
+ onValueChange: value => this.valueChange.emit(value),
374
+ });
326
375
  }
327
376
  /**
328
377
  * @param value The value to check.
@@ -330,37 +379,13 @@ class NgpAccordion {
330
379
  * @internal
331
380
  */
332
381
  isOpen(value) {
333
- if (this.state.type() === 'multiple') {
334
- return this.state.value()?.includes(value) ?? false;
335
- }
336
- return this.state.value() === value;
382
+ return this.state.isOpen(value);
337
383
  }
338
384
  toggle(value) {
339
- const isOpen = this.isOpen(value);
340
- // if we are in single mode and the value is already open and the accordion is not collapsible, do nothing
341
- if (this.state.type() === 'single' && isOpen && !this.state.collapsible()) {
342
- return;
343
- }
344
- // if we are in single mode then toggle the value
345
- if (this.state.type() === 'single') {
346
- const newValue = isOpen ? null : value;
347
- this.state.value.set(newValue);
348
- this.valueChange.emit(newValue);
349
- return;
350
- }
351
- // if we are in multiple mode then toggle the value
352
- let values = this.state.value() ?? [];
353
- if (isOpen) {
354
- values = values.filter(v => v !== value);
355
- }
356
- else {
357
- values = [...values, value];
358
- }
359
- this.state.value.set(values);
360
- this.valueChange.emit(values);
385
+ this.state.toggle(value);
361
386
  }
362
387
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordion, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
363
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordion, isStandalone: true, selector: "[ngpAccordion]", inputs: { type: { classPropertyName: "type", publicName: "ngpAccordionType", isSignal: true, isRequired: false, transformFunction: null }, collapsible: { classPropertyName: "collapsible", publicName: "ngpAccordionCollapsible", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "ngpAccordionValue", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpAccordionDisabled", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "ngpAccordionOrientation", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "ngpAccordionValueChange" }, host: { properties: { "attr.data-orientation": "state.orientation()", "attr.data-disabled": "state.disabled() ? \"\" : null" } }, providers: [provideAccordionState()], exportAs: ["ngpAccordion"], ngImport: i0 }); }
388
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.3.9", type: NgpAccordion, isStandalone: true, selector: "[ngpAccordion]", inputs: { type: { classPropertyName: "type", publicName: "ngpAccordionType", isSignal: true, isRequired: false, transformFunction: null }, collapsible: { classPropertyName: "collapsible", publicName: "ngpAccordionCollapsible", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "ngpAccordionValue", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngpAccordionDisabled", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "ngpAccordionOrientation", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "ngpAccordionValueChange" }, providers: [provideAccordionState()], exportAs: ["ngpAccordion"], ngImport: i0 }); }
364
389
  }
365
390
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: NgpAccordion, decorators: [{
366
391
  type: Directive,
@@ -368,10 +393,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
368
393
  selector: '[ngpAccordion]',
369
394
  exportAs: 'ngpAccordion',
370
395
  providers: [provideAccordionState()],
371
- host: {
372
- '[attr.data-orientation]': 'state.orientation()',
373
- '[attr.data-disabled]': 'state.disabled() ? "" : null',
374
- },
375
396
  }]
376
397
  }], propDecorators: { type: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionType", required: false }] }], collapsible: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionCollapsible", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionValue", required: false }] }], valueChange: [{ type: i0.Output, args: ["ngpAccordionValueChange"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionDisabled", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngpAccordionOrientation", required: false }] }] } });
377
398
 
@@ -379,5 +400,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
379
400
  * Generated bundle index. Do not edit.
380
401
  */
381
402
 
382
- export { NgpAccordion, NgpAccordionContent, NgpAccordionItem, NgpAccordionTrigger, injectAccordionItemState, injectAccordionState, provideAccordionConfig, provideAccordionItemState, provideAccordionState };
403
+ export { NgpAccordion, NgpAccordionContent, NgpAccordionContentStateToken, NgpAccordionItem, NgpAccordionItemStateToken, NgpAccordionStateToken, NgpAccordionTrigger, NgpAccordionTriggerStateToken, injectAccordionContentState, injectAccordionItemState, injectAccordionState, injectAccordionTriggerState, ngpAccordion, ngpAccordionContent, ngpAccordionItem, ngpAccordionTrigger, provideAccordionConfig, provideAccordionContentState, provideAccordionItemState, provideAccordionState, provideAccordionTriggerState };
383
404
  //# sourceMappingURL=ng-primitives-accordion.mjs.map