@dataengineeringformachinelearning/viking-ui 4.0.4 → 4.0.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.
- package/README.md +35 -11
- package/dist/README.md +35 -11
- package/dist/design-tokens.css +300 -85
- package/dist/fesm2022/dataengineeringformachinelearning-viking-ui.mjs +100 -64
- package/dist/fesm2022/dataengineeringformachinelearning-viking-ui.mjs.map +1 -1
- package/dist/icons.js +306 -0
- package/dist/package.json +24 -5
- package/{src/lib/site-drakkar/site-drakkar.config.ts → dist/site-drakkar.js} +64 -130
- package/dist/src/tokens/viking-tokens.json +9 -7
- package/dist/types/dataengineeringformachinelearning-viking-ui.d.ts +97 -3
- package/dist/viking-components.css +161 -70
- package/dist/viking-tokens.json +9 -7
- package/dist/viking-ui-elements.js +44 -32
- package/dist/viking-ui.css +1 -1
- package/dist/web-components.js +44 -32
- package/package.json +30 -8
- package/dist/scripts/build-web-components.mjs +0 -37
- package/dist/src/web/badge/viking-badge-wc.ts +0 -116
- package/dist/src/web/button/viking-button-wc.ts +0 -165
- package/dist/src/web/callout/viking-callout-wc.ts +0 -105
- package/dist/src/web/card/viking-card-wc.ts +0 -67
- package/dist/src/web/core/base.ts +0 -56
- package/dist/src/web/core/dom.ts +0 -53
- package/dist/src/web/core/icons-inline.ts +0 -44
- package/dist/src/web/core/styles.ts +0 -1261
- package/dist/src/web/core/types.ts +0 -19
- package/dist/src/web/field/viking-field-wc.ts +0 -154
- package/dist/src/web/index.ts +0 -73
- package/dist/src/web/input/viking-input-wc.ts +0 -211
- package/dist/src/web/modal/viking-modal-wc.ts +0 -187
- package/dist/src/web/search-palette/viking-search-palette-wc.ts +0 -495
- package/dist/src/web/select/viking-select-wc.ts +0 -218
- package/dist/src/web/suite-header/viking-suite-header-wc.ts +0 -729
- package/dist/src/web/suite-search-palette/viking-suite-search-palette-wc.ts +0 -234
- package/dist/src/web/theme-toggle/viking-theme-toggle-wc.ts +0 -139
- package/dist/src/web/types.ts +0 -37
- package/dist/src/web/web-components.spec.ts +0 -297
- package/src/assets/drakkar-favicon.svg +0 -17
- package/src/assets/fonts/inter/InterVariable-Italic.woff2 +0 -0
- package/src/assets/fonts/inter/InterVariable.woff2 +0 -0
- package/src/core/brand/deml-lockup.svg +0 -5
- package/src/core/brand/deml-mark-compact.svg +0 -4
- package/src/core/brand/deml-mark-filled.svg +0 -3
- package/src/core/brand/deml-mark-outline.svg +0 -4
- package/src/core/brand-icons.ts +0 -62
- package/src/core/icons.spec.ts +0 -52
- package/src/core/icons.ts +0 -206
- package/src/core/integration-brand-icons.ts +0 -77
- package/src/core/lucide-paths.generated.ts +0 -130
- package/src/core/types.ts +0 -85
- package/src/core/uid.ts +0 -7
- package/src/elements/button/viking-button.ts +0 -201
- package/src/elements/card/viking-card.ts +0 -60
- package/src/elements/core/dom.ts +0 -33
- package/src/elements/core/styles.ts +0 -28
- package/src/elements/modal/viking-modal.ts +0 -154
- package/src/index.ts +0 -1
- package/src/lib/accordion/accordion.ts +0 -126
- package/src/lib/app-header/app-header.scss +0 -274
- package/src/lib/app-header/app-header.ts +0 -43
- package/src/lib/app-sidebar/app-sidebar.scss +0 -415
- package/src/lib/app-sidebar/app-sidebar.ts +0 -29
- package/src/lib/auth-panel/auth-panel.spec.ts +0 -132
- package/src/lib/auth-panel/auth-panel.ts +0 -228
- package/src/lib/autocomplete/autocomplete.ts +0 -223
- package/src/lib/avatar/avatar.ts +0 -126
- package/src/lib/badge/badge.ts +0 -182
- package/src/lib/bar/bar.ts +0 -31
- package/src/lib/brand/brand.ts +0 -60
- package/src/lib/breadcrumbs/breadcrumbs.ts +0 -81
- package/src/lib/button/button-group.ts +0 -40
- package/src/lib/button/button.scss +0 -119
- package/src/lib/button/button.ts +0 -98
- package/src/lib/calendar/calendar.ts +0 -253
- package/src/lib/callout/callout.ts +0 -211
- package/src/lib/card/card-title.spec.ts +0 -27
- package/src/lib/card/card-title.ts +0 -50
- package/src/lib/card/card.ts +0 -200
- package/src/lib/carousel/carousel.ts +0 -206
- package/src/lib/chart/chart-zoom.spec.ts +0 -65
- package/src/lib/chart/chart-zoom.ts +0 -71
- package/src/lib/chart/chart.ts +0 -1257
- package/src/lib/chart-card-header/chart-card-header.ts +0 -80
- package/src/lib/chart-empty-state/chart-empty-state.ts +0 -146
- package/src/lib/chart-panel/chart-panel.ts +0 -133
- package/src/lib/checkbox/checkbox.ts +0 -139
- package/src/lib/color-picker/color-picker.ts +0 -148
- package/src/lib/command/command.ts +0 -260
- package/src/lib/composer/composer.ts +0 -180
- package/src/lib/confirm-dialog/confirm-dialog.ts +0 -163
- package/src/lib/confirm-dialog/dialog.service.ts +0 -79
- package/src/lib/context/context.ts +0 -75
- package/src/lib/core/brand-icons.ts +0 -62
- package/src/lib/core/cva.ts +0 -33
- package/src/lib/core/icons.ts +0 -206
- package/src/lib/core/integration-brand-icons.ts +0 -77
- package/src/lib/core/lucide-paths.generated.ts +0 -130
- package/src/lib/date-picker/date-picker.ts +0 -139
- package/src/lib/dropdown/dropdown.ts +0 -188
- package/src/lib/editor/editor.ts +0 -170
- package/src/lib/empty-state/empty-state.ts +0 -100
- package/src/lib/fab/fab.ts +0 -76
- package/src/lib/field/field.ts +0 -111
- package/src/lib/file-upload/file-upload.ts +0 -208
- package/src/lib/footer/footer.scss +0 -162
- package/src/lib/footer/footer.ts +0 -28
- package/src/lib/form-section/form-section.ts +0 -200
- package/src/lib/forms.spec.ts +0 -92
- package/src/lib/gauge-arc/gauge-arc.ts +0 -85
- package/src/lib/hud-panel/hud-panel.ts +0 -27
- package/src/lib/icon/icon.ts +0 -284
- package/src/lib/icon-badge/icon-badge.ts +0 -87
- package/src/lib/icon-heading/icon-heading.spec.ts +0 -32
- package/src/lib/icon-heading/icon-heading.ts +0 -38
- package/src/lib/icon-text/icon-text.ts +0 -120
- package/src/lib/input/input.ts +0 -119
- package/src/lib/kanban/kanban.ts +0 -211
- package/src/lib/kbd/kbd.ts +0 -32
- package/src/lib/label/label.ts +0 -39
- package/src/lib/loading-overlay/loading-overlay.ts +0 -80
- package/src/lib/menubar/menubar.ts +0 -77
- package/src/lib/metric-card/metric-card.ts +0 -33
- package/src/lib/modal/modal.ts +0 -207
- package/src/lib/native-select/native-select.ts +0 -124
- package/src/lib/navbar/navbar.ts +0 -124
- package/src/lib/navigation-menu/navigation-menu.ts +0 -116
- package/src/lib/otp-input/otp-input.ts +0 -164
- package/src/lib/page-back-link/page-back-link.ts +0 -74
- package/src/lib/page-header/page-header.ts +0 -70
- package/src/lib/pagination/pagination.ts +0 -157
- package/src/lib/pillbox/pillbox.ts +0 -157
- package/src/lib/popover/popover.ts +0 -92
- package/src/lib/profile/profile.ts +0 -73
- package/src/lib/progress/progress.ts +0 -123
- package/src/lib/radio/radio.ts +0 -132
- package/src/lib/ring-gauge/ring-gauge.ts +0 -75
- package/src/lib/scroll-area/scroll-area.ts +0 -57
- package/src/lib/search-palette/search-palette.scss +0 -288
- package/src/lib/search-palette/search-palette.ts +0 -114
- package/src/lib/select/select.ts +0 -292
- package/src/lib/separator/separator.ts +0 -59
- package/src/lib/sheet/sheet.ts +0 -192
- package/src/lib/sidebar-nav/sidebar-nav.scss +0 -218
- package/src/lib/sidebar-nav/sidebar-nav.ts +0 -158
- package/src/lib/site-drakkar/site-footer.ts +0 -133
- package/src/lib/site-drakkar/site-navbar.scss +0 -2
- package/src/lib/site-drakkar/site-navbar.ts +0 -286
- package/src/lib/site-drakkar/suite-search-items.spec.ts +0 -61
- package/src/lib/site-drakkar/suite-search-items.ts +0 -246
- package/src/lib/skeleton/skeleton.ts +0 -51
- package/src/lib/slider/slider.ts +0 -133
- package/src/lib/spinner/spinner.ts +0 -75
- package/src/lib/status-metric-row/status-metric-row.ts +0 -74
- package/src/lib/suite-search-palette/suite-search-palette.ts +0 -95
- package/src/lib/switch/switch.ts +0 -131
- package/src/lib/table/table.ts +0 -137
- package/src/lib/tabs/tab-panel.ts +0 -61
- package/src/lib/tabs/tab.ts +0 -107
- package/src/lib/tabs/tabs.ts +0 -109
- package/src/lib/textarea/textarea.ts +0 -103
- package/src/lib/theme-toggle/theme-toggle.spec.ts +0 -40
- package/src/lib/theme-toggle/theme-toggle.ts +0 -40
- package/src/lib/time-picker/time-picker.ts +0 -197
- package/src/lib/timeline/timeline.ts +0 -152
- package/src/lib/toast/toast.ts +0 -196
- package/src/lib/toggle/toggle-group.ts +0 -60
- package/src/lib/toggle/toggle.ts +0 -101
- package/src/lib/tooltip/tooltip.ts +0 -119
- package/src/lib/typography/heading.ts +0 -52
- package/src/lib/typography/text.ts +0 -51
- package/src/lib/uptime-bar/uptime-bar.ts +0 -55
- package/src/lib/verification-code-field/verification-code-field.ts +0 -149
- package/src/lib/whitepaper-cta/whitepaper-cta.scss +0 -130
- package/src/lib/whitepaper-cta/whitepaper-cta.ts +0 -78
- package/src/lib/wizard/wizard.ts +0 -80
- package/src/public-api.ts +0 -172
- package/src/styles/_buttons.scss +0 -386
- package/src/styles/_component-primitives.scss +0 -183
- package/src/styles/_drakkar-buttons.scss +0 -85
- package/src/styles/_fonts.scss +0 -22
- package/src/styles/_forms.scss +0 -66
- package/src/styles/_input.scss +0 -106
- package/src/styles/_layout-enforcement.scss +0 -229
- package/src/styles/_layout-rhythm.scss +0 -158
- package/src/styles/_legacy-aliases.scss +0 -212
- package/src/styles/_series-colors.scss +0 -24
- package/src/styles/_static-primitives.scss +0 -857
- package/src/styles/_typography.scss +0 -87
- package/src/styles/_variables.scss +0 -527
- package/src/styles/components/a11y.scss +0 -90
- package/src/styles/components/badges.scss +0 -102
- package/src/styles/components/extracted-utilities.scss +0 -459
- package/src/styles/components/footer.scss +0 -168
- package/src/styles/components/icon-heading.scss +0 -47
- package/src/styles/components/icon-inline.scss +0 -101
- package/src/styles/components/layout.scss +0 -59
- package/src/styles/components/utilities.scss +0 -131
- package/src/styles/components/viking-inspired.scss +0 -204
- package/src/styles/components/whitepaper-cta.scss +0 -130
- package/src/styles/components-bundle.scss +0 -9
- package/src/styles/components.scss +0 -442
- package/src/styles/deml-components.scss +0 -10
- package/src/styles/index.scss +0 -8
- package/src/styles/layout-shell.scss +0 -111
- package/src/styles/page-shell.scss +0 -859
- package/src/styles/static-navbar.scss +0 -1250
- package/src/styles/surfaces/backend.scss +0 -154
- package/src/styles/surfaces/docs-global.scss +0 -73
- package/src/styles/surfaces/docs-shell.scss +0 -437
- package/src/styles/surfaces/docs-showcase.scss +0 -1153
- package/src/styles/surfaces/marketing-cta.scss +0 -62
- package/src/styles/surfaces/marketing-docs-bento.scss +0 -67
- package/src/styles/surfaces/marketing-global.scss +0 -748
- package/src/styles/surfaces/marketing-landing.scss +0 -1526
- package/src/styles/surfaces/marketing-publication.scss +0 -535
- package/src/styles/surfaces/marketing-theme.scss +0 -14
- package/src/styles/surfaces/swagger-ui.scss +0 -1013
- package/src/styles/tokens-export.scss +0 -18
- package/src/styles/tokens.scss +0 -5
- package/src/styles/viking-ui-bundle.scss +0 -23
- package/src/styles/viking-ui.scss +0 -272
- package/src/tokens/series-presets.ts +0 -15
- package/src/tokens/tailwind.preset.js +0 -209
- package/src/tokens/viking-tokens.json +0 -318
- package/src/viking-ui.spec.ts +0 -416
- package/src/web/badge/viking-badge-wc.ts +0 -116
- package/src/web/button/viking-button-wc.ts +0 -165
- package/src/web/callout/viking-callout-wc.ts +0 -105
- package/src/web/card/viking-card-wc.ts +0 -67
- package/src/web/core/base.ts +0 -56
- package/src/web/core/dom.ts +0 -53
- package/src/web/core/icons-inline.ts +0 -44
- package/src/web/core/styles.ts +0 -1261
- package/src/web/core/types.ts +0 -19
- package/src/web/field/viking-field-wc.ts +0 -154
- package/src/web/index.ts +0 -73
- package/src/web/input/viking-input-wc.ts +0 -211
- package/src/web/modal/viking-modal-wc.ts +0 -187
- package/src/web/search-palette/viking-search-palette-wc.ts +0 -495
- package/src/web/select/viking-select-wc.ts +0 -218
- package/src/web/suite-header/viking-suite-header-wc.ts +0 -729
- package/src/web/suite-search-palette/viking-suite-search-palette-wc.ts +0 -234
- package/src/web/theme-toggle/viking-theme-toggle-wc.ts +0 -139
- package/src/web/types.ts +0 -37
- package/src/web/web-components.spec.ts +0 -297
- package/src/web-components/index.ts +0 -1
package/src/viking-ui.spec.ts
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
import { Component, signal } from "@angular/core";
|
|
2
|
-
import { TestBed, ComponentFixture } from "@angular/core/testing";
|
|
3
|
-
import { FormsModule } from "@angular/forms";
|
|
4
|
-
import {
|
|
5
|
-
VikingAccordion,
|
|
6
|
-
VikingAccordionItem,
|
|
7
|
-
VikingBadge,
|
|
8
|
-
VikingButton,
|
|
9
|
-
VikingCalendar,
|
|
10
|
-
VikingChart,
|
|
11
|
-
VikingCheckbox,
|
|
12
|
-
VikingFormPanel,
|
|
13
|
-
VikingFormSection,
|
|
14
|
-
VikingHeading,
|
|
15
|
-
VikingIcon,
|
|
16
|
-
VikingInput,
|
|
17
|
-
VikingField,
|
|
18
|
-
VikingPagination,
|
|
19
|
-
VikingProgress,
|
|
20
|
-
VikingSelect,
|
|
21
|
-
VikingSwitch,
|
|
22
|
-
VikingToastService,
|
|
23
|
-
VikingSelectOption,
|
|
24
|
-
} from "./public-api";
|
|
25
|
-
|
|
26
|
-
@Component({
|
|
27
|
-
imports: [VikingCheckbox, FormsModule],
|
|
28
|
-
template: `<viking-checkbox [(ngModel)]="accepted">Accept</viking-checkbox>`,
|
|
29
|
-
})
|
|
30
|
-
class CheckboxHost {
|
|
31
|
-
accepted = false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Component({
|
|
35
|
-
imports: [VikingSelect],
|
|
36
|
-
template: `<viking-select
|
|
37
|
-
[options]="options"
|
|
38
|
-
[value]="value()"
|
|
39
|
-
(valueChange)="value.set($event)"
|
|
40
|
-
/>`,
|
|
41
|
-
})
|
|
42
|
-
class SelectHost {
|
|
43
|
-
readonly options: VikingSelectOption[] = [
|
|
44
|
-
{ label: "Alpha", value: "a" },
|
|
45
|
-
{ label: "Beta", value: "b" },
|
|
46
|
-
];
|
|
47
|
-
readonly value = signal<unknown>(null);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
describe("viking-ui", () => {
|
|
51
|
-
const render = async <T>(
|
|
52
|
-
component: new () => T,
|
|
53
|
-
): Promise<ComponentFixture<T>> => {
|
|
54
|
-
const fixture = TestBed.createComponent(component);
|
|
55
|
-
fixture.detectChanges();
|
|
56
|
-
await fixture.whenStable();
|
|
57
|
-
return fixture;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
it("renders compact buttons without min-width for form actions", async (): Promise<void> => {
|
|
61
|
-
const fixture = TestBed.createComponent(VikingButton);
|
|
62
|
-
fixture.componentRef.setInput("variant", "primary");
|
|
63
|
-
fixture.componentRef.setInput("compact", true);
|
|
64
|
-
fixture.detectChanges();
|
|
65
|
-
expect(fixture.nativeElement.classList.contains("viking-compact")).toBe(
|
|
66
|
-
true,
|
|
67
|
-
);
|
|
68
|
-
const wc = fixture.nativeElement.querySelector(
|
|
69
|
-
"viking-button-wc",
|
|
70
|
-
) as HTMLElement;
|
|
71
|
-
const button = wc?.shadowRoot?.querySelector("button") as HTMLButtonElement;
|
|
72
|
-
expect(button.classList.contains("viking-btn-primary")).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("renders button variants with accessible focus and disabled semantics", async (): Promise<void> => {
|
|
76
|
-
const fixture = TestBed.createComponent(VikingButton);
|
|
77
|
-
fixture.componentRef.setInput("variant", "primary");
|
|
78
|
-
fixture.componentRef.setInput("disabled", true);
|
|
79
|
-
fixture.detectChanges();
|
|
80
|
-
const wc = fixture.nativeElement.querySelector(
|
|
81
|
-
"viking-button-wc",
|
|
82
|
-
) as HTMLElement;
|
|
83
|
-
const button = wc?.shadowRoot?.querySelector("button") as HTMLButtonElement;
|
|
84
|
-
expect(button.classList.contains("viking-btn-primary")).toBe(true);
|
|
85
|
-
expect(button.disabled).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("renders an anchor with rel guard when href and target are set", async (): Promise<void> => {
|
|
89
|
-
const fixture = TestBed.createComponent(VikingButton);
|
|
90
|
-
fixture.componentRef.setInput("href", "https://deml.app");
|
|
91
|
-
fixture.componentRef.setInput("target", "_blank");
|
|
92
|
-
fixture.detectChanges();
|
|
93
|
-
const wc = fixture.nativeElement.querySelector(
|
|
94
|
-
"viking-button-wc",
|
|
95
|
-
) as HTMLElement;
|
|
96
|
-
const anchor = wc?.shadowRoot?.querySelector("a") as HTMLAnchorElement;
|
|
97
|
-
expect(anchor.getAttribute("rel")).toBe("noopener noreferrer");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("applies tone classes on badges", async (): Promise<void> => {
|
|
101
|
-
const fixture = TestBed.createComponent(VikingBadge);
|
|
102
|
-
fixture.componentRef.setInput("tone", "danger");
|
|
103
|
-
fixture.detectChanges();
|
|
104
|
-
expect(
|
|
105
|
-
fixture.nativeElement.classList.contains("viking-badge-danger"),
|
|
106
|
-
).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("exposes heading level via aria-level", async (): Promise<void> => {
|
|
110
|
-
const fixture = TestBed.createComponent(VikingHeading);
|
|
111
|
-
fixture.componentRef.setInput("level", 2);
|
|
112
|
-
fixture.detectChanges();
|
|
113
|
-
expect(fixture.nativeElement.getAttribute("aria-level")).toBe("2");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("integrates checkbox with ngModel (ControlValueAccessor)", async (): Promise<void> => {
|
|
117
|
-
const fixture = await render(CheckboxHost);
|
|
118
|
-
const input = fixture.nativeElement.querySelector(
|
|
119
|
-
"input",
|
|
120
|
-
) as HTMLInputElement;
|
|
121
|
-
input.click();
|
|
122
|
-
fixture.detectChanges();
|
|
123
|
-
await fixture.whenStable();
|
|
124
|
-
expect(fixture.componentInstance.accepted).toBe(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("toggles switch state on change", async (): Promise<void> => {
|
|
128
|
-
const fixture = TestBed.createComponent(VikingSwitch);
|
|
129
|
-
fixture.detectChanges();
|
|
130
|
-
const input = fixture.nativeElement.querySelector(
|
|
131
|
-
"input",
|
|
132
|
-
) as HTMLInputElement;
|
|
133
|
-
input.click();
|
|
134
|
-
fixture.detectChanges();
|
|
135
|
-
expect(fixture.componentInstance.checked()).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("opens the select listbox and picks an option", async (): Promise<void> => {
|
|
139
|
-
const fixture = await render(SelectHost);
|
|
140
|
-
const trigger = fixture.nativeElement.querySelector(
|
|
141
|
-
".viking-select-trigger",
|
|
142
|
-
) as HTMLButtonElement;
|
|
143
|
-
trigger.click();
|
|
144
|
-
fixture.detectChanges();
|
|
145
|
-
const options = fixture.nativeElement.querySelectorAll(
|
|
146
|
-
".viking-select-option",
|
|
147
|
-
);
|
|
148
|
-
expect(options.length).toBe(2);
|
|
149
|
-
(options[1] as HTMLElement).click();
|
|
150
|
-
fixture.detectChanges();
|
|
151
|
-
expect(fixture.componentInstance.value()).toBe("b");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("windows pagination with ellipses for long ranges", async (): Promise<void> => {
|
|
155
|
-
const fixture = TestBed.createComponent(VikingPagination);
|
|
156
|
-
fixture.componentRef.setInput("totalPages", 20);
|
|
157
|
-
fixture.componentRef.setInput("page", 10);
|
|
158
|
-
fixture.detectChanges();
|
|
159
|
-
const text = (fixture.nativeElement as HTMLElement).textContent ?? "";
|
|
160
|
-
expect(text).toContain("…");
|
|
161
|
-
expect(text).toContain("10");
|
|
162
|
-
expect(text).toContain("20");
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("clamps progress values into 0-100 and sets aria-valuenow", async (): Promise<void> => {
|
|
166
|
-
const fixture = TestBed.createComponent(VikingProgress);
|
|
167
|
-
fixture.componentRef.setInput("value", 140);
|
|
168
|
-
fixture.detectChanges();
|
|
169
|
-
const bar = fixture.nativeElement.querySelector(
|
|
170
|
-
'[role="progressbar"]',
|
|
171
|
-
) as HTMLElement;
|
|
172
|
-
expect(bar.getAttribute("aria-valuenow")).toBe("100");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("renders a 42-day calendar grid and selects a day", async (): Promise<void> => {
|
|
176
|
-
const fixture = TestBed.createComponent(VikingCalendar);
|
|
177
|
-
fixture.detectChanges();
|
|
178
|
-
const days = fixture.nativeElement.querySelectorAll(".viking-calendar-day");
|
|
179
|
-
expect(days.length).toBe(42);
|
|
180
|
-
(days[15] as HTMLElement).click();
|
|
181
|
-
fixture.detectChanges();
|
|
182
|
-
expect(fixture.componentInstance.value()).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("builds SVG paths for every chart series", async (): Promise<void> => {
|
|
186
|
-
const fixture = TestBed.createComponent(VikingChart);
|
|
187
|
-
fixture.componentRef.setInput("series", [
|
|
188
|
-
{ name: "p50", data: [1, 2, 3] },
|
|
189
|
-
{ name: "p95", tone: "warning", data: [2, 4, 6] },
|
|
190
|
-
]);
|
|
191
|
-
fixture.detectChanges();
|
|
192
|
-
const lines = fixture.nativeElement.querySelectorAll(".viking-chart-line");
|
|
193
|
-
expect(lines.length).toBe(2);
|
|
194
|
-
expect((lines[0] as SVGPathElement).getAttribute("d")).toContain("M");
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("renders grouped and stacked bar rects", async (): Promise<void> => {
|
|
198
|
-
const grouped = TestBed.createComponent(VikingChart);
|
|
199
|
-
grouped.componentRef.setInput("kind", "grouped-bar");
|
|
200
|
-
grouped.componentRef.setInput("series", [
|
|
201
|
-
{ name: "A", tone: "accent", data: [4, 6, 5] },
|
|
202
|
-
{ name: "B", tone: "success", data: [3, 2, 4] },
|
|
203
|
-
]);
|
|
204
|
-
grouped.detectChanges();
|
|
205
|
-
expect(
|
|
206
|
-
grouped.nativeElement.querySelectorAll(".viking-chart-bar").length,
|
|
207
|
-
).toBe(6);
|
|
208
|
-
|
|
209
|
-
const stacked = TestBed.createComponent(VikingChart);
|
|
210
|
-
stacked.componentRef.setInput("kind", "stacked-bar");
|
|
211
|
-
stacked.componentRef.setInput("series", [
|
|
212
|
-
{ name: "Online", tone: "accent", data: [4, 3] },
|
|
213
|
-
{ name: "Retail", tone: "success", data: [2, 5] },
|
|
214
|
-
]);
|
|
215
|
-
stacked.detectChanges();
|
|
216
|
-
expect(
|
|
217
|
-
stacked.nativeElement.querySelectorAll(".viking-chart-bar").length,
|
|
218
|
-
).toBe(4);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("renders a minimum visible height for zero-value bars", async (): Promise<void> => {
|
|
222
|
-
const fixture = TestBed.createComponent(VikingChart);
|
|
223
|
-
fixture.componentRef.setInput("kind", "bar");
|
|
224
|
-
fixture.componentRef.setInput("series", [
|
|
225
|
-
{ name: "Revenue", data: [0, 5, 0] },
|
|
226
|
-
]);
|
|
227
|
-
fixture.componentRef.setInput("barMinHeight", 4);
|
|
228
|
-
fixture.detectChanges();
|
|
229
|
-
|
|
230
|
-
const bars = fixture.nativeElement.querySelectorAll(".viking-chart-bar");
|
|
231
|
-
expect(bars.length).toBe(3);
|
|
232
|
-
expect(Number((bars[0] as SVGRectElement).getAttribute("height"))).toBe(4);
|
|
233
|
-
expect(Number((bars[2] as SVGRectElement).getAttribute("height"))).toBe(4);
|
|
234
|
-
expect(
|
|
235
|
-
Number((bars[1] as SVGRectElement).getAttribute("height")),
|
|
236
|
-
).toBeGreaterThan(4);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("enforces exclusive accordion mode", async (): Promise<void> => {
|
|
240
|
-
@Component({
|
|
241
|
-
imports: [VikingAccordion, VikingAccordionItem],
|
|
242
|
-
template: `
|
|
243
|
-
<viking-accordion [exclusive]="true">
|
|
244
|
-
<viking-accordion-item heading="One">First</viking-accordion-item>
|
|
245
|
-
<viking-accordion-item heading="Two">Second</viking-accordion-item>
|
|
246
|
-
</viking-accordion>
|
|
247
|
-
`,
|
|
248
|
-
})
|
|
249
|
-
class AccordionHost {}
|
|
250
|
-
|
|
251
|
-
const fixture = await render(AccordionHost);
|
|
252
|
-
const triggers = fixture.nativeElement.querySelectorAll(
|
|
253
|
-
".viking-accordion-trigger",
|
|
254
|
-
);
|
|
255
|
-
(triggers[0] as HTMLElement).click();
|
|
256
|
-
fixture.detectChanges();
|
|
257
|
-
(triggers[1] as HTMLElement).click();
|
|
258
|
-
fixture.detectChanges();
|
|
259
|
-
const expanded = fixture.nativeElement.querySelectorAll(
|
|
260
|
-
'[aria-expanded="true"]',
|
|
261
|
-
);
|
|
262
|
-
expect(expanded.length).toBe(1);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("queues and auto-dismisses toasts via the service", (): void => {
|
|
266
|
-
const service = TestBed.inject(VikingToastService);
|
|
267
|
-
const id = service.show({
|
|
268
|
-
heading: "Saved",
|
|
269
|
-
text: "All good",
|
|
270
|
-
tone: "success",
|
|
271
|
-
duration: 0,
|
|
272
|
-
});
|
|
273
|
-
expect(service.toasts().length).toBe(1);
|
|
274
|
-
service.dismiss(id);
|
|
275
|
-
expect(service.toasts().length).toBe(0);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it("renders outline and filled Drakkar brand icons at 24×24 viewBox", async (): Promise<void> => {
|
|
279
|
-
const outline = TestBed.createComponent(VikingIcon);
|
|
280
|
-
outline.componentRef.setInput("name", "drakkar");
|
|
281
|
-
outline.componentRef.setInput("sizePreset", "lg");
|
|
282
|
-
outline.detectChanges();
|
|
283
|
-
const outlineSvg = outline.nativeElement.querySelector(
|
|
284
|
-
"svg",
|
|
285
|
-
) as SVGSVGElement;
|
|
286
|
-
expect(outlineSvg.getAttribute("viewBox")).toBe("0 0 24 24");
|
|
287
|
-
expect(outlineSvg.getAttribute("stroke")).toBe("currentColor");
|
|
288
|
-
expect(
|
|
289
|
-
outline.nativeElement.classList.contains("viking-icon-outline"),
|
|
290
|
-
).toBe(true);
|
|
291
|
-
expect(
|
|
292
|
-
outline.nativeElement.classList.contains("viking-icon-brand-drakkar"),
|
|
293
|
-
).toBe(true);
|
|
294
|
-
expect(outline.nativeElement.querySelector("g")?.innerHTML).toContain(
|
|
295
|
-
"M12 2v3",
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
const filled = TestBed.createComponent(VikingIcon);
|
|
299
|
-
filled.componentRef.setInput("name", "drakkar");
|
|
300
|
-
filled.componentRef.setInput("variant", "filled");
|
|
301
|
-
filled.componentRef.setInput("size", 28);
|
|
302
|
-
filled.detectChanges();
|
|
303
|
-
const filledSvg = filled.nativeElement.querySelector(
|
|
304
|
-
"svg",
|
|
305
|
-
) as SVGSVGElement;
|
|
306
|
-
expect(filledSvg.getAttribute("fill")).toBe("currentColor");
|
|
307
|
-
expect(filledSvg.getAttribute("fill-rule")).toBe("evenodd");
|
|
308
|
-
expect(filledSvg.getAttribute("stroke")).toBe("none");
|
|
309
|
-
expect(filled.nativeElement.classList.contains("viking-icon-filled")).toBe(
|
|
310
|
-
true,
|
|
311
|
-
);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it("renders outline and filled DEML brand icons at 24×24 viewBox", async (): Promise<void> => {
|
|
315
|
-
const outline = TestBed.createComponent(VikingIcon);
|
|
316
|
-
outline.componentRef.setInput("name", "deml");
|
|
317
|
-
outline.componentRef.setInput("sizePreset", "lg");
|
|
318
|
-
outline.detectChanges();
|
|
319
|
-
const outlineSvg = outline.nativeElement.querySelector(
|
|
320
|
-
"svg",
|
|
321
|
-
) as SVGSVGElement;
|
|
322
|
-
expect(outlineSvg.getAttribute("viewBox")).toBe("0 0 24 24");
|
|
323
|
-
expect(outlineSvg.getAttribute("stroke")).toBe("currentColor");
|
|
324
|
-
expect(
|
|
325
|
-
outline.nativeElement.classList.contains("viking-icon-outline"),
|
|
326
|
-
).toBe(true);
|
|
327
|
-
|
|
328
|
-
const filled = TestBed.createComponent(VikingIcon);
|
|
329
|
-
filled.componentRef.setInput("name", "deml");
|
|
330
|
-
filled.componentRef.setInput("variant", "filled");
|
|
331
|
-
filled.componentRef.setInput("size", 28);
|
|
332
|
-
filled.detectChanges();
|
|
333
|
-
const filledSvg = filled.nativeElement.querySelector(
|
|
334
|
-
"svg",
|
|
335
|
-
) as SVGSVGElement;
|
|
336
|
-
expect(filledSvg.getAttribute("fill")).toBe("currentColor");
|
|
337
|
-
expect(filledSvg.getAttribute("fill-rule")).toBe("evenodd");
|
|
338
|
-
expect(filledSvg.getAttribute("stroke")).toBe("none");
|
|
339
|
-
expect(filled.nativeElement.classList.contains("viking-icon-filled")).toBe(
|
|
340
|
-
true,
|
|
341
|
-
);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("maps size presets to pixel dimensions", async (): Promise<void> => {
|
|
345
|
-
const fixture = TestBed.createComponent(VikingIcon);
|
|
346
|
-
fixture.componentRef.setInput("name", "check");
|
|
347
|
-
fixture.componentRef.setInput("sizePreset", "sm");
|
|
348
|
-
fixture.detectChanges();
|
|
349
|
-
const svg = fixture.nativeElement.querySelector("svg") as SVGSVGElement;
|
|
350
|
-
expect(svg.style.width).toBe("16px");
|
|
351
|
-
expect(svg.style.height).toBe("16px");
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it("resolves semantic color tokens to CSS custom properties", async (): Promise<void> => {
|
|
355
|
-
const fixture = TestBed.createComponent(VikingIcon);
|
|
356
|
-
fixture.componentRef.setInput("name", "shield");
|
|
357
|
-
fixture.componentRef.setInput("color", "accent");
|
|
358
|
-
fixture.detectChanges();
|
|
359
|
-
expect((fixture.nativeElement as HTMLElement).style.color).toBe(
|
|
360
|
-
"var(--viking-accent)",
|
|
361
|
-
);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it("renders Lucide-sourced search icon paths", async (): Promise<void> => {
|
|
365
|
-
const fixture = TestBed.createComponent(VikingIcon);
|
|
366
|
-
fixture.componentRef.setInput("name", "search");
|
|
367
|
-
fixture.detectChanges();
|
|
368
|
-
const svg = fixture.nativeElement.querySelector("svg") as SVGSVGElement;
|
|
369
|
-
expect(svg.innerHTML).toContain("circle");
|
|
370
|
-
expect(svg.getAttribute("stroke")).toBe("currentColor");
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it("renders form section headings and layout classes", async (): Promise<void> => {
|
|
374
|
-
@Component({
|
|
375
|
-
imports: [VikingFormSection, VikingField, VikingInput, FormsModule],
|
|
376
|
-
template: `
|
|
377
|
-
<viking-form-section heading="Update Email" icon="mail" layout="inline">
|
|
378
|
-
<viking-field label="Email">
|
|
379
|
-
<viking-input />
|
|
380
|
-
</viking-field>
|
|
381
|
-
<button type="button" vikingFormActions>Save</button>
|
|
382
|
-
</viking-form-section>
|
|
383
|
-
`,
|
|
384
|
-
})
|
|
385
|
-
class FormSectionHost {}
|
|
386
|
-
|
|
387
|
-
const fixture = await render(FormSectionHost);
|
|
388
|
-
const section = fixture.nativeElement.querySelector(
|
|
389
|
-
"viking-form-section",
|
|
390
|
-
) as HTMLElement;
|
|
391
|
-
expect(section.classList.contains("viking-form-section-inline")).toBe(true);
|
|
392
|
-
expect(
|
|
393
|
-
section.querySelector(".viking-form-section-title")?.textContent,
|
|
394
|
-
).toContain("Update Email");
|
|
395
|
-
expect(section.querySelector("[vikingFormActions]")).toBeTruthy();
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it("separates stacked form sections inside a panel", async (): Promise<void> => {
|
|
399
|
-
@Component({
|
|
400
|
-
imports: [VikingFormPanel, VikingFormSection],
|
|
401
|
-
template: `
|
|
402
|
-
<viking-form-panel>
|
|
403
|
-
<viking-form-section heading="One" layout="stack" />
|
|
404
|
-
<viking-form-section heading="Two" layout="stack" />
|
|
405
|
-
</viking-form-panel>
|
|
406
|
-
`,
|
|
407
|
-
})
|
|
408
|
-
class FormPanelHost {}
|
|
409
|
-
|
|
410
|
-
const fixture = await render(FormPanelHost);
|
|
411
|
-
const sections = fixture.nativeElement.querySelectorAll(
|
|
412
|
-
"viking-form-section",
|
|
413
|
-
);
|
|
414
|
-
expect(sections.length).toBe(2);
|
|
415
|
-
});
|
|
416
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { attachShadowStyles } from "../core/base";
|
|
2
|
-
import {
|
|
3
|
-
defineCustomElement,
|
|
4
|
-
defineCustomElementAlias,
|
|
5
|
-
HTMLElementBase,
|
|
6
|
-
} from "../core/dom";
|
|
7
|
-
import { renderInlineIcon, TONE_ICON_NAMES } from "../core/icons-inline";
|
|
8
|
-
import { VIKING_BADGE_STYLES } from "../core/styles";
|
|
9
|
-
import type { VikingWcTone } from "../core/types";
|
|
10
|
-
|
|
11
|
-
const TONES = new Set<VikingWcTone>([
|
|
12
|
-
"accent",
|
|
13
|
-
"secondary",
|
|
14
|
-
"success",
|
|
15
|
-
"warning",
|
|
16
|
-
"danger",
|
|
17
|
-
"info",
|
|
18
|
-
"muted",
|
|
19
|
-
"subtle",
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Framework-agnostic Viking badge Web Component.
|
|
24
|
-
* Tag: `viking-badge` (legacy alias: `viking-badge-wc`)
|
|
25
|
-
*
|
|
26
|
-
* @attr tone - Semantic color: accent | secondary | success | warning | danger | info | muted
|
|
27
|
-
* @attr size - Compact density: sm
|
|
28
|
-
* @attr icon - Viking icon registry name (pairs with label for a11y)
|
|
29
|
-
* @attr removable - Shows remove control; dispatches `viking-removed`
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* <viking-badge-wc tone="success" icon="check">Healthy</viking-badge-wc>
|
|
33
|
-
*/
|
|
34
|
-
export class VikingBadgeWc extends HTMLElementBase {
|
|
35
|
-
static readonly tag = "viking-badge";
|
|
36
|
-
static readonly legacyTag = "viking-badge-wc";
|
|
37
|
-
|
|
38
|
-
static get observedAttributes(): string[] {
|
|
39
|
-
return ["tone", "size", "icon", "removable"];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private readonly shadow: ShadowRoot;
|
|
43
|
-
|
|
44
|
-
constructor() {
|
|
45
|
-
super();
|
|
46
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
47
|
-
attachShadowStyles(this.shadow, VIKING_BADGE_STYLES);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
connectedCallback(): void {
|
|
51
|
-
this.render();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
attributeChangedCallback(): void {
|
|
55
|
-
if (this.isConnected) {
|
|
56
|
-
this.render();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private get tone(): VikingWcTone | null {
|
|
61
|
-
const value = (this.getAttribute("tone") ?? "") as VikingWcTone;
|
|
62
|
-
return TONES.has(value) ? value : null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private get size(): "sm" | null {
|
|
66
|
-
return this.getAttribute("size") === "sm" ? "sm" : null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private get removable(): boolean {
|
|
70
|
-
return (
|
|
71
|
-
this.hasAttribute("removable") &&
|
|
72
|
-
this.getAttribute("removable") !== "false"
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private readonly onRemove = (): void => {
|
|
77
|
-
this.dispatchEvent(
|
|
78
|
-
new CustomEvent("viking-removed", { bubbles: true, composed: true }),
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
private render(): void {
|
|
83
|
-
const tone = this.tone;
|
|
84
|
-
if (tone && this.getAttribute("tone") !== tone) {
|
|
85
|
-
this.setAttribute("tone", tone);
|
|
86
|
-
} else if (!tone && this.hasAttribute("tone")) {
|
|
87
|
-
this.removeAttribute("tone");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const size = this.size;
|
|
91
|
-
if (size && this.getAttribute("size") !== size) {
|
|
92
|
-
this.setAttribute("size", size);
|
|
93
|
-
} else if (!size && this.hasAttribute("size")) {
|
|
94
|
-
this.removeAttribute("size");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const iconName =
|
|
98
|
-
this.getAttribute("icon") ?? (tone ? TONE_ICON_NAMES[tone] : null);
|
|
99
|
-
const iconMarkup = iconName ? renderInlineIcon(iconName, 16) : "";
|
|
100
|
-
|
|
101
|
-
this.shadow.innerHTML = `
|
|
102
|
-
${iconMarkup}
|
|
103
|
-
<span part="label"><slot></slot></span>
|
|
104
|
-
${this.removable ? `<button type="button" class="viking-badge-remove" part="remove" aria-label="Remove">${renderInlineIcon("x", 14)}</button>` : ""}
|
|
105
|
-
`;
|
|
106
|
-
|
|
107
|
-
this.shadow
|
|
108
|
-
.querySelector(".viking-badge-remove")
|
|
109
|
-
?.addEventListener("click", this.onRemove);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export const registerVikingBadgeWc = (): void => {
|
|
114
|
-
defineCustomElement(VikingBadgeWc.tag, VikingBadgeWc);
|
|
115
|
-
defineCustomElementAlias(VikingBadgeWc.legacyTag, VikingBadgeWc);
|
|
116
|
-
};
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { attachShadowStyles, readBoolAttr } from "../core/base";
|
|
2
|
-
import {
|
|
3
|
-
defineCustomElement,
|
|
4
|
-
defineCustomElementAlias,
|
|
5
|
-
escapeHtml,
|
|
6
|
-
HTMLElementBase,
|
|
7
|
-
} from "../core/dom";
|
|
8
|
-
import { VIKING_BUTTON_STYLES } from "../core/styles";
|
|
9
|
-
|
|
10
|
-
const VARIANTS = new Set([
|
|
11
|
-
"outline",
|
|
12
|
-
"primary",
|
|
13
|
-
"secondary",
|
|
14
|
-
"filled",
|
|
15
|
-
"danger",
|
|
16
|
-
"ghost",
|
|
17
|
-
"subtle",
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
const SIZES = new Set(["sm", "xs"]);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Framework-agnostic Viking button Web Component.
|
|
24
|
-
* Tag: `viking-button` (legacy alias: `viking-button-wc`)
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* <viking-button variant="primary">Launch</viking-button>
|
|
28
|
-
*/
|
|
29
|
-
export class VikingButtonWc extends HTMLElementBase {
|
|
30
|
-
static readonly tag = "viking-button";
|
|
31
|
-
static readonly legacyTag = "viking-button-wc";
|
|
32
|
-
|
|
33
|
-
static get observedAttributes(): string[] {
|
|
34
|
-
return [
|
|
35
|
-
"variant",
|
|
36
|
-
"size",
|
|
37
|
-
"type",
|
|
38
|
-
"disabled",
|
|
39
|
-
"loading",
|
|
40
|
-
"href",
|
|
41
|
-
"target",
|
|
42
|
-
"aria-label",
|
|
43
|
-
"aria-busy",
|
|
44
|
-
"square",
|
|
45
|
-
"full-width",
|
|
46
|
-
"compact",
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private readonly shadow: ShadowRoot;
|
|
51
|
-
private control: HTMLButtonElement | HTMLAnchorElement | null = null;
|
|
52
|
-
|
|
53
|
-
constructor() {
|
|
54
|
-
super();
|
|
55
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
56
|
-
attachShadowStyles(this.shadow, VIKING_BUTTON_STYLES);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
connectedCallback(): void {
|
|
60
|
-
this.render();
|
|
61
|
-
this.syncHostSemantics();
|
|
62
|
-
this.control?.addEventListener("click", this.onClick);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
disconnectedCallback(): void {
|
|
66
|
-
this.control?.removeEventListener("click", this.onClick);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
attributeChangedCallback(): void {
|
|
70
|
-
if (this.isConnected) {
|
|
71
|
-
this.render();
|
|
72
|
-
this.syncHostSemantics();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private readonly onClick = (event: Event): void => {
|
|
77
|
-
if (this.disabled || this.loading) {
|
|
78
|
-
event.preventDefault();
|
|
79
|
-
event.stopPropagation();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.dispatchEvent(
|
|
83
|
-
new CustomEvent("viking-press", {
|
|
84
|
-
bubbles: true,
|
|
85
|
-
composed: true,
|
|
86
|
-
detail: event,
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
private get variant(): string {
|
|
92
|
-
const value = this.getAttribute("variant") ?? "outline";
|
|
93
|
-
return VARIANTS.has(value) ? value : "outline";
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private get size(): string | null {
|
|
97
|
-
const value = this.getAttribute("size");
|
|
98
|
-
return value && SIZES.has(value) ? value : null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private get disabled(): boolean {
|
|
102
|
-
return readBoolAttr(this, "disabled");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private get loading(): boolean {
|
|
106
|
-
return readBoolAttr(this, "loading");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private get square(): boolean {
|
|
110
|
-
return readBoolAttr(this, "square");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private syncHostSemantics(): void {
|
|
114
|
-
if (!this.hasAttribute("role")) {
|
|
115
|
-
this.setAttribute("role", this.getAttribute("href") ? "link" : "button");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private render(): void {
|
|
120
|
-
const href = this.getAttribute("href");
|
|
121
|
-
const isLink = Boolean(href);
|
|
122
|
-
const tag = isLink ? "a" : "button";
|
|
123
|
-
|
|
124
|
-
const classes = [
|
|
125
|
-
"viking-btn",
|
|
126
|
-
`viking-btn-${this.variant}`,
|
|
127
|
-
this.size ? `viking-btn-${this.size}` : "",
|
|
128
|
-
this.square ? "viking-btn-square" : "",
|
|
129
|
-
]
|
|
130
|
-
.filter(Boolean)
|
|
131
|
-
.join(" ");
|
|
132
|
-
|
|
133
|
-
const label = this.getAttribute("aria-label") ?? "";
|
|
134
|
-
const busy =
|
|
135
|
-
this.getAttribute("aria-busy") === "true" || this.loading ? "true" : null;
|
|
136
|
-
const type = escapeHtml(this.getAttribute("type") ?? "button");
|
|
137
|
-
const hrefValue = href ? escapeHtml(href) : "";
|
|
138
|
-
const target = this.getAttribute("target");
|
|
139
|
-
const safeTarget = target ? escapeHtml(target) : "";
|
|
140
|
-
|
|
141
|
-
this.shadow.innerHTML = `
|
|
142
|
-
<${tag}
|
|
143
|
-
class="${classes}"
|
|
144
|
-
part="control"
|
|
145
|
-
${isLink ? `href="${hrefValue}"` : `type="${type}"`}
|
|
146
|
-
${isLink && safeTarget ? `target="${safeTarget}"` : ""}
|
|
147
|
-
${isLink && target === "_blank" ? 'rel="noopener noreferrer"' : ""}
|
|
148
|
-
${this.disabled || this.loading ? "disabled" : ""}
|
|
149
|
-
${label ? `aria-label="${escapeHtml(label)}"` : ""}
|
|
150
|
-
${busy ? `aria-busy="${busy}"` : ""}
|
|
151
|
-
${this.disabled && isLink ? 'aria-disabled="true" tabindex="-1"' : ""}
|
|
152
|
-
>
|
|
153
|
-
${this.loading ? '<span class="viking-btn-spinner" aria-hidden="true"></span>' : ""}
|
|
154
|
-
<span class="viking-btn-label" part="label"><slot></slot></span>
|
|
155
|
-
</${tag}>
|
|
156
|
-
`;
|
|
157
|
-
|
|
158
|
-
this.control = this.shadow.querySelector(tag);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export const registerVikingButtonWc = (): void => {
|
|
163
|
-
defineCustomElement(VikingButtonWc.tag, VikingButtonWc);
|
|
164
|
-
defineCustomElementAlias(VikingButtonWc.legacyTag, VikingButtonWc);
|
|
165
|
-
};
|