@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.
- package/fesm2022/radix-ng-primitives-accordion.mjs +105 -38
- package/fesm2022/radix-ng-primitives-accordion.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-alert-dialog.mjs +221 -129
- package/fesm2022/radix-ng-primitives-alert-dialog.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-arrow.mjs +20 -4
- package/fesm2022/radix-ng-primitives-arrow.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-aspect-ratio.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-avatar.mjs +54 -61
- package/fesm2022/radix-ng-primitives-avatar.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-button.mjs +123 -0
- package/fesm2022/radix-ng-primitives-button.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-calendar.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-checkbox.mjs +378 -54
- package/fesm2022/radix-ng-primitives-checkbox.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-collapsible.mjs +182 -81
- package/fesm2022/radix-ng-primitives-collapsible.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-collection.mjs +40 -57
- package/fesm2022/radix-ng-primitives-collection.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-config.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-context-menu.mjs +140 -424
- package/fesm2022/radix-ng-primitives-context-menu.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-core.mjs +735 -744
- package/fesm2022/radix-ng-primitives-core.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-cropper.mjs +1 -0
- package/fesm2022/radix-ng-primitives-cropper.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-date-field.mjs +51 -45
- package/fesm2022/radix-ng-primitives-date-field.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-dialog.mjs +655 -327
- package/fesm2022/radix-ng-primitives-dialog.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-dismissable-layer.mjs +70 -46
- package/fesm2022/radix-ng-primitives-dismissable-layer.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-drawer.mjs +1059 -0
- package/fesm2022/radix-ng-primitives-drawer.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-editable.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-field.mjs +363 -0
- package/fesm2022/radix-ng-primitives-field.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-fieldset.mjs +79 -0
- package/fesm2022/radix-ng-primitives-fieldset.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-focus-scope.mjs +23 -8
- package/fesm2022/radix-ng-primitives-focus-scope.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-input.mjs +172 -0
- package/fesm2022/radix-ng-primitives-input.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-label.mjs +6 -6
- package/fesm2022/radix-ng-primitives-label.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-menu.mjs +1480 -344
- package/fesm2022/radix-ng-primitives-menu.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-menubar.mjs +290 -162
- package/fesm2022/radix-ng-primitives-menubar.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-meter.mjs +271 -0
- package/fesm2022/radix-ng-primitives-meter.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-navigation-menu.mjs +1052 -1553
- package/fesm2022/radix-ng-primitives-navigation-menu.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-number-field.mjs +1102 -367
- package/fesm2022/radix-ng-primitives-number-field.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-pagination.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-popover.mjs +978 -989
- package/fesm2022/radix-ng-primitives-popover.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-popper.mjs +91 -41
- package/fesm2022/radix-ng-primitives-popper.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-portal.mjs +34 -10
- package/fesm2022/radix-ng-primitives-portal.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-presence.mjs +134 -246
- package/fesm2022/radix-ng-primitives-presence.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-preview-card.mjs +997 -0
- package/fesm2022/radix-ng-primitives-preview-card.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-progress.mjs +223 -84
- package/fesm2022/radix-ng-primitives-progress.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-radio.mjs +191 -51
- package/fesm2022/radix-ng-primitives-radio.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-roving-focus.mjs +96 -50
- package/fesm2022/radix-ng-primitives-roving-focus.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-select.mjs +791 -509
- package/fesm2022/radix-ng-primitives-select.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-separator.mjs +12 -35
- package/fesm2022/radix-ng-primitives-separator.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-slider.mjs +969 -717
- package/fesm2022/radix-ng-primitives-slider.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-stepper.mjs +15 -19
- package/fesm2022/radix-ng-primitives-stepper.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-switch.mjs +125 -113
- package/fesm2022/radix-ng-primitives-switch.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-tabs.mjs +381 -108
- package/fesm2022/radix-ng-primitives-tabs.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-time-field.mjs +55 -46
- package/fesm2022/radix-ng-primitives-time-field.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-toggle-group.mjs +121 -247
- package/fesm2022/radix-ng-primitives-toggle-group.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-toggle.mjs +98 -61
- package/fesm2022/radix-ng-primitives-toggle.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-toolbar.mjs +303 -92
- package/fesm2022/radix-ng-primitives-toolbar.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-tooltip.mjs +690 -1071
- package/fesm2022/radix-ng-primitives-tooltip.mjs.map +1 -1
- package/fesm2022/radix-ng-primitives-visually-hidden.mjs +25 -66
- package/fesm2022/radix-ng-primitives-visually-hidden.mjs.map +1 -1
- package/meter/README.md +3 -0
- package/navigation-menu/README.md +2 -1
- package/package.json +31 -18
- package/portal/README.md +2 -0
- package/preview-card/README.md +3 -0
- package/schematics/collection.json +1 -0
- package/schematics/ng-add/index.d.ts +3 -2
- package/schematics/ng-add/index.js +62 -31
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/package-config.d.ts +4 -2
- package/schematics/ng-add/package-config.js +10 -2
- package/schematics/ng-add/package-config.js.map +1 -1
- package/schematics/ng-add/schema.d.ts +3 -0
- package/schematics/ng-add/schema.js +3 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/schematics/ng-add/schema.json +14 -0
- package/select/README.md +2 -0
- package/types/radix-ng-primitives-accordion.d.ts +48 -14
- package/types/radix-ng-primitives-alert-dialog.d.ts +95 -38
- package/types/radix-ng-primitives-arrow.d.ts +1 -1
- package/types/radix-ng-primitives-aspect-ratio.d.ts +1 -1
- package/types/radix-ng-primitives-avatar.d.ts +7 -11
- package/types/radix-ng-primitives-button.d.ts +73 -0
- package/types/radix-ng-primitives-calendar.d.ts +1 -2
- package/types/radix-ng-primitives-checkbox.d.ts +201 -32
- package/types/radix-ng-primitives-collapsible.d.ts +112 -39
- package/types/radix-ng-primitives-collection.d.ts +38 -34
- package/types/radix-ng-primitives-config.d.ts +1 -1
- package/types/radix-ng-primitives-context-menu.d.ts +60 -116
- package/types/radix-ng-primitives-core.d.ts +307 -236
- package/types/radix-ng-primitives-cropper.d.ts +2 -2
- package/types/radix-ng-primitives-date-field.d.ts +38 -23
- package/types/radix-ng-primitives-dialog.d.ts +282 -165
- package/types/radix-ng-primitives-dismissable-layer.d.ts +15 -7
- package/types/radix-ng-primitives-drawer.d.ts +448 -0
- package/types/radix-ng-primitives-editable.d.ts +1 -1
- package/types/radix-ng-primitives-field.d.ts +373 -0
- package/types/radix-ng-primitives-fieldset.d.ts +48 -0
- package/types/radix-ng-primitives-focus-scope.d.ts +13 -5
- package/types/radix-ng-primitives-input.d.ts +87 -0
- package/types/radix-ng-primitives-label.d.ts +0 -1
- package/types/radix-ng-primitives-menu.d.ts +572 -99
- package/types/radix-ng-primitives-menubar.d.ts +60 -50
- package/types/radix-ng-primitives-meter.d.ts +193 -0
- package/types/radix-ng-primitives-navigation-menu.d.ts +422 -340
- package/types/radix-ng-primitives-number-field.d.ts +405 -145
- package/types/radix-ng-primitives-pagination.d.ts +2 -2
- package/types/radix-ng-primitives-popover.d.ts +365 -351
- package/types/radix-ng-primitives-popper.d.ts +49 -9
- package/types/radix-ng-primitives-portal.d.ts +14 -6
- package/types/radix-ng-primitives-presence.d.ts +28 -76
- package/types/radix-ng-primitives-preview-card.d.ts +359 -0
- package/types/radix-ng-primitives-progress.d.ts +174 -48
- package/types/radix-ng-primitives-radio.d.ts +55 -25
- package/types/radix-ng-primitives-roving-focus.d.ts +30 -21
- package/types/radix-ng-primitives-select.d.ts +475 -177
- package/types/radix-ng-primitives-separator.d.ts +7 -32
- package/types/radix-ng-primitives-slider.d.ts +315 -201
- package/types/radix-ng-primitives-stepper.d.ts +5 -7
- package/types/radix-ng-primitives-switch.d.ts +86 -71
- package/types/radix-ng-primitives-tabs.d.ts +213 -79
- package/types/radix-ng-primitives-time-field.d.ts +42 -27
- package/types/radix-ng-primitives-toggle-group.d.ts +85 -164
- package/types/radix-ng-primitives-toggle.d.ts +43 -53
- package/types/radix-ng-primitives-toolbar.d.ts +163 -38
- package/types/radix-ng-primitives-tooltip.d.ts +347 -384
- package/types/radix-ng-primitives-visually-hidden.d.ts +19 -19
- package/dropdown-menu/README.md +0 -1
- package/fesm2022/radix-ng-primitives-dropdown-menu.mjs +0 -581
- package/fesm2022/radix-ng-primitives-dropdown-menu.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-hover-card.mjs +0 -1238
- package/fesm2022/radix-ng-primitives-hover-card.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-select2.mjs +0 -897
- package/fesm2022/radix-ng-primitives-select2.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-tooltip2.mjs +0 -735
- package/fesm2022/radix-ng-primitives-tooltip2.mjs.map +0 -1
- package/hover-card/README.md +0 -3
- package/select2/README.md +0 -3
- package/tooltip2/README.md +0 -3
- package/types/radix-ng-primitives-dropdown-menu.d.ts +0 -171
- package/types/radix-ng-primitives-hover-card.d.ts +0 -471
- package/types/radix-ng-primitives-select2.d.ts +0 -511
- package/types/radix-ng-primitives-tooltip2.d.ts +0 -325
|
@@ -39,23 +39,25 @@ class RdxAvatarFallbackDirective {
|
|
|
39
39
|
*/
|
|
40
40
|
this.delayMs = input(this.config.delayMs, ...(ngDevMode ? [{ debugName: "delayMs" }] : /* istanbul ignore next */ []));
|
|
41
41
|
this.canRender = signal(false, ...(ngDevMode ? [{ debugName: "canRender" }] : /* istanbul ignore next */ []));
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
// Enable the fallback after an optional delay (so it only appears for
|
|
43
|
+
// those on slower connections), independent of the image load status —
|
|
44
|
+
// matches Radix/Base UI. The `display` binding then hides it once the
|
|
45
|
+
// image has loaded.
|
|
46
|
+
watch([this.delayMs], ([delayMs], onCleanup) => {
|
|
47
|
+
this.canRender.set(false);
|
|
48
|
+
if (delayMs) {
|
|
49
|
+
const timeout = setTimeout(() => this.canRender.set(true), delayMs);
|
|
50
|
+
// Cancel a pending delay if delayMs changes or the directive is
|
|
51
|
+
// destroyed before it fires.
|
|
52
|
+
onCleanup(() => clearTimeout(timeout));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.canRender.set(true);
|
|
54
56
|
}
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarFallbackDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
58
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxAvatarFallbackDirective, isStandalone: true, selector: "span[rdxAvatarFallback]", inputs: { delayMs: { classPropertyName: "delayMs", publicName: "delayMs", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.display": "canRender() && rootContext.imageLoadingStatus() !== \"loaded\" ? null : \"none\"
|
|
60
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxAvatarFallbackDirective, isStandalone: true, selector: "span[rdxAvatarFallback]", inputs: { delayMs: { classPropertyName: "delayMs", publicName: "delayMs", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.display": "canRender() && rootContext.imageLoadingStatus() !== \"loaded\" ? null : \"none\"" } }, exportAs: ["rdxAvatarFallback"], ngImport: i0 }); }
|
|
59
61
|
}
|
|
60
62
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarFallbackDirective, decorators: [{
|
|
61
63
|
type: Directive,
|
|
@@ -63,7 +65,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
63
65
|
selector: 'span[rdxAvatarFallback]',
|
|
64
66
|
exportAs: 'rdxAvatarFallback',
|
|
65
67
|
host: {
|
|
66
|
-
'[style.display]': 'canRender() && rootContext.imageLoadingStatus() !== "loaded" ? null : "none"
|
|
68
|
+
'[style.display]': 'canRender() && rootContext.imageLoadingStatus() !== "loaded" ? null : "none"'
|
|
67
69
|
}
|
|
68
70
|
}]
|
|
69
71
|
}], ctorParameters: () => [], propDecorators: { delayMs: [{ type: i0.Input, args: [{ isSignal: true, alias: "delayMs", required: false }] }] } });
|
|
@@ -87,50 +89,41 @@ class RdxAvatarImageDirective {
|
|
|
87
89
|
* @group Emits
|
|
88
90
|
*/
|
|
89
91
|
this.onLoadingStatusChange = output();
|
|
90
|
-
this.isMounted = signal(false, ...(ngDevMode ? [{ debugName: "isMounted" }] : /* istanbul ignore next */ []));
|
|
91
92
|
this.loadingStatus = signal('idle', ...(ngDevMode ? [{ debugName: "loadingStatus" }] : /* istanbul ignore next */ []));
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
// Loading is browser-only; on the server the status stays 'idle'.
|
|
94
|
+
if (!isPlatformBrowser(this.platformId)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
watch([this.src, this.referrerPolicy], ([src, referrer], onCleanup) => {
|
|
98
|
+
if (!src) {
|
|
99
|
+
this.loadingStatus.set('error');
|
|
100
|
+
return;
|
|
95
101
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
image.referrerPolicy = referrer;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
watch([this.loadingStatus], ([value]) => {
|
|
116
|
-
this.onLoadingStatusChange.emit(value);
|
|
117
|
-
if (value !== 'idle') {
|
|
118
|
-
this.rootContext.imageLoadingStatus.set(value);
|
|
119
|
-
}
|
|
102
|
+
const image = new window.Image();
|
|
103
|
+
this.loadingStatus.set('loading');
|
|
104
|
+
image.onload = () => this.loadingStatus.set('loaded');
|
|
105
|
+
image.onerror = () => this.loadingStatus.set('error');
|
|
106
|
+
// Set referrerPolicy before src so it applies to the fetch.
|
|
107
|
+
if (referrer) {
|
|
108
|
+
image.referrerPolicy = referrer;
|
|
109
|
+
}
|
|
110
|
+
image.src = src;
|
|
111
|
+
// Drop handlers for a stale src (or on destroy) so a late load/error
|
|
112
|
+
// can't overwrite the status for the current one.
|
|
113
|
+
onCleanup(() => {
|
|
114
|
+
image.onload = null;
|
|
115
|
+
image.onerror = null;
|
|
120
116
|
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
ngOnDestroy() {
|
|
130
|
-
this.isMounted.set(false);
|
|
117
|
+
});
|
|
118
|
+
watch([this.loadingStatus], ([value]) => {
|
|
119
|
+
this.onLoadingStatusChange.emit(value);
|
|
120
|
+
if (value !== 'idle') {
|
|
121
|
+
this.rootContext.imageLoadingStatus.set(value);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
131
124
|
}
|
|
132
125
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarImageDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
133
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxAvatarImageDirective, isStandalone: true, selector: "img[rdxAvatarImage]", inputs: { src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: false, transformFunction: null }, referrerPolicy: { classPropertyName: "referrerPolicy", publicName: "referrerPolicy", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onLoadingStatusChange: "onLoadingStatusChange" }, host: { attributes: { "role": "img" }, properties: { "attr.src": "src()", "attr.
|
|
126
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxAvatarImageDirective, isStandalone: true, selector: "img[rdxAvatarImage]", inputs: { src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: false, transformFunction: null }, referrerPolicy: { classPropertyName: "referrerPolicy", publicName: "referrerPolicy", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onLoadingStatusChange: "onLoadingStatusChange" }, host: { attributes: { "role": "img" }, properties: { "attr.src": "src()", "attr.referrerpolicy": "referrerPolicy()", "style.display": "(rootContext.imageLoadingStatus() === \"loaded\") ? null : \"none\"" } }, exportAs: ["rdxAvatarImage"], ngImport: i0 }); }
|
|
134
127
|
}
|
|
135
128
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarImageDirective, decorators: [{
|
|
136
129
|
type: Directive,
|
|
@@ -140,7 +133,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
140
133
|
host: {
|
|
141
134
|
role: 'img',
|
|
142
135
|
'[attr.src]': 'src()',
|
|
143
|
-
'[attr.
|
|
136
|
+
'[attr.referrerpolicy]': 'referrerPolicy()',
|
|
144
137
|
'[style.display]': '(rootContext.imageLoadingStatus() === "loaded") ? null : "none"'
|
|
145
138
|
}
|
|
146
139
|
}]
|
|
@@ -148,7 +141,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
148
141
|
|
|
149
142
|
class RdxAvatarRootDirective {
|
|
150
143
|
constructor() {
|
|
151
|
-
this.imageLoadingStatus = signal('
|
|
144
|
+
this.imageLoadingStatus = signal('idle', ...(ngDevMode ? [{ debugName: "imageLoadingStatus" }] : /* istanbul ignore next */ []));
|
|
152
145
|
}
|
|
153
146
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarRootDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
154
147
|
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: RdxAvatarRootDirective, isStandalone: true, selector: "span[rdxAvatarRoot]", providers: [provideToken(AVATAR_ROOT_CONTEXT, RdxAvatarRootDirective)], exportAs: ["rdxAvatarRoot"], ngImport: i0 }); }
|
|
@@ -163,12 +156,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
163
156
|
}] });
|
|
164
157
|
|
|
165
158
|
const _imports = [RdxAvatarRootDirective, RdxAvatarFallbackDirective, RdxAvatarImageDirective];
|
|
166
|
-
class
|
|
167
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type:
|
|
168
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type:
|
|
169
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type:
|
|
159
|
+
class RdxAvatarModule {
|
|
160
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
161
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarModule, imports: [RdxAvatarRootDirective, RdxAvatarFallbackDirective, RdxAvatarImageDirective], exports: [RdxAvatarRootDirective, RdxAvatarFallbackDirective, RdxAvatarImageDirective] }); }
|
|
162
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarModule }); }
|
|
170
163
|
}
|
|
171
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type:
|
|
164
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxAvatarModule, decorators: [{
|
|
172
165
|
type: NgModule,
|
|
173
166
|
args: [{
|
|
174
167
|
imports: [..._imports],
|
|
@@ -180,5 +173,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
|
|
|
180
173
|
* Generated bundle index. Do not edit.
|
|
181
174
|
*/
|
|
182
175
|
|
|
183
|
-
export { RdxAvatarConfigToken, RdxAvatarFallbackDirective, RdxAvatarImageDirective,
|
|
176
|
+
export { RdxAvatarConfigToken, RdxAvatarFallbackDirective, RdxAvatarImageDirective, RdxAvatarModule, RdxAvatarRootDirective, defaultAvatarConfig, injectAvatarConfig, provideRdxAvatarConfig };
|
|
184
177
|
//# sourceMappingURL=radix-ng-primitives-avatar.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radix-ng-primitives-avatar.mjs","sources":["../../../packages/primitives/avatar/src/avatar-context.token.ts","../../../packages/primitives/avatar/src/avatar.config.ts","../../../packages/primitives/avatar/src/avatar-fallback.directive.ts","../../../packages/primitives/avatar/src/avatar-image.directive.ts","../../../packages/primitives/avatar/src/avatar-root.directive.ts","../../../packages/primitives/avatar/index.ts","../../../packages/primitives/avatar/radix-ng-primitives-avatar.ts"],"sourcesContent":["import { inject, InjectionToken, WritableSignal } from '@angular/core';\nimport { RdxImageLoadingStatus } from './types';\n\nexport interface AvatarContextToken {\n imageLoadingStatus: WritableSignal<RdxImageLoadingStatus>;\n}\n\nexport const AVATAR_ROOT_CONTEXT = new InjectionToken<AvatarContextToken>('AVATAR_ROOT_CONTEXT');\n\nexport function injectAvatarRootContext(): AvatarContextToken {\n return inject(AVATAR_ROOT_CONTEXT);\n}\n","import { inject, InjectionToken, Provider } from '@angular/core';\n\nexport interface RdxAvatarConfig {\n /**\n * Define a delay before the fallback is shown.\n * This is useful to only show the fallback for those with slower connections.\n * @default 0\n */\n delayMs: number;\n}\n\nexport const defaultAvatarConfig: RdxAvatarConfig = {\n delayMs: 0\n};\n\nexport const RdxAvatarConfigToken = new InjectionToken<RdxAvatarConfig>('RdxAvatarConfigToken');\n\nexport function provideRdxAvatarConfig(config: Partial<RdxAvatarConfig>): Provider[] {\n return [\n {\n provide: RdxAvatarConfigToken,\n useValue: { ...defaultAvatarConfig, ...config }\n }\n ];\n}\n\nexport function injectAvatarConfig(): RdxAvatarConfig {\n return inject(RdxAvatarConfigToken, { optional: true }) ?? defaultAvatarConfig;\n}\n","import { Directive, input, signal } from '@angular/core';\nimport { watch } from '@radix-ng/primitives/core';\nimport { injectAvatarRootContext } from './avatar-context.token';\nimport { injectAvatarConfig } from './avatar.config';\n\n/**\n * @group Components\n */\n@Directive({\n selector: 'span[rdxAvatarFallback]',\n exportAs: 'rdxAvatarFallback',\n host: {\n '[style.display]': 'canRender() && rootContext.imageLoadingStatus() !== \"loaded\" ? null : \"none\" '\n }\n})\nexport class RdxAvatarFallbackDirective {\n private readonly config = injectAvatarConfig();\n\n protected readonly rootContext = injectAvatarRootContext();\n\n /**\n * Useful for delaying rendering so it only appears for those with slower connections.\n *\n * @group Props\n * @defaultValue 0\n */\n readonly delayMs = input<number>(this.config.delayMs);\n\n protected readonly canRender = signal(false);\n\n private timeout: ReturnType<typeof setTimeout> | undefined;\n\n constructor() {\n watch([this.rootContext.imageLoadingStatus], ([value]) => {\n if (value === 'loading') {\n this.canRender.set(false);\n if (this.delayMs()) {\n this.timeout = setTimeout(() => {\n this.canRender.set(true);\n clearTimeout(this.timeout);\n }, this.delayMs());\n } else {\n this.canRender.set(true);\n }\n }\n });\n }\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport { Directive, inject, input, OnDestroy, OnInit, output, PLATFORM_ID, signal } from '@angular/core';\nimport { watch } from '@radix-ng/primitives/core';\nimport { injectAvatarRootContext } from './avatar-context.token';\nimport { HTMLAttributeReferrerPolicy, RdxImageLoadingStatus } from './types';\n\n/**\n * @group Components\n */\n@Directive({\n selector: 'img[rdxAvatarImage]',\n exportAs: 'rdxAvatarImage',\n host: {\n role: 'img',\n '[attr.src]': 'src()',\n '[attr.referrer-policy]': 'referrerPolicy()',\n '[style.display]': '(rootContext.imageLoadingStatus() === \"loaded\") ? null : \"none\"'\n }\n})\nexport class RdxAvatarImageDirective implements OnInit, OnDestroy {\n private readonly platformId = inject(PLATFORM_ID);\n\n protected readonly rootContext = injectAvatarRootContext();\n\n /**\n * @group Props\n */\n readonly src = input<string>();\n\n readonly referrerPolicy = input<HTMLAttributeReferrerPolicy>();\n\n /**\n * A callback providing information about the loading status of the image.\n * This is useful in case you want to control more precisely what to render as the image is loading.\n *\n * @group Emits\n */\n readonly onLoadingStatusChange = output<RdxImageLoadingStatus>();\n\n private readonly isMounted = signal<boolean>(false);\n\n private readonly loadingStatus = signal<RdxImageLoadingStatus>('idle');\n\n constructor() {\n const updateStatus = (status: RdxImageLoadingStatus) => () => {\n if (this.isMounted()) {\n this.loadingStatus.set(status);\n }\n };\n\n if (isPlatformBrowser(this.platformId)) {\n watch([this.src, this.referrerPolicy], ([src, referrer]) => {\n if (this.isMounted()) {\n if (!src) {\n this.loadingStatus.set('error');\n } else {\n const image = new window.Image();\n this.loadingStatus.set('loading');\n image.onload = updateStatus('loaded');\n image.onerror = updateStatus('error');\n image.src = src;\n if (referrer) {\n image.referrerPolicy = referrer;\n }\n }\n }\n });\n\n watch([this.loadingStatus], ([value]) => {\n this.onLoadingStatusChange.emit(value);\n if (value !== 'idle') {\n this.rootContext.imageLoadingStatus.set(value);\n }\n });\n } else {\n this.loadingStatus.set('idle');\n }\n }\n\n ngOnInit() {\n this.isMounted.set(true);\n }\n\n ngOnDestroy() {\n this.isMounted.set(false);\n }\n}\n","import { Directive, signal } from '@angular/core';\nimport { provideToken } from '@radix-ng/primitives/core';\nimport { AVATAR_ROOT_CONTEXT, AvatarContextToken } from './avatar-context.token';\nimport { RdxImageLoadingStatus } from './types';\n\n@Directive({\n selector: 'span[rdxAvatarRoot]',\n exportAs: 'rdxAvatarRoot',\n providers: [provideToken(AVATAR_ROOT_CONTEXT, RdxAvatarRootDirective)]\n})\nexport class RdxAvatarRootDirective implements AvatarContextToken {\n readonly imageLoadingStatus = signal<RdxImageLoadingStatus>('loading');\n}\n","import { NgModule } from '@angular/core';\nimport { RdxAvatarFallbackDirective } from './src/avatar-fallback.directive';\nimport { RdxAvatarImageDirective } from './src/avatar-image.directive';\nimport { RdxAvatarRootDirective } from './src/avatar-root.directive';\n\nexport * from './src/avatar-fallback.directive';\nexport * from './src/avatar-image.directive';\nexport * from './src/avatar-root.directive';\nexport * from './src/avatar.config';\nexport type { RdxImageLoadingStatus } from './src/types';\n\nconst _imports = [RdxAvatarRootDirective, RdxAvatarFallbackDirective, RdxAvatarImageDirective];\n\n@NgModule({\n imports: [..._imports],\n exports: [..._imports]\n})\nexport class RdxCheckboxModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAOO,MAAM,mBAAmB,GAAG,IAAI,cAAc,CAAqB,qBAAqB,CAAC;SAEhF,uBAAuB,GAAA;AACnC,IAAA,OAAO,MAAM,CAAC,mBAAmB,CAAC;AACtC;;ACAO,MAAM,mBAAmB,GAAoB;AAChD,IAAA,OAAO,EAAE;;MAGA,oBAAoB,GAAG,IAAI,cAAc,CAAkB,sBAAsB;AAExF,SAAU,sBAAsB,CAAC,MAAgC,EAAA;IACnE,OAAO;AACH,QAAA;AACI,YAAA,OAAO,EAAE,oBAAoB;AAC7B,YAAA,QAAQ,EAAE,EAAE,GAAG,mBAAmB,EAAE,GAAG,MAAM;AAChD;KACJ;AACL;SAEgB,kBAAkB,GAAA;AAC9B,IAAA,OAAO,MAAM,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,mBAAmB;AAClF;;ACvBA;;AAEG;MAQU,0BAA0B,CAAA;AAiBnC,IAAA,WAAA,GAAA;QAhBiB,IAAA,CAAA,MAAM,GAAG,kBAAkB,EAAE;QAE3B,IAAA,CAAA,WAAW,GAAG,uBAAuB,EAAE;AAE1D;;;;;AAKG;QACM,IAAA,CAAA,OAAO,GAAG,KA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../../packages/primitives/avatar/src/avatar.config.ts","../../../packages/primitives/avatar/src/avatar-fallback.directive.ts","../../../packages/primitives/avatar/src/avatar-image.directive.ts","../../../packages/primitives/avatar/src/avatar-root.directive.ts","../../../packages/primitives/avatar/index.ts","../../../packages/primitives/avatar/radix-ng-primitives-avatar.ts"],"sourcesContent":["import { inject, InjectionToken, WritableSignal } from '@angular/core';\nimport { RdxImageLoadingStatus } from './types';\n\nexport interface AvatarContextToken {\n imageLoadingStatus: WritableSignal<RdxImageLoadingStatus>;\n}\n\nexport const AVATAR_ROOT_CONTEXT = new InjectionToken<AvatarContextToken>('AVATAR_ROOT_CONTEXT');\n\nexport function injectAvatarRootContext(): AvatarContextToken {\n return inject(AVATAR_ROOT_CONTEXT);\n}\n","import { inject, InjectionToken, Provider } from '@angular/core';\n\nexport interface RdxAvatarConfig {\n /**\n * Define a delay before the fallback is shown.\n * This is useful to only show the fallback for those with slower connections.\n * @default 0\n */\n delayMs: number;\n}\n\nexport const defaultAvatarConfig: RdxAvatarConfig = {\n delayMs: 0\n};\n\nexport const RdxAvatarConfigToken = new InjectionToken<RdxAvatarConfig>('RdxAvatarConfigToken');\n\nexport function provideRdxAvatarConfig(config: Partial<RdxAvatarConfig>): Provider[] {\n return [\n {\n provide: RdxAvatarConfigToken,\n useValue: { ...defaultAvatarConfig, ...config }\n }\n ];\n}\n\nexport function injectAvatarConfig(): RdxAvatarConfig {\n return inject(RdxAvatarConfigToken, { optional: true }) ?? defaultAvatarConfig;\n}\n","import { Directive, input, signal } from '@angular/core';\nimport { watch } from '@radix-ng/primitives/core';\nimport { injectAvatarRootContext } from './avatar-context.token';\nimport { injectAvatarConfig } from './avatar.config';\n\n/**\n * @group Components\n */\n@Directive({\n selector: 'span[rdxAvatarFallback]',\n exportAs: 'rdxAvatarFallback',\n host: {\n '[style.display]': 'canRender() && rootContext.imageLoadingStatus() !== \"loaded\" ? null : \"none\"'\n }\n})\nexport class RdxAvatarFallbackDirective {\n private readonly config = injectAvatarConfig();\n\n protected readonly rootContext = injectAvatarRootContext();\n\n /**\n * Useful for delaying rendering so it only appears for those with slower connections.\n *\n * @group Props\n * @defaultValue 0\n */\n readonly delayMs = input<number>(this.config.delayMs);\n\n protected readonly canRender = signal(false);\n\n constructor() {\n // Enable the fallback after an optional delay (so it only appears for\n // those on slower connections), independent of the image load status —\n // matches Radix/Base UI. The `display` binding then hides it once the\n // image has loaded.\n watch([this.delayMs], ([delayMs], onCleanup) => {\n this.canRender.set(false);\n\n if (delayMs) {\n const timeout = setTimeout(() => this.canRender.set(true), delayMs);\n // Cancel a pending delay if delayMs changes or the directive is\n // destroyed before it fires.\n onCleanup(() => clearTimeout(timeout));\n } else {\n this.canRender.set(true);\n }\n });\n }\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport { Directive, inject, input, output, PLATFORM_ID, signal } from '@angular/core';\nimport { watch } from '@radix-ng/primitives/core';\nimport { injectAvatarRootContext } from './avatar-context.token';\nimport { HTMLAttributeReferrerPolicy, RdxImageLoadingStatus } from './types';\n\n/**\n * @group Components\n */\n@Directive({\n selector: 'img[rdxAvatarImage]',\n exportAs: 'rdxAvatarImage',\n host: {\n role: 'img',\n '[attr.src]': 'src()',\n '[attr.referrerpolicy]': 'referrerPolicy()',\n '[style.display]': '(rootContext.imageLoadingStatus() === \"loaded\") ? null : \"none\"'\n }\n})\nexport class RdxAvatarImageDirective {\n private readonly platformId = inject(PLATFORM_ID);\n\n protected readonly rootContext = injectAvatarRootContext();\n\n /**\n * @group Props\n */\n readonly src = input<string>();\n\n readonly referrerPolicy = input<HTMLAttributeReferrerPolicy>();\n\n /**\n * A callback providing information about the loading status of the image.\n * This is useful in case you want to control more precisely what to render as the image is loading.\n *\n * @group Emits\n */\n readonly onLoadingStatusChange = output<RdxImageLoadingStatus>();\n\n private readonly loadingStatus = signal<RdxImageLoadingStatus>('idle');\n\n constructor() {\n // Loading is browser-only; on the server the status stays 'idle'.\n if (!isPlatformBrowser(this.platformId)) {\n return;\n }\n\n watch([this.src, this.referrerPolicy], ([src, referrer], onCleanup) => {\n if (!src) {\n this.loadingStatus.set('error');\n return;\n }\n\n const image = new window.Image();\n this.loadingStatus.set('loading');\n image.onload = () => this.loadingStatus.set('loaded');\n image.onerror = () => this.loadingStatus.set('error');\n // Set referrerPolicy before src so it applies to the fetch.\n if (referrer) {\n image.referrerPolicy = referrer;\n }\n image.src = src;\n\n // Drop handlers for a stale src (or on destroy) so a late load/error\n // can't overwrite the status for the current one.\n onCleanup(() => {\n image.onload = null;\n image.onerror = null;\n });\n });\n\n watch([this.loadingStatus], ([value]) => {\n this.onLoadingStatusChange.emit(value);\n if (value !== 'idle') {\n this.rootContext.imageLoadingStatus.set(value);\n }\n });\n }\n}\n","import { Directive, signal } from '@angular/core';\nimport { provideToken } from '@radix-ng/primitives/core';\nimport { AVATAR_ROOT_CONTEXT, AvatarContextToken } from './avatar-context.token';\nimport { RdxImageLoadingStatus } from './types';\n\n@Directive({\n selector: 'span[rdxAvatarRoot]',\n exportAs: 'rdxAvatarRoot',\n providers: [provideToken(AVATAR_ROOT_CONTEXT, RdxAvatarRootDirective)]\n})\nexport class RdxAvatarRootDirective implements AvatarContextToken {\n readonly imageLoadingStatus = signal<RdxImageLoadingStatus>('idle');\n}\n","import { NgModule } from '@angular/core';\nimport { RdxAvatarFallbackDirective } from './src/avatar-fallback.directive';\nimport { RdxAvatarImageDirective } from './src/avatar-image.directive';\nimport { RdxAvatarRootDirective } from './src/avatar-root.directive';\n\nexport * from './src/avatar-fallback.directive';\nexport * from './src/avatar-image.directive';\nexport * from './src/avatar-root.directive';\nexport * from './src/avatar.config';\nexport type { RdxImageLoadingStatus } from './src/types';\n\nconst _imports = [RdxAvatarRootDirective, RdxAvatarFallbackDirective, RdxAvatarImageDirective];\n\n@NgModule({\n imports: [..._imports],\n exports: [..._imports]\n})\nexport class RdxAvatarModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAOO,MAAM,mBAA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AA,EAAA,CAAA;AACN,oBAAA,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC;AACtB,oBAAA,OAAO,EAAE,CAAC,GAAG,QAAQ;AACxB,iBAAA;;;AChBD;;AAEG;;;;"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, ElementRef, input, booleanAttribute, computed, DestroyRef, Directive } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Headless button behavior, modeled on Base UI's `useButton`.
|
|
6
|
+
*
|
|
7
|
+
* Renders accessible button semantics on a native `<button>` or on any other
|
|
8
|
+
* element (e.g. `<a>`, `<span>`). Carries no styles — state is exposed via
|
|
9
|
+
* `data-disabled` for consumers to style.
|
|
10
|
+
*
|
|
11
|
+
* @group Components
|
|
12
|
+
*/
|
|
13
|
+
class RdxButtonDirective {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.elementRef = inject((ElementRef));
|
|
16
|
+
/**
|
|
17
|
+
* Whether the button is disabled.
|
|
18
|
+
* @group Props
|
|
19
|
+
*/
|
|
20
|
+
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
21
|
+
/**
|
|
22
|
+
* Keep the button focusable while disabled (uses `aria-disabled`).
|
|
23
|
+
* @group Props
|
|
24
|
+
*/
|
|
25
|
+
this.focusableWhenDisabled = input(false, { ...(ngDevMode ? { debugName: "focusableWhenDisabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
26
|
+
/**
|
|
27
|
+
* The `type` attribute applied to native `<button>` hosts.
|
|
28
|
+
* @group Props
|
|
29
|
+
*/
|
|
30
|
+
this.type = input('button', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
|
|
31
|
+
/**
|
|
32
|
+
* @ignore
|
|
33
|
+
*/
|
|
34
|
+
this.isNativeButton = computed(() => this.elementRef.nativeElement.tagName === 'BUTTON', ...(ngDevMode ? [{ debugName: "isNativeButton" }] : /* istanbul ignore next */ []));
|
|
35
|
+
/**
|
|
36
|
+
* @ignore
|
|
37
|
+
* Express disabled via `aria-disabled` on non-button hosts, or whenever the
|
|
38
|
+
* control must stay focusable.
|
|
39
|
+
*/
|
|
40
|
+
this.ariaDisabled = computed(() => {
|
|
41
|
+
if (!this.disabled()) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return !this.isNativeButton() || this.focusableWhenDisabled() ? 'true' : undefined;
|
|
45
|
+
}, ...(ngDevMode ? [{ debugName: "ariaDisabled" }] : /* istanbul ignore next */ []));
|
|
46
|
+
/**
|
|
47
|
+
* @ignore
|
|
48
|
+
*/
|
|
49
|
+
this.tabIndex = computed(() => {
|
|
50
|
+
if (this.isNativeButton()) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return this.disabled() && !this.focusableWhenDisabled() ? -1 : 0;
|
|
54
|
+
}, ...(ngDevMode ? [{ debugName: "tabIndex" }] : /* istanbul ignore next */ []));
|
|
55
|
+
const element = this.elementRef.nativeElement;
|
|
56
|
+
// Capture-phase listeners registered here run before any consumer
|
|
57
|
+
// `(click)`/`(keydown)` binding on the same element, so a disabled
|
|
58
|
+
// button reliably suppresses activation (the native `disabled`
|
|
59
|
+
// attribute can't be used when the control must stay focusable).
|
|
60
|
+
const onClick = (event) => this.handleClick(event);
|
|
61
|
+
const onKeydown = (event) => this.handleKeydown(event);
|
|
62
|
+
element.addEventListener('click', onClick, true);
|
|
63
|
+
element.addEventListener('keydown', onKeydown, true);
|
|
64
|
+
inject(DestroyRef).onDestroy(() => {
|
|
65
|
+
element.removeEventListener('click', onClick, true);
|
|
66
|
+
element.removeEventListener('keydown', onKeydown, true);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
handleClick(event) {
|
|
70
|
+
if (this.disabled()) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
event.stopImmediatePropagation();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
handleKeydown(event) {
|
|
76
|
+
const isActivationKey = event.key === 'Enter' || event.key === ' ';
|
|
77
|
+
if (!isActivationKey) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (this.disabled()) {
|
|
81
|
+
// Native buttons fire a click on Enter/Space; the capture click
|
|
82
|
+
// handler stops it. Non-button hosts never do, so just block here.
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
if (!this.isNativeButton()) {
|
|
85
|
+
event.stopImmediatePropagation();
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// Non-button hosts have no native activation; synthesize a click.
|
|
90
|
+
// Space must not scroll the page.
|
|
91
|
+
if (!this.isNativeButton()) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
this.elementRef.nativeElement.click();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxButtonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
97
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.9", type: RdxButtonDirective, isStandalone: true, selector: "[rdxButton]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, focusableWhenDisabled: { classPropertyName: "focusableWhenDisabled", publicName: "focusableWhenDisabled", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-disabled": "disabled() ? \"\" : undefined", "attr.disabled": "isNativeButton() && disabled() && !focusableWhenDisabled() ? \"\" : undefined", "attr.aria-disabled": "ariaDisabled()", "attr.type": "isNativeButton() ? type() : undefined", "attr.role": "isNativeButton() ? undefined : \"button\"", "attr.tabindex": "tabIndex()" } }, exportAs: ["rdxButton"], ngImport: i0 }); }
|
|
98
|
+
}
|
|
99
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RdxButtonDirective, decorators: [{
|
|
100
|
+
type: Directive,
|
|
101
|
+
args: [{
|
|
102
|
+
selector: '[rdxButton]',
|
|
103
|
+
exportAs: 'rdxButton',
|
|
104
|
+
host: {
|
|
105
|
+
'[attr.data-disabled]': 'disabled() ? "" : undefined',
|
|
106
|
+
// Native disabled only when we do NOT need it focusable; otherwise we
|
|
107
|
+
// keep it focusable and express the state via aria-disabled below.
|
|
108
|
+
'[attr.disabled]': 'isNativeButton() && disabled() && !focusableWhenDisabled() ? "" : undefined',
|
|
109
|
+
'[attr.aria-disabled]': 'ariaDisabled()',
|
|
110
|
+
// Native buttons get their type; non-button hosts get button semantics.
|
|
111
|
+
'[attr.type]': 'isNativeButton() ? type() : undefined',
|
|
112
|
+
'[attr.role]': 'isNativeButton() ? undefined : "button"',
|
|
113
|
+
'[attr.tabindex]': 'tabIndex()'
|
|
114
|
+
}
|
|
115
|
+
}]
|
|
116
|
+
}], ctorParameters: () => [], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], focusableWhenDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusableWhenDisabled", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }] } });
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Generated bundle index. Do not edit.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
export { RdxButtonDirective };
|
|
123
|
+
//# sourceMappingURL=radix-ng-primitives-button.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radix-ng-primitives-button.mjs","sources":["../../../packages/primitives/button/src/button.directive.ts","../../../packages/primitives/button/radix-ng-primitives-button.ts"],"sourcesContent":["import { booleanAttribute, computed, DestroyRef, Directive, ElementRef, inject, input } from '@angular/core';\nimport { BooleanInput } from '@radix-ng/primitives/core';\n\nexport type RdxButtonType = 'button' | 'submit' | 'reset';\n\nexport interface RdxButtonProps {\n /**\n * Whether the button is disabled.\n * @defaultValue false\n */\n disabled?: boolean;\n\n /**\n * Whether the button should remain focusable when disabled. When `true`,\n * the disabled state is expressed with `aria-disabled` (instead of the\n * native `disabled` attribute) so the control stays in the tab order while\n * its activation is suppressed.\n * @defaultValue false\n */\n focusableWhenDisabled?: boolean;\n\n /**\n * The `type` attribute applied to native `<button>` hosts.\n * @defaultValue 'button'\n */\n type?: RdxButtonType;\n}\n\n/**\n * Headless button behavior, modeled on Base UI's `useButton`.\n *\n * Renders accessible button semantics on a native `<button>` or on any other\n * element (e.g. `<a>`, `<span>`). Carries no styles — state is exposed via\n * `data-disabled` for consumers to style.\n *\n * @group Components\n */\n@Directive({\n selector: '[rdxButton]',\n exportAs: 'rdxButton',\n host: {\n '[attr.data-disabled]': 'disabled() ? \"\" : undefined',\n\n // Native disabled only when we do NOT need it focusable; otherwise we\n // keep it focusable and express the state via aria-disabled below.\n '[attr.disabled]': 'isNativeButton() && disabled() && !focusableWhenDisabled() ? \"\" : undefined',\n '[attr.aria-disabled]': 'ariaDisabled()',\n\n // Native buttons get their type; non-button hosts get button semantics.\n '[attr.type]': 'isNativeButton() ? type() : undefined',\n '[attr.role]': 'isNativeButton() ? undefined : \"button\"',\n '[attr.tabindex]': 'tabIndex()'\n }\n})\nexport class RdxButtonDirective {\n private readonly elementRef = inject(ElementRef<HTMLElement>);\n\n /**\n * Whether the button is disabled.\n * @group Props\n */\n readonly disabled = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * Keep the button focusable while disabled (uses `aria-disabled`).\n * @group Props\n */\n readonly focusableWhenDisabled = input<boolean, BooleanInput>(false, { transform: booleanAttribute });\n\n /**\n * The `type` attribute applied to native `<button>` hosts.\n * @group Props\n */\n readonly type = input<RdxButtonType>('button');\n\n /**\n * @ignore\n */\n protected readonly isNativeButton = computed(() => this.elementRef.nativeElement.tagName === 'BUTTON');\n\n /**\n * @ignore\n * Express disabled via `aria-disabled` on non-button hosts, or whenever the\n * control must stay focusable.\n */\n protected readonly ariaDisabled = computed(() => {\n if (!this.disabled()) {\n return undefined;\n }\n return !this.isNativeButton() || this.focusableWhenDisabled() ? 'true' : undefined;\n });\n\n /**\n * @ignore\n */\n protected readonly tabIndex = computed(() => {\n if (this.isNativeButton()) {\n return undefined;\n }\n return this.disabled() && !this.focusableWhenDisabled() ? -1 : 0;\n });\n\n constructor() {\n const element = this.elementRef.nativeElement;\n\n // Capture-phase listeners registered here run before any consumer\n // `(click)`/`(keydown)` binding on the same element, so a disabled\n // button reliably suppresses activation (the native `disabled`\n // attribute can't be used when the control must stay focusable).\n const onClick = (event: MouseEvent): void => this.handleClick(event);\n const onKeydown = (event: KeyboardEvent): void => this.handleKeydown(event);\n\n element.addEventListener('click', onClick, true);\n element.addEventListener('keydown', onKeydown, true);\n\n inject(DestroyRef).onDestroy(() => {\n element.removeEventListener('click', onClick, true);\n element.removeEventListener('keydown', onKeydown, true);\n });\n }\n\n private handleClick(event: MouseEvent): void {\n if (this.disabled()) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const isActivationKey = event.key === 'Enter' || event.key === ' ';\n if (!isActivationKey) {\n return;\n }\n\n if (this.disabled()) {\n // Native buttons fire a click on Enter/Space; the capture click\n // handler stops it. Non-button hosts never do, so just block here.\n event.preventDefault();\n if (!this.isNativeButton()) {\n event.stopImmediatePropagation();\n }\n return;\n }\n\n // Non-button hosts have no native activation; synthesize a click.\n // Space must not scroll the page.\n if (!this.isNativeButton()) {\n event.preventDefault();\n this.elementRef.nativeElement.click();\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AA4BA;;;;;;;;AAQG;MAkBU,kBAAkB,CAAA;AAgD3B,IAAA,WAAA,GAAA;AA/CiB,QAAA,IAAA,CAAA,UAAU,GAAG,MAAM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