@cngx/common 0.1.0-rc.4 → 0.1.0-rc.5

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ElementRef, DestroyRef, input, signal, computed, Directive, TemplateRef, isDevMode, contentChild, output, ViewEncapsulation, ChangeDetectionStrategy, Component, Injectable, InjectionToken, effect, afterNextRender, model, booleanAttribute, linkedSignal, contentChildren, Renderer2, untracked, makeEnvironmentProviders, SkipSelf, Optional, PLATFORM_ID, provideEnvironmentInitializer } from '@angular/core';
2
+ import { inject, ElementRef, DestroyRef, input, signal, computed, Directive, TemplateRef, isDevMode, contentChild, output, ViewEncapsulation, ChangeDetectionStrategy, Component, Injectable, InjectionToken, effect, afterNextRender, model, booleanAttribute, linkedSignal, contentChildren, viewChild, Renderer2, untracked, makeEnvironmentProviders, SkipSelf, Optional, PLATFORM_ID, provideEnvironmentInitializer } from '@angular/core';
3
3
  import { buildAsyncStateView, nextUid, CNGX_SELECTION_CONTROLLER_FACTORY, CNGX_STATEFUL, matchesKeyCombo, parseKeyCombo } from '@cngx/core/utils';
4
4
  import { isObservable, firstValueFrom, timer, take, fromEvent, filter, switchMap, merge, tap, takeUntil, map } from 'rxjs';
5
5
  import { DOCUMENT, NgTemplateOutlet, NgComponentOutlet, isPlatformBrowser } from '@angular/common';
