ng-primitives 0.123.0 → 0.124.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ng-primitives-toggle-group.mjs","sources":["../../../../packages/ng-primitives/toggle-group/src/config/toggle-group-config.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group/toggle-group-state.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group-item/toggle-group-item-state.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group-item/toggle-group-item.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group/toggle-group.ts","../../../../packages/ng-primitives/toggle-group/src/ng-primitives-toggle-group.ts"],"sourcesContent":["import { InjectionToken, Provider, inject } from '@angular/core';\nimport { NgpOrientation } from 'ng-primitives/common';\n\nexport interface NgpToggleGroupConfig {\n /**\n * The orientation of the toggle group.\n * @default 'horizontal'\n */\n orientation: NgpOrientation;\n\n /**\n * The type of the toggle group, whether only one item can be selected or multiple.\n * @default 'single'\n */\n type: 'single' | 'multiple';\n\n /**\n * Whether a toggle button can be deselected.\n * @default true\n */\n allowDeselection: boolean;\n\n /**\n * Whether focus should wrap around when reaching the end of the toggle group.\n * @default true\n */\n wrap: boolean;\n}\n\nexport const defaultToggleGroupConfig: NgpToggleGroupConfig = {\n orientation: 'horizontal',\n type: 'single',\n allowDeselection: true,\n wrap: true,\n};\n\nexport const NgpToggleGroupConfigToken = new InjectionToken<NgpToggleGroupConfig>(\n 'NgpToggleGroupConfigToken',\n);\n\n/**\n * Provide the default ToggleGroup configuration\n * @param config The ToggleGroup configuration\n * @returns The provider\n */\nexport function provideToggleGroupConfig(config: Partial<NgpToggleGroupConfig>): Provider[] {\n return [\n {\n provide: NgpToggleGroupConfigToken,\n useValue: { ...defaultToggleGroupConfig, ...config },\n },\n ];\n}\n\n/**\n * Inject the ToggleGroup configuration\n * @returns The global ToggleGroup configuration\n */\nexport function injectToggleGroupConfig(): NgpToggleGroupConfig {\n return inject(NgpToggleGroupConfigToken, { optional: true }) ?? defaultToggleGroupConfig;\n}\n","import { Signal, WritableSignal } from '@angular/core';\nimport { NgpOrientation } from 'ng-primitives/common';\nimport { injectElementRef } from 'ng-primitives/internal';\nimport { NgpRovingFocusGroupState } from 'ng-primitives/roving-focus';\nimport {\n attrBinding,\n controlled,\n controlledState,\n createPrimitive,\n dataBinding,\n deprecatedSetter,\n SetterOptions,\n} from 'ng-primitives/state';\nimport { Observable } from 'rxjs';\n\n/**\n * The state interface for the ToggleGroup pattern.\n */\nexport interface NgpToggleGroupState {\n /**\n * The current value(s) of the toggle group.\n */\n readonly value: WritableSignal<string[]>;\n\n /**\n * Emit when the value changes.\n */\n readonly valueChange: Observable<string[]>;\n\n /**\n * Whether the toggle group is disabled.\n */\n readonly disabled: WritableSignal<boolean>;\n\n /**\n * The orientation of the toggle group.\n */\n readonly orientation: WritableSignal<NgpOrientation>;\n /**\n * Select a value in the toggle group.\n */\n select(selection: string): void;\n\n /**\n * De-select a value in the toggle group.\n */\n deselect(selection: string): void;\n\n /**\n * Check if a value is selected in the toggle group.\n */\n isSelected(selection: string): boolean;\n\n /**\n * Toggle a value in the toggle group.\n */\n toggle(selection: string): void;\n\n /**\n * Set the value(s) of the toggle group.\n */\n setValue(newValue: string[], options?: SetterOptions): void;\n\n /**\n * Set the default value(s) of the toggle group.\n */\n setDefaultValue(defaultValue: string[]): void;\n\n /**\n * Set the disabled state of the toggle group.\n */\n setDisabled(isDisabled: boolean): void;\n\n /**\n * Set the orientation of the toggle group.\n */\n setOrientation(newOrientation: NgpOrientation): void;\n}\n\n/**\n * The props interface for the ToggleGroup pattern.\n */\nexport interface NgpToggleGroupProps {\n /**\n * The roving focus group state for the toggle-group.\n */\n readonly rovingFocusGroup: NgpRovingFocusGroupState;\n\n /**\n * The orientation of the toggle-group.\n */\n readonly orientation?: Signal<NgpOrientation>;\n /**\n * Whether deselection is allowed in the toggle-group.\n */\n readonly allowDeselection?: Signal<boolean>;\n /**\n * The type of the toggle-group (e.g., 'single' or 'multiple').\n */\n readonly type?: Signal<'single' | 'multiple'>;\n /**\n * The value(s) of the toggle-group.\n */\n readonly value: Signal<string[] | undefined>;\n /**\n * The default value(s) of the toggle-group for uncontrolled usage.\n */\n readonly defaultValue?: Signal<string[]>;\n /**\n * Whether the toggle-group is disabled.\n */\n readonly disabled?: Signal<boolean>;\n /**\n * Emit when the value changes.\n */\n readonly onValueChange?: (value: string[]) => void;\n}\n\nexport const [\n NgpToggleGroupStateToken,\n ngpToggleGroup,\n injectToggleGroupState,\n provideToggleGroupState,\n] = createPrimitive(\n 'NgpToggleGroup',\n ({\n rovingFocusGroup,\n orientation: _orientation,\n allowDeselection: _allowDeselection,\n type: _type,\n value: _value,\n defaultValue: _defaultValue,\n disabled: _disabled,\n onValueChange,\n }: NgpToggleGroupProps): NgpToggleGroupState => {\n const element = injectElementRef();\n\n const allowDeselection = controlled(_allowDeselection, true);\n const type = controlled(_type, 'single');\n const disabled = controlled(_disabled, false);\n const orientation = controlled(_orientation, 'horizontal');\n const defaultValue = controlled(_defaultValue, []);\n\n const [value, setValueInternal, valueChange] = controlledState<string[]>({\n value: _value,\n defaultValue,\n onChange: onValueChange,\n });\n\n // Host bindings\n attrBinding(element, 'role', 'group');\n dataBinding(element, 'data-orientation', orientation);\n dataBinding(element, 'data-type', type);\n dataBinding(element, 'data-disabled', disabled);\n\n /**\n * Select a value in the toggle group.\n */\n function select(selection: string): void {\n if (disabled()) {\n return;\n }\n\n let newValue: string[] = [];\n\n if (type() === 'single') {\n newValue = [selection];\n } else {\n newValue = [...value(), selection];\n }\n\n setValue(newValue);\n }\n\n /**\n * De-select a value in the toggle group.\n */\n function deselect(selection: string): void {\n if (disabled() || !allowDeselection()) {\n return;\n }\n\n const newValue = value().filter(v => v !== selection);\n setValue(newValue);\n }\n\n /**\n * Check if a value is selected in the toggle group.\n * @internal\n */\n function isSelected(itemValue: string): boolean {\n return value().includes(itemValue);\n }\n\n /**\n * Toggle a value in the toggle group.\n * @internal\n */\n function toggle(itemValue: string): void {\n if (isSelected(itemValue)) {\n deselect(itemValue);\n } else {\n select(itemValue);\n }\n }\n\n function setValue(newValue: string[], options?: SetterOptions): void {\n setValueInternal(newValue, options);\n }\n\n function setDisabled(isDisabled: boolean): void {\n disabled.set(isDisabled);\n }\n\n function setOrientation(newOrientation: NgpOrientation): void {\n orientation.set(newOrientation);\n rovingFocusGroup.setOrientation(newOrientation);\n }\n\n return {\n select,\n deselect,\n disabled: deprecatedSetter(disabled, 'setDisabled'),\n isSelected,\n toggle,\n value: deprecatedSetter(value, 'setValue', setValue),\n orientation: deprecatedSetter(orientation, 'setOrientation', setOrientation),\n setValue,\n setDefaultValue: defaultValue.set,\n setDisabled,\n setOrientation,\n valueChange,\n } satisfies NgpToggleGroupState;\n },\n);\n","import { computed, signal, Signal } from '@angular/core';\nimport { injectElementRef } from 'ng-primitives/internal';\nimport { attrBinding, createPrimitive, dataBinding, listener } from 'ng-primitives/state';\nimport { injectToggleGroupState } from '../toggle-group/toggle-group-state';\n\n/**\n * The state interface for the ToggleGroupItem pattern.\n */\nexport interface NgpToggleGroupItemState {\n selected: Signal<boolean>;\n toggle(): void;\n}\n\n/**\n * The props interface for the ToggleGroupItem pattern.\n */\nexport interface NgpToggleGroupItemProps {\n /**\n * The value of the toggle group item.\n */\n value: Signal<string>;\n\n /**\n * Whether the toggle group item is disabled.\n */\n disabled?: Signal<boolean>;\n}\n\nexport const [\n NgpToggleGroupItemToken,\n ngpToggleGroupItem,\n injectToggleGroupItemState,\n provideToggleGroupItemState,\n] = createPrimitive(\n 'NgpToggleGroupItem',\n ({ value, disabled = signal(false) }: NgpToggleGroupItemProps): NgpToggleGroupItemState => {\n const element = injectElementRef();\n const toggleGroup = injectToggleGroupState();\n\n // Whether the item is selected.\n const selected = computed(() => toggleGroup()?.isSelected(value()!) ?? false);\n\n // Host bindings\n attrBinding(element, 'role', 'radio');\n attrBinding(element, 'aria-checked', selected);\n dataBinding(element, 'data-selected', selected);\n attrBinding(element, 'aria-disabled', disabled);\n dataBinding(element, 'data-disabled', disabled);\n\n // Host listener\n listener(element, 'click', () => toggle());\n\n // Toggle the item.\n const toggle = (): void => {\n if (disabled?.()) {\n return;\n }\n toggleGroup()?.toggle(value()!);\n };\n\n return { selected, toggle } satisfies NgpToggleGroupItemState;\n },\n);\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input, OnInit, Signal } from '@angular/core';\nimport { ngpRovingFocusItem, provideRovingFocusItemState } from 'ng-primitives/roving-focus';\nimport { ngpToggleGroupItem, provideToggleGroupItemState } from './toggle-group-item-state';\n\n@Directive({\n selector: '[ngpToggleGroupItem]',\n exportAs: 'ngpToggleGroupItem',\n providers: [provideToggleGroupItemState(), provideRovingFocusItemState()],\n})\nexport class NgpToggleGroupItem implements OnInit {\n /**\n * The value of the item.\n * @required\n */\n readonly value = input<string>(undefined, {\n alias: 'ngpToggleGroupItemValue',\n });\n\n /**\n * Whether the item is disabled.\n */\n readonly disabled = input<boolean, BooleanInput>(false, {\n alias: 'ngpToggleGroupItemDisabled',\n transform: booleanAttribute,\n });\n\n constructor() {\n ngpToggleGroupItem({\n value: this.value as Signal<string>,\n disabled: this.disabled,\n });\n // Initialize the roving focus item state\n ngpRovingFocusItem({ disabled: this.disabled });\n }\n\n ngOnInit(): void {\n // we can't use a required input for value as it is used in a computed property before the input is set\n if (this.value() === undefined) {\n throw new Error('The value input is required for the toggle group item.');\n }\n }\n}\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input, output } from '@angular/core';\nimport { NgpOrientation } from 'ng-primitives/common';\nimport { ngpRovingFocusGroup, provideRovingFocusGroupState } from 'ng-primitives/roving-focus';\nimport { SetterOptions } from 'ng-primitives/state';\nimport { injectToggleGroupConfig } from '../config/toggle-group-config';\nimport { ngpToggleGroup, provideToggleGroupState } from './toggle-group-state';\n\n@Directive({\n selector: '[ngpToggleGroup]',\n exportAs: 'ngpToggleGroup',\n providers: [provideToggleGroupState(), provideRovingFocusGroupState({ inherit: true })],\n})\nexport class NgpToggleGroup {\n /**\n * Access the global toggle group configuration.\n */\n private readonly config = injectToggleGroupConfig();\n\n /**\n * The orientation of the toggle group.\n */\n readonly orientation = input<NgpOrientation>(this.config.orientation, {\n alias: 'ngpToggleGroupOrientation',\n });\n\n /**\n * Whether focus should wrap around when reaching the end of the toggle group.\n * @default true\n */\n readonly wrap = input<boolean, BooleanInput>(this.config.wrap, {\n alias: 'ngpToggleGroupWrap',\n transform: booleanAttribute,\n });\n\n /**\n * Whether toggle buttons can be deselected. If set to `false`, clicking a selected toggle button will not deselect it.\n * @default true\n */\n readonly allowDeselection = input<boolean, BooleanInput>(this.config.allowDeselection, {\n alias: 'ngpToggleGroupAllowDeselection',\n transform: booleanAttribute,\n });\n\n /**\n * The type of the toggle group, whether only one item can be selected or multiple.\n */\n readonly type = input<'single' | 'multiple'>(this.config.type, { alias: 'ngpToggleGroupType' });\n\n /**\n * The selected value(s) of the toggle group.\n */\n readonly value = input<string[] | undefined>(undefined, { alias: 'ngpToggleGroupValue' });\n\n /**\n * The default selected value(s) for uncontrolled usage.\n * @default []\n */\n readonly defaultValue = input<string[]>([], { alias: 'ngpToggleGroupDefaultValue' });\n\n /**\n * Emits when the value of the toggle group changes.\n */\n readonly valueChange = output<string[]>({ alias: 'ngpToggleGroupValueChange' });\n\n /**\n * Whether the toggle group is disabled.\n */\n readonly disabled = input<boolean, BooleanInput>(false, {\n alias: 'ngpToggleGroupDisabled',\n transform: booleanAttribute,\n });\n\n /**\n * The state of the toggle group.\n */\n protected readonly state = ngpToggleGroup({\n rovingFocusGroup: ngpRovingFocusGroup({\n orientation: this.orientation,\n disabled: this.disabled,\n wrap: this.wrap,\n }),\n orientation: this.orientation,\n allowDeselection: this.allowDeselection,\n type: this.type,\n value: this.value,\n defaultValue: this.defaultValue,\n disabled: this.disabled,\n onValueChange: (value: string[]) => this.valueChange.emit(value),\n });\n\n /**\n * Toggle a value in the toggle group.\n */\n toggle(value: string): void {\n this.state.toggle(value);\n }\n\n /**\n * Set the value(s) of the toggle group.\n */\n setValue(newValue: string[], options?: SetterOptions): void {\n this.state.setValue(newValue, options);\n }\n\n /**\n * Set the default value(s) of the toggle group.\n */\n setDefaultValue(defaultValue: string[]): void {\n this.state.setDefaultValue(defaultValue);\n }\n\n /**\n * Set the disabled state of the toggle group.\n */\n setDisabled(isDisabled: boolean): void {\n this.state.setDisabled(isDisabled);\n }\n\n /**\n * Set the orientation of the toggle group.\n */\n setOrientation(newOrientation: NgpOrientation): void {\n this.state.setOrientation(newOrientation);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AA6BO,MAAM,wBAAwB,GAAyB;AAC5D,IAAA,WAAW,EAAE,YAAY;AACzB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,gBAAgB,EAAE,IAAI;AACtB,IAAA,IAAI,EAAE,IAAI;CACX;AAEM,MAAM,yBAAyB,GAAG,IAAI,cAAc,CACzD,2BAA2B,CAC5B;AAED;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,MAAqC,EAAA;IAC5E,OAAO;AACL,QAAA;AACE,YAAA,OAAO,EAAE,yBAAyB;AAClC,YAAA,QAAQ,EAAE,EAAE,GAAG,wBAAwB,EAAE,GAAG,MAAM,EAAE;AACrD,SAAA;KACF;AACH;AAEA;;;AAGG;SACa,uBAAuB,GAAA;AACrC,IAAA,OAAO,MAAM,CAAC,yBAAyB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,wBAAwB;AAC1F;;MC0Da,CACX,wBAAwB,EACxB,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACxB,GAAG,eAAe,CACjB,gBAAgB,EAChB,CAAC,EACC,gBAAgB,EAChB,WAAW,EAAE,YAAY,EACzB,gBAAgB,EAAE,iBAAiB,EACnC,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,MAAM,EACb,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AA,EAAA,IAAA,EAAA,EAAA,QAAA,EAAA,EAAA,iBAAA,EAAA,UAAA,EAAA,UAAA,EAAA,wBAAA,EAAA,QAAA,EAAA,IAAA,EAAA,UAAA,EAAA,KAAA,EAAA,iBAAA,EAAA,IAAA,EAAA,EAAA,EAAA,OAAA,EAAA,EAAA,WAAA,EAAA,2BAAA,EAAA,EAAA,SAAA,EAFd,CAAC,uBAAuB,EAAE,EAAE,4BAA4B,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAA,QAAA,EAAA,CAAA,gBAAA,CAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA,CAAA;;4FAE5E,cAAc,EAAA,UAAA,EAAA,CAAA;kBAL1B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,kBAAkB;AAC5B,oBAAA,QAAQ,EAAE,gBAAgB;AAC1B,oBAAA,SAAS,EAAE,CAAC,uBAAuB,EAAE,EAAE,4BAA4B,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACxF,iBAAA;;;ACZD;;AAEG;;;;"}
1
+ {"version":3,"file":"ng-primitives-toggle-group.mjs","sources":["../../../../packages/ng-primitives/toggle-group/src/config/toggle-group-config.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group/toggle-group-state.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group-item/toggle-group-item-state.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group-item/toggle-group-item.ts","../../../../packages/ng-primitives/toggle-group/src/toggle-group/toggle-group.ts","../../../../packages/ng-primitives/toggle-group/src/ng-primitives-toggle-group.ts"],"sourcesContent":["import { InjectionToken, Provider, inject } from '@angular/core';\nimport { NgpOrientation } from 'ng-primitives/common';\n\nexport interface NgpToggleGroupConfig {\n /**\n * The orientation of the toggle group.\n * @default 'horizontal'\n */\n orientation: NgpOrientation;\n\n /**\n * The type of the toggle group, whether only one item can be selected or multiple.\n * @default 'single'\n */\n type: 'single' | 'multiple';\n\n /**\n * Whether a toggle button can be deselected.\n * @default true\n */\n allowDeselection: boolean;\n\n /**\n * Whether focus should wrap around when reaching the end of the toggle group.\n * @default true\n */\n wrap: boolean;\n}\n\nexport const defaultToggleGroupConfig: NgpToggleGroupConfig = {\n orientation: 'horizontal',\n type: 'single',\n allowDeselection: true,\n wrap: true,\n};\n\nexport const NgpToggleGroupConfigToken = new InjectionToken<NgpToggleGroupConfig>(\n 'NgpToggleGroupConfigToken',\n);\n\n/**\n * Provide the default ToggleGroup configuration\n * @param config The ToggleGroup configuration\n * @returns The provider\n */\nexport function provideToggleGroupConfig(config: Partial<NgpToggleGroupConfig>): Provider[] {\n return [\n {\n provide: NgpToggleGroupConfigToken,\n useValue: { ...defaultToggleGroupConfig, ...config },\n },\n ];\n}\n\n/**\n * Inject the ToggleGroup configuration\n * @returns The global ToggleGroup configuration\n */\nexport function injectToggleGroupConfig(): NgpToggleGroupConfig {\n return inject(NgpToggleGroupConfigToken, { optional: true }) ?? defaultToggleGroupConfig;\n}\n","import { Signal, WritableSignal } from '@angular/core';\nimport { NgpOrientation } from 'ng-primitives/common';\nimport { injectElementRef } from 'ng-primitives/internal';\nimport { ngpRovingFocusGroup } from 'ng-primitives/roving-focus';\nimport {\n attrBinding,\n controlled,\n controlledState,\n createPrimitive,\n dataBinding,\n deprecatedSetter,\n SetterOptions,\n} from 'ng-primitives/state';\nimport { Observable } from 'rxjs';\n\n/**\n * The state interface for the ToggleGroup pattern.\n */\nexport interface NgpToggleGroupState {\n /**\n * The current value(s) of the toggle group.\n */\n readonly value: WritableSignal<string[]>;\n\n /**\n * Emit when the value changes.\n */\n readonly valueChange: Observable<string[]>;\n\n /**\n * Whether the toggle group is disabled.\n */\n readonly disabled: WritableSignal<boolean>;\n\n /**\n * The orientation of the toggle group.\n */\n readonly orientation: WritableSignal<NgpOrientation>;\n /**\n * Select a value in the toggle group.\n */\n select(selection: string): void;\n\n /**\n * De-select a value in the toggle group.\n */\n deselect(selection: string): void;\n\n /**\n * Check if a value is selected in the toggle group.\n */\n isSelected(selection: string): boolean;\n\n /**\n * Toggle a value in the toggle group.\n */\n toggle(selection: string): void;\n\n /**\n * Set the value(s) of the toggle group.\n */\n setValue(newValue: string[], options?: SetterOptions): void;\n\n /**\n * Set the default value(s) of the toggle group.\n */\n setDefaultValue(defaultValue: string[]): void;\n\n /**\n * Set the disabled state of the toggle group.\n */\n setDisabled(isDisabled: boolean): void;\n\n /**\n * Set the orientation of the toggle group.\n */\n setOrientation(newOrientation: NgpOrientation): void;\n}\n\n/**\n * The props interface for the ToggleGroup pattern.\n */\nexport interface NgpToggleGroupProps {\n /**\n * The orientation of the toggle-group.\n */\n readonly orientation?: Signal<NgpOrientation>;\n /**\n * Whether focus should wrap around when reaching the end of the toggle-group.\n */\n readonly wrap?: Signal<boolean>;\n /**\n * Whether deselection is allowed in the toggle-group.\n */\n readonly allowDeselection?: Signal<boolean>;\n /**\n * The type of the toggle-group (e.g., 'single' or 'multiple').\n */\n readonly type?: Signal<'single' | 'multiple'>;\n /**\n * The value(s) of the toggle-group.\n */\n readonly value: Signal<string[] | undefined>;\n /**\n * The default value(s) of the toggle-group for uncontrolled usage.\n */\n readonly defaultValue?: Signal<string[]>;\n /**\n * Whether the toggle-group is disabled.\n */\n readonly disabled?: Signal<boolean>;\n /**\n * Emit when the value changes.\n */\n readonly onValueChange?: (value: string[]) => void;\n}\n\nexport const [\n NgpToggleGroupStateToken,\n ngpToggleGroup,\n injectToggleGroupState,\n provideToggleGroupState,\n] = createPrimitive(\n 'NgpToggleGroup',\n ({\n orientation: _orientation,\n wrap: _wrap,\n allowDeselection: _allowDeselection,\n type: _type,\n value: _value,\n defaultValue: _defaultValue,\n disabled: _disabled,\n onValueChange,\n }: NgpToggleGroupProps): NgpToggleGroupState => {\n const element = injectElementRef();\n\n const allowDeselection = controlled(_allowDeselection, true);\n const type = controlled(_type, 'single');\n const disabled = controlled(_disabled, false);\n const orientation = controlled(_orientation, 'horizontal');\n const wrap = controlled(_wrap, true);\n const defaultValue = controlled(_defaultValue, []);\n\n const [value, setValueInternal, valueChange] = controlledState<string[]>({\n value: _value,\n defaultValue,\n onChange: onValueChange,\n });\n\n // Own the roving focus group so it shares the group's `disabled` and\n // `orientation` signals directly. This keeps keyboard navigation in sync\n // with programmatic/form-driven changes (e.g. `setDisabled`, `setOrientation`)\n // without needing to re-push each value across a directive boundary.\n ngpRovingFocusGroup({ orientation, disabled, wrap });\n\n // Host bindings\n attrBinding(element, 'role', 'group');\n dataBinding(element, 'data-orientation', orientation);\n dataBinding(element, 'data-type', type);\n dataBinding(element, 'data-disabled', disabled);\n\n /**\n * Select a value in the toggle group.\n */\n function select(selection: string): void {\n if (disabled()) {\n return;\n }\n\n let newValue: string[] = [];\n\n if (type() === 'single') {\n newValue = [selection];\n } else {\n newValue = [...value(), selection];\n }\n\n setValue(newValue);\n }\n\n /**\n * De-select a value in the toggle group.\n */\n function deselect(selection: string): void {\n if (disabled() || !allowDeselection()) {\n return;\n }\n\n const newValue = value().filter(v => v !== selection);\n setValue(newValue);\n }\n\n /**\n * Check if a value is selected in the toggle group.\n * @internal\n */\n function isSelected(itemValue: string): boolean {\n return value().includes(itemValue);\n }\n\n /**\n * Toggle a value in the toggle group.\n * @internal\n */\n function toggle(itemValue: string): void {\n if (isSelected(itemValue)) {\n deselect(itemValue);\n } else {\n select(itemValue);\n }\n }\n\n function setValue(newValue: string[], options?: SetterOptions): void {\n setValueInternal(newValue, options);\n }\n\n function setDisabled(isDisabled: boolean): void {\n disabled.set(isDisabled);\n }\n\n function setOrientation(newOrientation: NgpOrientation): void {\n // The roving focus group shares this signal, so it stays in sync.\n orientation.set(newOrientation);\n }\n\n return {\n select,\n deselect,\n disabled: deprecatedSetter(disabled, 'setDisabled'),\n isSelected,\n toggle,\n value: deprecatedSetter(value, 'setValue', setValue),\n orientation: deprecatedSetter(orientation, 'setOrientation', setOrientation),\n setValue,\n setDefaultValue: defaultValue.set,\n setDisabled,\n setOrientation,\n valueChange,\n } satisfies NgpToggleGroupState;\n },\n);\n","import { computed, signal, Signal } from '@angular/core';\nimport { injectElementRef } from 'ng-primitives/internal';\nimport { attrBinding, createPrimitive, dataBinding, listener } from 'ng-primitives/state';\nimport { injectToggleGroupState } from '../toggle-group/toggle-group-state';\n\n/**\n * The state interface for the ToggleGroupItem pattern.\n */\nexport interface NgpToggleGroupItemState {\n selected: Signal<boolean>;\n toggle(): void;\n}\n\n/**\n * The props interface for the ToggleGroupItem pattern.\n */\nexport interface NgpToggleGroupItemProps {\n /**\n * The value of the toggle group item.\n */\n value: Signal<string>;\n\n /**\n * Whether the toggle group item is disabled.\n */\n disabled?: Signal<boolean>;\n}\n\nexport const [\n NgpToggleGroupItemToken,\n ngpToggleGroupItem,\n injectToggleGroupItemState,\n provideToggleGroupItemState,\n] = createPrimitive(\n 'NgpToggleGroupItem',\n ({ value, disabled = signal(false) }: NgpToggleGroupItemProps): NgpToggleGroupItemState => {\n const element = injectElementRef();\n const toggleGroup = injectToggleGroupState();\n\n // Whether the item is selected.\n const selected = computed(() => toggleGroup()?.isSelected(value()!) ?? false);\n\n // Host bindings\n attrBinding(element, 'role', 'radio');\n attrBinding(element, 'aria-checked', selected);\n dataBinding(element, 'data-selected', selected);\n attrBinding(element, 'aria-disabled', disabled);\n dataBinding(element, 'data-disabled', disabled);\n\n // Host listener\n listener(element, 'click', () => toggle());\n\n // Toggle the item.\n const toggle = (): void => {\n if (disabled?.()) {\n return;\n }\n toggleGroup()?.toggle(value()!);\n };\n\n return { selected, toggle } satisfies NgpToggleGroupItemState;\n },\n);\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input, OnInit, Signal } from '@angular/core';\nimport { ngpRovingFocusItem, provideRovingFocusItemState } from 'ng-primitives/roving-focus';\nimport { ngpToggleGroupItem, provideToggleGroupItemState } from './toggle-group-item-state';\n\n@Directive({\n selector: '[ngpToggleGroupItem]',\n exportAs: 'ngpToggleGroupItem',\n providers: [provideToggleGroupItemState(), provideRovingFocusItemState()],\n})\nexport class NgpToggleGroupItem implements OnInit {\n /**\n * The value of the item.\n * @required\n */\n readonly value = input<string>(undefined, {\n alias: 'ngpToggleGroupItemValue',\n });\n\n /**\n * Whether the item is disabled.\n */\n readonly disabled = input<boolean, BooleanInput>(false, {\n alias: 'ngpToggleGroupItemDisabled',\n transform: booleanAttribute,\n });\n\n constructor() {\n ngpToggleGroupItem({\n value: this.value as Signal<string>,\n disabled: this.disabled,\n });\n // Initialize the roving focus item state\n ngpRovingFocusItem({ disabled: this.disabled });\n }\n\n ngOnInit(): void {\n // we can't use a required input for value as it is used in a computed property before the input is set\n if (this.value() === undefined) {\n throw new Error('The value input is required for the toggle group item.');\n }\n }\n}\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input, output } from '@angular/core';\nimport { NgpOrientation } from 'ng-primitives/common';\nimport { provideRovingFocusGroupState } from 'ng-primitives/roving-focus';\nimport { SetterOptions } from 'ng-primitives/state';\nimport { injectToggleGroupConfig } from '../config/toggle-group-config';\nimport { ngpToggleGroup, provideToggleGroupState } from './toggle-group-state';\n\n@Directive({\n selector: '[ngpToggleGroup]',\n exportAs: 'ngpToggleGroup',\n providers: [provideToggleGroupState(), provideRovingFocusGroupState({ inherit: true })],\n})\nexport class NgpToggleGroup {\n /**\n * Access the global toggle group configuration.\n */\n private readonly config = injectToggleGroupConfig();\n\n /**\n * The orientation of the toggle group.\n */\n readonly orientation = input<NgpOrientation>(this.config.orientation, {\n alias: 'ngpToggleGroupOrientation',\n });\n\n /**\n * Whether focus should wrap around when reaching the end of the toggle group.\n * @default true\n */\n readonly wrap = input<boolean, BooleanInput>(this.config.wrap, {\n alias: 'ngpToggleGroupWrap',\n transform: booleanAttribute,\n });\n\n /**\n * Whether toggle buttons can be deselected. If set to `false`, clicking a selected toggle button will not deselect it.\n * @default true\n */\n readonly allowDeselection = input<boolean, BooleanInput>(this.config.allowDeselection, {\n alias: 'ngpToggleGroupAllowDeselection',\n transform: booleanAttribute,\n });\n\n /**\n * The type of the toggle group, whether only one item can be selected or multiple.\n */\n readonly type = input<'single' | 'multiple'>(this.config.type, { alias: 'ngpToggleGroupType' });\n\n /**\n * The selected value(s) of the toggle group.\n */\n readonly value = input<string[] | undefined>(undefined, { alias: 'ngpToggleGroupValue' });\n\n /**\n * The default selected value(s) for uncontrolled usage.\n * @default []\n */\n readonly defaultValue = input<string[]>([], { alias: 'ngpToggleGroupDefaultValue' });\n\n /**\n * Emits when the value of the toggle group changes.\n */\n readonly valueChange = output<string[]>({ alias: 'ngpToggleGroupValueChange' });\n\n /**\n * Whether the toggle group is disabled.\n */\n readonly disabled = input<boolean, BooleanInput>(false, {\n alias: 'ngpToggleGroupDisabled',\n transform: booleanAttribute,\n });\n\n /**\n * The state of the toggle group.\n */\n protected readonly state = ngpToggleGroup({\n orientation: this.orientation,\n wrap: this.wrap,\n allowDeselection: this.allowDeselection,\n type: this.type,\n value: this.value,\n defaultValue: this.defaultValue,\n disabled: this.disabled,\n onValueChange: (value: string[]) => this.valueChange.emit(value),\n });\n\n /**\n * Toggle a value in the toggle group.\n */\n toggle(value: string): void {\n this.state.toggle(value);\n }\n\n /**\n * Set the value(s) of the toggle group.\n */\n setValue(newValue: string[], options?: SetterOptions): void {\n this.state.setValue(newValue, options);\n }\n\n /**\n * Set the default value(s) of the toggle group.\n */\n setDefaultValue(defaultValue: string[]): void {\n this.state.setDefaultValue(defaultValue);\n }\n\n /**\n * Set the disabled state of the toggle group.\n */\n setDisabled(isDisabled: boolean): void {\n this.state.setDisabled(isDisabled);\n }\n\n /**\n * Set the orientation of the toggle group.\n */\n setOrientation(newOrientation: NgpOrientation): void {\n this.state.setOrientation(newOrientation);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AA6BO,MAAM,wBAAwB,GAAyB;AAC5D,IAAA,WAAW,EAAE,YAAY;AACzB,IAAA,IAAI,EAAE,QAAQ;AACd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EAAE,CAAC,uBAAuB,EAAE,EAAE,4BAA4B,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACxF,iBAAA;;;ACZD;;AAEG;;;;"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ng-primitives",
3
3
  "description": "Angular Primitives is a low-level headless UI component library with a focus on accessibility, customization, and developer experience. ",
4
4
  "license": "Apache-2.0",
5
- "version": "0.123.0",
5
+ "version": "0.124.0",
6
6
  "keywords": [
7
7
  "angular",
8
8
  "primitives",
@@ -1,7 +1,12 @@
1
1
  import { Component } from '@angular/core';
2
2
  import { ControlValueAccessor } from '@angular/forms';
3
3
  import { injectRadioGroupState, NgpRadioGroup } from 'ng-primitives/radio';
4
- import { ChangeFn, provideValueAccessor, TouchedFn } from 'ng-primitives/utils';
4
+ import {
5
+ ChangeFn,
6
+ provideValueAccessor,
7
+ safeTakeUntilDestroyed,
8
+ TouchedFn,
9
+ } from 'ng-primitives/utils';
5
10
 
6
11
  @Component({
7
12
  selector: '<%= prefix %>-radio-group',
@@ -44,12 +49,14 @@ export class RadioGroup<%= componentSuffix %> implements ControlValueAccessor {
44
49
  protected onTouched?: TouchedFn;
45
50
 
46
51
  constructor() {
47
- this.state().valueChange.subscribe(value => this.onChange?.(value));
52
+ this.state()
53
+ .valueChange.pipe(safeTakeUntilDestroyed())
54
+ .subscribe(value => this.onChange?.(value));
48
55
  }
49
56
 
50
57
  /** Write a new value to the radio group */
51
- writeValue(value: string): void {
52
- this.state().value.set(value);
58
+ writeValue(value: string | null): void {
59
+ this.state().setValue(value, { emit: false });
53
60
  }
54
61
 
55
62
  /** Register the on change callback */
@@ -61,4 +68,9 @@ export class RadioGroup<%= componentSuffix %> implements ControlValueAccessor {
61
68
  registerOnTouched(onTouched: TouchedFn): void {
62
69
  this.onTouched = onTouched;
63
70
  }
71
+
72
+ /** Set the disabled state of the radio group */
73
+ setDisabledState(isDisabled: boolean): void {
74
+ this.state().setDisabled(isDisabled);
75
+ }
64
76
  }
@@ -1,29 +1,27 @@
1
- import * as ng_primitives_state from 'ng-primitives/state';
2
- import { InjectedState } from 'ng-primitives/state';
1
+ import * as ng_primitives_radio from 'ng-primitives/radio';
3
2
  import * as _angular_core from '@angular/core';
4
- import { OnInit } from '@angular/core';
3
+ import { Signal, WritableSignal, OnInit } from '@angular/core';
5
4
  import { BooleanInput } from '@angular/cdk/coercion';
6
5
  import { NgpOrientation } from 'ng-primitives/common';
7
- import * as i1 from 'ng-primitives/roving-focus';
8
- import * as ng_primitives_radio from 'ng-primitives/radio';
9
- import * as i2 from 'ng-primitives/interactions';
6
+ import { StateInjectionOptions, SetterOptions } from 'ng-primitives/state';
7
+ import { Observable } from 'rxjs';
10
8
 
11
9
  /**
12
10
  * Apply the `ngpRadioGroup` directive to an element that represents the group of radio items.
13
11
  */
14
- declare class NgpRadioGroup<T> implements OnInit {
15
- /**
16
- * Access the roving focus group state.
17
- */
18
- private readonly rovingFocusGroupState;
12
+ declare class NgpRadioGroup<T> {
19
13
  /**
20
14
  * The id of the radio group. If not provided, a unique id will be generated.
21
15
  */
22
16
  readonly id: _angular_core.InputSignal<string>;
23
17
  /**
24
- * The value of the radio group.
18
+ * The value of the radio group. Leave unset for uncontrolled usage.
19
+ */
20
+ readonly value: _angular_core.InputSignal<T | null | undefined>;
21
+ /**
22
+ * The default value of the radio group for uncontrolled usage.
25
23
  */
26
- readonly value: _angular_core.InputSignal<T | null>;
24
+ readonly defaultValue: _angular_core.InputSignal<T | null>;
27
25
  /**
28
26
  * Event emitted when the radio group value changes.
29
27
  */
@@ -44,57 +42,140 @@ declare class NgpRadioGroup<T> implements OnInit {
44
42
  readonly compareWith: _angular_core.InputSignal<(a: T | null, b: T | null) => boolean>;
45
43
  /**
46
44
  * The state of the radio group.
47
- * @internal
48
45
  */
49
- protected readonly state: ng_primitives_state.CreatedState<NgpRadioGroup<T>>;
50
- constructor();
51
- ngOnInit(): void;
46
+ protected readonly state: ng_primitives_radio.NgpRadioGroupState<T>;
52
47
  /**
53
48
  * Select a radio item.
54
49
  * @param value The value of the radio item to select.
55
50
  */
56
51
  select(value: T): void;
52
+ /**
53
+ * Set the default value of the radio group.
54
+ */
55
+ setDefaultValue(value: T | null): void;
56
+ /**
57
+ * Set the orientation of the radio group.
58
+ */
59
+ setOrientation(orientation: NgpOrientation): void;
57
60
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRadioGroup<any>, never>;
58
- static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRadioGroup<any>, "[ngpRadioGroup]", never, { "id": { "alias": "id"; "required": false; "isSignal": true; }; "value": { "alias": "ngpRadioGroupValue"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRadioGroupDisabled"; "required": false; "isSignal": true; }; "orientation": { "alias": "ngpRadioGroupOrientation"; "required": false; "isSignal": true; }; "compareWith": { "alias": "ngpRadioGroupCompareWith"; "required": false; "isSignal": true; }; }, { "valueChange": "ngpRadioGroupValueChange"; }, never, never, true, [{ directive: typeof i1.NgpRovingFocusGroup; inputs: { "ngpRovingFocusGroupOrientation": "ngpRadioGroupOrientation"; "ngpRovingFocusGroupDisabled": "ngpRadioGroupDisabled"; }; outputs: {}; }]>;
61
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRadioGroup<any>, "[ngpRadioGroup]", never, { "id": { "alias": "id"; "required": false; "isSignal": true; }; "value": { "alias": "ngpRadioGroupValue"; "required": false; "isSignal": true; }; "defaultValue": { "alias": "ngpRadioGroupDefaultValue"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRadioGroupDisabled"; "required": false; "isSignal": true; }; "orientation": { "alias": "ngpRadioGroupOrientation"; "required": false; "isSignal": true; }; "compareWith": { "alias": "ngpRadioGroupCompareWith"; "required": false; "isSignal": true; }; }, { "valueChange": "ngpRadioGroupValueChange"; }, never, never, true, never>;
59
62
  }
60
63
 
61
64
  /**
62
- * Provides the RadioGroup state.
65
+ * Public state surface for the RadioGroup primitive.
66
+ */
67
+ interface NgpRadioGroupState<T> {
68
+ /**
69
+ * The id of the radio group.
70
+ */
71
+ readonly id: Signal<string>;
72
+ /**
73
+ * The selected value of the radio group.
74
+ */
75
+ readonly value: WritableSignal<T | null>;
76
+ /**
77
+ * Whether the radio group is disabled.
78
+ */
79
+ readonly disabled: WritableSignal<boolean>;
80
+ /**
81
+ * The orientation of the radio group.
82
+ */
83
+ readonly orientation: WritableSignal<NgpOrientation>;
84
+ /**
85
+ * The comparator function used to compare values.
86
+ */
87
+ readonly compareWith: Signal<(a: T | null, b: T | null) => boolean>;
88
+ /**
89
+ * Emits when the selected value changes.
90
+ */
91
+ readonly valueChange: Observable<T | null>;
92
+ /**
93
+ * Select a value in the radio group.
94
+ */
95
+ select(value: T): void;
96
+ /**
97
+ * Set the value of the radio group. Fires `onValueChange` and emits on the
98
+ * `valueChange` observable by default. Pass `{ emit: false }` for cases like
99
+ * form `writeValue` where the internal state should sync without notifying.
100
+ */
101
+ setValue(value: T | null, options?: SetterOptions): void;
102
+ /**
103
+ * Set the default value used for uncontrolled usage.
104
+ */
105
+ setDefaultValue(value: T | null): void;
106
+ /**
107
+ * Set the disabled value.
108
+ */
109
+ setDisabled(value: boolean): void;
110
+ /**
111
+ * Set the orientation of the radio group.
112
+ */
113
+ setOrientation(value: NgpOrientation): void;
114
+ }
115
+ /**
116
+ * Inputs for configuring the RadioGroup primitive.
63
117
  */
64
- declare const provideRadioGroupState: (options?: ng_primitives_state.CreateStateProviderOptions) => _angular_core.FactoryProvider;
118
+ interface NgpRadioGroupProps<T> {
119
+ /**
120
+ * The id of the radio group.
121
+ */
122
+ readonly id?: Signal<string>;
123
+ /**
124
+ * The selected value of the radio group. Leave `undefined` for uncontrolled
125
+ * usage (the group manages its own value from `defaultValue`).
126
+ */
127
+ readonly value?: Signal<T | null | undefined>;
128
+ /**
129
+ * The default value for uncontrolled usage.
130
+ */
131
+ readonly defaultValue?: Signal<T | null>;
132
+ /**
133
+ * Whether the radio group is disabled.
134
+ */
135
+ readonly disabled?: Signal<boolean>;
136
+ /**
137
+ * The orientation of the radio group.
138
+ */
139
+ readonly orientation?: Signal<NgpOrientation>;
140
+ /**
141
+ * The comparator function used to compare values.
142
+ */
143
+ readonly compareWith?: Signal<(a: T | null, b: T | null) => boolean>;
144
+ /**
145
+ * Callback fired when the selected value changes.
146
+ */
147
+ readonly onValueChange?: (value: T | null) => void;
148
+ }
149
+ declare const ngpRadioGroup: <T>({ id, value: _value, defaultValue: _defaultValue, disabled: _disabled, orientation: _orientation, compareWith, onValueChange, }: NgpRadioGroupProps<T>) => NgpRadioGroupState<T>;
150
+ declare const provideRadioGroupState: (opts?: {
151
+ inherit?: boolean;
152
+ }) => _angular_core.FactoryProvider;
65
153
  /**
66
154
  * Injects the RadioGroup state.
67
155
  */
68
- declare const injectRadioGroupState: <T>() => InjectedState<NgpRadioGroup<T>>;
156
+ declare function injectRadioGroupState<T>(options?: StateInjectionOptions): Signal<NgpRadioGroupState<T>>;
69
157
 
70
158
  /**
71
159
  * Apply the `ngpRadioIndicator` directive to an element that represents the radio indicator (i.e. the dot).
72
160
  */
73
161
  declare class NgpRadioIndicator<T> {
74
- /**
75
- * Access the radio group state.
76
- */
77
- protected readonly radioGroupState: ng_primitives_state.InjectedState<ng_primitives_radio.NgpRadioGroup<T>>;
78
162
  /**
79
163
  * Access the radio group item state
80
164
  */
81
- protected readonly radioItemState: ng_primitives_state.InjectedState<ng_primitives_radio.NgpRadioItem<T>>;
165
+ protected readonly radioItemState: _angular_core.Signal<ng_primitives_radio.NgpRadioItemState<T>>;
82
166
  /**
83
- * Determine if the radio indicator is checked.
167
+ * Determine if the radio indicator is checked. Delegates to the item's
168
+ * checked state so it honours the group's `compareWith` comparator.
84
169
  */
85
170
  protected readonly checked: _angular_core.Signal<boolean>;
86
171
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRadioIndicator<any>, never>;
87
- static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRadioIndicator<any>, "[ngpRadioIndicator]", never, {}, {}, never, never, true, [{ directive: typeof i2.NgpHover; inputs: {}; outputs: {}; }, { directive: typeof i2.NgpPress; inputs: {}; outputs: {}; }]>;
172
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRadioIndicator<any>, "[ngpRadioIndicator]", never, {}, {}, never, never, true, never>;
88
173
  }
89
174
 
90
175
  /**
91
176
  * Apply the `ngpRadioItem` directive to an element that represents a radio item. This would typically be a `button` element.
92
177
  */
93
178
  declare class NgpRadioItem<T> implements OnInit {
94
- /**
95
- * Access the radio group state.
96
- */
97
- private readonly radioGroupState;
98
179
  /**
99
180
  * The value of the radio item.
100
181
  * @required
@@ -105,36 +186,50 @@ declare class NgpRadioItem<T> implements OnInit {
105
186
  * @default false
106
187
  */
107
188
  readonly disabled: _angular_core.InputSignalWithTransform<boolean, BooleanInput>;
189
+ constructor();
190
+ ngOnInit(): void;
191
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRadioItem<any>, never>;
192
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRadioItem<any>, "[ngpRadioItem]", never, { "value": { "alias": "ngpRadioItemValue"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRadioItemDisabled"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
193
+ }
194
+
195
+ /**
196
+ * Public state surface for the RadioItem primitive.
197
+ */
198
+ interface NgpRadioItemState<T> {
108
199
  /**
109
- * Whether the radio item is checked.
110
- */
111
- readonly checked: _angular_core.Signal<boolean>;
112
- /**
113
- * The state of the radio item.
200
+ * The value of the radio item.
114
201
  */
115
- protected readonly state: ng_primitives_state.CreatedState<NgpRadioItem<T>>;
116
- ngOnInit(): void;
202
+ readonly value: Signal<T>;
117
203
  /**
118
- * When the item receives focus, select it.
119
- * @internal
204
+ * Whether the radio item is disabled.
120
205
  */
121
- protected onFocus(): void;
206
+ readonly disabled: Signal<boolean>;
122
207
  /**
123
- * When the item receives a click, select it.
124
- * @internal
208
+ * Whether the radio item is checked.
125
209
  */
126
- protected onClick(): void;
127
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRadioItem<any>, never>;
128
- static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRadioItem<any>, "[ngpRadioItem]", never, { "value": { "alias": "ngpRadioItemValue"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRadioItemDisabled"; "required": false; "isSignal": true; }; }, {}, never, never, true, [{ directive: typeof i1.NgpRovingFocusItem; inputs: {}; outputs: {}; }, { directive: typeof i2.NgpHover; inputs: {}; outputs: {}; }, { directive: typeof i2.NgpFocusVisible; inputs: {}; outputs: {}; }, { directive: typeof i2.NgpPress; inputs: {}; outputs: {}; }]>;
210
+ readonly checked: Signal<boolean>;
129
211
  }
130
-
131
212
  /**
132
- * Provides the RadioItem state.
213
+ * Inputs for configuring the RadioItem primitive.
133
214
  */
134
- declare const provideRadioItemState: (options?: ng_primitives_state.CreateStateProviderOptions) => _angular_core.FactoryProvider;
215
+ interface NgpRadioItemProps<T> {
216
+ /**
217
+ * The value of the radio item.
218
+ */
219
+ readonly value: Signal<T>;
220
+ /**
221
+ * Whether the radio item is disabled.
222
+ */
223
+ readonly disabled?: Signal<boolean>;
224
+ }
225
+ declare const ngpRadioItem: <T>({ value, disabled }: NgpRadioItemProps<T>) => NgpRadioItemState<T>;
226
+ declare const provideRadioItemState: (opts?: {
227
+ inherit?: boolean;
228
+ }) => _angular_core.FactoryProvider;
135
229
  /**
136
230
  * Injects the RadioItem state.
137
231
  */
138
- declare const injectRadioItemState: <T>() => InjectedState<NgpRadioItem<T>>;
232
+ declare function injectRadioItemState<T>(options?: StateInjectionOptions): Signal<NgpRadioItemState<T>>;
139
233
 
140
- export { NgpRadioGroup, NgpRadioIndicator, NgpRadioItem, injectRadioGroupState, injectRadioItemState, provideRadioGroupState, provideRadioItemState };
234
+ export { NgpRadioGroup, NgpRadioIndicator, NgpRadioItem, injectRadioGroupState, injectRadioItemState, ngpRadioGroup, ngpRadioItem, provideRadioGroupState, provideRadioItemState };
235
+ export type { NgpRadioGroupProps, NgpRadioGroupState, NgpRadioItemProps, NgpRadioItemState };
@@ -5,7 +5,6 @@ import { BooleanInput } from '@angular/cdk/coercion';
5
5
  import * as ng_primitives_state from 'ng-primitives/state';
6
6
  import { SetterOptions } from 'ng-primitives/state';
7
7
  import * as ng_primitives_toggle_group from 'ng-primitives/toggle-group';
8
- import { NgpRovingFocusGroupState } from 'ng-primitives/roving-focus';
9
8
  import { Observable } from 'rxjs';
10
9
 
11
10
  interface NgpToggleGroupConfig {
@@ -208,14 +207,14 @@ interface NgpToggleGroupState {
208
207
  * The props interface for the ToggleGroup pattern.
209
208
  */
210
209
  interface NgpToggleGroupProps {
211
- /**
212
- * The roving focus group state for the toggle-group.
213
- */
214
- readonly rovingFocusGroup: NgpRovingFocusGroupState;
215
210
  /**
216
211
  * The orientation of the toggle-group.
217
212
  */
218
213
  readonly orientation?: Signal<NgpOrientation>;
214
+ /**
215
+ * Whether focus should wrap around when reaching the end of the toggle-group.
216
+ */
217
+ readonly wrap?: Signal<boolean>;
219
218
  /**
220
219
  * Whether deselection is allowed in the toggle-group.
221
220
  */
@@ -241,7 +240,7 @@ interface NgpToggleGroupProps {
241
240
  */
242
241
  readonly onValueChange?: (value: string[]) => void;
243
242
  }
244
- declare const ngpToggleGroup: ({ rovingFocusGroup, orientation: _orientation, allowDeselection: _allowDeselection, type: _type, value: _value, defaultValue: _defaultValue, disabled: _disabled, onValueChange, }: NgpToggleGroupProps) => NgpToggleGroupState;
243
+ declare const ngpToggleGroup: ({ orientation: _orientation, wrap: _wrap, allowDeselection: _allowDeselection, type: _type, value: _value, defaultValue: _defaultValue, disabled: _disabled, onValueChange, }: NgpToggleGroupProps) => NgpToggleGroupState;
245
244
  declare const injectToggleGroupState: {
246
245
  (): Signal<NgpToggleGroupState>;
247
246
  (options: ng_primitives_state.StateInjectionOptions): Signal<NgpToggleGroupState | null>;