ng-primitives 0.74.0 → 0.75.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.
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.74.0",
5
+ "version": "0.75.0",
6
6
  "keywords": [
7
7
  "angular",
8
8
  "primitives",
@@ -67,21 +67,25 @@
67
67
  "types": "./a11y/index.d.ts",
68
68
  "default": "./fesm2022/ng-primitives-a11y.mjs"
69
69
  },
70
+ "./accordion": {
71
+ "types": "./accordion/index.d.ts",
72
+ "default": "./fesm2022/ng-primitives-accordion.mjs"
73
+ },
70
74
  "./autofill": {
71
75
  "types": "./autofill/index.d.ts",
72
76
  "default": "./fesm2022/ng-primitives-autofill.mjs"
73
77
  },
74
- "./accordion": {
75
- "types": "./accordion/index.d.ts",
76
- "default": "./fesm2022/ng-primitives-accordion.mjs"
78
+ "./avatar": {
79
+ "types": "./avatar/index.d.ts",
80
+ "default": "./fesm2022/ng-primitives-avatar.mjs"
77
81
  },
78
82
  "./button": {
79
83
  "types": "./button/index.d.ts",
80
84
  "default": "./fesm2022/ng-primitives-button.mjs"
81
85
  },
82
- "./avatar": {
83
- "types": "./avatar/index.d.ts",
84
- "default": "./fesm2022/ng-primitives-avatar.mjs"
86
+ "./checkbox": {
87
+ "types": "./checkbox/index.d.ts",
88
+ "default": "./fesm2022/ng-primitives-checkbox.mjs"
85
89
  },
86
90
  "./combobox": {
87
91
  "types": "./combobox/index.d.ts",
@@ -91,10 +95,6 @@
91
95
  "types": "./common/index.d.ts",
92
96
  "default": "./fesm2022/ng-primitives-common.mjs"
93
97
  },
94
- "./checkbox": {
95
- "types": "./checkbox/index.d.ts",
96
- "default": "./fesm2022/ng-primitives-checkbox.mjs"
97
- },
98
98
  "./date-picker": {
99
99
  "types": "./date-picker/index.d.ts",
100
100
  "default": "./fesm2022/ng-primitives-date-picker.mjs"
@@ -103,14 +103,14 @@
103
103
  "types": "./date-time/index.d.ts",
104
104
  "default": "./fesm2022/ng-primitives-date-time.mjs"
105
105
  },
106
- "./dialog": {
107
- "types": "./dialog/index.d.ts",
108
- "default": "./fesm2022/ng-primitives-dialog.mjs"
109
- },
110
106
  "./date-time-luxon": {
111
107
  "types": "./date-time-luxon/index.d.ts",
112
108
  "default": "./fesm2022/ng-primitives-date-time-luxon.mjs"
113
109
  },
110
+ "./dialog": {
111
+ "types": "./dialog/index.d.ts",
112
+ "default": "./fesm2022/ng-primitives-dialog.mjs"
113
+ },
114
114
  "./file-upload": {
115
115
  "types": "./file-upload/index.d.ts",
116
116
  "default": "./fesm2022/ng-primitives-file-upload.mjs"
@@ -0,0 +1,136 @@
1
+ import { Component, input } from '@angular/core';
2
+ import { ControlValueAccessor } from '@angular/forms';
3
+ import { explicitEffect } from 'ng-primitives/internal';
4
+ import {
5
+ injectRangeSliderState,
6
+ NgpRangeSlider,
7
+ NgpRangeSliderRange,
8
+ NgpRangeSliderThumb,
9
+ NgpRangeSliderTrack,
10
+ provideRangeSliderState,
11
+ } from 'ng-primitives/slider';
12
+ import { ChangeFn, provideValueAccessor, TouchedFn } from 'ng-primitives/utils';
13
+
14
+ @Component({
15
+ selector: '<%= prefix %>-range-slider',
16
+ hostDirectives: [
17
+ {
18
+ directive: NgpRangeSlider,
19
+ inputs: [
20
+ 'ngpRangeSliderLow:low',
21
+ 'ngpRangeSliderHigh:high',
22
+ 'ngpRangeSliderMin:min',
23
+ 'ngpRangeSliderMax:max',
24
+ 'ngpRangeSliderStep:step',
25
+ 'ngpRangeSliderDisabled:disabled',
26
+ 'ngpRangeSliderOrientation:orientation',
27
+ ],
28
+ outputs: ['ngpRangeSliderLowChange:lowChange', 'ngpRangeSliderHighChange:highChange'],
29
+ },
30
+ ],
31
+ imports: [NgpRangeSliderTrack, NgpRangeSliderRange, NgpRangeSliderThumb],
32
+ providers: [provideRangeSliderState(), provideValueAccessor(RangeSlider<%= componentSuffix %>)],
33
+ template: `
34
+ <div ngpRangeSliderTrack>
35
+ <div ngpRangeSliderRange></div>
36
+ </div>
37
+ <div ngpRangeSliderThumb></div>
38
+ <div ngpRangeSliderThumb></div>
39
+ `,
40
+ styles: `
41
+ /* These styles rely on CSS variables that can be imported from ng-primitives/example-theme/index.css in your global styles */
42
+
43
+ :host {
44
+ display: flex;
45
+ position: relative;
46
+ width: 200px;
47
+ height: 20px;
48
+ touch-action: none;
49
+ user-select: none;
50
+ align-items: center;
51
+ }
52
+
53
+ [ngpRangeSliderTrack] {
54
+ position: relative;
55
+ height: 5px;
56
+ width: 100%;
57
+ border-radius: 999px;
58
+ background-color: var(--ngp-background-secondary);
59
+ }
60
+
61
+ [ngpRangeSliderRange] {
62
+ position: absolute;
63
+ height: 100%;
64
+ border-radius: 999px;
65
+ background-color: var(--ngp-background-inverse);
66
+ }
67
+
68
+ [ngpRangeSliderThumb] {
69
+ position: absolute;
70
+ display: block;
71
+ height: 20px;
72
+ width: 20px;
73
+ border-radius: 10px;
74
+ background-color: white;
75
+ box-shadow: var(--ngp-button-shadow);
76
+ outline: none;
77
+ transform: translateX(-50%);
78
+ }
79
+
80
+ [ngpRangeSliderThumb][data-focus-visible] {
81
+ outline: 2px solid var(--ngp-focus-ring);
82
+ outline-offset: 0;
83
+ }
84
+
85
+ [ngpRangeSliderThumb][data-thumb='high'] {
86
+ z-index: 2;
87
+ }
88
+ `,
89
+ host: {
90
+ '(focusout)': 'onTouched?.()',
91
+ },
92
+ })
93
+ export class RangeSlider<%= componentSuffix %> implements ControlValueAccessor {
94
+ /** Access the range slider state */
95
+ private readonly state = injectRangeSliderState();
96
+
97
+ /** Forward aria-labels to each thumb */
98
+ readonly ariaLabelLow = input<string | null>(null);
99
+ readonly ariaLabelHigh = input<string | null>(null);
100
+
101
+ /** The onChange callback function. */
102
+ private onChange?: ChangeFn<[number, number]>;
103
+
104
+ /** The onTouched callback function. */
105
+ protected onTouched?: TouchedFn;
106
+
107
+ constructor() {
108
+ // Whenever either value changes, call the onChange function with the new tuple [low, high].
109
+ explicitEffect([this.state().low, this.state().high], ([low, high]) =>
110
+ this.onChange?.([low, high]),
111
+ );
112
+ }
113
+
114
+ writeValue(value: [number, number]): void {
115
+ if (!value || value.length !== 2) {
116
+ return;
117
+ }
118
+
119
+ const [low, high] = value;
120
+ // Use the directive's clamping setters to respect min/max and ordering
121
+ this.state().setLowValue(low);
122
+ this.state().setHighValue(high);
123
+ }
124
+
125
+ registerOnChange(fn: ChangeFn<[number, number]>): void {
126
+ this.onChange = fn;
127
+ }
128
+
129
+ registerOnTouched(fn: TouchedFn): void {
130
+ this.onTouched = fn;
131
+ }
132
+
133
+ setDisabledState(isDisabled: boolean): void {
134
+ this.state().disabled.set(isDisabled);
135
+ }
136
+ }
package/slider/index.d.ts CHANGED
@@ -3,3 +3,8 @@ export { NgpSliderThumb } from './slider-thumb/slider-thumb';
3
3
  export { NgpSliderTrack } from './slider-track/slider-track';
4
4
  export { NgpSlider } from './slider/slider';
5
5
  export { injectSliderState, provideSliderState } from './slider/slider-state';
6
+ export { NgpRangeSliderRange } from './range-slider/range-slider-range/range-slider-range';
7
+ export { NgpRangeSliderThumb } from './range-slider/range-slider-thumb/range-slider-thumb';
8
+ export { NgpRangeSliderTrack } from './range-slider/range-slider-track/range-slider-track';
9
+ export { NgpRangeSlider } from './range-slider/range-slider/range-slider';
10
+ export { injectRangeSliderState, provideRangeSliderState, } from './range-slider/range-slider/range-slider-state';
@@ -0,0 +1,17 @@
1
+ import type { NgpRangeSlider } from './range-slider';
2
+ /**
3
+ * The state token for the Range Slider primitive.
4
+ */
5
+ export declare const NgpRangeSliderStateToken: import("@angular/core").InjectionToken<NgpRangeSlider>;
6
+ /**
7
+ * Provides the Range Slider state.
8
+ */
9
+ export declare const provideRangeSliderState: (options?: import("ng-primitives/state").CreateStateProviderOptions) => import("@angular/core").FactoryProvider;
10
+ /**
11
+ * Injects the Range Slider state.
12
+ */
13
+ export declare const injectRangeSliderState: <U = NgpRangeSlider>(injectOptions?: import("@angular/core").InjectOptions) => import("@angular/core").Signal<import("ng-primitives/state").State<U>>;
14
+ /**
15
+ * The Range Slider state registration function.
16
+ */
17
+ export declare const rangeSliderState: <U>(state: U) => import("ng-primitives/state").CreatedState<U>;
@@ -0,0 +1,115 @@
1
+ import { BooleanInput, NumberInput } from '@angular/cdk/coercion';
2
+ import { NgpOrientation } from 'ng-primitives/common';
3
+ import { NgpRangeSliderThumb } from '../range-slider-thumb/range-slider-thumb';
4
+ import type { NgpRangeSliderTrack } from '../range-slider-track/range-slider-track';
5
+ import * as i0 from "@angular/core";
6
+ /**
7
+ * Apply the `ngpRangeSlider` directive to an element that represents the range slider and contains the track, range, and thumbs.
8
+ */
9
+ export declare class NgpRangeSlider {
10
+ /**
11
+ * The id of the range slider. If not provided, a unique id will be generated.
12
+ */
13
+ readonly id: import("@angular/core").InputSignal<string>;
14
+ /**
15
+ * The low value of the range slider.
16
+ */
17
+ readonly low: import("@angular/core").InputSignalWithTransform<number, NumberInput>;
18
+ /**
19
+ * Emits when the low value changes.
20
+ */
21
+ readonly lowChange: import("@angular/core").OutputEmitterRef<number>;
22
+ /**
23
+ * The high value of the range slider.
24
+ */
25
+ readonly high: import("@angular/core").InputSignalWithTransform<number, NumberInput>;
26
+ /**
27
+ * Emits when the high value changes.
28
+ */
29
+ readonly highChange: import("@angular/core").OutputEmitterRef<number>;
30
+ /**
31
+ * The minimum value of the range slider.
32
+ */
33
+ readonly min: import("@angular/core").InputSignalWithTransform<number, NumberInput>;
34
+ /**
35
+ * The maximum value of the range slider.
36
+ */
37
+ readonly max: import("@angular/core").InputSignalWithTransform<number, NumberInput>;
38
+ /**
39
+ * The step value of the range slider.
40
+ */
41
+ readonly step: import("@angular/core").InputSignalWithTransform<number, NumberInput>;
42
+ /**
43
+ * The orientation of the range slider.
44
+ */
45
+ readonly orientation: import("@angular/core").InputSignal<NgpOrientation>;
46
+ /**
47
+ * The disabled state of the range slider.
48
+ */
49
+ readonly disabled: import("@angular/core").InputSignalWithTransform<boolean, BooleanInput>;
50
+ /**
51
+ * Access the slider track.
52
+ * @internal
53
+ */
54
+ readonly track: import("@angular/core").WritableSignal<NgpRangeSliderTrack | undefined>;
55
+ /**
56
+ * The thumbs of the range slider.
57
+ * @internal
58
+ */
59
+ readonly thumbs: import("@angular/core").WritableSignal<NgpRangeSliderThumb[]>;
60
+ /**
61
+ * The low value as a percentage based on the min and max values.
62
+ * @internal
63
+ */
64
+ readonly lowPercentage: import("@angular/core").Signal<number>;
65
+ /**
66
+ * The high value as a percentage based on the min and max values.
67
+ * @internal
68
+ */
69
+ readonly highPercentage: import("@angular/core").Signal<number>;
70
+ /**
71
+ * The range between low and high values as a percentage.
72
+ * @internal
73
+ */
74
+ readonly rangePercentage: import("@angular/core").Signal<number>;
75
+ /**
76
+ * The state of the range slider. We use this for the range slider state rather than relying on the inputs.
77
+ * @internal
78
+ */
79
+ protected readonly state: import("ng-primitives/state").CreatedState<NgpRangeSlider>;
80
+ constructor();
81
+ /**
82
+ * Updates the low value, ensuring it doesn't exceed the high value.
83
+ * @param value The new low value
84
+ * @internal
85
+ */
86
+ setLowValue(value: number): void;
87
+ /**
88
+ * Updates the high value, ensuring it doesn't go below the low value.
89
+ * @param value The new high value
90
+ * @internal
91
+ */
92
+ setHighValue(value: number): void;
93
+ /**
94
+ * Determines which thumb should be moved based on the position clicked.
95
+ * @param percentage The percentage position of the click
96
+ * @returns 'low' or 'high' indicating which thumb should move
97
+ *
98
+ * @internal
99
+ */
100
+ getClosestThumb(percentage: number): 'low' | 'high';
101
+ /**
102
+ * Updates the thumbs array when a new thumb is added.
103
+ * @param thumb The new thumb to add
104
+ * @internal
105
+ */
106
+ addThumb(thumb: NgpRangeSliderThumb): void;
107
+ /**
108
+ * Removes a thumb from the thumbs array.
109
+ * @param thumb The thumb to remove
110
+ * @internal
111
+ */
112
+ removeThumb(thumb: NgpRangeSliderThumb): void;
113
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgpRangeSlider, never>;
114
+ static ɵdir: i0.ɵɵDirectiveDeclaration<NgpRangeSlider, "[ngpRangeSlider]", ["ngpRangeSlider"], { "id": { "alias": "id"; "required": false; "isSignal": true; }; "low": { "alias": "ngpRangeSliderLow"; "required": false; "isSignal": true; }; "high": { "alias": "ngpRangeSliderHigh"; "required": false; "isSignal": true; }; "min": { "alias": "ngpRangeSliderMin"; "required": false; "isSignal": true; }; "max": { "alias": "ngpRangeSliderMax"; "required": false; "isSignal": true; }; "step": { "alias": "ngpRangeSliderStep"; "required": false; "isSignal": true; }; "orientation": { "alias": "ngpRangeSliderOrientation"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRangeSliderDisabled"; "required": false; "isSignal": true; }; }, { "lowChange": "ngpRangeSliderLowChange"; "highChange": "ngpRangeSliderHighChange"; }, never, never, true, never>;
115
+ }
@@ -0,0 +1,12 @@
1
+ import * as i0 from "@angular/core";
2
+ /**
3
+ * Apply the `ngpRangeSliderRange` directive to an element that represents the range between the low and high values.
4
+ */
5
+ export declare class NgpRangeSliderRange {
6
+ /**
7
+ * Access the range slider state.
8
+ */
9
+ protected readonly rangeSliderState: import("@angular/core").Signal<import("ng-primitives/state").State<import("ng-primitives/slider").NgpRangeSlider>>;
10
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgpRangeSliderRange, never>;
11
+ static ɵdir: i0.ɵɵDirectiveDeclaration<NgpRangeSliderRange, "[ngpRangeSliderRange]", ["ngpRangeSliderRange"], {}, {}, never, never, true, never>;
12
+ }
@@ -0,0 +1,44 @@
1
+ import { OnDestroy } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Apply the `ngpRangeSliderThumb` directive to an element that represents a thumb of the range slider.
5
+ * Each thumb can be configured to control either the 'low' or 'high' value.
6
+ */
7
+ export declare class NgpRangeSliderThumb implements OnDestroy {
8
+ /**
9
+ * Access the range slider state.
10
+ */
11
+ protected readonly state: import("@angular/core").Signal<import("ng-primitives/state").State<import("ng-primitives/slider").NgpRangeSlider>>;
12
+ /**
13
+ * Access the thumb element.
14
+ */
15
+ private readonly elementRef;
16
+ /**
17
+ * Determines which value this thumb controls ('low' or 'high').
18
+ */
19
+ protected readonly thumb: import("@angular/core").Signal<"low" | "high">;
20
+ /**
21
+ * Store the dragging state.
22
+ */
23
+ protected dragging: boolean;
24
+ /**
25
+ * Get the current value for this thumb.
26
+ */
27
+ protected readonly value: import("@angular/core").Signal<number>;
28
+ /**
29
+ * Get the current percentage for this thumb.
30
+ */
31
+ protected readonly percentage: import("@angular/core").Signal<number>;
32
+ constructor();
33
+ ngOnDestroy(): void;
34
+ protected handlePointerDown(event: PointerEvent): void;
35
+ protected handlePointerUp(): void;
36
+ protected handlePointerMove(event: PointerEvent): void;
37
+ /**
38
+ * Handle keyboard events.
39
+ * @param event
40
+ */
41
+ protected handleKeydown(event: KeyboardEvent): void;
42
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgpRangeSliderThumb, never>;
43
+ static ɵdir: i0.ɵɵDirectiveDeclaration<NgpRangeSliderThumb, "[ngpRangeSliderThumb]", ["ngpRangeSliderThumb"], {}, {}, never, never, true, never>;
44
+ }
@@ -0,0 +1,22 @@
1
+ import * as i0 from "@angular/core";
2
+ /**
3
+ * Apply the `ngpRangeSliderTrack` directive to an element that represents the track of the range slider.
4
+ */
5
+ export declare class NgpRangeSliderTrack {
6
+ /**
7
+ * Access the range slider state.
8
+ */
9
+ protected readonly rangeSliderState: import("@angular/core").Signal<import("ng-primitives/state").State<import("ng-primitives/slider").NgpRangeSlider>>;
10
+ /**
11
+ * The element that represents the slider track.
12
+ */
13
+ readonly element: import("@angular/core").ElementRef<HTMLElement>;
14
+ constructor();
15
+ /**
16
+ * When the slider track is clicked, update the closest thumb value.
17
+ * @param event The click event.
18
+ */
19
+ protected handlePointerDown(event: PointerEvent): void;
20
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgpRangeSliderTrack, never>;
21
+ static ɵdir: i0.ɵɵDirectiveDeclaration<NgpRangeSliderTrack, "[ngpRangeSliderTrack]", ["ngpRangeSliderTrack"], {}, {}, never, never, true, never>;
22
+ }