@@ -3159,7 +3159,31 @@ class CngxToggle {
3159
3159
  labelPosition = input('after', ...(ngDevMode ? [{ debugName: "labelPosition" }] : /* istanbul ignore next */ []));
3160
3160
  thumbGlyph = input(null, ...(ngDevMode ? [{ debugName: "thumbGlyph" }] : /* istanbul ignore next */ []));
3161
3161
  describedId = nextUid('cngx-toggle-desc');
3162
+ labelId = nextUid('cngx-toggle-label');
3162
3163
  describedById = computed(() => this.disabledReason() ? this.describedId : null, ...(ngDevMode ? [{ debugName: "describedById" }] : /* istanbul ignore next */ []));
3164
+ labelRef = viewChild('label', ...(ngDevMode ? [{ debugName: "labelRef" }] : /* istanbul ignore next */ []));
3165
+ hasProjectedLabelState = signal(false, ...(ngDevMode ? [{ debugName: "hasProjectedLabelState" }] : /* istanbul ignore next */ []));
3166
+ /**
3167
+ * True when static content is projected into the label span. Gates
3168
+ * `aria-labelledby`: Chrome's name-from-contents for `role="switch"`
3169
+ * does not recurse into the nested `.cngx-toggle__label`, so a
3170
+ * projected label would otherwise yield an empty accessible name
3171
+ * (Pillar 2). Emitting `aria-labelledby` only when a label is present
3172
+ * leaves an icon-only toggle's consumer `aria-label` in force -
3173
+ * pointing labelledby at an empty span would blank the name instead.
3174
+ */
3175
+ hasProjectedLabel = this.hasProjectedLabelState.asReadonly();
3176
+ constructor() {
3177
+ // One-shot post-render read of the projected content (static-label
3178
+ // case, the switch-label norm). afterNextRender runs after `<ng-content>`
3179
+ // resolves and is outside the reactive graph; on SSR it no-ops and
3180
+ // hydrates true on the client (attribute-only, hydration-safe). A
3181
+ // late-changing projected label (empty->filled after first render) is
3182
+ // intentionally not tracked here.
3183
+ afterNextRender(() => {
3184
+ this.hasProjectedLabelState.set(!!this.labelRef()?.nativeElement.textContent?.trim());
3185
+ });
3186
+ }
3163
3187
  /** Stable per-instance id used for `<label for>` wiring. */
3164
3188
  id = signal(nextUid('cngx-toggle-')).asReadonly();
3165
3189
  focusedState = signal(false, ...(ngDevMode ? [{ debugName: "focusedState" }] : /* istanbul ignore next */ []));
@@ -3201,10 +3225,10 @@ class CngxToggle {
3201
3225
  this.fieldHost?.markAsTouched();
3202
3226
  }
3203
3227
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxToggle, deps: [], target: i0.ɵɵFactoryTarget.Component });
3204
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxToggle, isStandalone: true, selector: "[cngxToggle], cngx-toggle", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, errorMessageId: { classPropertyName: "errorMessageId", publicName: "errorMessageId", isSignal: true, isRequired: false, transformFunction: null }, disabledReason: { classPropertyName: "disabledReason", publicName: "disabledReason", isSignal: true, isRequired: false, transformFunction: null }, labelPosition: { classPropertyName: "labelPosition", publicName: "labelPosition", isSignal: true, isRequired: false, transformFunction: null }, thumbGlyph: { classPropertyName: "thumbGlyph", publicName: "thumbGlyph", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", disabled: "disabledChange", invalid: "invalidChange" }, host: { attributes: { "role": "switch" }, listeners: { "click": "handleClick()", "keydown.space": "handleKeydown($event)", "keydown.enter": "handleKeydown($event)", "focusin": "handleFocusIn()", "focusout": "handleFocusOut()" }, properties: { "attr.id": "id()", "attr.aria-checked": "value() ? \"true\" : \"false\"", "attr.aria-disabled": "disabled() ? \"true\" : null", "attr.aria-invalid": "(invalid() || errorState()) ? \"true\" : null", "attr.aria-errormessage": "errorMessageId()", "attr.aria-describedby": "describedById()", "attr.tabindex": "disabled() ? -1 : 0", "class.cngx-toggle--checked": "value()", "class.cngx-toggle--disabled": "disabled()", "class.cngx-toggle--label-before": "labelPosition() === \"before\"" }, classAttribute: "cngx-toggle" }, providers: [
3228
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxToggle, isStandalone: true, selector: "[cngxToggle], cngx-toggle", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, errorMessageId: { classPropertyName: "errorMessageId", publicName: "errorMessageId", isSignal: true, isRequired: false, transformFunction: null }, disabledReason: { classPropertyName: "disabledReason", publicName: "disabledReason", isSignal: true, isRequired: false, transformFunction: null }, labelPosition: { classPropertyName: "labelPosition", publicName: "labelPosition", isSignal: true, isRequired: false, transformFunction: null }, thumbGlyph: { classPropertyName: "thumbGlyph", publicName: "thumbGlyph", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", disabled: "disabledChange", invalid: "invalidChange" }, host: { attributes: { "role": "switch" }, listeners: { "click": "handleClick()", "keydown.space": "handleKeydown($event)", "keydown.enter": "handleKeydown($event)", "focusin": "handleFocusIn()", "focusout": "handleFocusOut()" }, properties: { "attr.id": "id()", "attr.aria-checked": "value() ? \"true\" : \"false\"", "attr.aria-disabled": "disabled() ? \"true\" : null", "attr.aria-invalid": "(invalid() || errorState()) ? \"true\" : null", "attr.aria-errormessage": "errorMessageId()", "attr.aria-labelledby": "hasProjectedLabel() ? labelId : null", "attr.aria-describedby": "describedById()", "attr.tabindex": "disabled() ? -1 : 0", "class.cngx-toggle--checked": "value()", "class.cngx-toggle--disabled": "disabled()", "class.cngx-toggle--label-before": "labelPosition() === \"before\"" }, classAttribute: "cngx-toggle" }, providers: [
3205
3229
  { provide: CNGX_CONTROL_VALUE, useExisting: CngxToggle },
3206
3230
  { provide: CNGX_FORM_FIELD_CONTROL, useExisting: CngxToggle },
3207
- ], exportAs: ["cngxToggle"], ngImport: i0, template: `
3231
+ ], viewQueries: [{ propertyName: "labelRef", first: true, predicate: ["label"], descendants: true, isSignal: true }], exportAs: ["cngxToggle"], ngImport: i0, template: `
3208
3232
  <span class="cngx-toggle__track" aria-hidden="true">
