@radix-ng/primitives 0.51.0 → 1.0.0-beta.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 (178) hide show
  1. package/fesm2022/radix-ng-primitives-accordion.mjs +105 -38
  2. package/fesm2022/radix-ng-primitives-accordion.mjs.map +1 -1
  3. package/fesm2022/radix-ng-primitives-alert-dialog.mjs +221 -129
  4. package/fesm2022/radix-ng-primitives-alert-dialog.mjs.map +1 -1
  5. package/fesm2022/radix-ng-primitives-arrow.mjs +20 -4
  6. package/fesm2022/radix-ng-primitives-arrow.mjs.map +1 -1
  7. package/fesm2022/radix-ng-primitives-aspect-ratio.mjs.map +1 -1
  8. package/fesm2022/radix-ng-primitives-avatar.mjs +54 -61
  9. package/fesm2022/radix-ng-primitives-avatar.mjs.map +1 -1
  10. package/fesm2022/radix-ng-primitives-button.mjs +123 -0
  11. package/fesm2022/radix-ng-primitives-button.mjs.map +1 -0
  12. package/fesm2022/radix-ng-primitives-calendar.mjs.map +1 -1
  13. package/fesm2022/radix-ng-primitives-checkbox.mjs +378 -54
  14. package/fesm2022/radix-ng-primitives-checkbox.mjs.map +1 -1
  15. package/fesm2022/radix-ng-primitives-collapsible.mjs +182 -81
  16. package/fesm2022/radix-ng-primitives-collapsible.mjs.map +1 -1
  17. package/fesm2022/radix-ng-primitives-collection.mjs +40 -57
  18. package/fesm2022/radix-ng-primitives-collection.mjs.map +1 -1
  19. package/fesm2022/radix-ng-primitives-config.mjs.map +1 -1
  20. package/fesm2022/radix-ng-primitives-context-menu.mjs +140 -424
  21. package/fesm2022/radix-ng-primitives-context-menu.mjs.map +1 -1
  22. package/fesm2022/radix-ng-primitives-core.mjs +735 -744
  23. package/fesm2022/radix-ng-primitives-core.mjs.map +1 -1
  24. package/fesm2022/radix-ng-primitives-cropper.mjs +1 -0
  25. package/fesm2022/radix-ng-primitives-cropper.mjs.map +1 -1
  26. package/fesm2022/radix-ng-primitives-date-field.mjs +51 -45
  27. package/fesm2022/radix-ng-primitives-date-field.mjs.map +1 -1
  28. package/fesm2022/radix-ng-primitives-dialog.mjs +655 -327
  29. package/fesm2022/radix-ng-primitives-dialog.mjs.map +1 -1
  30. package/fesm2022/radix-ng-primitives-dismissable-layer.mjs +70 -46
  31. package/fesm2022/radix-ng-primitives-dismissable-layer.mjs.map +1 -1
  32. package/fesm2022/radix-ng-primitives-drawer.mjs +1059 -0
  33. package/fesm2022/radix-ng-primitives-drawer.mjs.map +1 -0
  34. package/fesm2022/radix-ng-primitives-editable.mjs.map +1 -1
  35. package/fesm2022/radix-ng-primitives-field.mjs +363 -0
  36. package/fesm2022/radix-ng-primitives-field.mjs.map +1 -0
  37. package/fesm2022/radix-ng-primitives-fieldset.mjs +79 -0
  38. package/fesm2022/radix-ng-primitives-fieldset.mjs.map +1 -0
  39. package/fesm2022/radix-ng-primitives-focus-scope.mjs +23 -8
  40. package/fesm2022/radix-ng-primitives-focus-scope.mjs.map +1 -1
  41. package/fesm2022/radix-ng-primitives-input.mjs +172 -0
  42. package/fesm2022/radix-ng-primitives-input.mjs.map +1 -0
  43. package/fesm2022/radix-ng-primitives-label.mjs +6 -6
  44. package/fesm2022/radix-ng-primitives-label.mjs.map +1 -1
  45. package/fesm2022/radix-ng-primitives-menu.mjs +1480 -344
  46. package/fesm2022/radix-ng-primitives-menu.mjs.map +1 -1
  47. package/fesm2022/radix-ng-primitives-menubar.mjs +290 -162
  48. package/fesm2022/radix-ng-primitives-menubar.mjs.map +1 -1
  49. package/fesm2022/radix-ng-primitives-meter.mjs +271 -0
  50. package/fesm2022/radix-ng-primitives-meter.mjs.map +1 -0
  51. package/fesm2022/radix-ng-primitives-navigation-menu.mjs +1052 -1553
  52. package/fesm2022/radix-ng-primitives-navigation-menu.mjs.map +1 -1
  53. package/fesm2022/radix-ng-primitives-number-field.mjs +1102 -367
  54. package/fesm2022/radix-ng-primitives-number-field.mjs.map +1 -1
  55. package/fesm2022/radix-ng-primitives-pagination.mjs.map +1 -1
  56. package/fesm2022/radix-ng-primitives-popover.mjs +978 -989
  57. package/fesm2022/radix-ng-primitives-popover.mjs.map +1 -1
  58. package/fesm2022/radix-ng-primitives-popper.mjs +91 -41
  59. package/fesm2022/radix-ng-primitives-popper.mjs.map +1 -1
  60. package/fesm2022/radix-ng-primitives-portal.mjs +34 -10
  61. package/fesm2022/radix-ng-primitives-portal.mjs.map +1 -1
  62. package/fesm2022/radix-ng-primitives-presence.mjs +134 -246
  63. package/fesm2022/radix-ng-primitives-presence.mjs.map +1 -1
  64. package/fesm2022/radix-ng-primitives-preview-card.mjs +997 -0
  65. package/fesm2022/radix-ng-primitives-preview-card.mjs.map +1 -0
  66. package/fesm2022/radix-ng-primitives-progress.mjs +223 -84
  67. package/fesm2022/radix-ng-primitives-progress.mjs.map +1 -1
  68. package/fesm2022/radix-ng-primitives-radio.mjs +191 -51
  69. package/fesm2022/radix-ng-primitives-radio.mjs.map +1 -1
  70. package/fesm2022/radix-ng-primitives-roving-focus.mjs +96 -50
  71. package/fesm2022/radix-ng-primitives-roving-focus.mjs.map +1 -1
  72. package/fesm2022/radix-ng-primitives-select.mjs +791 -509
  73. package/fesm2022/radix-ng-primitives-select.mjs.map +1 -1
  74. package/fesm2022/radix-ng-primitives-separator.mjs +12 -35
  75. package/fesm2022/radix-ng-primitives-separator.mjs.map +1 -1
  76. package/fesm2022/radix-ng-primitives-slider.mjs +969 -717
  77. package/fesm2022/radix-ng-primitives-slider.mjs.map +1 -1
  78. package/fesm2022/radix-ng-primitives-stepper.mjs +15 -19
  79. package/fesm2022/radix-ng-primitives-stepper.mjs.map +1 -1
  80. package/fesm2022/radix-ng-primitives-switch.mjs +125 -113
  81. package/fesm2022/radix-ng-primitives-switch.mjs.map +1 -1
  82. package/fesm2022/radix-ng-primitives-tabs.mjs +381 -108
  83. package/fesm2022/radix-ng-primitives-tabs.mjs.map +1 -1
  84. package/fesm2022/radix-ng-primitives-time-field.mjs +55 -46
  85. package/fesm2022/radix-ng-primitives-time-field.mjs.map +1 -1
  86. package/fesm2022/radix-ng-primitives-toggle-group.mjs +121 -247
  87. package/fesm2022/radix-ng-primitives-toggle-group.mjs.map +1 -1
  88. package/fesm2022/radix-ng-primitives-toggle.mjs +98 -61
  89. package/fesm2022/radix-ng-primitives-toggle.mjs.map +1 -1
  90. package/fesm2022/radix-ng-primitives-toolbar.mjs +303 -92
  91. package/fesm2022/radix-ng-primitives-toolbar.mjs.map +1 -1
  92. package/fesm2022/radix-ng-primitives-tooltip.mjs +690 -1071
  93. package/fesm2022/radix-ng-primitives-tooltip.mjs.map +1 -1
  94. package/fesm2022/radix-ng-primitives-visually-hidden.mjs +25 -66
  95. package/fesm2022/radix-ng-primitives-visually-hidden.mjs.map +1 -1
  96. package/meter/README.md +3 -0
  97. package/navigation-menu/README.md +2 -1
  98. package/package.json +31 -18
  99. package/portal/README.md +2 -0
  100. package/preview-card/README.md +3 -0
  101. package/schematics/collection.json +1 -0
  102. package/schematics/ng-add/index.d.ts +3 -2
  103. package/schematics/ng-add/index.js +62 -31
  104. package/schematics/ng-add/index.js.map +1 -1
  105. package/schematics/ng-add/package-config.d.ts +4 -2
  106. package/schematics/ng-add/package-config.js +10 -2
  107. package/schematics/ng-add/package-config.js.map +1 -1
  108. package/schematics/ng-add/schema.d.ts +3 -0
  109. package/schematics/ng-add/schema.js +3 -0
  110. package/schematics/ng-add/schema.js.map +1 -0
  111. package/schematics/ng-add/schema.json +14 -0
  112. package/select/README.md +2 -0
  113. package/types/radix-ng-primitives-accordion.d.ts +48 -14
  114. package/types/radix-ng-primitives-alert-dialog.d.ts +95 -38
  115. package/types/radix-ng-primitives-arrow.d.ts +1 -1
  116. package/types/radix-ng-primitives-aspect-ratio.d.ts +1 -1
  117. package/types/radix-ng-primitives-avatar.d.ts +7 -11
  118. package/types/radix-ng-primitives-button.d.ts +73 -0
  119. package/types/radix-ng-primitives-calendar.d.ts +1 -2
  120. package/types/radix-ng-primitives-checkbox.d.ts +201 -32
  121. package/types/radix-ng-primitives-collapsible.d.ts +112 -39
  122. package/types/radix-ng-primitives-collection.d.ts +38 -34
  123. package/types/radix-ng-primitives-config.d.ts +1 -1
  124. package/types/radix-ng-primitives-context-menu.d.ts +60 -116
  125. package/types/radix-ng-primitives-core.d.ts +307 -236
  126. package/types/radix-ng-primitives-cropper.d.ts +2 -2
  127. package/types/radix-ng-primitives-date-field.d.ts +38 -23
  128. package/types/radix-ng-primitives-dialog.d.ts +282 -165
  129. package/types/radix-ng-primitives-dismissable-layer.d.ts +15 -7
  130. package/types/radix-ng-primitives-drawer.d.ts +448 -0
  131. package/types/radix-ng-primitives-editable.d.ts +1 -1
  132. package/types/radix-ng-primitives-field.d.ts +373 -0
  133. package/types/radix-ng-primitives-fieldset.d.ts +48 -0
  134. package/types/radix-ng-primitives-focus-scope.d.ts +13 -5
  135. package/types/radix-ng-primitives-input.d.ts +87 -0
  136. package/types/radix-ng-primitives-label.d.ts +0 -1
  137. package/types/radix-ng-primitives-menu.d.ts +572 -99
  138. package/types/radix-ng-primitives-menubar.d.ts +60 -50
  139. package/types/radix-ng-primitives-meter.d.ts +193 -0
  140. package/types/radix-ng-primitives-navigation-menu.d.ts +422 -340
  141. package/types/radix-ng-primitives-number-field.d.ts +405 -145
  142. package/types/radix-ng-primitives-pagination.d.ts +2 -2
  143. package/types/radix-ng-primitives-popover.d.ts +365 -351
  144. package/types/radix-ng-primitives-popper.d.ts +49 -9
  145. package/types/radix-ng-primitives-portal.d.ts +14 -6
  146. package/types/radix-ng-primitives-presence.d.ts +28 -76
  147. package/types/radix-ng-primitives-preview-card.d.ts +359 -0
  148. package/types/radix-ng-primitives-progress.d.ts +174 -48
  149. package/types/radix-ng-primitives-radio.d.ts +55 -25
  150. package/types/radix-ng-primitives-roving-focus.d.ts +30 -21
  151. package/types/radix-ng-primitives-select.d.ts +475 -177
  152. package/types/radix-ng-primitives-separator.d.ts +7 -32
  153. package/types/radix-ng-primitives-slider.d.ts +315 -201
  154. package/types/radix-ng-primitives-stepper.d.ts +5 -7
  155. package/types/radix-ng-primitives-switch.d.ts +86 -71
  156. package/types/radix-ng-primitives-tabs.d.ts +213 -79
  157. package/types/radix-ng-primitives-time-field.d.ts +42 -27
  158. package/types/radix-ng-primitives-toggle-group.d.ts +85 -164
  159. package/types/radix-ng-primitives-toggle.d.ts +43 -53
  160. package/types/radix-ng-primitives-toolbar.d.ts +163 -38
  161. package/types/radix-ng-primitives-tooltip.d.ts +347 -384
  162. package/types/radix-ng-primitives-visually-hidden.d.ts +19 -19
  163. package/dropdown-menu/README.md +0 -1
  164. package/fesm2022/radix-ng-primitives-dropdown-menu.mjs +0 -581
  165. package/fesm2022/radix-ng-primitives-dropdown-menu.mjs.map +0 -1
  166. package/fesm2022/radix-ng-primitives-hover-card.mjs +0 -1238
  167. package/fesm2022/radix-ng-primitives-hover-card.mjs.map +0 -1
  168. package/fesm2022/radix-ng-primitives-select2.mjs +0 -897
  169. package/fesm2022/radix-ng-primitives-select2.mjs.map +0 -1
  170. package/fesm2022/radix-ng-primitives-tooltip2.mjs +0 -735
  171. package/fesm2022/radix-ng-primitives-tooltip2.mjs.map +0 -1
  172. package/hover-card/README.md +0 -3
  173. package/select2/README.md +0 -3
  174. package/tooltip2/README.md +0 -3
  175. package/types/radix-ng-primitives-dropdown-menu.d.ts +0 -171
  176. package/types/radix-ng-primitives-hover-card.d.ts +0 -471
  177. package/types/radix-ng-primitives-select2.d.ts +0 -511
  178. package/types/radix-ng-primitives-tooltip2.d.ts +0 -325
