@dataengineeringformachinelearning/viking-ui 1.0.2 → 3.0.0-alpha.4
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/LICENSE +201 -0
- package/README.md +217 -38
- package/dist/core/brand-icons.d.ts +29 -0
- package/dist/core/icons.d.ts +132 -0
- package/dist/core/integration-brand-icons.d.ts +18 -0
- package/dist/core/lucide-paths.generated.d.ts +90 -0
- package/dist/core/types.d.ts +56 -0
- package/dist/core/uid.d.ts +2 -0
- package/dist/deml-components.css +1122 -0
- package/dist/design-tokens.css +688 -0
- package/dist/elements/button/viking-button.d.ts +14 -0
- package/dist/elements/card/viking-card.d.ts +8 -0
- package/dist/elements/core/dom.d.ts +4 -0
- package/dist/elements/core/styles.d.ts +2 -0
- package/dist/elements/modal/viking-modal.d.ts +15 -0
- package/dist/fonts/inter/InterVariable-Italic.woff2 +0 -0
- package/dist/fonts/inter/InterVariable.woff2 +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4051 -0
- package/dist/lib/accordion/accordion.d.ts +19 -0
- package/dist/lib/app-header/app-header.d.ts +8 -0
- package/dist/lib/app-sidebar/app-sidebar.d.ts +10 -0
- package/dist/lib/auth-panel/auth-panel.d.ts +13 -0
- package/dist/lib/autocomplete/autocomplete.d.ts +25 -0
- package/dist/lib/avatar/avatar.d.ts +14 -0
- package/dist/lib/badge/badge.d.ts +16 -0
- package/dist/lib/bar/bar.d.ts +4 -0
- package/dist/lib/brand/brand.d.ts +8 -0
- package/dist/lib/breadcrumbs/breadcrumbs.d.ts +10 -0
- package/dist/lib/button/button-group.d.ts +6 -0
- package/dist/lib/button/button.d.ts +25 -0
- package/dist/lib/calendar/calendar.d.ts +22 -0
- package/dist/lib/callout/callout.d.ts +14 -0
- package/dist/lib/card/card-title.d.ts +12 -0
- package/dist/lib/card/card.d.ts +19 -0
- package/dist/lib/carousel/carousel.d.ts +13 -0
- package/dist/lib/chart/chart-zoom.d.ts +14 -0
- package/dist/lib/chart/chart.d.ts +119 -0
- package/dist/lib/chart-card-header/chart-card-header.d.ts +10 -0
- package/dist/lib/chart-empty-state/chart-empty-state.d.ts +13 -0
- package/dist/lib/chart-panel/chart-panel.d.ts +10 -0
- package/dist/lib/checkbox/checkbox.d.ts +13 -0
- package/dist/lib/color-picker/color-picker.d.ts +16 -0
- package/dist/lib/command/command.d.ts +23 -0
- package/dist/lib/composer/composer.d.ts +15 -0
- package/dist/lib/confirm-dialog/confirm-dialog.d.ts +18 -0
- package/dist/lib/confirm-dialog/dialog.service.d.ts +28 -0
- package/dist/lib/context/context.d.ts +17 -0
- package/dist/lib/core/brand-icons.d.ts +29 -0
- package/dist/lib/core/cva.d.ts +15 -0
- package/dist/lib/core/icons.d.ts +132 -0
- package/dist/lib/core/integration-brand-icons.d.ts +18 -0
- package/dist/lib/core/lucide-paths.generated.d.ts +90 -0
- package/dist/lib/date-picker/date-picker.d.ts +18 -0
- package/dist/lib/dropdown/dropdown.d.ts +29 -0
- package/dist/lib/editor/editor.d.ts +26 -0
- package/dist/lib/empty-state/empty-state.d.ts +9 -0
- package/dist/lib/fab/fab.d.ts +9 -0
- package/dist/lib/field/field.d.ts +14 -0
- package/dist/lib/file-upload/file-upload.d.ts +19 -0
- package/dist/lib/footer/footer.d.ts +6 -0
- package/dist/lib/form-section/form-section.d.ts +15 -0
- package/dist/lib/gauge-arc/gauge-arc.d.ts +8 -0
- package/dist/lib/hud-panel/hud-panel.d.ts +5 -0
- package/dist/lib/icon/icon.d.ts +44 -0
- package/dist/lib/icon-badge/icon-badge.d.ts +14 -0
- package/dist/lib/icon-heading/icon-heading.d.ts +9 -0
- package/dist/lib/icon-text/icon-text.d.ts +12 -0
- package/dist/lib/input/input.d.ts +23 -0
- package/dist/lib/kanban/kanban.d.ts +16 -0
- package/dist/lib/kbd/kbd.d.ts +5 -0
- package/dist/lib/label/label.d.ts +7 -0
- package/dist/lib/loading-overlay/loading-overlay.d.ts +10 -0
- package/dist/lib/menubar/menubar.d.ts +10 -0
- package/dist/lib/metric-card/metric-card.d.ts +9 -0
- package/dist/lib/modal/modal.d.ts +13 -0
- package/dist/lib/native-select/native-select.d.ts +17 -0
- package/dist/lib/navbar/navbar.d.ts +13 -0
- package/dist/lib/navigation-menu/navigation-menu.d.ts +13 -0
- package/dist/lib/otp-input/otp-input.d.ts +23 -0
- package/dist/lib/page-back-link/page-back-link.d.ts +11 -0
- package/dist/lib/page-header/page-header.d.ts +15 -0
- package/dist/lib/pagination/pagination.d.ts +10 -0
- package/dist/lib/pillbox/pillbox.d.ts +15 -0
- package/dist/lib/popover/popover.d.ts +15 -0
- package/dist/lib/profile/profile.d.ts +11 -0
- package/dist/lib/progress/progress.d.ts +12 -0
- package/dist/lib/radio/radio.d.ts +16 -0
- package/dist/lib/ring-gauge/ring-gauge.d.ts +8 -0
- package/dist/lib/scroll-area/scroll-area.d.ts +7 -0
- package/dist/lib/search-palette/search-palette.d.ts +16 -0
- package/dist/lib/select/select.d.ts +26 -0
- package/dist/lib/separator/separator.d.ts +8 -0
- package/dist/lib/sheet/sheet.d.ts +13 -0
- package/dist/lib/sidebar-nav/sidebar-nav.d.ts +46 -0
- package/dist/lib/site-drakkar/site-drakkar.config.d.ts +50 -0
- package/dist/lib/site-drakkar/site-footer.d.ts +18 -0
- package/dist/lib/site-drakkar/site-navbar.d.ts +25 -0
- package/dist/lib/site-drakkar/suite-search-items.d.ts +17 -0
- package/dist/lib/skeleton/skeleton.d.ts +8 -0
- package/dist/lib/slider/slider.d.ts +17 -0
- package/dist/lib/spinner/spinner.d.ts +7 -0
- package/dist/lib/status-metric-row/status-metric-row.d.ts +9 -0
- package/dist/lib/suite-search-palette/suite-search-palette.d.ts +25 -0
- package/dist/lib/switch/switch.d.ts +12 -0
- package/dist/lib/table/table.d.ts +10 -0
- package/dist/lib/tabs/tab-panel.d.ts +12 -0
- package/dist/lib/tabs/tab.d.ts +14 -0
- package/dist/lib/tabs/tabs.d.ts +10 -0
- package/dist/lib/textarea/textarea.d.ts +16 -0
- package/dist/lib/theme-toggle/theme-toggle.d.ts +9 -0
- package/dist/lib/time-picker/time-picker.d.ts +21 -0
- package/dist/lib/timeline/timeline.d.ts +14 -0
- package/dist/lib/toast/toast.d.ts +21 -0
- package/dist/lib/toggle/toggle-group.d.ts +9 -0
- package/dist/lib/toggle/toggle.d.ts +15 -0
- package/dist/lib/tooltip/tooltip.d.ts +20 -0
- package/dist/lib/typography/heading.d.ts +9 -0
- package/dist/lib/typography/text.d.ts +11 -0
- package/dist/lib/uptime-bar/uptime-bar.d.ts +6 -0
- package/dist/lib/verification-code-field/verification-code-field.d.ts +19 -0
- package/dist/lib/whitepaper-cta/whitepaper-cta.d.ts +15 -0
- package/dist/lib/wizard/wizard.d.ts +13 -0
- package/dist/public-api.d.ts +109 -0
- package/dist/tokens/series-presets.d.ts +4 -0
- package/dist/viking-components.css +1837 -0
- package/dist/viking-tokens.json +318 -0
- package/dist/viking-ui-elements.js +1750 -0
- package/dist/viking-ui.css +1 -0
- package/dist/web/badge/viking-badge-wc.d.ts +28 -0
- package/dist/web/button/viking-button-wc.d.ts +28 -0
- package/dist/web/callout/viking-callout-wc.d.ts +27 -0
- package/dist/web/card/viking-card-wc.d.ts +29 -0
- package/dist/web/core/base.d.ts +12 -0
- package/dist/web/core/dom.d.ts +11 -0
- package/dist/web/core/icons-inline.d.ts +7 -0
- package/dist/web/core/styles.d.ts +12 -0
- package/dist/web/core/types.d.ts +10 -0
- package/dist/web/field/viking-field-wc.d.ts +32 -0
- package/dist/web/index.d.ts +15 -0
- package/dist/web/input/viking-input-wc.d.ts +32 -0
- package/dist/web/modal/viking-modal-wc.d.ts +50 -0
- package/dist/web/search-palette/viking-search-palette-wc.d.ts +64 -0
- package/dist/web/select/viking-select-wc.d.ts +48 -0
- package/dist/web/suite-header/viking-suite-header-wc.d.ts +36 -0
- package/dist/web/suite-search-palette/viking-suite-search-palette-wc.d.ts +39 -0
- package/dist/web/theme-toggle/viking-theme-toggle-wc.d.ts +19 -0
- package/dist/web/types.d.ts +40 -0
- package/dist/web-components/index.d.ts +1 -0
- package/dist/web-components.js +1750 -0
- package/dist/widget.js +1182 -0
- package/package.json +89 -30
- package/src/assets/drakkar-favicon.svg +17 -0
- 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 +5 -0
- package/src/core/brand/deml-mark-compact.svg +4 -0
- package/src/core/brand/deml-mark-filled.svg +3 -0
- package/src/core/brand/deml-mark-outline.svg +4 -0
- package/src/core/brand-icons.ts +62 -0
- package/src/core/icons.spec.ts +52 -0
- package/src/core/icons.ts +206 -0
- package/src/core/integration-brand-icons.ts +77 -0
- package/src/core/lucide-paths.generated.ts +130 -0
- package/src/core/types.ts +85 -0
- package/src/core/uid.ts +7 -0
- package/src/elements/button/viking-button.ts +201 -0
- package/src/elements/card/viking-card.ts +60 -0
- package/src/elements/core/dom.ts +33 -0
- package/src/elements/core/styles.ts +28 -0
- package/src/elements/modal/viking-modal.ts +154 -0
- package/src/index.ts +1 -0
- package/src/lib/accordion/accordion.ts +126 -0
- package/src/lib/app-header/app-header.scss +274 -0
- package/src/lib/app-header/app-header.ts +43 -0
- package/src/lib/app-sidebar/app-sidebar.scss +415 -0
- package/src/lib/app-sidebar/app-sidebar.ts +29 -0
- package/src/lib/auth-panel/auth-panel.spec.ts +132 -0
- package/src/lib/auth-panel/auth-panel.ts +228 -0
- package/src/lib/autocomplete/autocomplete.ts +223 -0
- package/src/lib/avatar/avatar.ts +126 -0
- package/src/lib/badge/badge.ts +182 -0
- package/src/lib/bar/bar.ts +31 -0
- package/src/lib/brand/brand.ts +60 -0
- package/src/lib/breadcrumbs/breadcrumbs.ts +81 -0
- package/src/lib/button/button-group.ts +40 -0
- package/src/lib/button/button.scss +96 -0
- package/src/lib/button/button.ts +98 -0
- package/src/lib/calendar/calendar.ts +253 -0
- package/src/lib/callout/callout.ts +211 -0
- package/src/lib/card/card-title.spec.ts +27 -0
- package/src/lib/card/card-title.ts +50 -0
- package/src/lib/card/card.ts +170 -0
- package/src/lib/carousel/carousel.ts +206 -0
- package/src/lib/chart/chart-zoom.spec.ts +65 -0
- package/src/lib/chart/chart-zoom.ts +71 -0
- package/src/lib/chart/chart.ts +1257 -0
- package/src/lib/chart-card-header/chart-card-header.ts +80 -0
- package/src/lib/chart-empty-state/chart-empty-state.ts +146 -0
- package/src/lib/chart-panel/chart-panel.ts +133 -0
- package/src/lib/checkbox/checkbox.ts +139 -0
- package/src/lib/color-picker/color-picker.ts +148 -0
- package/src/lib/command/command.ts +260 -0
- package/src/lib/composer/composer.ts +180 -0
- package/src/lib/confirm-dialog/confirm-dialog.ts +163 -0
- package/src/lib/confirm-dialog/dialog.service.ts +79 -0
- package/src/lib/context/context.ts +75 -0
- package/src/lib/core/brand-icons.ts +62 -0
- package/src/lib/core/cva.ts +33 -0
- package/src/lib/core/icons.ts +206 -0
- package/src/lib/core/integration-brand-icons.ts +77 -0
- package/src/lib/core/lucide-paths.generated.ts +130 -0
- package/src/lib/date-picker/date-picker.ts +139 -0
- package/src/lib/dropdown/dropdown.ts +188 -0
- package/src/lib/editor/editor.ts +170 -0
- package/src/lib/empty-state/empty-state.ts +100 -0
- package/src/lib/fab/fab.ts +76 -0
- package/src/lib/field/field.ts +111 -0
- package/src/lib/file-upload/file-upload.ts +208 -0
- package/src/lib/footer/footer.scss +155 -0
- package/src/lib/footer/footer.ts +28 -0
- package/src/lib/form-section/form-section.ts +200 -0
- package/src/lib/forms.spec.ts +92 -0
- package/src/lib/gauge-arc/gauge-arc.ts +85 -0
- package/src/lib/hud-panel/hud-panel.ts +27 -0
- package/src/lib/icon/icon.ts +284 -0
- package/src/lib/icon-badge/icon-badge.ts +87 -0
- package/src/lib/icon-heading/icon-heading.spec.ts +32 -0
- package/src/lib/icon-heading/icon-heading.ts +38 -0
- package/src/lib/icon-text/icon-text.ts +120 -0
- package/src/lib/input/input.ts +119 -0
- package/src/lib/kanban/kanban.ts +211 -0
- package/src/lib/kbd/kbd.ts +32 -0
- package/src/lib/label/label.ts +39 -0
- package/src/lib/loading-overlay/loading-overlay.ts +80 -0
- package/src/lib/menubar/menubar.ts +77 -0
- package/src/lib/metric-card/metric-card.ts +33 -0
- package/src/lib/modal/modal.ts +207 -0
- package/src/lib/native-select/native-select.ts +124 -0
- package/src/lib/navbar/navbar.ts +124 -0
- package/src/lib/navigation-menu/navigation-menu.ts +116 -0
- package/src/lib/otp-input/otp-input.ts +164 -0
- package/src/lib/page-back-link/page-back-link.ts +74 -0
- package/src/lib/page-header/page-header.ts +70 -0
- package/src/lib/pagination/pagination.ts +157 -0
- package/src/lib/pillbox/pillbox.ts +157 -0
- package/src/lib/popover/popover.ts +92 -0
- package/src/lib/profile/profile.ts +73 -0
- package/src/lib/progress/progress.ts +123 -0
- package/src/lib/radio/radio.ts +132 -0
- package/src/lib/ring-gauge/ring-gauge.ts +75 -0
- package/src/lib/scroll-area/scroll-area.ts +57 -0
- package/src/lib/search-palette/search-palette.scss +288 -0
- package/src/lib/search-palette/search-palette.ts +114 -0
- package/src/lib/select/select.ts +292 -0
- package/src/lib/separator/separator.ts +59 -0
- package/src/lib/sheet/sheet.ts +192 -0
- package/src/lib/sidebar-nav/sidebar-nav.scss +218 -0
- package/src/lib/sidebar-nav/sidebar-nav.ts +158 -0
- package/src/lib/site-drakkar/site-drakkar.config.ts +295 -0
- package/src/lib/site-drakkar/site-footer.ts +129 -0
- package/src/lib/site-drakkar/site-navbar.scss +2 -0
- package/src/lib/site-drakkar/site-navbar.ts +267 -0
- package/src/lib/site-drakkar/suite-search-items.spec.ts +61 -0
- package/src/lib/site-drakkar/suite-search-items.ts +246 -0
- package/src/lib/skeleton/skeleton.ts +51 -0
- package/src/lib/slider/slider.ts +133 -0
- package/src/lib/spinner/spinner.ts +75 -0
- package/src/lib/status-metric-row/status-metric-row.ts +74 -0
- package/src/lib/suite-search-palette/suite-search-palette.ts +95 -0
- package/src/lib/switch/switch.ts +131 -0
- package/src/lib/table/table.ts +137 -0
- package/src/lib/tabs/tab-panel.ts +61 -0
- package/src/lib/tabs/tab.ts +107 -0
- package/src/lib/tabs/tabs.ts +109 -0
- package/src/lib/textarea/textarea.ts +103 -0
- package/src/lib/theme-toggle/theme-toggle.spec.ts +40 -0
- package/src/lib/theme-toggle/theme-toggle.ts +39 -0
- package/src/lib/time-picker/time-picker.ts +197 -0
- package/src/lib/timeline/timeline.ts +152 -0
- package/src/lib/toast/toast.ts +196 -0
- package/src/lib/toggle/toggle-group.ts +60 -0
- package/src/lib/toggle/toggle.ts +101 -0
- package/src/lib/tooltip/tooltip.ts +119 -0
- package/src/lib/typography/heading.ts +52 -0
- package/src/lib/typography/text.ts +51 -0
- package/src/lib/uptime-bar/uptime-bar.ts +55 -0
- package/src/lib/verification-code-field/verification-code-field.ts +149 -0
- package/src/lib/whitepaper-cta/whitepaper-cta.scss +130 -0
- package/src/lib/whitepaper-cta/whitepaper-cta.ts +78 -0
- package/src/lib/wizard/wizard.ts +80 -0
- package/src/public-api.ts +172 -0
- package/src/styles/_buttons.scss +301 -0
- package/src/styles/_component-primitives.scss +183 -0
- package/src/styles/_drakkar-buttons.scss +85 -0
- package/src/styles/_fonts.scss +22 -0
- package/src/styles/_forms.scss +66 -0
- package/src/styles/_input.scss +106 -0
- package/src/styles/_layout-enforcement.scss +166 -0
- package/src/styles/_layout-rhythm.scss +158 -0
- package/src/styles/_legacy-aliases.scss +212 -0
- package/src/styles/_series-colors.scss +24 -0
- package/src/styles/_static-primitives.scss +857 -0
- package/src/styles/_typography.scss +87 -0
- package/src/styles/_variables.scss +527 -0
- package/src/styles/components/a11y.scss +90 -0
- package/src/styles/components/badges.scss +102 -0
- package/src/styles/components/extracted-utilities.scss +459 -0
- package/src/styles/components/footer.scss +155 -0
- package/src/styles/components/icon-heading.scss +47 -0
- package/src/styles/components/icon-inline.scss +78 -0
- package/src/styles/components/layout.scss +59 -0
- package/src/styles/components/utilities.scss +131 -0
- package/src/styles/components/viking-inspired.scss +204 -0
- package/src/styles/components/whitepaper-cta.scss +130 -0
- package/src/styles/components-bundle.scss +9 -0
- package/src/styles/components.scss +175 -0
- package/src/styles/deml-components.scss +10 -0
- package/src/styles/index.scss +8 -0
- package/src/styles/layout-shell.scss +39 -11
- package/src/styles/page-shell.scss +663 -33
- package/src/styles/static-navbar.scss +862 -146
- package/src/styles/surfaces/backend.scss +142 -0
- package/src/styles/surfaces/docs-global.scss +73 -0
- package/src/styles/surfaces/docs-shell.scss +412 -0
- package/src/styles/surfaces/docs-showcase.scss +1051 -0
- package/src/styles/surfaces/marketing-cta.scss +62 -0
- package/src/styles/surfaces/marketing-docs-bento.scss +67 -0
- package/src/styles/surfaces/marketing-global.scss +748 -0
- package/src/styles/surfaces/marketing-landing.scss +1260 -0
- package/src/styles/surfaces/marketing-publication.scss +535 -0
- package/src/styles/surfaces/marketing-theme.scss +14 -0
- package/src/styles/surfaces/swagger-ui.scss +921 -0
- package/src/styles/tokens-export.scss +18 -0
- package/src/styles/tokens.scss +5 -0
- package/src/styles/viking-ui-bundle.scss +20 -2
- package/src/styles/viking-ui.scss +213 -51
- package/src/tokens/series-presets.ts +15 -0
- package/src/tokens/tailwind.preset.js +209 -0
- package/src/tokens/viking-tokens.json +318 -0
- package/src/viking-ui.spec.ts +416 -0
- package/src/web/badge/viking-badge-wc.ts +116 -0
- package/src/web/button/viking-button-wc.ts +165 -0
- package/src/web/callout/viking-callout-wc.ts +105 -0
- package/src/web/card/viking-card-wc.ts +66 -0
- package/src/web/core/base.ts +56 -0
- package/src/web/core/dom.ts +53 -0
- package/src/web/core/icons-inline.ts +44 -0
- package/src/web/core/styles.ts +1138 -0
- package/src/web/core/types.ts +19 -0
- package/src/web/field/viking-field-wc.ts +154 -0
- package/src/web/index.ts +73 -0
- package/src/web/input/viking-input-wc.ts +211 -0
- package/src/web/modal/viking-modal-wc.ts +187 -0
- package/src/web/search-palette/viking-search-palette-wc.ts +494 -0
- package/src/web/select/viking-select-wc.ts +218 -0
- package/src/web/suite-header/viking-suite-header-wc.ts +714 -0
- package/src/web/suite-search-palette/viking-suite-search-palette-wc.ts +234 -0
- package/src/web/theme-toggle/viking-theme-toggle-wc.ts +139 -0
- package/src/web/types.ts +37 -0
- package/src/web/web-components.spec.ts +297 -0
- package/src/web-components/index.ts +1 -0
- package/fesm2022/dataengineeringformachinelearning-viking-ui.mjs +0 -6114
- package/fesm2022/dataengineeringformachinelearning-viking-ui.mjs.map +0 -1
- package/types/dataengineeringformachinelearning-viking-ui.d.ts +0 -1397
- package/viking.manifest.json +0 -238
|
@@ -0,0 +1,416 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
};
|