3209
3233
  <span class="cngx-toggle__thumb">
3210
3234
  @if (thumbGlyph(); as glyph) {
@@ -3212,7 +3236,7 @@ class CngxToggle {
3212
3236
  }
3213
3237
  </span>
3214
3238
  </span>
3215
- <span class="cngx-toggle__label">
3239
+ <span #label class="cngx-toggle__label" [id]="labelId">
3216
3240
  <ng-content />
3217
3241
  </span>
3218
3242
  <span
@@ -3233,6 +3257,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
3233
3257
  '[attr.aria-disabled]': 'disabled() ? "true" : null',
3234
3258
  '[attr.aria-invalid]': '(invalid() || errorState()) ? "true" : null',
3235
3259
  '[attr.aria-errormessage]': 'errorMessageId()',
3260
+ '[attr.aria-labelledby]': 'hasProjectedLabel() ? labelId : null',
3236
3261
  '[attr.aria-describedby]': 'describedById()',
3237
3262
  '[attr.tabindex]': 'disabled() ? -1 : 0',
3238
3263
  '[class.cngx-toggle--checked]': 'value()',
@@ -3254,7 +3279,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
3254
3279
  }
3255
3280
  </span>
3256
3281
  </span>
3257
- <span class="cngx-toggle__label">
3282
+ <span #label class="cngx-toggle__label" [id]="labelId">
3258
3283
  <ng-content />
3259
3284
  </span>
3260
3285
  <span
@@ -3264,7 +3289,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
3264
3289
  >{{ disabledReason() }}</span
3265
3290
  >