@@ -1,313 +1,187 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, input, booleanAttribute, computed, effect, Directive, model, output, signal } from '@angular/core';
2
+ import { model, input, booleanAttribute, output, computed, signal, effect, untracked, Directive, inject } from '@angular/core';
3
+ import { createContext, provideValueAccessor } from '@radix-ng/primitives/core';
3
4
  import * as i1 from '@radix-ng/primitives/roving-focus';
4
- import { RdxRovingFocusItemDirective, RdxRovingFocusGroupDirective } from '@radix-ng/primitives/roving-focus';
5
- import * as i2 from '@radix-ng/primitives/toggle';
6
- import { RdxToggleDirective } from '@radix-ng/primitives/toggle';
7
- import { provideValueAccessor, isEqual, isValueEqualOrExist, provideToken } from '@radix-ng/primitives/core';
5
+ import { RdxRovingFocusGroupDirective } from '@radix-ng/primitives/roving-focus';
8
6
 
9
- const RdxToggleGroupItemToken = new InjectionToken('RdxToggleGroupItemToken');
10
- function injectToggleGroupItem() {
11
- return inject(RdxToggleGroupItemToken);
7
+ /** Builds the shared context a {@link RdxToggle} reads when it belongs to this group. */
8
+ function toggleGroupContext(instance) {
9
+ return {
10
+ value: instance.pressedValues,
11
+ disabled: instance.isDisabled,
12
+ multiple: instance.multiple,
13
+ orientation: instance.orientation,
14
+ toggle: (value) => instance.toggle(value)
15
+ };
12
16
  }
13
-
14
- const RdxToggleGroupToken = new InjectionToken('RdxToggleGroupToken');
15
- function injectToggleGroup() {
16
- return inject(RdxToggleGroupToken);
17
- }
18
-
19
17
  /**
20
- * @group Components
18
+ * Shared state and behavior for the toggle group. Concrete directives add the roving-focus group
19
+ * ({@link RdxToggleGroup}) or omit it when an ancestor already owns focus, e.g. a toolbar
20
+ * ({@link RdxToggleGroupWithoutFocus}).
21
21
  */
22
- class RdxToggleGroupItemDirective {
22
+ class RdxToggleGroupBase {
23
23
  constructor() {
24
- this.rdxToggleDirective = inject(RdxToggleDirective);
25
- this.rdxRovingFocusItemDirective = inject(RdxRovingFocusItemDirective);
26
24
  /**
27
- * Access the toggle group.
28
- * @ignore
25
+ * The pressed values. Always an array — a single value is `[value]`. Use with `(onValueChange)`
26
+ * for controlled state.
29
27
  */
30
- this.rootContext = injectToggleGroup();
28
+ this.value = model(...(ngDevMode ? [undefined, { debugName: "value" }] : /* istanbul ignore next */ []));
29
+ /** The values pressed when the group is initially rendered (uncontrolled). */
30
+ this.defaultValue = input(...(ngDevMode ? [undefined, { debugName: "defaultValue" }] : /* istanbul ignore next */ []));
31
31
  /**
32
- * The value of this toggle button.
32
+ * Whether multiple items can be pressed at the same time.
33
33
  *
34
- * @group Props
35
- */
36
- this.value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
37
- /**
38
- * Whether this toggle button is disabled.
39
- * @defaultValue false
40
- * @group Props
41
- */
42
- this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
43
- this.isPressed = computed(() => {
44
- return this.rootContext.type() === 'single'
45
- ? this.rootContext.value() === this.value()
46
- : this.rootContext.value()?.includes(this.value());
47
- }, ...(ngDevMode ? [{ debugName: "isPressed" }] : /* istanbul ignore next */ []));
48
- this.isDisabled = computed(() => this.rootContext.disabled() || this.rootContext.accessorDisabled() || this.disabled(), ...(ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []));
49
- effect(() => {
50
- this.rdxToggleDirective.cva.writeValue(!!this.isPressed());
51
- this.rdxToggleDirective.cva.setValue(!!this.isPressed());
52
- this.rdxToggleDirective.cva.setDisabledState(this.isDisabled());
53
- this.rdxRovingFocusItemDirective.setActive(!!this.isPressed());
54
- });
55
- }
56
- /**
57
- * @ignore
58
- */
59
- toggle() {
60
- if (this.disabled()) {
61
- return;
62
- }
63
- this.rootContext.toggle(this.value());
64
- }
65
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupItemDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
66
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxToggleGroupItemDirective, isStandalone: true, selector: "[rdxToggleGroupItem]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "toggle()" } }, providers: [{ provide: RdxToggleGroupItemToken, useExisting: RdxToggleGroupItemDirective }], exportAs: ["rdxToggleGroupItem"], hostDirectives: [{ directive: i1.RdxRovingFocusItemDirective, inputs: ["focusable", "focusable", "active", "active", "allowShiftKey", "allowShiftKey"] }, { directive: i2.RdxToggleDirective, inputs: ["pressed", "pressed", "disabled", "disabled"] }], ngImport: i0 }); }
67
- }
68
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupItemDirective, decorators: [{
69
- type: Directive,
70
- args: [{
71
- selector: '[rdxToggleGroupItem]',
72
- exportAs: 'rdxToggleGroupItem',
73
- providers: [{ provide: RdxToggleGroupItemToken, useExisting: RdxToggleGroupItemDirective }],
74
- hostDirectives: [
75
- {
76
- directive: RdxRovingFocusItemDirective,
77
- inputs: ['focusable', 'active', 'allowShiftKey']
78
- },
79
- {
80
- directive: RdxToggleDirective,
81
- inputs: ['pressed', 'disabled']
82
- }
83
- ],
84
- host: {
85
- '(click)': 'toggle()'
86
- }
87
- }]
88
- }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }] } });
89
-
90
- let nextId$1 = 0;
91
- class RdxToggleGroupWithoutFocusDirective {
92
- constructor() {
93
- /**
94
- * @ignore
95
- */
96
- this.id = `rdx-toggle-group-${nextId$1++}`;
97
- /**
98
- * @group Props
34
+ * @default false
99
35
  */
100
- this.value = model(undefined, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
36
+ this.multiple = input(false, { ...(ngDevMode ? { debugName: "multiple" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
101
37
  /**
102
- * @group Props
103
- */
104
- this.type = input('single', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
105
- /**
106
- * Whether the toggle group is disabled.
107
- * @defaultValue false
108
- * @group Props
38
+ * Whether the whole group is disabled.
39
+ *
40
+ * @default false
109
41
  */
110
42
  this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
111
43
  /**
112
- * Event emitted when the selected toggle button changes.
113
- * @group Emits
44
+ * The orientation of the group, controlling arrow-key navigation.
45
+ *
46
+ * @default 'horizontal'
114
47
  */
48
+ this.orientation = input('horizontal', ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
49
+ /** Event emitted when the pressed values change. */
115
50
  this.onValueChange = output();
51
+ /** @ignore */
52
+ this.pressedValues = computed(() => this.value() ?? [], ...(ngDevMode ? [{ debugName: "pressedValues" }] : /* istanbul ignore next */ []));
116
53
  this.accessorDisabled = signal(false, ...(ngDevMode ? [{ debugName: "accessorDisabled" }] : /* istanbul ignore next */ []));
54
+ /** @ignore */
55
+ this.isDisabled = computed(() => this.disabled() || this.accessorDisabled(), ...(ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []));
56
+ effect(() => {
57
+ const initial = this.defaultValue();
58
+ if (initial !== undefined && untracked(this.value) === undefined) {
59
+ this.value.set(initial);
60
+ }
61
+ });
117
62
  }
118
- /**
119
- * Toggle a value.
120
- * @param value The value to toggle.
121
- * @ignore
122
- */
63
+ /** @ignore */
123
64
  toggle(value) {
124
- if (this.disabled()) {
65
+ if (this.isDisabled()) {
125
66
  return;
126
67
  }
127
- if (this.type() === 'single') {
128
- this.value.set(value);
68
+ const current = this.pressedValues();
69
+ let next;
70
+ if (this.multiple()) {
71
+ next = current.includes(value) ? current.filter((item) => item !== value) : [...current, value];
129
72
  }
130
73
  else {
131
- this.value.set(((currentValue) => currentValue && Array.isArray(currentValue)
132
- ? currentValue.includes(value)
133
- ? currentValue.filter((v) => v !== value) // delete
134
- : [...currentValue, value] // update
135
- : [value])(this.value()));
74
+ next = current.includes(value) ? [] : [value];
136
75
  }
137
- this.onValueChange.emit(this.value());
138
- this.onChange?.(this.value());
76
+ this.value.set(next);
77
+ this.onValueChange.emit(next);
78
+ this.onChange?.(next);
139
79
  }
140
- /**
141
- * Select a value from Angular forms.
142
- * @param value The value to select.
143
- * @ignore
144
- */
80
+ /** @ignore */
145
81
  writeValue(value) {
146
- this.value.set(value);
82
+ this.value.set(value == null ? [] : Array.isArray(value) ? value : [value]);
147
83
  }
148
- /**
149
- * Register a callback to be called when the value changes.
150
- * @param fn The callback to register.
151
- * @ignore
152
- */
84
+ /** @ignore */
153
85
  registerOnChange(fn) {
154
86
  this.onChange = fn;
155
87
  }
156
- /**
157
- * Register a callback to be called when the toggle group is touched.
158
- * @param fn The callback to register.
159
- * @ignore
160
- */
88
+ /** @ignore */
161
89
  registerOnTouched(fn) {
162
90
  this.onTouched = fn;
163
91
  }
164
- /**
165
- * Set the disabled state of the toggle group.
166
- * @param isDisabled Whether the toggle group is disabled.
167
- * @ignore
168
- */
92
+ /** @ignore */
169
93
  setDisabledState(isDisabled) {
170
94
  this.accessorDisabled.set(isDisabled);
171
95
  }
172
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupWithoutFocusDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
173
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxToggleGroupWithoutFocusDirective, isStandalone: true, selector: "[rdxToggleGroupWithoutFocus]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", onValueChange: "onValueChange" }, host: { attributes: { "role": "group" }, listeners: { "focusout": "onTouched?.()" } }, providers: [
174
- { provide: RdxToggleGroupToken, useExisting: RdxToggleGroupWithoutFocusDirective },
175
- provideValueAccessor(RdxToggleGroupWithoutFocusDirective)
176
- ], exportAs: ["rdxToggleGroupWithoutFocus"], ngImport: i0 }); }
96
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupBase, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
97
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxToggleGroupBase, isStandalone: true, inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, defaultValue: { classPropertyName: "defaultValue", publicName: "defaultValue", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", onValueChange: "onValueChange" }, host: { attributes: { "role": "group" }, listeners: { "focusout": "onTouched?.()" }, properties: { "attr.data-orientation": "orientation()", "attr.data-disabled": "isDisabled() ? \"\" : undefined", "attr.data-multiple": "multiple() ? \"\" : undefined" } }, ngImport: i0 }); }
177
98
  }
178
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupWithoutFocusDirective, decorators: [{
99
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupBase, decorators: [{
179
100
  type: Directive,
180
101
  args: [{
181
- selector: '[rdxToggleGroupWithoutFocus]',
182
- exportAs: 'rdxToggleGroupWithoutFocus',
183
- providers: [
184
- { provide: RdxToggleGroupToken, useExisting: RdxToggleGroupWithoutFocusDirective },
185
- provideValueAccessor(RdxToggleGroupWithoutFocusDirective)
186
- ],
187
102
  host: {
188
103
  role: 'group',
104
+ '[attr.data-orientation]': 'orientation()',
105
+ '[attr.data-disabled]': 'isDisabled() ? "" : undefined',
106
+ '[attr.data-multiple]': 'multiple() ? "" : undefined',
189
107
  '(focusout)': 'onTouched?.()'
190
108
  }
191
109
  }]
192
- }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], onValueChange: [{ type: i0.Output, args: ["onValueChange"] }] } });
110
+ }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], defaultValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultValue", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], onValueChange: [{ type: i0.Output, args: ["onValueChange"] }] } });
111
+
112
+ const [injectToggleGroupContext, provideToggleGroupContext] = createContext('RdxToggleGroupContext');
193
113
 
