@ckui/core 0.1.0-next.2 → 0.1.0-next.3

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ckui-core-switch.mjs","names":[],"sources":["../../../../projects/core/switch/switch-hint.ts","../../../../projects/core/switch/switch.ts","../../../../projects/core/switch/index.ts"],"sourcesContent":["import { Directive, input } from '@angular/core';\nimport { createCkId } from '@ckui/core/internal';\n\n/**\n * Help text under the label of a `ck-switch`. It is part of the row, so a click on it toggles the\n * switch, and the switch's input is described by it. Give it an `id` to choose the id.\n */\n@Directive({\n selector: 'ck-switch-hint',\n host: { class: 'ck-switch-hint', '[attr.id]': 'id()' },\n})\nexport class CkSwitchHint {\n readonly id = input(createCkId('ck-switch-hint'));\n}\n","import {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n ModelSignal,\n PLATFORM_ID,\n Renderer2,\n ViewEncapsulation,\n afterNextRender,\n computed,\n contentChild,\n inject,\n input,\n model,\n viewChild,\n} from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\nimport { CK_CONFIG, CkSize } from '@ckui/core';\nimport {\n CkValueControl,\n createCkId,\n hasAccessibleName,\n provideCkValueAccessor,\n} from '@ckui/core/internal';\nimport { CkSwitchHint } from './switch-hint';\n\ndeclare const ngDevMode: unknown;\n\n/**\n * An on/off switch with a label. It is one native `<input type=\"checkbox\" role=\"switch\">`, so the\n * checked state, Space and a click on the whole row (label text, hint and switch) work natively.\n * The value is a `boolean`; `null` or `undefined` from a form counts as off.\n *\n * The projected text names the switch; a `ck-switch-hint` describes it. Without visible text, give\n * `ck-switch` an `aria-label` or `aria-labelledby`: they are inputs and move onto the input element.\n */\n@Component({\n selector: 'ck-switch',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n providers: [provideCkValueAccessor(CkSwitch)],\n host: { class: 'ck-switch-host' },\n template: `\n <label class=\"ck-switch\" [class]=\"modifierClasses()\" [class.ck-switch--disabled]=\"isDisabled()\">\n <span class=\"ck-switch__control\">\n <input\n #input\n class=\"ck-switch__input\"\n type=\"checkbox\"\n role=\"switch\"\n [checked]=\"on()\"\n [disabled]=\"isDisabled()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-labelledby]=\"labelledby()\"\n [attr.aria-describedby]=\"describedby()\"\n (change)=\"onToggle()\"\n (blur)=\"markTouched()\"\n />\n <span class=\"ck-switch__track\" aria-hidden=\"true\">\n <span class=\"ck-switch__thumb\"></span>\n </span>\n </span>\n <span class=\"ck-switch__body\">\n <span class=\"ck-switch__text\" [id]=\"textId\"><ng-content /></span>\n <ng-content select=\"ck-switch-hint\" />\n </span>\n </label>\n `,\n styleUrl: './switch.css',\n})\nexport class CkSwitch extends CkValueControl<boolean> {\n /** On or off. `null` or `undefined` from a form counts as off. */\n override readonly value: ModelSignal<boolean> = model(false);\n /** `undefined` uses the size from `provideCkui`. */\n readonly size = input<CkSize | undefined>(undefined);\n /** Where the text goes: `start` puts it first and the switch at the end of the row. */\n readonly labelPosition = input<'start' | 'end'>('start');\n /** The accessible name for a switch without visible text. Moves from the host to the input. */\n readonly ariaLabel = input<string | null>(null, { alias: 'aria-label' });\n /** The ids of the elements that name the input. Moves from the host to the input. */\n readonly ariaLabelledby = input<string | null>(null, { alias: 'aria-labelledby' });\n /** More ids that describe the input, after the hint. Moves from the host to the input. */\n readonly ariaDescribedby = input<string | null>(null, { alias: 'aria-describedby' });\n\n private readonly config = inject(CK_CONFIG);\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly inputRef = viewChild.required<ElementRef<HTMLInputElement>>('input');\n private readonly hint = contentChild(CkSwitchHint);\n\n protected readonly textId = createCkId('ck-switch-text');\n\n protected readonly on = computed(() => this.value() === true);\n\n protected readonly modifierClasses = computed(\n () =>\n `ck-switch--${this.size() ?? this.config.size} ck-switch--label-${this.labelPosition() === 'end' ? 'end' : 'start'}`,\n );\n\n /** The consumer's names win; otherwise the projected text names the input. */\n protected readonly labelledby = computed(\n () => this.ariaLabelledby() ?? (this.ariaLabel() ? null : this.textId),\n );\n\n protected readonly describedby = computed(() => {\n const ids = [this.hint()?.id(), this.ariaDescribedby()].filter((id) => !!id);\n return ids.length > 0 ? ids.join(' ') : null;\n });\n\n constructor() {\n super();\n // The names are inputs here, so the host must not also keep them as a (role-less) attribute.\n const renderer = inject(Renderer2);\n renderer.removeAttribute(this.element, 'aria-label');\n renderer.removeAttribute(this.element, 'aria-labelledby');\n renderer.removeAttribute(this.element, 'aria-describedby');\n\n if (typeof ngDevMode !== 'undefined' && ngDevMode && isPlatformBrowser(inject(PLATFORM_ID))) {\n let destroyed = false;\n inject(DestroyRef).onDestroy(() => (destroyed = true));\n afterNextRender(() => {\n if (\n !destroyed &&\n !hasAccessibleName(this.inputRef().nativeElement, { title: false, text: false })\n ) {\n console.warn(\n '[ckui] ck-switch has no accessible name. Add text, or an aria-label or aria-labelledby.',\n this.element,\n );\n }\n });\n }\n }\n\n protected onToggle(): void {\n const input = this.inputRef().nativeElement;\n this.commit(input.checked);\n // A refused change (disabled in between) puts the native state back.\n input.checked = this.on();\n }\n}\n","import { CkSwitch } from './switch';\nimport { CkSwitchHint } from './switch-hint';\n\nexport { CkSwitch } from './switch';\nexport { CkSwitchHint } from './switch-hint';\n\n/** Everything a template needs for a switch: `imports: [CK_SWITCH_IMPORTS]`. */\nexport const CK_SWITCH_IMPORTS = [CkSwitch, CkSwitchHint] as const;\n"],"mappings":";;;;;AAWA,IAAa,eAAb,MAAa,aAAY;CACd,KAAK,MAAM,WAAW,gBAAgB,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,KAAA,CAAA,+BAAA,CAAA,CAAA;CADtC,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAY,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAZ,OA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