3266
3291
  `, encapsulation: ViewEncapsulation.None, styles: ["@layer cngx.tokens{@property --cngx-toggle-gap{syntax: \"*\"; inherits: false; initial-value: .5rem;}@property --cngx-toggle-color{syntax: \"*\"; inherits: true; initial-value: currentColor;}@property --cngx-toggle-disabled-opacity{syntax: \"<number>\"; inherits: false; initial-value: .5;}@property --cngx-toggle-focus-outline{syntax: \"*\"; inherits: false; initial-value: 2px solid currentColor;}@property --cngx-toggle-focus-offset{syntax: \"*\"; inherits: false; initial-value: 2px;}@property --cngx-toggle-focus-radius{syntax: \"*\"; inherits: false; initial-value: .25rem;}@property --cngx-toggle-transition{syntax: \"*\"; inherits: false; initial-value: .15s ease;}@property --cngx-toggle-track-width{syntax: \"*\"; inherits: false; initial-value: 2.25rem;}@property --cngx-toggle-track-height{syntax: \"*\"; inherits: false; initial-value: 1.25rem;}@property --cngx-toggle-track-radius{syntax: \"<length>\"; inherits: false; initial-value: 9999px;}@property --cngx-toggle-track-bg-off{syntax: \"<color>\"; inherits: true; initial-value: oklch(0 0 0 / .25);}@property --cngx-toggle-track-bg-on{syntax: \"<color>\"; inherits: false; initial-value: oklch(.66 .19 50);}@property --cngx-toggle-thumb-inset{syntax: \"*\"; inherits: true; initial-value: .125rem;}@property --cngx-toggle-thumb-size{syntax: \"*\"; inherits: false; initial-value: 1rem;}@property --cngx-toggle-thumb-travel{syntax: \"*\"; inherits: false; initial-value: 1rem;}@property --cngx-toggle-thumb-bg{syntax: \"<color>\"; inherits: false; initial-value: oklch(1 0 0);}@property --cngx-toggle-thumb-shadow{syntax: \"*\"; inherits: false; initial-value: 0 1px 2px oklch(0 0 0 / .25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-toggle-track-bg-off: oklch(1 0 0 / .25)}}[data-color-scheme=dark],.dark{--cngx-toggle-track-bg-off: oklch(1 0 0 / .25)}[data-color-scheme=light],.light{--cngx-toggle-track-bg-off: oklch(0 0 0 / .25)}}@layer cngx.components{@scope(.cngx-toggle){:scope{--cngx-toggle-gap: var(--cngx-space-sm);--cngx-toggle-thumb-inset: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-toggle-gap, var(--cngx-space-sm, .5rem));cursor:pointer;-webkit-user-select:none;user-select:none;outline:none;font:inherit;color:var(--cngx-toggle-color, inherit)}:scope.cngx-toggle--label-before{flex-direction:row-reverse}:scope.cngx-toggle--disabled{cursor:not-allowed;opacity:var(--cngx-toggle-disabled-opacity, .5)}:scope:focus-visible{outline:var(--cngx-toggle-focus-outline, 2px solid currentColor);outline-offset:var(--cngx-toggle-focus-offset, 2px);border-radius:var(--cngx-toggle-focus-radius, var(--cngx-radius-sm, .25rem))}.cngx-toggle__track{position:relative;flex:0 0 auto;inline-size:var(--cngx-toggle-track-width, 2.25rem);block-size:var(--cngx-toggle-track-height, 1.25rem);border-radius:var(--cngx-toggle-track-radius, var(--cngx-radius-pill, 9999px));background:var(--cngx-toggle-track-bg-off, oklch(0 0 0 / .25));transition:background-color var(--cngx-toggle-transition, .15s ease)}:scope.cngx-toggle--checked .cngx-toggle__track{background:var(--cngx-toggle-track-bg-on, var(--cngx-color-primary, oklch(.66 .19 50)))}.cngx-toggle__thumb{position:absolute;inset-block-start:var(--cngx-toggle-thumb-inset, .125rem);inset-inline-start:var(--cngx-toggle-thumb-inset, .125rem);inline-size:var(--cngx-toggle-thumb-size, 1rem);block-size:var(--cngx-toggle-thumb-size, 1rem);display:inline-flex;align-items:center;justify-content:center;line-height:1;border-radius:50%;background:var(--cngx-toggle-thumb-bg, oklch(1 0 0));box-shadow:var(--cngx-toggle-thumb-shadow, 0 1px 2px oklch(0 0 0 / .25));transition:transform var(--cngx-toggle-transition, .15s ease)}.cngx-toggle__thumb:has(*){background:transparent;box-shadow:none;font-size:var(--cngx-toggle-thumb-size, 1rem);color:var(--cngx-toggle-thumb-bg, oklch(1 0 0))}:scope.cngx-toggle--checked .cngx-toggle__thumb{transform:translate(var(--cngx-toggle-thumb-travel, 1rem))}.cngx-toggle__label{flex:0 1 auto;min-inline-size:0}.cngx-toggle__sr-only{position:absolute;inline-size:1px;block-size:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@media(prefers-reduced-motion:reduce){.cngx-toggle__track,.cngx-toggle__thumb{transition:none}}}}\n"] }]
3267
- }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.Output, args: ["disabledChange"] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }, { type: i0.Output, args: ["invalidChange"] }], errorMessageId: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessageId", required: false }] }], disabledReason: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabledReason", required: false }] }], labelPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelPosition", required: false }] }], thumbGlyph: [{ type: i0.Input, args: [{ isSignal: true, alias: "thumbGlyph", required: false }] }] } });
3292
+ }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.Output, args: ["disabledChange"] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }, { type: i0.Output, args: ["invalidChange"] }], errorMessageId: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessageId", required: false }] }], disabledReason: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabledReason", required: false }] }], labelPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelPosition", required: false }] }], thumbGlyph: [{ type: i0.Input, args: [{ isSignal: true, alias: "thumbGlyph", required: false }] }], labelRef: [{ type: i0.ViewChild, args: ['label', { isSignal: true }] }] } });
3268
3293
 
3269
3294
  /**
3270
3295
  * Single-value boolean checkbox with indeterminate support and W3C