194
- let nextId = 0;
195
114
  /**
196
- * @group Components
115
+ * A set of two-state buttons that can be toggled on or off. Owns roving keyboard focus over its
116
+ * `[rdxToggle]` children.
117
+ *
118
+ * @see https://base-ui.com/react/components/toggle-group
197
119
  */
198
- class RdxToggleGroupDirective {
120
+ class RdxToggleGroup extends RdxToggleGroupBase {
199
121
  constructor() {
122
+ super();
123
+ /** Text direction for arrow-key navigation. */
124
+ this.dir = input('ltr', ...(ngDevMode ? [{ debugName: "dir" }] : /* istanbul ignore next */ []));
200
125
  /**
201
- * @ignore
202
- */
203
- this.id = `rdx-toggle-group-${nextId++}`;
204
- /**
205
- * @group Props
206
- */
207
- this.value = model(undefined, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
208
- /**
209
- * @group Props
210
- */
211
- this.type = input('single', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
212
- /**
213
- * Whether the toggle group is disabled.
214
- * @defaultValue false
215
- * @group Props
216
- */
217
- this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
218
- /**
219
- * Event emitted when the selected toggle button changes.
220
- * @group Emits
126
+ * Whether keyboard navigation should loop from the last item back to the first.
127
+ *
128
+ * @default true
221
129
  */
222
- this.onValueChange = output();
223
- this.accessorDisabled = signal(false, ...(ngDevMode ? [{ debugName: "accessorDisabled" }] : /* istanbul ignore next */ []));
224
- }
225
- /**
226
- * Toggle a value.
227
- * @param value The value to toggle.
228
- * @ignore
229
- */
230
- toggle(value) {
231
- if (this.disabled()) {
232
- return;
233
- }
234
- if (this.type() === 'single') {
235
- this.value.set(isEqual(value, this.value()) ? undefined : value);
236
- }
237
- else {
238
- const modelValueArray = Array.isArray(this.value())
239
- ? [...(this.value() || [])]
240
- : [this.value()].filter(Boolean);
241
- if (isValueEqualOrExist(modelValueArray, value)) {
242
- const index = modelValueArray.findIndex((i) => isEqual(i, value));
243
- modelValueArray.splice(index, 1);
244
- }
245
- else {
246
- modelValueArray.push(value);
247
- }
248
- this.value.set(modelValueArray);
249
- }
250
- this.onValueChange.emit(this.value());
251
- this.onChange?.(this.value());
252
- }
253
- /**
254
- * Select a value from Angular forms.
255
- * @param value The value to select.
256
- * @ignore
257
- */
258
- writeValue(value) {
259
- this.value.set(value);
260
- }
261
- /**
262
- * Register a callback to be called when the value changes.
263
- * @param fn The callback to register.
264
- * @ignore
265
- */
266
- registerOnChange(fn) {
267
- this.onChange = fn;
268
- }
269
- /**
270
- * Register a callback to be called when the toggle group is touched.
271
- * @param fn The callback to register.
272
- * @ignore
273
- */
274
- registerOnTouched(fn) {
275
- this.onTouched = fn;
276
- }
277
- /**
278
- * Set the disabled state of the toggle group.
279
- * @param isDisabled Whether the toggle group is disabled.
280
- * @ignore
281
- */
282
- setDisabledState(isDisabled) {
283
- this.accessorDisabled.set(isDisabled);
130
+ this.loopFocus = input(true, { ...(ngDevMode ? { debugName: "loopFocus" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
131
+ this.rovingFocusGroup = inject(RdxRovingFocusGroupDirective, { self: true });
132
+ effect(() => {
133
+ this.rovingFocusGroup.setOrientation(this.orientation());
134
+ this.rovingFocusGroup.setDir(this.dir());
135
+ this.rovingFocusGroup.setLoop(this.loopFocus());
136
+ });
284
137
  }
285
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
286
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxToggleGroupDirective, isStandalone: true, selector: "[rdxToggleGroup]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", onValueChange: "onValueChange" }, host: { attributes: { "role": "group" }, listeners: { "focusout": "onTouched?.()" } }, providers: [
287
- provideToken(RdxToggleGroupToken, RdxToggleGroupDirective),
288
- provideValueAccessor(RdxToggleGroupDirective)
289
- ], exportAs: ["rdxToggleGroup"], hostDirectives: [{ directive: i1.RdxRovingFocusGroupDirective, inputs: ["dir", "dir", "orientation", "orientation", "loop", "loop"] }], ngImport: i0 }); }
138
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroup, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
139
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxToggleGroup, isStandalone: true, selector: "[rdxToggleGroup]", inputs: { dir: { classPropertyName: "dir", publicName: "dir", isSignal: true, isRequired: false, transformFunction: null }, loopFocus: { classPropertyName: "loopFocus", publicName: "loopFocus", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
140
+ provideToggleGroupContext(() => toggleGroupContext(inject(RdxToggleGroup))),
141
+ provideValueAccessor(RdxToggleGroup)
142
+ ], exportAs: ["rdxToggleGroup"], usesInheritance: true, hostDirectives: [{ directive: i1.RdxRovingFocusGroupDirective }], ngImport: i0 }); }
290
143
  }
291
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupDirective, decorators: [{
144
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroup, decorators: [{
292
145
  type: Directive,
293
146
  args: [{
294
147
  selector: '[rdxToggleGroup]',
295
148
  exportAs: 'rdxToggleGroup',
149
+ hostDirectives: [RdxRovingFocusGroupDirective],
296
150
  providers: [
297
- provideToken(RdxToggleGroupToken, RdxToggleGroupDirective),
298
- provideValueAccessor(RdxToggleGroupDirective)
299
- ],
300
- hostDirectives: [{ directive: RdxRovingFocusGroupDirective, inputs: ['dir', 'orientation', 'loop'] }],
301
- host: {
302
- role: 'group',
303
- '(focusout)': 'onTouched?.()'
304
- }
151
+ provideToggleGroupContext(() => toggleGroupContext(inject(RdxToggleGroup))),
152
+ provideValueAccessor(RdxToggleGroup)
153
+ ]
154
+ }]
155
+ }], ctorParameters: () => [], propDecorators: { dir: [{ type: i0.Input, args: [{ isSignal: true, alias: "dir", required: false }] }], loopFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "loopFocus", required: false }] }] } });
156
+
157
+ /**
158
+ * A toggle group that does NOT create its own roving-focus group, for use inside a container that
159
+ * already owns keyboard focus (e.g. a toolbar). The `[rdxToggle]` children register with the nearest
160
+ * ancestor roving-focus group instead. Mirrors Base UI's behavior of skipping its composite root
161
+ * when nested in a toolbar.
162
+ */
163
+ class RdxToggleGroupWithoutFocus extends RdxToggleGroupBase {
164
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupWithoutFocus, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
165
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: RdxToggleGroupWithoutFocus, isStandalone: true, selector: "[rdxToggleGroupWithoutFocus]", providers: [
166
+ provideToggleGroupContext(() => toggleGroupContext(inject(RdxToggleGroupWithoutFocus))),
167
+ provideValueAccessor(RdxToggleGroupWithoutFocus)
168
+ ], exportAs: ["rdxToggleGroupWithoutFocus"], usesInheritance: true, ngImport: i0 }); }
169
+ }
170
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxToggleGroupWithoutFocus, decorators: [{
171
+ type: Directive,
172
+ args: [{
173
+ selector: '[rdxToggleGroupWithoutFocus]',
174
+ exportAs: 'rdxToggleGroupWithoutFocus',
175
+ providers: [
176
+ provideToggleGroupContext(() => toggleGroupContext(inject(RdxToggleGroupWithoutFocus))),
177
+ provideValueAccessor(RdxToggleGroupWithoutFocus)
178
+ ]
305
179
  }]
306
- }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], onValueChange: [{ type: i0.Output, args: ["onValueChange"] }] } });
180
+ }] });
307
181
 
