ngx-com 0.1.16 → 0.1.18
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/ngx-com-components-alert-testing.mjs +80 -0
- package/fesm2022/ngx-com-components-alert-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-calendar-testing.mjs +157 -0
- package/fesm2022/ngx-com-components-calendar-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-carousel-testing.mjs +121 -0
- package/fesm2022/ngx-com-components-carousel-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-checkbox-testing.mjs +113 -0
- package/fesm2022/ngx-com-components-checkbox-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-checkbox.mjs +2 -2
- package/fesm2022/ngx-com-components-checkbox.mjs.map +1 -1
- package/fesm2022/ngx-com-components-code-block-testing.mjs +88 -0
- package/fesm2022/ngx-com-components-code-block-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-collapsible-testing.mjs +104 -0
- package/fesm2022/ngx-com-components-collapsible-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-confirm-testing.mjs +150 -0
- package/fesm2022/ngx-com-components-confirm-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-datepicker-testing.mjs +137 -0
- package/fesm2022/ngx-com-components-datepicker-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-dialog-testing.mjs +109 -0
- package/fesm2022/ngx-com-components-dialog-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-dialog.mjs +18 -18
- package/fesm2022/ngx-com-components-dialog.mjs.map +1 -1
- package/fesm2022/ngx-com-components-dropdown.mjs +39 -0
- package/fesm2022/ngx-com-components-dropdown.mjs.map +1 -1
- package/fesm2022/ngx-com-components-form-field-testing.mjs +140 -0
- package/fesm2022/ngx-com-components-form-field-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-form-field.mjs +5 -1
- package/fesm2022/ngx-com-components-form-field.mjs.map +1 -1
- package/fesm2022/ngx-com-components-menu-testing.mjs +298 -0
- package/fesm2022/ngx-com-components-menu-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-paginator-testing.mjs +128 -0
- package/fesm2022/ngx-com-components-paginator-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-popover-testing.mjs +115 -0
- package/fesm2022/ngx-com-components-popover-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-radio-testing.mjs +157 -0
- package/fesm2022/ngx-com-components-radio-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-radio.mjs +2 -2
- package/fesm2022/ngx-com-components-radio.mjs.map +1 -1
- package/fesm2022/ngx-com-components-segmented-control-testing.mjs +122 -0
- package/fesm2022/ngx-com-components-segmented-control-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-sort-testing.mjs +108 -0
- package/fesm2022/ngx-com-components-sort-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-switch-testing.mjs +103 -0
- package/fesm2022/ngx-com-components-switch-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-switch.mjs +2 -2
- package/fesm2022/ngx-com-components-switch.mjs.map +1 -1
- package/fesm2022/ngx-com-components-table-testing.mjs +198 -0
- package/fesm2022/ngx-com-components-table-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-tabs-testing.mjs +126 -0
- package/fesm2022/ngx-com-components-tabs-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-timepicker-testing.mjs +117 -0
- package/fesm2022/ngx-com-components-timepicker-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-toast-testing.mjs +172 -0
- package/fesm2022/ngx-com-components-toast-testing.mjs.map +1 -0
- package/fesm2022/ngx-com-components-toast.mjs +4 -4
- package/fesm2022/ngx-com-components-toast.mjs.map +1 -1
- package/fesm2022/ngx-com-components-tooltip-testing.mjs +117 -0
- package/fesm2022/ngx-com-components-tooltip-testing.mjs.map +1 -0
- package/package.json +89 -1
- package/types/ngx-com-components-alert-testing.d.ts +41 -0
- package/types/ngx-com-components-calendar-testing.d.ts +80 -0
- package/types/ngx-com-components-carousel-testing.d.ts +51 -0
- package/types/ngx-com-components-checkbox-testing.d.ts +56 -0
- package/types/ngx-com-components-code-block-testing.d.ts +45 -0
- package/types/ngx-com-components-collapsible-testing.d.ts +53 -0
- package/types/ngx-com-components-confirm-testing.d.ts +78 -0
- package/types/ngx-com-components-datepicker-testing.d.ts +61 -0
- package/types/ngx-com-components-dialog-testing.d.ts +57 -0
- package/types/ngx-com-components-dropdown.d.ts +12 -0
- package/types/ngx-com-components-form-field-testing.d.ts +61 -0
- package/types/ngx-com-components-menu-testing.d.ts +167 -0
- package/types/ngx-com-components-paginator-testing.d.ts +58 -0
- package/types/ngx-com-components-popover-testing.d.ts +63 -0
- package/types/ngx-com-components-radio-testing.d.ts +86 -0
- package/types/ngx-com-components-segmented-control-testing.d.ts +66 -0
- package/types/ngx-com-components-sort-testing.d.ts +62 -0
- package/types/ngx-com-components-switch-testing.d.ts +52 -0
- package/types/ngx-com-components-table-testing.d.ts +124 -0
- package/types/ngx-com-components-tabs-testing.d.ts +67 -0
- package/types/ngx-com-components-timepicker-testing.d.ts +53 -0
- package/types/ngx-com-components-toast-testing.d.ts +93 -0
- package/types/ngx-com-components-tooltip-testing.d.ts +57 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Harness for interacting with a sort header in tests.
|
|
5
|
+
*/
|
|
6
|
+
class ComSortHeaderHarness extends ComponentHarness {
|
|
7
|
+
static hostSelector = '[comSortHeader]';
|
|
8
|
+
/**
|
|
9
|
+
* Gets a HarnessPredicate for matching sort headers.
|
|
10
|
+
* @param options Filter options.
|
|
11
|
+
*/
|
|
12
|
+
static with(options = {}) {
|
|
13
|
+
return new HarnessPredicate(ComSortHeaderHarness, options)
|
|
14
|
+
.addOption('label', options.label, async (harness, label) => {
|
|
15
|
+
const text = await harness.getLabel();
|
|
16
|
+
return HarnessPredicate.stringMatches(text, label);
|
|
17
|
+
})
|
|
18
|
+
.addOption('id', options.id, async (harness, id) => {
|
|
19
|
+
const headerId = await harness.getId();
|
|
20
|
+
return HarnessPredicate.stringMatches(headerId, id);
|
|
21
|
+
})
|
|
22
|
+
.addOption('sortDirection', options.sortDirection, async (harness, sortDirection) => {
|
|
23
|
+
return (await harness.getSortDirection()) === sortDirection;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Gets the header's text content. */
|
|
27
|
+
async getLabel() {
|
|
28
|
+
const host = await this.host();
|
|
29
|
+
return host.text();
|
|
30
|
+
}
|
|
31
|
+
/** Gets the column id (comSortHeader attribute value). */
|
|
32
|
+
async getId() {
|
|
33
|
+
const host = await this.host();
|
|
34
|
+
const id = await host.getAttribute('comSortHeader');
|
|
35
|
+
return id ?? '';
|
|
36
|
+
}
|
|
37
|
+
/** Gets the current sort direction from aria-sort. */
|
|
38
|
+
async getSortDirection() {
|
|
39
|
+
const host = await this.host();
|
|
40
|
+
const ariaSort = await host.getAttribute('aria-sort');
|
|
41
|
+
if (ariaSort === 'ascending' || ariaSort === 'descending') {
|
|
42
|
+
return ariaSort;
|
|
43
|
+
}
|
|
44
|
+
return 'none';
|
|
45
|
+
}
|
|
46
|
+
/** Whether this header is actively sorted (direction is not 'none'). */
|
|
47
|
+
async isActive() {
|
|
48
|
+
return (await this.getSortDirection()) !== 'none';
|
|
49
|
+
}
|
|
50
|
+
/** Whether this header is disabled. */
|
|
51
|
+
async isDisabled() {
|
|
52
|
+
const host = await this.host();
|
|
53
|
+
return (await host.getAttribute('aria-disabled')) === 'true';
|
|
54
|
+
}
|
|
55
|
+
/** Clicks the header to cycle sort direction. */
|
|
56
|
+
async click() {
|
|
57
|
+
const host = await this.host();
|
|
58
|
+
return host.click();
|
|
59
|
+
}
|
|
60
|
+
/** Focuses the header element. */
|
|
61
|
+
async focus() {
|
|
62
|
+
const host = await this.host();
|
|
63
|
+
return host.focus();
|
|
64
|
+
}
|
|
65
|
+
/** Blurs the header element. */
|
|
66
|
+
async blur() {
|
|
67
|
+
const host = await this.host();
|
|
68
|
+
return host.blur();
|
|
69
|
+
}
|
|
70
|
+
/** Whether the header element is focused. */
|
|
71
|
+
async isFocused() {
|
|
72
|
+
const host = await this.host();
|
|
73
|
+
return host.isFocused();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Harness for interacting with a sort container in tests.
|
|
78
|
+
*/
|
|
79
|
+
class ComSortHarness extends ComponentHarness {
|
|
80
|
+
static hostSelector = '[comSort]';
|
|
81
|
+
/**
|
|
82
|
+
* Gets a HarnessPredicate for matching sort containers.
|
|
83
|
+
* @param options Filter options.
|
|
84
|
+
*/
|
|
85
|
+
static with(options = {}) {
|
|
86
|
+
return new HarnessPredicate(ComSortHarness, options);
|
|
87
|
+
}
|
|
88
|
+
/** Gets all sort headers, optionally filtered. */
|
|
89
|
+
async getSortHeaders(filters = {}) {
|
|
90
|
+
return this.locatorForAll(ComSortHeaderHarness.with(filters))();
|
|
91
|
+
}
|
|
92
|
+
/** Gets the actively sorted header, or null if none is sorted. */
|
|
93
|
+
async getActiveHeader() {
|
|
94
|
+
const headers = await this.getSortHeaders();
|
|
95
|
+
const activeFlags = await parallel(() => headers.map((h) => h.isActive()));
|
|
96
|
+
const index = activeFlags.indexOf(true);
|
|
97
|
+
return index >= 0 ? headers[index] : null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Testing utilities for the sort component
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Generated bundle index. Do not edit.
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
export { ComSortHarness, ComSortHeaderHarness };
|
|
108
|
+
//# sourceMappingURL=ngx-com-components-sort-testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ngx-com-components-sort-testing.mjs","sources":["../../../projects/com/components/sort/testing/sort.harness.ts","../../../projects/com/components/sort/testing/index.ts","../../../projects/com/components/sort/testing/ngx-com-components-sort-testing.ts"],"sourcesContent":["import {\n ComponentHarness,\n HarnessPredicate,\n parallel,\n} from '@angular/cdk/testing';\nimport type { BaseHarnessFilters } from '@angular/cdk/testing';\n\n/** Sort direction as exposed by the aria-sort attribute. */\nexport type SortHeaderSortDirection = 'ascending' | 'descending' | 'none';\n\n/** Harness filters for ComSortHeaderHarness. */\nexport interface ComSortHeaderHarnessFilters extends BaseHarnessFilters {\n /** Filter by the header's text content. */\n label?: string | RegExp;\n /** Filter by the column id (comSortHeader attribute value). */\n id?: string | RegExp;\n /** Filter by the current sort direction. */\n sortDirection?: SortHeaderSortDirection;\n}\n\n/** Harness filters for ComSortHarness. */\nexport type ComSortHarnessFilters = BaseHarnessFilters;\n\n/**\n * Harness for interacting with a sort header in tests.\n */\nexport class ComSortHeaderHarness extends ComponentHarness {\n static hostSelector = '[comSortHeader]';\n\n /**\n * Gets a HarnessPredicate for matching sort headers.\n * @param options Filter options.\n */\n static with(options: ComSortHeaderHarnessFilters = {}): HarnessPredicate<ComSortHeaderHarness> {\n return new HarnessPredicate(ComSortHeaderHarness, options)\n .addOption('label', options.label, async (harness, label) => {\n const text = await harness.getLabel();\n return HarnessPredicate.stringMatches(text, label);\n })\n .addOption('id', options.id, async (harness, id) => {\n const headerId = await harness.getId();\n return HarnessPredicate.stringMatches(headerId, id);\n })\n .addOption('sortDirection', options.sortDirection, async (harness, sortDirection) => {\n return (await harness.getSortDirection()) === sortDirection;\n });\n }\n\n /** Gets the header's text content. */\n async getLabel(): Promise<string> {\n const host = await this.host();\n return host.text();\n }\n\n /** Gets the column id (comSortHeader attribute value). */\n async getId(): Promise<string> {\n const host = await this.host();\n const id = await host.getAttribute('comSortHeader');\n return id ?? '';\n }\n\n /** Gets the current sort direction from aria-sort. */\n async getSortDirection(): Promise<SortHeaderSortDirection> {\n const host = await this.host();\n const ariaSort = await host.getAttribute('aria-sort');\n if (ariaSort === 'ascending' || ariaSort === 'descending') {\n return ariaSort;\n }\n return 'none';\n }\n\n /** Whether this header is actively sorted (direction is not 'none'). */\n async isActive(): Promise<boolean> {\n return (await this.getSortDirection()) !== 'none';\n }\n\n /** Whether this header is disabled. */\n async isDisabled(): Promise<boolean> {\n const host = await this.host();\n return (await host.getAttribute('aria-disabled')) === 'true';\n }\n\n /** Clicks the header to cycle sort direction. */\n async click(): Promise<void> {\n const host = await this.host();\n return host.click();\n }\n\n /** Focuses the header element. */\n async focus(): Promise<void> {\n const host = await this.host();\n return host.focus();\n }\n\n /** Blurs the header element. */\n async blur(): Promise<void> {\n const host = await this.host();\n return host.blur();\n }\n\n /** Whether the header element is focused. */\n async isFocused(): Promise<boolean> {\n const host = await this.host();\n return host.isFocused();\n }\n}\n\n/**\n * Harness for interacting with a sort container in tests.\n */\nexport class ComSortHarness extends ComponentHarness {\n static hostSelector = '[comSort]';\n\n /**\n * Gets a HarnessPredicate for matching sort containers.\n * @param options Filter options.\n */\n static with(options: ComSortHarnessFilters = {}): HarnessPredicate<ComSortHarness> {\n return new HarnessPredicate(ComSortHarness, options);\n }\n\n /** Gets all sort headers, optionally filtered. */\n async getSortHeaders(filters: ComSortHeaderHarnessFilters = {}): Promise<ComSortHeaderHarness[]> {\n return this.locatorForAll(ComSortHeaderHarness.with(filters))();\n }\n\n /** Gets the actively sorted header, or null if none is sorted. */\n async getActiveHeader(): Promise<ComSortHeaderHarness | null> {\n const headers = await this.getSortHeaders();\n const activeFlags = await parallel(() => headers.map((h) => h.isActive()));\n const index = activeFlags.indexOf(true);\n return index >= 0 ? headers[index]! : null;\n }\n}\n","// Testing utilities for the sort component\n\nexport {\n ComSortHarness,\n ComSortHeaderHarness,\n} from './sort.harness';\n\nexport type {\n SortHeaderSortDirection,\n ComSortHarnessFilters,\n ComSortHeaderHarnessFilters,\n} from './sort.harness';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAu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AAE,EAAA;AAC7C,QAAA,OAAO,IAAI,gBAAgB,CAAC,cAAc,EAAE,OAAO,CAAC;IACtD;;AAGA,IAAA,MAAM,cAAc,CAAC,OAAA,GAAuC,EAAE,EAAA;AAC5D,QAAA,OAAO,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;IACjE;;AAGA,IAAA,MAAM,eAAe,GAAA;AACnB,QAAA,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE;QAC3C,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1E,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;AACvC,QAAA,OAAO,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAE,GAAG,IAAI;IAC5C;;;ACpIF;;ACAA;;AAEG;;;;"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Harness for interacting with a ComSwitch in tests.
|
|
5
|
+
*/
|
|
6
|
+
class ComSwitchHarness extends ComponentHarness {
|
|
7
|
+
static hostSelector = 'com-switch';
|
|
8
|
+
label = this.locatorFor('label');
|
|
9
|
+
input = this.locatorFor('input[type="checkbox"][role="switch"]');
|
|
10
|
+
labelText = this.locatorFor('.com-switch__label');
|
|
11
|
+
/**
|
|
12
|
+
* Gets a HarnessPredicate for matching switches.
|
|
13
|
+
* @param options Filter options.
|
|
14
|
+
*/
|
|
15
|
+
static with(options = {}) {
|
|
16
|
+
return new HarnessPredicate(ComSwitchHarness, options)
|
|
17
|
+
.addOption('label', options.label, async (harness, label) => {
|
|
18
|
+
const text = await harness.getLabelText();
|
|
19
|
+
return HarnessPredicate.stringMatches(text, label);
|
|
20
|
+
})
|
|
21
|
+
.addOption('disabled', options.disabled, async (harness, disabled) => {
|
|
22
|
+
return (await harness.isDisabled()) === disabled;
|
|
23
|
+
})
|
|
24
|
+
.addOption('checked', options.checked, async (harness, checked) => {
|
|
25
|
+
return (await harness.isChecked()) === checked;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Whether the switch is currently checked. */
|
|
29
|
+
async isChecked() {
|
|
30
|
+
const inputEl = await this.input();
|
|
31
|
+
return inputEl.getProperty('checked');
|
|
32
|
+
}
|
|
33
|
+
/** Whether the switch is disabled. */
|
|
34
|
+
async isDisabled() {
|
|
35
|
+
const inputEl = await this.input();
|
|
36
|
+
return inputEl.getProperty('disabled');
|
|
37
|
+
}
|
|
38
|
+
/** Whether the switch is required. */
|
|
39
|
+
async isRequired() {
|
|
40
|
+
const inputEl = await this.input();
|
|
41
|
+
const ariaRequired = await inputEl.getAttribute('aria-required');
|
|
42
|
+
if (ariaRequired !== null) {
|
|
43
|
+
return ariaRequired === 'true';
|
|
44
|
+
}
|
|
45
|
+
return inputEl.getProperty('required');
|
|
46
|
+
}
|
|
47
|
+
/** Gets the switch's label text. */
|
|
48
|
+
async getLabelText() {
|
|
49
|
+
const labelEl = await this.labelText();
|
|
50
|
+
return labelEl.text();
|
|
51
|
+
}
|
|
52
|
+
/** Gets the switch's name attribute. */
|
|
53
|
+
async getName() {
|
|
54
|
+
const inputEl = await this.input();
|
|
55
|
+
return inputEl.getAttribute('name');
|
|
56
|
+
}
|
|
57
|
+
/** Gets the switch's aria-label attribute. */
|
|
58
|
+
async getAriaLabel() {
|
|
59
|
+
const inputEl = await this.input();
|
|
60
|
+
return inputEl.getAttribute('aria-label');
|
|
61
|
+
}
|
|
62
|
+
/** Toggles the switch by clicking its label. */
|
|
63
|
+
async toggle() {
|
|
64
|
+
const labelEl = await this.label();
|
|
65
|
+
return labelEl.click();
|
|
66
|
+
}
|
|
67
|
+
/** Checks the switch if it is not already checked. */
|
|
68
|
+
async check() {
|
|
69
|
+
if (!(await this.isChecked())) {
|
|
70
|
+
await this.toggle();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Unchecks the switch if it is currently checked. */
|
|
74
|
+
async uncheck() {
|
|
75
|
+
if (await this.isChecked()) {
|
|
76
|
+
await this.toggle();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Focuses the switch's input element. */
|
|
80
|
+
async focus() {
|
|
81
|
+
const inputEl = await this.input();
|
|
82
|
+
return inputEl.focus();
|
|
83
|
+
}
|
|
84
|
+
/** Blurs the switch's input element. */
|
|
85
|
+
async blur() {
|
|
86
|
+
const inputEl = await this.input();
|
|
87
|
+
return inputEl.blur();
|
|
88
|
+
}
|
|
89
|
+
/** Whether the switch's input element is focused. */
|
|
90
|
+
async isFocused() {
|
|
91
|
+
const inputEl = await this.input();
|
|
92
|
+
return inputEl.isFocused();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Testing utilities for the switch component
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generated bundle index. Do not edit.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
export { ComSwitchHarness };
|
|
103
|
+
//# sourceMappingURL=ngx-com-components-switch-testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ngx-com-components-switch-testing.mjs","sources":["../../../projects/com/components/switch/testing/switch.harness.ts","../../../projects/com/components/switch/testing/index.ts","../../../projects/com/components/switch/testing/ngx-com-components-switch-testing.ts"],"sourcesContent":["import {\n ComponentHarness,\n HarnessPredicate,\n} from '@angular/cdk/testing';\nimport type { BaseHarnessFilters } from '@angular/cdk/testing';\n\n/** Harness filters for ComSwitchHarness. */\nexport interface ComSwitchHarnessFilters extends BaseHarnessFilters {\n /** Filter by the switch's label text. */\n label?: string | RegExp;\n /** Filter by whether the switch is disabled. */\n disabled?: boolean;\n /** Filter by whether the switch is checked. */\n checked?: boolean;\n}\n\n/**\n * Harness for interacting with a ComSwitch in tests.\n */\nexport class ComSwitchHarness extends ComponentHarness {\n static hostSelector = 'com-switch';\n\n private readonly label = this.locatorFor('label');\n private readonly input = this.locatorFor('input[type=\"checkbox\"][role=\"switch\"]');\n private readonly labelText = this.locatorFor('.com-switch__label');\n\n /**\n * Gets a HarnessPredicate for matching switches.\n * @param options Filter options.\n */\n static with(options: ComSwitchHarnessFilters = {}): HarnessPredicate<ComSwitchHarness> {\n return new HarnessPredicate(ComSwitchHarness, options)\n .addOption('label', options.label, async (harness, label) => {\n const text = await harness.getLabelText();\n return HarnessPredicate.stringMatches(text, label);\n })\n .addOption('disabled', options.disabled, async (harness, disabled) => {\n return (await harness.isDisabled()) === disabled;\n })\n .addOption('checked', options.checked, async (harness, checked) => {\n return (await harness.isChecked()) === checked;\n });\n }\n\n /** Whether the switch is currently checked. */\n async isChecked(): Promise<boolean> {\n const inputEl = await this.input();\n return inputEl.getProperty<boolean>('checked');\n }\n\n /** Whether the switch is disabled. */\n async isDisabled(): Promise<boolean> {\n const inputEl = await this.input();\n return inputEl.getProperty<boolean>('disabled');\n }\n\n /** Whether the switch is required. */\n async isRequired(): Promise<boolean> {\n const inputEl = await this.input();\n const ariaRequired = await inputEl.getAttribute('aria-required');\n if (ariaRequired !== null) {\n return ariaRequired === 'true';\n }\n return inputEl.getProperty<boolean>('required');\n }\n\n /** Gets the switch's label text. */\n async getLabelText(): Promise<string> {\n const labelEl = await this.labelText();\n return labelEl.text();\n }\n\n /** Gets the switch's name attribute. */\n async getName(): Promise<string | null> {\n const inputEl = await this.input();\n return inputEl.getAttribute('name');\n }\n\n /** Gets the switch's aria-label attribute. */\n async getAriaLabel(): Promise<string | null> {\n const inputEl = await this.input();\n return inputEl.getAttribute('aria-label');\n }\n\n /** Toggles the switch by clicking its label. */\n async toggle(): Promise<void> {\n const labelEl = await this.label();\n return labelEl.click();\n }\n\n /** Checks the switch if it is not already checked. */\n async check(): Promise<void> {\n if (!(await this.isChecked())) {\n await this.toggle();\n }\n }\n\n /** Unchecks the switch if it is currently checked. */\n async uncheck(): Promise<void> {\n if (await this.isChecked()) {\n await this.toggle();\n }\n }\n\n /** Focuses the switch's input element. */\n async focus(): Promise<void> {\n const inputEl = await this.input();\n return inputEl.focus();\n }\n\n /** Blurs the switch's input element. */\n async blur(): Promise<void> {\n const inputEl = await this.input();\n return inputEl.blur();\n }\n\n /** Whether the switch's input element is focused. */\n async isFocused(): Promise<boolean> {\n const inputEl = await this.input();\n return inputEl.isFocused();\n }\n}\n","// Testing utilities for the switch component\n\nexport { ComSwitchHarness } from './switch.harness';\n\nexport type { ComSwitchHarnessFilters } from './switch.harness';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAgBA;;AAEG;AACG,MAAO,gBAAiB,SAAQ,gBAAgB,CAAA;AACpD,IAAA,OAAO,YAAY,GAAG,YAAY;AAEjB,IAAA,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;AAChC,IAAA,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,uCAAuC,CAAC;AAChE,IAAA,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC;AAElE;;;AAGG;AACH,IAAA,OAAO,IAAI,CAAC,OAAA,GAAmC,EAAE,EAAA;AAC/C,QAAA,OAAO,IAAI,gBAAgB,CAAC,gBAAgB,EAAE,OAAO;AAClD,aAAA,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,KAAI;AAC1D,YAAA,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,YAAY,EAAE;YACzC,OAAO,gBAAgB,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC;AACpD,QAAA,CAAC;AACA,aAAA,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,OAAO,EAAE,QAAQ,KAAI;YACnE,OAAO,CAAC,MAAM,OAAO,C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YAAY,CAAC,YAAY,CAAC;IAC3C;;AAGA,IAAA,MAAM,MAAM,GAAA;AACV,QAAA,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE;AAClC,QAAA,OAAO,OAAO,CAAC,KAAK,EAAE;IACxB;;AAGA,IAAA,MAAM,KAAK,GAAA;QACT,IAAI,EAAE,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE;AAC7B,YAAA,MAAM,IAAI,CAAC,MAAM,EAAE;QACrB;IACF;;AAGA,IAAA,MAAM,OAAO,GAAA;AACX,QAAA,IAAI,MAAM,IAAI,CAAC,SAAS,EAAE,EAAE;AAC1B,YAAA,MAAM,IAAI,CAAC,MAAM,EAAE;QACrB;IACF;;AAGA,IAAA,MAAM,KAAK,GAAA;AACT,QAAA,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE;AAClC,QAAA,OAAO,OAAO,CAAC,KAAK,EAAE;IACxB;;AAGA,IAAA,MAAM,IAAI,GAAA;AACR,QAAA,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE;AAClC,QAAA,OAAO,OAAO,CAAC,IAAI,EAAE;IACvB;;AAGA,IAAA,MAAM,SAAS,GAAA;AACb,QAAA,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE;AAClC,QAAA,OAAO,OAAO,CAAC,SAAS,EAAE;IAC5B;;;ACxHF;;ACAA;;AAEG;;;;"}
|
|
@@ -187,7 +187,7 @@ class ComSwitch {
|
|
|
187
187
|
this.changed.emit({ checked: newChecked, source: this });
|
|
188
188
|
}
|
|
189
189
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: ComSwitch, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
190
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.2.0", type: ComSwitch, isStandalone: true, selector: "com-switch", inputs: { size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, variant: { classPropertyName: "variant", publicName: "variant", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, htmlValue: { classPropertyName: "htmlValue", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, ariaDescribedby: { classPropertyName: "ariaDescribedby", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, sfErrors: { classPropertyName: "sfErrors", publicName: "errors", isSignal: true, isRequired: false, transformFunction: null }, sfRequired: { classPropertyName: "sfRequired", publicName: "required", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", disabled: "disabledChange", touched: "touchedChange", changed: "changed" }, host: { properties: { "class.com-switch--disabled": "disabled()", "class.com-switch--checked": "checked()" }, classAttribute: "com-switch inline-
|
|
190
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.2.0", type: ComSwitch, isStandalone: true, selector: "com-switch", inputs: { size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, variant: { classPropertyName: "variant", publicName: "variant", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, htmlValue: { classPropertyName: "htmlValue", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, ariaDescribedby: { classPropertyName: "ariaDescribedby", publicName: "aria-describedby", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, sfErrors: { classPropertyName: "sfErrors", publicName: "errors", isSignal: true, isRequired: false, transformFunction: null }, sfRequired: { classPropertyName: "sfRequired", publicName: "required", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", disabled: "disabledChange", touched: "touchedChange", changed: "changed" }, host: { properties: { "class.com-switch--disabled": "disabled()", "class.com-switch--checked": "checked()" }, classAttribute: "com-switch inline-flex align-middle" }, viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["inputElement"], descendants: true, isSignal: true }], exportAs: ["comSwitch"], ngImport: i0, template: `
|
|
191
191
|
<label
|
|
192
192
|
class="group relative inline-flex items-center"
|
|
193
193
|
[class.cursor-pointer]="!disabled()"
|
|
@@ -250,7 +250,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImpor
|
|
|
250
250
|
</span>
|
|
251
251
|
</label>
|
|
252
252
|
`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
253
|
-
class: 'com-switch inline-
|
|
253
|
+
class: 'com-switch inline-flex align-middle',
|
|
254
254
|
'[class.com-switch--disabled]': 'disabled()',
|
|
255
255
|
'[class.com-switch--checked]': 'checked()',
|
|
256
256
|
}, styles: [".sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}\n"] }]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-com-components-switch.mjs","sources":["../../../projects/com/components/switch/switch.variants.ts","../../../projects/com/components/switch/switch.component.ts","../../../projects/com/components/switch/index.ts","../../../projects/com/components/switch/ngx-com-components-switch.ts"],"sourcesContent":["import { cva } from 'class-variance-authority';\n\n/** Switch size variants. */\nexport type SwitchSize = 'sm' | 'md' | 'lg';\n\n/** Switch color variants. */\nexport type SwitchVariant = 'primary' | 'accent' | 'warn';\n\n/**\n * CVA variants for the switch track (pill-shaped container).\n *\n * Uses `peer` selectors to style based on native input state:\n * - `peer-checked:` for on state\n * - `peer-focus-visible:` for keyboard focus\n * - `peer-disabled:` for disabled state\n *\n * @tokens `--color-primary`, `--color-primary-hover`,\n * `--color-accent`, `--color-accent-hover`,\n * `--color-warn`, `--color-warn-hover`,\n * `--color-muted`, `--color-muted-hover`,\n * `--color-disabled`, `--color-ring`, `--radius-pill`\n */\nexport const switchTrackVariants: (props?: {\n variant?: SwitchVariant;\n size?: SwitchSize;\n}) => string = cva(\n [\n 'com-switch__track',\n 'relative inline-flex shrink-0 cursor-pointer items-center',\n 'rounded-pill border-2 border-transparent',\n 'transition-colors duration-normal',\n 'bg-muted hover:bg-muted-hover',\n 'peer-focus-visible:outline-[1px] peer-focus-visible:outline-offset-2 peer-focus-visible:outline-ring',\n 'peer-disabled:cursor-not-allowed peer-disabled:bg-disabled peer-disabled:hover:bg-disabled',\n ],\n {\n variants: {\n variant: {\n primary: [\n 'peer-checked:bg-primary peer-checked:hover:bg-primary-hover',\n 'peer-disabled:peer-checked:bg-disabled',\n ],\n accent: [\n 'peer-checked:bg-accent peer-checked:hover:bg-accent-hover',\n 'peer-disabled:peer-checked:bg-disabled',\n ],\n warn: [\n 'peer-checked:bg-warn peer-checked:hover:bg-warn-hover',\n 'peer-disabled:peer-checked:bg-disabled',\n ],\n },\n size: {\n sm: 'h-5 w-9',\n md: 'h-6 w-11',\n lg: 'h-7 w-13',\n },\n },\n defaultVariants: {\n variant: 'primary',\n size: 'md',\n },\n }\n);\n\n/** Size-based classes for the sliding thumb. */\nexport const SWITCH_THUMB_SIZES: Record<SwitchSize, string> = {\n sm: 'size-4',\n md: 'size-5',\n lg: 'size-6',\n};\n\n/** Size-based translate classes applied when the switch is checked. */\nexport const SWITCH_THUMB_TRANSLATE: Record<SwitchSize, string> = {\n sm: 'translate-x-4',\n md: 'translate-x-5',\n lg: 'translate-x-6',\n};\n\n/** Size-based classes for the label content. */\nexport const SWITCH_LABEL_SIZES: Record<SwitchSize, string> = {\n sm: 'text-sm ms-2',\n md: 'text-base ms-2.5',\n lg: 'text-lg ms-3',\n};\n","import {\n ChangeDetectionStrategy,\n Component,\n computed,\n ElementRef,\n inject,\n input,\n model,\n output,\n viewChild,\n ViewEncapsulation,\n} from '@angular/core';\nimport type {\n InputSignal,\n ModelSignal,\n OutputEmitterRef,\n Signal,\n} from '@angular/core';\nimport { NgControl } from '@angular/forms';\nimport type { ControlValueAccessor } from '@angular/forms';\nimport {\n switchTrackVariants,\n SWITCH_THUMB_SIZES,\n SWITCH_THUMB_TRANSLATE,\n SWITCH_LABEL_SIZES,\n} from './switch.variants';\nimport type { SwitchSize, SwitchVariant } from './switch.variants';\n\n/** Event emitted when switch state changes. */\nexport interface SwitchChange {\n checked: boolean;\n source: ComSwitch;\n}\n\n/** Auto-incrementing ID counter for unique switch IDs. */\nlet nextId = 0;\n\n/**\n * Toggle switch component with full accessibility support.\n *\n * Uses a native `<input type=\"checkbox\" role=\"switch\">` for built-in keyboard\n * handling, `:checked` pseudo-class, and screen reader support.\n *\n * Implements `ControlValueAccessor` for Reactive Forms integration via\n * `NgControl` injection pattern (no `NG_VALUE_ACCESSOR` provider).\n *\n * @tokens `--color-primary`, `--color-primary-hover`,\n * `--color-accent`, `--color-accent-hover`,\n * `--color-warn`, `--color-warn-hover`,\n * `--color-muted`, `--color-muted-hover`,\n * `--color-background`, `--color-disabled`, `--color-disabled-foreground`,\n * `--color-ring`, `--radius-pill`\n *\n * @example Basic usage\n * ```html\n * <com-switch [(checked)]=\"darkMode\">Dark mode</com-switch>\n * ```\n *\n * @example With reactive forms\n * ```html\n * <com-switch formControlName=\"notifications\">Push notifications</com-switch>\n * ```\n *\n * @example Variants and sizes\n * ```html\n * <com-switch variant=\"accent\" size=\"lg\">Large accent switch</com-switch>\n * <com-switch variant=\"warn\" size=\"sm\">Small warning switch</com-switch>\n * ```\n */\n@Component({\n selector: 'com-switch',\n exportAs: 'comSwitch',\n template: `\n <label\n class=\"group relative inline-flex items-center\"\n [class.cursor-pointer]=\"!disabled()\"\n [class.cursor-not-allowed]=\"disabled()\"\n >\n <input\n #inputElement\n type=\"checkbox\"\n role=\"switch\"\n class=\"peer sr-only\"\n [id]=\"inputId()\"\n [checked]=\"checked()\"\n [disabled]=\"disabled()\"\n [attr.name]=\"name()\"\n [attr.value]=\"htmlValue()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-labelledby]=\"ariaLabelledby()\"\n [attr.aria-describedby]=\"ariaDescribedby()\"\n (change)=\"onInputChange($event)\"\n (blur)=\"onBlur()\"\n />\n <span [class]=\"trackClasses()\">\n <span [class]=\"thumbClasses()\"></span>\n </span>\n <span [class]=\"labelClasses()\">\n <ng-content />\n </span>\n </label>\n `,\n styles: `\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n }\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'com-switch inline-block align-middle',\n '[class.com-switch--disabled]': 'disabled()',\n '[class.com-switch--checked]': 'checked()',\n },\n})\nexport class ComSwitch implements ControlValueAccessor {\n /** Optional NgControl for reactive forms integration. */\n readonly ngControl: NgControl | null = inject(NgControl, { optional: true, self: true });\n\n /** Reference to the native input element. */\n readonly inputRef: Signal<ElementRef<HTMLInputElement> | undefined> =\n viewChild<ElementRef<HTMLInputElement>>('inputElement');\n\n /** Unique ID for this switch instance. */\n private readonly uniqueId: string = `com-switch-${nextId++}`;\n\n // Inputs\n readonly size: InputSignal<SwitchSize> = input<SwitchSize>('md');\n readonly variant: InputSignal<SwitchVariant> = input<SwitchVariant>('primary');\n readonly checked: ModelSignal<boolean> = model<boolean>(false);\n readonly disabled: ModelSignal<boolean> = model<boolean>(false);\n readonly htmlValue: InputSignal<string | undefined> = input<string | undefined>(undefined, { alias: 'value' });\n readonly name: InputSignal<string | undefined> = input<string>();\n readonly id: InputSignal<string | undefined> = input<string>();\n readonly ariaLabel: InputSignal<string | null> = input<string | null>(null, { alias: 'aria-label' });\n readonly ariaLabelledby: InputSignal<string | null> = input<string | null>(null, { alias: 'aria-labelledby' });\n readonly ariaDescribedby: InputSignal<string | null> = input<string | null>(null, { alias: 'aria-describedby' });\n\n // Signal Forms inputs — set automatically by [formField] via setInputOnDirectives\n readonly touched: ModelSignal<boolean> = model<boolean>(false);\n readonly invalid: InputSignal<boolean> = input<boolean>(false);\n readonly sfErrors: InputSignal<readonly unknown[]> = input<readonly unknown[]>([], { alias: 'errors' });\n readonly sfRequired: InputSignal<boolean> = input<boolean>(false, { alias: 'required' });\n\n // Outputs\n readonly changed: OutputEmitterRef<SwitchChange> = output<SwitchChange>();\n\n // Computed state\n readonly inputId: Signal<string> = computed(() => this.id() ?? this.uniqueId);\n\n protected readonly trackClasses: Signal<string> = computed(() =>\n switchTrackVariants({ variant: this.variant(), size: this.size() })\n );\n\n protected readonly thumbClasses: Signal<string> = computed(() => {\n const base = `pointer-events-none block rounded-pill bg-background shadow-sm transition-transform duration-normal ${SWITCH_THUMB_SIZES[this.size()]}`;\n return this.checked() ? `${base} ${SWITCH_THUMB_TRANSLATE[this.size()]}` : base;\n });\n\n protected readonly labelClasses: Signal<string> = computed(() =>\n `com-switch__label select-none peer-disabled:cursor-not-allowed peer-disabled:text-disabled-foreground ${SWITCH_LABEL_SIZES[this.size()]}`\n );\n\n // CVA callbacks\n private onChange: (value: boolean) => void = () => {};\n protected onTouched: () => void = () => {};\n\n constructor() {\n if (this.ngControl) {\n this.ngControl.valueAccessor = this;\n }\n }\n\n // ControlValueAccessor implementation\n writeValue(value: boolean): void {\n this.checked.set(value ?? false);\n }\n\n registerOnChange(fn: (value: boolean) => void): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n setDisabledState(isDisabled: boolean): void {\n this.disabled.set(isDisabled);\n }\n\n // Event handlers\n protected onBlur(): void {\n this.onTouched();\n this.touched.set(true);\n }\n\n protected onInputChange(event: Event): void {\n const input = event.target as HTMLInputElement;\n const newChecked = input.checked;\n\n this.checked.set(newChecked);\n this.onChange(newChecked);\n this.changed.emit({ checked: newChecked, source: this });\n }\n\n // Public API\n /** Focuses this switch's input element. */\n focus(): void {\n this.inputRef()?.nativeElement.focus();\n }\n\n /** Toggles the switch state programmatically. */\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n\n const newChecked = !this.checked();\n this.checked.set(newChecked);\n this.onChange(newChecked);\n this.changed.emit({ checked: newChecked, source: this });\n }\n}\n","// Public API for the switch component\n\n// Main component\nexport { ComSwitch } from './switch.component';\n\n// Types\nexport type { SwitchChange } from './switch.component';\n\n// Variants (for advanced customization)\nexport {\n switchTrackVariants,\n SWITCH_THUMB_SIZES,\n SWITCH_THUMB_TRANSLATE,\n SWITCH_LABEL_SIZES,\n} from './switch.variants';\n\nexport type { SwitchSize, SwitchVariant } from './switch.variants';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAQA;;;;;;;;;;;;;AAaG;AACI,MAAM,mBAAmB,GAGj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AA,CAAA,EAAA,IAAA,EAAA,EAAA,CAAA,MAAA,EAAA,IAAA,EAAA,CAAA,SAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA;;ACjI1D;AAEA;;ACFA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngx-com-components-switch.mjs","sources":["../../../projects/com/components/switch/switch.variants.ts","../../../projects/com/components/switch/switch.component.ts","../../../projects/com/components/switch/index.ts","../../../projects/com/components/switch/ngx-com-components-switch.ts"],"sourcesContent":["import { cva } from 'class-variance-authority';\n\n/** Switch size variants. */\nexport type SwitchSize = 'sm' | 'md' | 'lg';\n\n/** Switch color variants. */\nexport type SwitchVariant = 'primary' | 'accent' | 'warn';\n\n/**\n * CVA variants for the switch track (pill-shaped container).\n *\n * Uses `peer` selectors to style based on native input state:\n * - `peer-checked:` for on state\n * - `peer-focus-visible:` for keyboard focus\n * - `peer-disabled:` for disabled state\n *\n * @tokens `--color-primary`, `--color-primary-hover`,\n * `--color-accent`, `--color-accent-hover`,\n * `--color-warn`, `--color-warn-hover`,\n * `--color-muted`, `--color-muted-hover`,\n * `--color-disabled`, `--color-ring`, `--radius-pill`\n */\nexport const switchTrackVariants: (props?: {\n variant?: SwitchVariant;\n size?: SwitchSize;\n}) => string = cva(\n [\n 'com-switch__track',\n 'relative inline-flex shrink-0 cursor-pointer items-center',\n 'rounded-pill border-2 border-transparent',\n 'transition-colors duration-normal',\n 'bg-muted hover:bg-muted-hover',\n 'peer-focus-visible:outline-[1px] peer-focus-visible:outline-offset-2 peer-focus-visible:outline-ring',\n 'peer-disabled:cursor-not-allowed peer-disabled:bg-disabled peer-disabled:hover:bg-disabled',\n ],\n {\n variants: {\n variant: {\n primary: [\n 'peer-checked:bg-primary peer-checked:hover:bg-primary-hover',\n 'peer-disabled:peer-checked:bg-disabled',\n ],\n accent: [\n 'peer-checked:bg-accent peer-checked:hover:bg-accent-hover',\n 'peer-disabled:peer-checked:bg-disabled',\n ],\n warn: [\n 'peer-checked:bg-warn peer-checked:hover:bg-warn-hover',\n 'peer-disabled:peer-checked:bg-disabled',\n ],\n },\n size: {\n sm: 'h-5 w-9',\n md: 'h-6 w-11',\n lg: 'h-7 w-13',\n },\n },\n defaultVariants: {\n variant: 'primary',\n size: 'md',\n },\n }\n);\n\n/** Size-based classes for the sliding thumb. */\nexport const SWITCH_THUMB_SIZES: Record<SwitchSize, string> = {\n sm: 'size-4',\n md: 'size-5',\n lg: 'size-6',\n};\n\n/** Size-based translate classes applied when the switch is checked. */\nexport const SWITCH_THUMB_TRANSLATE: Record<SwitchSize, string> = {\n sm: 'translate-x-4',\n md: 'translate-x-5',\n lg: 'translate-x-6',\n};\n\n/** Size-based classes for the label content. */\nexport const SWITCH_LABEL_SIZES: Record<SwitchSize, string> = {\n sm: 'text-sm ms-2',\n md: 'text-base ms-2.5',\n lg: 'text-lg ms-3',\n};\n","import {\n ChangeDetectionStrategy,\n Component,\n computed,\n ElementRef,\n inject,\n input,\n model,\n output,\n viewChild,\n ViewEncapsulation,\n} from '@angular/core';\nimport type {\n InputSignal,\n ModelSignal,\n OutputEmitterRef,\n Signal,\n} from '@angular/core';\nimport { NgControl } from '@angular/forms';\nimport type { ControlValueAccessor } from '@angular/forms';\nimport {\n switchTrackVariants,\n SWITCH_THUMB_SIZES,\n SWITCH_THUMB_TRANSLATE,\n SWITCH_LABEL_SIZES,\n} from './switch.variants';\nimport type { SwitchSize, SwitchVariant } from './switch.variants';\n\n/** Event emitted when switch state changes. */\nexport interface SwitchChange {\n checked: boolean;\n source: ComSwitch;\n}\n\n/** Auto-incrementing ID counter for unique switch IDs. */\nlet nextId = 0;\n\n/**\n * Toggle switch component with full accessibility support.\n *\n * Uses a native `<input type=\"checkbox\" role=\"switch\">` for built-in keyboard\n * handling, `:checked` pseudo-class, and screen reader support.\n *\n * Implements `ControlValueAccessor` for Reactive Forms integration via\n * `NgControl` injection pattern (no `NG_VALUE_ACCESSOR` provider).\n *\n * @tokens `--color-primary`, `--color-primary-hover`,\n * `--color-accent`, `--color-accent-hover`,\n * `--color-warn`, `--color-warn-hover`,\n * `--color-muted`, `--color-muted-hover`,\n * `--color-background`, `--color-disabled`, `--color-disabled-foreground`,\n * `--color-ring`, `--radius-pill`\n *\n * @example Basic usage\n * ```html\n * <com-switch [(checked)]=\"darkMode\">Dark mode</com-switch>\n * ```\n *\n * @example With reactive forms\n * ```html\n * <com-switch formControlName=\"notifications\">Push notifications</com-switch>\n * ```\n *\n * @example Variants and sizes\n * ```html\n * <com-switch variant=\"accent\" size=\"lg\">Large accent switch</com-switch>\n * <com-switch variant=\"warn\" size=\"sm\">Small warning switch</com-switch>\n * ```\n */\n@Component({\n selector: 'com-switch',\n exportAs: 'comSwitch',\n template: `\n <label\n class=\"group relative inline-flex items-center\"\n [class.cursor-pointer]=\"!disabled()\"\n [class.cursor-not-allowed]=\"disabled()\"\n >\n <input\n #inputElement\n type=\"checkbox\"\n role=\"switch\"\n class=\"peer sr-only\"\n [id]=\"inputId()\"\n [checked]=\"checked()\"\n [disabled]=\"disabled()\"\n [attr.name]=\"name()\"\n [attr.value]=\"htmlValue()\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-labelledby]=\"ariaLabelledby()\"\n [attr.aria-describedby]=\"ariaDescribedby()\"\n (change)=\"onInputChange($event)\"\n (blur)=\"onBlur()\"\n />\n <span [class]=\"trackClasses()\">\n <span [class]=\"thumbClasses()\"></span>\n </span>\n <span [class]=\"labelClasses()\">\n <ng-content />\n </span>\n </label>\n `,\n styles: `\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n }\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'com-switch inline-flex align-middle',\n '[class.com-switch--disabled]': 'disabled()',\n '[class.com-switch--checked]': 'checked()',\n },\n})\nexport class ComSwitch implements ControlValueAccessor {\n /** Optional NgControl for reactive forms integration. */\n readonly ngControl: NgControl | null = inject(NgControl, { optional: true, self: true });\n\n /** Reference to the native input element. */\n readonly inputRef: Signal<ElementRef<HTMLInputElement> | undefined> =\n viewChild<ElementRef<HTMLInputElement>>('inputElement');\n\n /** Unique ID for this switch instance. */\n private readonly uniqueId: string = `com-switch-${nextId++}`;\n\n // Inputs\n readonly size: InputSignal<SwitchSize> = input<SwitchSize>('md');\n readonly variant: InputSignal<SwitchVariant> = input<SwitchVariant>('primary');\n readonly checked: ModelSignal<boolean> = model<boolean>(false);\n readonly disabled: ModelSignal<boolean> = model<boolean>(false);\n readonly htmlValue: InputSignal<string | undefined> = input<string | undefined>(undefined, { alias: 'value' });\n readonly name: InputSignal<string | undefined> = input<string>();\n readonly id: InputSignal<string | undefined> = input<string>();\n readonly ariaLabel: InputSignal<string | null> = input<string | null>(null, { alias: 'aria-label' });\n readonly ariaLabelledby: InputSignal<string | null> = input<string | null>(null, { alias: 'aria-labelledby' });\n readonly ariaDescribedby: InputSignal<string | null> = input<string | null>(null, { alias: 'aria-describedby' });\n\n // Signal Forms inputs — set automatically by [formField] via setInputOnDirectives\n readonly touched: ModelSignal<boolean> = model<boolean>(false);\n readonly invalid: InputSignal<boolean> = input<boolean>(false);\n readonly sfErrors: InputSignal<readonly unknown[]> = input<readonly unknown[]>([], { alias: 'errors' });\n readonly sfRequired: InputSignal<boolean> = input<boolean>(false, { alias: 'required' });\n\n // Outputs\n readonly changed: OutputEmitterRef<SwitchChange> = output<SwitchChange>();\n\n // Computed state\n readonly inputId: Signal<string> = computed(() => this.id() ?? this.uniqueId);\n\n protected readonly trackClasses: Signal<string> = computed(() =>\n switchTrackVariants({ variant: this.variant(), size: this.size() })\n );\n\n protected readonly thumbClasses: Signal<string> = computed(() => {\n const base = `pointer-events-none block rounded-pill bg-background shadow-sm transition-transform duration-normal ${SWITCH_THUMB_SIZES[this.size()]}`;\n return this.checked() ? `${base} ${SWITCH_THUMB_TRANSLATE[this.size()]}` : base;\n });\n\n protected readonly labelClasses: Signal<string> = computed(() =>\n `com-switch__label select-none peer-disabled:cursor-not-allowed peer-disabled:text-disabled-foreground ${SWITCH_LABEL_SIZES[this.size()]}`\n );\n\n // CVA callbacks\n private onChange: (value: boolean) => void = () => {};\n protected onTouched: () => void = () => {};\n\n constructor() {\n if (this.ngControl) {\n this.ngControl.valueAccessor = this;\n }\n }\n\n // ControlValueAccessor implementation\n writeValue(value: boolean): void {\n this.checked.set(value ?? false);\n }\n\n registerOnChange(fn: (value: boolean) => void): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n setDisabledState(isDisabled: boolean): void {\n this.disabled.set(isDisabled);\n }\n\n // Event handlers\n protected onBlur(): void {\n this.onTouched();\n this.touched.set(true);\n }\n\n protected onInputChange(event: Event): void {\n const input = event.target as HTMLInputElement;\n const newChecked = input.checked;\n\n this.checked.set(newChecked);\n this.onChange(newChecked);\n this.changed.emit({ checked: newChecked, source: this });\n }\n\n // Public API\n /** Focuses this switch's input element. */\n focus(): void {\n this.inputRef()?.nativeElement.focus();\n }\n\n /** Toggles the switch state programmatically. */\n toggle(): void {\n if (this.disabled()) {\n return;\n }\n\n const newChecked = !this.checked();\n this.checked.set(newChecked);\n this.onChange(newChecked);\n this.changed.emit({ checked: newChecked, source: this });\n }\n}\n","// Public API for the switch component\n\n// Main component\nexport { ComSwitch } from './switch.component';\n\n// Types\nexport type { SwitchChange } from './switch.component';\n\n// Variants (for advanced customization)\nexport {\n switchTrackVariants,\n SWITCH_THUMB_SIZES,\n SWITCH_THUMB_TRANSLATE,\n SWITCH_LABEL_SIZES,\n} from './switch.variants';\n\nexport type { SwitchSize, SwitchVariant } from './switch.variants';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAQA;;;;;;;;;;;;;AAaG;AACI,MAAM,mBAAmB,GAGjB,GAAG,CAChB;IACE,mBAAmB;IACnB,2DAA2D;IAC3D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AA,IAAA,EAAA,CAAA,SAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA;;ACjI1D;AAEA;;ACFA;;AAEG;;;;"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Harness for interacting with a table cell (`<th>` or `<td>`) in tests.
|
|
5
|
+
*/
|
|
6
|
+
class ComTableCellHarness extends ComponentHarness {
|
|
7
|
+
static hostSelector = 'th, td';
|
|
8
|
+
/**
|
|
9
|
+
* Gets a HarnessPredicate for matching table cells.
|
|
10
|
+
* @param options Filter options.
|
|
11
|
+
*/
|
|
12
|
+
static with(options = {}) {
|
|
13
|
+
return new HarnessPredicate(ComTableCellHarness, options)
|
|
14
|
+
.addOption('text', options.text, async (harness, text) => {
|
|
15
|
+
const cellText = await harness.getText();
|
|
16
|
+
return HarnessPredicate.stringMatches(cellText, text);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** Gets the cell's text content. */
|
|
20
|
+
async getText() {
|
|
21
|
+
const host = await this.host();
|
|
22
|
+
return host.text();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Harness for interacting with a table header row (`<thead> <tr>`) in tests.
|
|
27
|
+
*/
|
|
28
|
+
class ComTableHeaderRowHarness extends ComponentHarness {
|
|
29
|
+
static hostSelector = 'thead tr';
|
|
30
|
+
/**
|
|
31
|
+
* Gets a HarnessPredicate for matching header rows.
|
|
32
|
+
* @param options Filter options.
|
|
33
|
+
*/
|
|
34
|
+
static with(options = {}) {
|
|
35
|
+
return new HarnessPredicate(ComTableHeaderRowHarness, options);
|
|
36
|
+
}
|
|
37
|
+
/** Gets all header cells in this row, optionally filtered. */
|
|
38
|
+
async getCells(filters = {}) {
|
|
39
|
+
return this.locatorForAll(ComTableCellHarness.with(filters))();
|
|
40
|
+
}
|
|
41
|
+
/** Gets the text content of all header cells. */
|
|
42
|
+
async getCellTexts() {
|
|
43
|
+
const cells = await this.getCells();
|
|
44
|
+
return parallel(() => cells.map((cell) => cell.getText()));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Harness for interacting with a table body row (`<tbody> <tr>`) in tests.
|
|
49
|
+
*/
|
|
50
|
+
class ComTableRowHarness extends ComponentHarness {
|
|
51
|
+
static hostSelector = 'tbody tr';
|
|
52
|
+
/**
|
|
53
|
+
* Gets a HarnessPredicate for matching body rows.
|
|
54
|
+
* @param options Filter options.
|
|
55
|
+
*/
|
|
56
|
+
static with(options = {}) {
|
|
57
|
+
return new HarnessPredicate(ComTableRowHarness, options);
|
|
58
|
+
}
|
|
59
|
+
/** Gets all cells in this row, optionally filtered. */
|
|
60
|
+
async getCells(filters = {}) {
|
|
61
|
+
return this.locatorForAll(ComTableCellHarness.with(filters))();
|
|
62
|
+
}
|
|
63
|
+
/** Gets the text content of all cells in this row. */
|
|
64
|
+
async getCellTexts() {
|
|
65
|
+
const cells = await this.getCells();
|
|
66
|
+
return parallel(() => cells.map((cell) => cell.getText()));
|
|
67
|
+
}
|
|
68
|
+
/** Clicks the row. Useful for tables with clickable rows. */
|
|
69
|
+
async click() {
|
|
70
|
+
const host = await this.host();
|
|
71
|
+
return host.click();
|
|
72
|
+
}
|
|
73
|
+
/** Whether the row is clickable (has tabindex="0"). */
|
|
74
|
+
async isClickable() {
|
|
75
|
+
const host = await this.host();
|
|
76
|
+
return (await host.getAttribute('tabindex')) === '0';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Harness for interacting with a table footer row (`<tfoot> <tr>`) in tests.
|
|
81
|
+
*/
|
|
82
|
+
class ComTableFooterRowHarness extends ComponentHarness {
|
|
83
|
+
static hostSelector = 'tfoot tr';
|
|
84
|
+
/**
|
|
85
|
+
* Gets a HarnessPredicate for matching footer rows.
|
|
86
|
+
* @param options Filter options.
|
|
87
|
+
*/
|
|
88
|
+
static with(options = {}) {
|
|
89
|
+
return new HarnessPredicate(ComTableFooterRowHarness, options);
|
|
90
|
+
}
|
|
91
|
+
/** Gets all cells in this footer row, optionally filtered. */
|
|
92
|
+
async getCells(filters = {}) {
|
|
93
|
+
return this.locatorForAll(ComTableCellHarness.with(filters))();
|
|
94
|
+
}
|
|
95
|
+
/** Gets the text content of all cells in this footer row. */
|
|
96
|
+
async getCellTexts() {
|
|
97
|
+
const cells = await this.getCells();
|
|
98
|
+
return parallel(() => cells.map((cell) => cell.getText()));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Harness for interacting with a ComTable in tests.
|
|
103
|
+
*/
|
|
104
|
+
class ComTableHarness extends ComponentHarness {
|
|
105
|
+
static hostSelector = 'com-table';
|
|
106
|
+
tableElement = this.locatorFor('table');
|
|
107
|
+
/**
|
|
108
|
+
* Gets a HarnessPredicate for matching tables.
|
|
109
|
+
* @param options Filter options.
|
|
110
|
+
*/
|
|
111
|
+
static with(options = {}) {
|
|
112
|
+
return new HarnessPredicate(ComTableHarness, options)
|
|
113
|
+
.addOption('ariaLabel', options.ariaLabel, async (harness, ariaLabel) => {
|
|
114
|
+
const label = await harness.getAriaLabel();
|
|
115
|
+
return HarnessPredicate.stringMatches(label, ariaLabel);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Gets the table's aria-label. */
|
|
119
|
+
async getAriaLabel() {
|
|
120
|
+
const table = await this.tableElement();
|
|
121
|
+
return table.getAttribute('aria-label');
|
|
122
|
+
}
|
|
123
|
+
/** Whether the table is currently loading (aria-busy="true"). */
|
|
124
|
+
async isLoading() {
|
|
125
|
+
const table = await this.tableElement();
|
|
126
|
+
return (await table.getAttribute('aria-busy')) === 'true';
|
|
127
|
+
}
|
|
128
|
+
/** Gets all header rows. */
|
|
129
|
+
async getHeaderRows() {
|
|
130
|
+
return this.locatorForAll(ComTableHeaderRowHarness.with({}))();
|
|
131
|
+
}
|
|
132
|
+
/** Gets the text content of all header cells from the first header row. */
|
|
133
|
+
async getHeaderCellTexts() {
|
|
134
|
+
const headerRows = await this.getHeaderRows();
|
|
135
|
+
if (headerRows.length === 0) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
return headerRows[0].getCellTexts();
|
|
139
|
+
}
|
|
140
|
+
/** Gets all body rows, optionally filtered. */
|
|
141
|
+
async getRows(filters = {}) {
|
|
142
|
+
return this.locatorForAll(ComTableRowHarness.with(filters))();
|
|
143
|
+
}
|
|
144
|
+
/** Gets the number of body rows. */
|
|
145
|
+
async getRowCount() {
|
|
146
|
+
const rows = await this.getRows();
|
|
147
|
+
return rows.length;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets the text content of all body cells as a 2D array.
|
|
151
|
+
* Each inner array contains the cell texts for a single row.
|
|
152
|
+
*/
|
|
153
|
+
async getCellTexts() {
|
|
154
|
+
const rows = await this.getRows();
|
|
155
|
+
return parallel(() => rows.map((row) => row.getCellTexts()));
|
|
156
|
+
}
|
|
157
|
+
/** Gets all footer rows. */
|
|
158
|
+
async getFooterRows() {
|
|
159
|
+
return this.locatorForAll(ComTableFooterRowHarness.with({}))();
|
|
160
|
+
}
|
|
161
|
+
/** Gets the text content of all footer cells from the first footer row. */
|
|
162
|
+
async getFooterCellTexts() {
|
|
163
|
+
const footerRows = await this.getFooterRows();
|
|
164
|
+
if (footerRows.length === 0) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
return footerRows[0].getCellTexts();
|
|
168
|
+
}
|
|
169
|
+
/** Whether the table is disabled (aria-disabled). */
|
|
170
|
+
async isDisabled() {
|
|
171
|
+
const table = await this.tableElement();
|
|
172
|
+
return (await table.getAttribute('aria-disabled')) === 'true';
|
|
173
|
+
}
|
|
174
|
+
/** Whether the table host is focused. */
|
|
175
|
+
async isFocused() {
|
|
176
|
+
const host = await this.host();
|
|
177
|
+
return host.isFocused();
|
|
178
|
+
}
|
|
179
|
+
/** Focuses the table host element. */
|
|
180
|
+
async focus() {
|
|
181
|
+
const host = await this.host();
|
|
182
|
+
return host.focus();
|
|
183
|
+
}
|
|
184
|
+
/** Blurs the table host element. */
|
|
185
|
+
async blur() {
|
|
186
|
+
const host = await this.host();
|
|
187
|
+
return host.blur();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Testing utilities for the table component
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Generated bundle index. Do not edit.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
export { ComTableCellHarness, ComTableFooterRowHarness, ComTableHarness, ComTableHeaderRowHarness, ComTableRowHarness };
|
|
198
|
+
//# sourceMappingURL=ngx-com-components-table-testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ngx-com-components-table-testing.mjs","sources":["../../../projects/com/components/table/testing/table.harness.ts","../../../projects/com/components/table/testing/index.ts","../../../projects/com/components/table/testing/ngx-com-components-table-testing.ts"],"sourcesContent":["import {\n ComponentHarness,\n HarnessPredicate,\n parallel,\n} from '@angular/cdk/testing';\nimport type { BaseHarnessFilters } from '@angular/cdk/testing';\n\n/** Harness filters for ComTableCellHarness. */\nexport interface ComTableCellHarnessFilters extends BaseHarnessFilters {\n /** Filter by the cell's text content. */\n text?: string | RegExp;\n}\n\n/** Harness filters for ComTableRowHarness. */\nexport type ComTableRowHarnessFilters = BaseHarnessFilters;\n\n/** Harness filters for ComTableHeaderRowHarness. */\nexport type ComTableHeaderRowHarnessFilters = BaseHarnessFilters;\n\n/** Harness filters for ComTableFooterRowHarness. */\nexport type ComTableFooterRowHarnessFilters = BaseHarnessFilters;\n\n/** Harness filters for ComTableHarness. */\nexport interface ComTableHarnessFilters extends BaseHarnessFilters {\n /** Filter by the table's aria-label. */\n ariaLabel?: string | RegExp;\n}\n\n/**\n * Harness for interacting with a table cell (`<th>` or `<td>`) in tests.\n */\nexport class ComTableCellHarness extends ComponentHarness {\n static hostSelector = 'th, td';\n\n /**\n * Gets a HarnessPredicate for matching table cells.\n * @param options Filter options.\n */\n static with(options: ComTableCellHarnessFilters = {}): HarnessPredicate<ComTableCellHarness> {\n return new HarnessPredicate(ComTableCellHarness, options)\n .addOption('text', options.text, async (harness, text) => {\n const cellText = await harness.getText();\n return HarnessPredicate.stringMatches(cellText, text);\n });\n }\n\n /** Gets the cell's text content. */\n async getText(): Promise<string> {\n const host = await this.host();\n return host.text();\n }\n}\n\n/**\n * Harness for interacting with a table header row (`<thead> <tr>`) in tests.\n */\nexport class ComTableHeaderRowHarness extends ComponentHarness {\n static hostSelector = 'thead tr';\n\n /**\n * Gets a HarnessPredicate for matching header rows.\n * @param options Filter options.\n */\n static with(options: ComTableHeaderRowHarnessFilters = {}): HarnessPredicate<ComTableHeaderRowHarness> {\n return new HarnessPredicate(ComTableHeaderRowHarness, options);\n }\n\n /** Gets all header cells in this row, optionally filtered. */\n async getCells(filters: ComTableCellHarnessFilters = {}): Promise<ComTableCellHarness[]> {\n return this.locatorForAll(ComTableCellHarness.with(filters))();\n }\n\n /** Gets the text content of all header cells. */\n async getCellTexts(): Promise<string[]> {\n const cells = await this.getCells();\n return parallel(() => cells.map((cell) => cell.getText()));\n }\n}\n\n/**\n * Harness for interacting with a table body row (`<tbody> <tr>`) in tests.\n */\nexport class ComTableRowHarness extends ComponentHarness {\n static hostSelector = 'tbody tr';\n\n /**\n * Gets a HarnessPredicate for matching body rows.\n * @param options Filter options.\n */\n static with(options: ComTableRowHarnessFilters = {}): HarnessPredicate<ComTableRowHarness> {\n return new HarnessPredicate(ComTableRowHarness, options);\n }\n\n /** Gets all cells in this row, optionally filtered. */\n async getCells(filters: ComTableCellHarnessFilters = {}): Promise<ComTableCellHarness[]> {\n return this.locatorForAll(ComTableCellHarness.with(filters))();\n }\n\n /** Gets the text content of all cells in this row. */\n async getCellTexts(): Promise<string[]> {\n const cells = await this.getCells();\n return parallel(() => cells.map((cell) => cell.getText()));\n }\n\n /** Clicks the row. Useful for tables with clickable rows. */\n async click(): Promise<void> {\n const host = await this.host();\n return host.click();\n }\n\n /** Whether the row is clickable (has tabindex=\"0\"). */\n async isClickable(): Promise<boolean> {\n const host = await this.host();\n return (await host.getAttribute('tabindex')) === '0';\n }\n}\n\n/**\n * Harness for interacting with a table footer row (`<tfoot> <tr>`) in tests.\n */\nexport class ComTableFooterRowHarness extends ComponentHarness {\n static hostSelector = 'tfoot tr';\n\n /**\n * Gets a HarnessPredicate for matching footer rows.\n * @param options Filter options.\n */\n static with(options: ComTableFooterRowHarnessFilters = {}): HarnessPredicate<ComTableFooterRowHarness> {\n return new HarnessPredicate(ComTableFooterRowHarness, options);\n }\n\n /** Gets all cells in this footer row, optionally filtered. */\n async getCells(filters: ComTableCellHarnessFilters = {}): Promise<ComTableCellHarness[]> {\n return this.locatorForAll(ComTableCellHarness.with(filters))();\n }\n\n /** Gets the text content of all cells in this footer row. */\n async getCellTexts(): Promise<string[]> {\n const cells = await this.getCells();\n return parallel(() => cells.map((cell) => cell.getText()));\n }\n}\n\n/**\n * Harness for interacting with a ComTable in tests.\n */\nexport class ComTableHarness extends ComponentHarness {\n static hostSelector = 'com-table';\n\n private readonly tableElement = this.locatorFor('table');\n\n /**\n * Gets a HarnessPredicate for matching tables.\n * @param options Filter options.\n */\n static with(options: ComTableHarnessFilters = {}): HarnessPredicate<ComTableHarness> {\n return new HarnessPredicate(ComTableHarness, options)\n .addOption('ariaLabel', options.ariaLabel, async (harness, ariaLabel) => {\n const label = await harness.getAriaLabel();\n return HarnessPredicate.stringMatches(label, ariaLabel);\n });\n }\n\n /** Gets the table's aria-label. */\n async getAriaLabel(): Promise<string | null> {\n const table = await this.tableElement();\n return table.getAttribute('aria-label');\n }\n\n /** Whether the table is currently loading (aria-busy=\"true\"). */\n async isLoading(): Promise<boolean> {\n const table = await this.tableElement();\n return (await table.getAttribute('aria-busy')) === 'true';\n }\n\n /** Gets all header rows. */\n async getHeaderRows(): Promise<ComTableHeaderRowHarness[]> {\n return this.locatorForAll(ComTableHeaderRowHarness.with({}))();\n }\n\n /** Gets the text content of all header cells from the first header row. */\n async getHeaderCellTexts(): Promise<string[]> {\n const headerRows = await this.getHeaderRows();\n if (headerRows.length === 0) {\n return [];\n }\n return headerRows[0]!.getCellTexts();\n }\n\n /** Gets all body rows, optionally filtered. */\n async getRows(filters: ComTableRowHarnessFilters = {}): Promise<ComTableRowHarness[]> {\n return this.locatorForAll(ComTableRowHarness.with(filters))();\n }\n\n /** Gets the number of body rows. */\n async getRowCount(): Promise<number> {\n const rows = await this.getRows();\n return rows.length;\n }\n\n /**\n * Gets the text content of all body cells as a 2D array.\n * Each inner array contains the cell texts for a single row.\n */\n async getCellTexts(): Promise<string[][]> {\n const rows = await this.getRows();\n return parallel(() => rows.map((row) => row.getCellTexts()));\n }\n\n /** Gets all footer rows. */\n async getFooterRows(): Promise<ComTableFooterRowHarness[]> {\n return this.locatorForAll(ComTableFooterRowHarness.with({}))();\n }\n\n /** Gets the text content of all footer cells from the first footer row. */\n async getFooterCellTexts(): Promise<string[]> {\n const footerRows = await this.getFooterRows();\n if (footerRows.length === 0) {\n return [];\n }\n return footerRows[0]!.getCellTexts();\n }\n\n /** Whether the table is disabled (aria-disabled). */\n async isDisabled(): Promise<boolean> {\n const table = await this.tableElement();\n return (await table.getAttribute('aria-disabled')) === 'true';\n }\n\n /** Whether the table host is focused. */\n async isFocused(): Promise<boolean> {\n const host = await this.host();\n return host.isFocused();\n }\n\n /** Focuses the table host element. */\n async focus(): Promise<void> {\n const host = await this.host();\n return host.focus();\n }\n\n /** Blurs the table host element. */\n async blur(): Promise<void> {\n const host = await this.host();\n return host.blur();\n }\n}\n","// Testing utilities for the table component\n\nexport {\n ComTableCellHarness,\n ComTableHeaderRowHarness,\n ComTableRowHarness,\n ComTableFooterRowHarness,\n ComTableHarness,\n} from './table.harness';\n\nexport type {\n ComTableCellHarnessFilters,\n ComTableHeaderRowHarnessFilters,\n ComTableRowHarnessFilters,\n ComTableFooterRowHarnessFilters,\n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