308
182
  /**
309
183
  * Generated bundle index. Do not edit.
310
184
  */
311
185
 
312
- export { RdxToggleGroupDirective, RdxToggleGroupItemDirective, RdxToggleGroupItemToken, RdxToggleGroupToken, RdxToggleGroupWithoutFocusDirective, injectToggleGroup, injectToggleGroupItem };
186
+ export { RdxToggleGroup, RdxToggleGroupBase, RdxToggleGroupWithoutFocus, injectToggleGroupContext, provideToggleGroupContext, toggleGroupContext };
313
187
  //# sourceMappingURL=radix-ng-primitives-toggle-group.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"radix-ng-primitives-toggle-group.mjs","sources":["../../../packages/primitives/toggle-group/src/toggle-group-item.token.ts","../../../packages/primitives/toggle-group/src/toggle-group.token.ts","../../../packages/primitives/toggle-group/src/toggle-group-item.directive.ts","../../../packages/primitives/toggle-group/src/toggle-group-without-focus.directive.ts","../../../packages/primitives/toggle-group/src/toggle-group.directive.ts","../../../packages/primitives/toggle-group/radix-ng-primitives-toggle-group.ts"],"sourcesContent":["import { inject, InjectionToken } from '@angular/core';\nimport type { RdxToggleGroupItemDirective } from './toggle-group-item.directive';\n\nexport const RdxToggleGroupItemToken = new InjectionToken<RdxToggleGroupItemDirective>('RdxToggleGroupItemToken');\n\nexport function injectToggleGroupItem(): RdxToggleGroupItemDirective {\n return inject(RdxToggleGroupItemToken);\n}\n","import { inject, InjectionToken } from '@angular/core';\n\nexport interface IRdxToggleGroup {\n toggle(value: string): void;\n disabled: any;\n value: any;\n type: any;\n accessorDisabled: any;\n}\n\nexport const RdxToggleGroupToken = new InjectionToken<IRdxToggleGroup>('RdxToggleGroupToken');\n\nexport function injectToggleGroup(): IRdxToggleGroup {\n return inject(RdxToggleGroupToken);\n}\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, computed, Directive, effect, inject, input } from '@angular/core';\nimport { RdxRovingFocusItemDirective } from '@radix-ng/primitives/roving-focus';\nimport { RdxToggleDirective } from '@radix-ng/primitives/toggle';\nimport { RdxToggleGroupItemToken } from './toggle-group-item.token';\nimport { injectToggleGroup } from './toggle-group.token';\n\n/**\n * @group Components\n */\n@Directive({\n selector: '[rdxToggleGroupItem]',\n exportAs: 'rdxToggleGroupItem',\n providers: [{ provide: RdxToggleGroupItemToken, useExisting: RdxToggleGroupItemDirective }],\n hostDirectives: [\n {\n directive: RdxRovingFocusItemDirective,\n inputs: ['focusable', 'active', 'allowShiftKey']\n },\n {\n directive: RdxToggleDirective,\n inputs: ['pressed', 'disabled']\n }\n ],\n host: {\n '(click)': 'toggle()'\n }\n})\nexport class RdxToggleGroupItemDirective {\n private readonly rdxToggleDirective = inject(RdxToggleDirective);\n\n private readonly rdxRovingFocusItemDirective = inject(RdxRovingFocusItemDirective);\n\n /**\n * Access the toggle group.\n * @ignore\n */\n protected readonly rootContext = injectToggleGroup();\n\n /**\n * The value of this toggle button.\n *\n * @group Props\n */\n readonly value = input.required<string>();\n\n /**\n * Whether this toggle button is disabled.\n * @defaultValue false\n * @group Props\n */\n readonly disabled = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n private readonly isPressed = computed(() => {\n return this.rootContext.type() === 'single'\n ? this.rootContext.value() === this.value()\n : this.rootContext.value()?.includes(this.value());\n });\n\n private readonly isDisabled = computed(\n () => this.rootContext.disabled() || this.rootContext.accessorDisabled() || this.disabled()\n );\n\n constructor() {\n effect(() => {\n this.rdxToggleDirective.cva.writeValue(!!this.isPressed());\n this.rdxToggleDirective.cva.setValue(!!this.isPressed());\n this.rdxToggleDirective.cva.setDisabledState(this.isDisabled());\n\n this.rdxRovingFocusItemDirective.setActive(!!this.isPressed());\n });\n }\n\n /**\n * @ignore\n */\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n\n this.rootContext.toggle(this.value());\n }\n}\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input, model, output, signal } from '@angular/core';\nimport { ControlValueAccessor } from '@angular/forms';\nimport { provideValueAccessor } from '@radix-ng/primitives/core';\nimport { RdxToggleGroupToken } from './toggle-group.token';\n\nlet nextId = 0;\n\n@Directive({\n selector: '[rdxToggleGroupWithoutFocus]',\n exportAs: 'rdxToggleGroupWithoutFocus',\n providers: [\n { provide: RdxToggleGroupToken, useExisting: RdxToggleGroupWithoutFocusDirective },\n provideValueAccessor(RdxToggleGroupWithoutFocusDirective)\n ],\n host: {\n role: 'group',\n '(focusout)': 'onTouched?.()'\n }\n})\nexport class RdxToggleGroupWithoutFocusDirective implements ControlValueAccessor {\n /**\n * @ignore\n */\n readonly id: string = `rdx-toggle-group-${nextId++}`;\n\n /**\n * @group Props\n */\n readonly value = model<string | string[] | undefined>(undefined);\n\n /**\n * @group Props\n */\n readonly type = input<'single' | 'multiple'>('single');\n\n /**\n * Whether the toggle group is disabled.\n * @defaultValue false\n * @group Props\n */\n readonly disabled = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * Event emitted when the selected toggle button changes.\n * @group Emits\n */\n readonly onValueChange = output<string[] | string | undefined>();\n\n /**\n * The value change callback.\n */\n private onChange?: (value: string | string[] | undefined) => void;\n\n /**\n * onTouch function registered via registerOnTouch (ControlValueAccessor).\n */\n protected onTouched?: () => void;\n\n /**\n * Toggle a value.\n * @param value The value to toggle.\n * @ignore\n */\n toggle(value: string): void {\n if (this.disabled()) {\n return;\n }\n\n if (this.type() === 'single') {\n this.value.set(value);\n } else {\n this.value.set(\n ((currentValue) =>\n currentValue && Array.isArray(currentValue)\n ? currentValue.includes(value)\n ? currentValue.filter((v) => v !== value) // delete\n : [...currentValue, value] // update\n : [value])(this.value())\n );\n }\n\n this.onValueChange.emit(this.value());\n this.onChange?.(this.value());\n }\n\n /**\n * Select a value from Angular forms.\n * @param value The value to select.\n * @ignore\n */\n writeValue(value: string): void {\n this.value.set(value);\n }\n\n /**\n * Register a callback to be called when the value changes.\n * @param fn The callback to register.\n * @ignore\n */\n registerOnChange(fn: (value: string | string[] | undefined) => void): void {\n this.onChange = fn;\n }\n\n /**\n * Register a callback to be called when the toggle group is touched.\n * @param fn The callback to register.\n * @ignore\n */\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n private readonly accessorDisabled = signal(false);\n\n /**\n * Set the disabled state of the toggle group.\n * @param isDisabled Whether the toggle group is disabled.\n * @ignore\n */\n setDisabledState(isDisabled: boolean): void {\n this.accessorDisabled.set(isDisabled);\n }\n}\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input, model, output, signal } from '@angular/core';\nimport { ControlValueAccessor } from '@angular/forms';\nimport {\n AcceptableValue,\n isEqual,\n isValueEqualOrExist,\n provideToken,\n provideValueAccessor\n} from '@radix-ng/primitives/core';\nimport { RdxRovingFocusGroupDirective } from '@radix-ng/primitives/roving-focus';\nimport { RdxToggleGroupToken } from './toggle-group.token';\n\nlet nextId = 0;\n\n/**\n * @group Components\n */\n@Directive({\n selector: '[rdxToggleGroup]',\n exportAs: 'rdxToggleGroup',\n providers: [\n provideToken(RdxToggleGroupToken, RdxToggleGroupDirective),\n provideValueAccessor(RdxToggleGroupDirective)\n ],\n hostDirectives: [{ directive: RdxRovingFocusGroupDirective, inputs: ['dir', 'orientation', 'loop'] }],\n host: {\n role: 'group',\n\n '(focusout)': 'onTouched?.()'\n }\n})\nexport class RdxToggleGroupDirective implements ControlValueAccessor {\n /**\n * @ignore\n */\n readonly id: string = `rdx-toggle-group-${nextId++}`;\n\n /**\n * @group Props\n */\n readonly value = model<AcceptableValue | AcceptableValue[] | undefined>(undefined);\n\n /**\n * @group Props\n */\n readonly type = input<'single' | 'multiple'>('single');\n\n /**\n * Whether the toggle group is disabled.\n * @defaultValue false\n * @group Props\n */\n readonly disabled = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * Event emitted when the selected toggle button changes.\n * @group Emits\n */\n readonly onValueChange = output<AcceptableValue | AcceptableValue[] | undefined>();\n\n /**\n * The value change callback.\n */\n private onChange?: (value: AcceptableValue | AcceptableValue[] | undefined) => void;\n\n /**\n * onTouch function registered via registerOnTouch (ControlValueAccessor).\n */\n protected onTouched?: () => void;\n\n /**\n * Toggle a value.\n * @param value The value to toggle.\n * @ignore\n */\n toggle(value: AcceptableValue): void {\n if (this.disabled()) {\n return;\n }\n\n if (this.type() === 'single') {\n this.value.set(isEqual(value, this.value()) ? undefined : value);\n } else {\n const modelValueArray = Array.isArray(this.value())\n ? [...((this.value() as AcceptableValue[]) || [])]\n : [this.value()].filter(Boolean);\n if (isValueEqualOrExist(modelValueArray, value)) {\n const index = modelValueArray.findIndex((i) => isEqual(i, value));\n modelValueArray.splice(index, 1);\n } else {\n modelValueArray.push(value);\n }\n this.value.set(modelValueArray);\n }\n\n this.onValueChange.emit(this.value());\n this.onChange?.(this.value());\n }\n\n /**\n * Select a value from Angular forms.\n * @param value The value to select.\n * @ignore\n */\n writeValue(value: string): void {\n this.value.set(value);\n }\n\n /**\n * Register a callback to be called when the value changes.\n * @param fn The callback to register.\n * @ignore\n */\n registerOnChange(fn: (value: AcceptableValue | AcceptableValue[] | undefined) => void): void {\n this.onChange = fn;\n }\n\n /**\n * Register a callback to be called when the toggle group is touched.\n * @param fn The callback to register.\n * @ignore\n */\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n readonly accessorDisabled = signal(false);\n /**\n * Set the disabled state of the toggle group.\n * @param isDisabled Whether the toggle group is disabled.\n * @ignore\n */\n setDisabledState(isDisabled: boolean): void {\n this.accessorDisabled.set(isDisabled);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["nextId"],"mappings":";;;;;;;;MAGa,uBAAuB,GAAG,IAAI,cAAc,CAA8B,yBAAyB;SAEhG,qBAAqB,GAAA;AACjC,IAAA,OAAO,MAAM,CAAC,uBAAuB,CAAC;AAC1C;;MCGa,mBAAmB,GAAG,IAAI,cAAc,CAAkB,qBAAqB;SAE5E,iBAAiB,GAAA;AAC7B,IAAA,OAAO,MAAM,CAAC,mBAAmB,CAAC;AACtC;;ACPA;;AAEG;MAmBU,2BAA2B,CAAA;AAmCpC,IAAA,WAAA,GAAA;AAlCiB,QAAA,IAAA,CAAA,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AAE/C,QAAA,IAAA,CAAA,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC;AAElF;;;AAGG;QACgB,IAAA,CAAA,WAAW,GAAG,iBAAiB,EAAE;AAEpD;;;;AAIG;AACM,QAAA,IAAA,CAAA,KAAK,GAAG,KAAK,CAAC,QAAQ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AACvB,qBAAA;AACD,oBAAA,cAAc,EAAE,CAAC,EAAE,SAAS,EAAE,4BAA4B,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC;AACrG,oBAAA,IAAI,EAAE;AACF,wBAAA,IAAI,EAAE,OAAO;AAEb,wBAAA,YAAY,EAAE;AACjB;AACJ,iBAAA;;;AC/BD;;AAEG;;;;"}
1
+ {"version":3,"file":"radix-ng-primitives-toggle-group.mjs","sources":["../../../packages/primitives/toggle-group/src/toggle-group-base.ts","../../../packages/primitives/toggle-group/src/toggle-group-context.ts","../../../packages/primitives/toggle-group/src/toggle-group.ts","../../../packages/primitives/toggle-group/src/toggle-group-without-focus.ts","../../../packages/primitives/toggle-group/radix-ng-primitives-toggle-group.ts"],"sourcesContent":["import { booleanAttribute, computed, Directive, effect, input, model, output, signal, untracked } from '@angular/core';\nimport { ControlValueAccessor } from '@angular/forms';\nimport { BooleanInput, DataOrientation } from '@radix-ng/primitives/core';\nimport { RdxToggleGroupContext } from './toggle-group-context';\n\n/** Builds the shared context a {@link RdxToggle} reads when it belongs to this group. */\nexport function toggleGroupContext(instance: RdxToggleGroupBase): RdxToggleGroupContext {\n return {\n value: instance.pressedValues,\n disabled: instance.isDisabled,\n multiple: instance.multiple,\n orientation: instance.orientation,\n toggle: (value) => instance.toggle(value)\n };\n}\n\n/**\n * Shared state and behavior for the toggle group. Concrete directives add the roving-focus group\n * ({@link RdxToggleGroup}) or omit it when an ancestor already owns focus, e.g. a toolbar\n * ({@link RdxToggleGroupWithoutFocus}).\n */\n@Directive({\n host: {\n role: 'group',\n '[attr.data-orientation]': 'orientation()',\n '[attr.data-disabled]': 'isDisabled() ? \"\" : undefined',\n '[attr.data-multiple]': 'multiple() ? \"\" : undefined',\n '(focusout)': 'onTouched?.()'\n }\n})\nexport abstract class RdxToggleGroupBase implements ControlValueAccessor {\n /**\n * The pressed values. Always an array — a single value is `[value]`. Use with `(onValueChange)`\n * for controlled state.\n */\n readonly value = model<string[]>();\n\n /** The values pressed when the group is initially rendered (uncontrolled). */\n readonly defaultValue = input<string[]>();\n\n /**\n * Whether multiple items can be pressed at the same time.\n *\n * @default false\n */\n readonly multiple = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * Whether the whole group is disabled.\n *\n * @default false\n */\n readonly disabled = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * The orientation of the group, controlling arrow-key navigation.\n *\n * @default 'horizontal'\n */\n readonly orientation = input<DataOrientation>('horizontal');\n\n /** Event emitted when the pressed values change. */\n readonly onValueChange = output<string[]>();\n\n /** @ignore */\n readonly pressedValues = computed(() => this.value() ?? []);\n\n protected readonly accessorDisabled = signal(false);\n /** @ignore */\n readonly isDisabled = computed(() => this.disabled() || this.accessorDisabled());\n\n private onChange?: (value: string[]) => void;\n protected onTouched?: () => void;\n\n constructor() {\n effect(() => {\n const initial = this.defaultValue();\n if (initial !== undefined && untracked(this.value) === undefined) {\n this.value.set(initial);\n }\n });\n }\n\n /** @ignore */\n toggle(value: string): void {\n if (this.isDisabled()) {\n return;\n }\n\n const current = this.pressedValues();\n let next: string[];\n\n if (this.multiple()) {\n next = current.includes(value) ? current.filter((item) => item !== value) : [...current, value];\n } else {\n next = current.includes(value) ? [] : [value];\n }\n\n this.value.set(next);\n this.onValueChange.emit(next);\n this.onChange?.(next);\n }\n\n /** @ignore */\n writeValue(value: string[] | string | null): void {\n this.value.set(value == null ? [] : Array.isArray(value) ? value : [value]);\n }\n\n /** @ignore */\n registerOnChange(fn: (value: string[]) => void): void {\n this.onChange = fn;\n }\n\n /** @ignore */\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n /** @ignore */\n setDisabledState(isDisabled: boolean): void {\n this.accessorDisabled.set(isDisabled);\n }\n}\n","import { Signal } from '@angular/core';\nimport { createContext, DataOrientation } from '@radix-ng/primitives/core';\n\n/**\n * Shared state a {@link RdxToggle} reads when it participates in a toggle group.\n */\nexport interface RdxToggleGroupContext {\n /** The currently pressed values. */\n readonly value: Signal<string[]>;\n\n /** Whether the whole group is disabled. */\n readonly disabled: Signal<boolean>;\n\n /** Whether more than one item can be pressed at a time. */\n readonly multiple: Signal<boolean>;\n\n /** The orientation of the group. */\n readonly orientation: Signal<DataOrientation>;\n\n /** Toggle the pressed state of `value` within the group. */\n toggle(value: string): void;\n}\n\nexport const [injectToggleGroupContext, provideToggleGroupContext] =\n createContext<RdxToggleGroupContext>('RdxToggleGroupContext');\n","import { booleanAttribute, Directive, effect, inject, input } from '@angular/core';\nimport { BooleanInput, provideValueAccessor } from '@radix-ng/primitives/core';\nimport { Direction, RdxRovingFocusGroupDirective } from '@radix-ng/primitives/roving-focus';\nimport { RdxToggleGroupBase, toggleGroupContext } from './toggle-group-base';\nimport { provideToggleGroupContext } from './toggle-group-context';\n\n/**\n * A set of two-state buttons that can be toggled on or off. Owns roving keyboard focus over its\n * `[rdxToggle]` children.\n *\n * @see https://base-ui.com/react/components/toggle-group\n */\n@Directive({\n selector: '[rdxToggleGroup]',\n exportAs: 'rdxToggleGroup',\n hostDirectives: [RdxRovingFocusGroupDirective],\n providers: [\n provideToggleGroupContext(() => toggleGroupContext(inject(RdxToggleGroup))),\n provideValueAccessor(RdxToggleGroup)\n ]\n})\nexport class RdxToggleGroup extends RdxToggleGroupBase {\n /** Text direction for arrow-key navigation. */\n readonly dir = input<Direction>('ltr');\n\n /**\n * Whether keyboard navigation should loop from the last item back to the first.\n *\n * @default true\n */\n readonly loopFocus = input<boolean, BooleanInput>(true, { transform: booleanAttribute });\n\n private readonly rovingFocusGroup = inject(RdxRovingFocusGroupDirective, { self: true });\n\n constructor() {\n super();\n\n effect(() => {\n this.rovingFocusGroup.setOrientation(this.orientation());\n this.rovingFocusGroup.setDir(this.dir());\n this.rovingFocusGroup.setLoop(this.loopFocus());\n });\n }\n}\n","import { Directive, inject } from '@angular/core';\nimport { provideValueAccessor } from '@radix-ng/primitives/core';\nimport { RdxToggleGroupBase, toggleGroupContext } from './toggle-group-base';\nimport { provideToggleGroupContext } from './toggle-group-context';\n\n/**\n * A toggle group that does NOT create its own roving-focus group, for use inside a container that\n * already owns keyboard focus (e.g. a toolbar). The `[rdxToggle]` children register with the nearest\n * ancestor roving-focus group instead. Mirrors Base UI's behavior of skipping its composite root\n * when nested in a toolbar.\n */\n@Directive({\n selector: '[rdxToggleGroupWithoutFocus]',\n exportAs: 'rdxToggleGroupWithoutFocus',\n providers: [\n provideToggleGroupContext(() => toggleGroupContext(inject(RdxToggleGroupWithoutFocus))),\n provideValueAccessor(RdxToggleGroupWithoutFocus)\n ]\n})\nexport class RdxToggleGroupWithoutFocus extends RdxToggleGroupBase {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAKA;AACM,SAAU,kBAAkB,CAAC,QAA4B,EAAA;IAC3D,OAAO;QACH,KAAK,EAAE,QAAQ,CAAC,aAAa;QAC7B,QAAQ,EAAE,QAAQ,CAAC,UAAU;QAC7B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,MAAM,EAAE,CAAC,KAAK,KAAK,QAAQ,CAAC,MAAM,CAAC,KAAK;KAC3C;AACL;AAEA;;;;AAIG;MAUmB,kBAAkB,CAAA;AA4CpC,IAAA,WAAA,GAAA;AA3CA;;;AAGG;QACM,IAAA,CAAA,KAAK,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,OAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAY;;QAGzB,IAAA,CAAA,YAAY,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,cAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAY;AAEzC;;;;AAIG;QACM,IAAA,CAAA,QAAQ,GAAG,KAAK,CAAwB,KAAK,gFAAI,SAAS,EAAE,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