@unofficialbox/box-open-elements 0.1.0
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 +21 -0
- package/README.md +125 -0
- package/dist/components/actions/button-group.d.ts +22 -0
- package/dist/components/actions/button-group.js +255 -0
- package/dist/components/actions/button.d.ts +16 -0
- package/dist/components/actions/button.js +190 -0
- package/dist/components/actions/icon-button.d.ts +20 -0
- package/dist/components/actions/icon-button.js +187 -0
- package/dist/components/actions/link-button.d.ts +14 -0
- package/dist/components/actions/link-button.js +137 -0
- package/dist/components/actions/menu-item.d.ts +17 -0
- package/dist/components/actions/menu-item.js +137 -0
- package/dist/components/actions/menu.d.ts +22 -0
- package/dist/components/actions/menu.js +178 -0
- package/dist/components/actions/segmented-control.d.ts +27 -0
- package/dist/components/actions/segmented-control.js +273 -0
- package/dist/components/collections/card.d.ts +13 -0
- package/dist/components/collections/card.js +110 -0
- package/dist/components/collections/carousel.d.ts +40 -0
- package/dist/components/collections/carousel.js +406 -0
- package/dist/components/collections/datalist-item.d.ts +32 -0
- package/dist/components/collections/datalist-item.js +196 -0
- package/dist/components/collections/draggable-list.d.ts +33 -0
- package/dist/components/collections/draggable-list.js +306 -0
- package/dist/components/collections/grid-view.d.ts +38 -0
- package/dist/components/collections/grid-view.js +321 -0
- package/dist/components/collections/pagination.d.ts +19 -0
- package/dist/components/collections/pagination.js +147 -0
- package/dist/components/collections/tree-grid.d.ts +47 -0
- package/dist/components/collections/tree-grid.js +593 -0
- package/dist/components/collections/tree.d.ts +37 -0
- package/dist/components/collections/tree.js +526 -0
- package/dist/components/feedback/alert.d.ts +27 -0
- package/dist/components/feedback/alert.js +263 -0
- package/dist/components/feedback/badge.d.ts +12 -0
- package/dist/components/feedback/badge.js +99 -0
- package/dist/components/feedback/chip.d.ts +33 -0
- package/dist/components/feedback/chip.js +261 -0
- package/dist/components/feedback/empty-state.d.ts +19 -0
- package/dist/components/feedback/empty-state.js +137 -0
- package/dist/components/feedback/error-mask.d.ts +25 -0
- package/dist/components/feedback/error-mask.js +199 -0
- package/dist/components/feedback/help-text.d.ts +22 -0
- package/dist/components/feedback/help-text.js +176 -0
- package/dist/components/feedback/nudge.d.ts +32 -0
- package/dist/components/feedback/nudge.js +299 -0
- package/dist/components/feedback/progress-bar.d.ts +18 -0
- package/dist/components/feedback/progress-bar.js +128 -0
- package/dist/components/feedback/progress-ring.d.ts +21 -0
- package/dist/components/feedback/progress-ring.js +155 -0
- package/dist/components/feedback/progress-steps.d.ts +25 -0
- package/dist/components/feedback/progress-steps.js +276 -0
- package/dist/components/feedback/skeleton.d.ts +14 -0
- package/dist/components/feedback/skeleton.js +95 -0
- package/dist/components/feedback/spinner.d.ts +10 -0
- package/dist/components/feedback/spinner.js +80 -0
- package/dist/components/feedback/toast.d.ts +26 -0
- package/dist/components/feedback/toast.js +205 -0
- package/dist/components/files/drop-zone.d.ts +19 -0
- package/dist/components/files/drop-zone.js +169 -0
- package/dist/components/forms/calendar.d.ts +47 -0
- package/dist/components/forms/calendar.js +499 -0
- package/dist/components/forms/category-selector.d.ts +35 -0
- package/dist/components/forms/category-selector.js +269 -0
- package/dist/components/forms/checkbox-group.d.ts +31 -0
- package/dist/components/forms/checkbox-group.js +267 -0
- package/dist/components/forms/checkbox.d.ts +28 -0
- package/dist/components/forms/checkbox.js +250 -0
- package/dist/components/forms/color-picker.d.ts +34 -0
- package/dist/components/forms/color-picker.js +314 -0
- package/dist/components/forms/combobox.d.ts +37 -0
- package/dist/components/forms/combobox.js +234 -0
- package/dist/components/forms/date-field.d.ts +27 -0
- package/dist/components/forms/date-field.js +187 -0
- package/dist/components/forms/dropdown.d.ts +38 -0
- package/dist/components/forms/dropdown.js +405 -0
- package/dist/components/forms/dual-listbox.d.ts +44 -0
- package/dist/components/forms/dual-listbox.js +484 -0
- package/dist/components/forms/fieldset.d.ts +32 -0
- package/dist/components/forms/fieldset.js +168 -0
- package/dist/components/forms/multi-select.d.ts +30 -0
- package/dist/components/forms/multi-select.js +264 -0
- package/dist/components/forms/number-input.d.ts +32 -0
- package/dist/components/forms/number-input.js +245 -0
- package/dist/components/forms/pill-cloud.d.ts +35 -0
- package/dist/components/forms/pill-cloud.js +230 -0
- package/dist/components/forms/pill-selector-dropdown.d.ts +55 -0
- package/dist/components/forms/pill-selector-dropdown.js +499 -0
- package/dist/components/forms/radio-group.d.ts +32 -0
- package/dist/components/forms/radio-group.js +285 -0
- package/dist/components/forms/range-slider.d.ts +36 -0
- package/dist/components/forms/range-slider.js +294 -0
- package/dist/components/forms/rating.d.ts +31 -0
- package/dist/components/forms/rating.js +302 -0
- package/dist/components/forms/rich-text-input.d.ts +32 -0
- package/dist/components/forms/rich-text-input.js +403 -0
- package/dist/components/forms/search-field.d.ts +27 -0
- package/dist/components/forms/search-field.js +293 -0
- package/dist/components/forms/select.d.ts +30 -0
- package/dist/components/forms/select.js +198 -0
- package/dist/components/forms/slider.d.ts +31 -0
- package/dist/components/forms/slider.js +221 -0
- package/dist/components/forms/spin-button.d.ts +33 -0
- package/dist/components/forms/spin-button.js +352 -0
- package/dist/components/forms/switch.d.ts +32 -0
- package/dist/components/forms/switch.js +302 -0
- package/dist/components/forms/tag-input.d.ts +46 -0
- package/dist/components/forms/tag-input.js +420 -0
- package/dist/components/forms/text-area.d.ts +26 -0
- package/dist/components/forms/text-area.js +188 -0
- package/dist/components/forms/text-field.d.ts +24 -0
- package/dist/components/forms/text-field.js +151 -0
- package/dist/components/forms/time-field.d.ts +29 -0
- package/dist/components/forms/time-field.js +203 -0
- package/dist/components/identity/avatar.d.ts +21 -0
- package/dist/components/identity/avatar.js +191 -0
- package/dist/components/identity/contact-datalist-item.d.ts +31 -0
- package/dist/components/identity/contact-datalist-item.js +235 -0
- package/dist/components/identity/persona.d.ts +28 -0
- package/dist/components/identity/persona.js +272 -0
- package/dist/components/layout/app-shell.d.ts +26 -0
- package/dist/components/layout/app-shell.js +258 -0
- package/dist/components/layout/divider.d.ts +12 -0
- package/dist/components/layout/divider.js +119 -0
- package/dist/components/layout/nav-sidebar.d.ts +23 -0
- package/dist/components/layout/nav-sidebar.js +167 -0
- package/dist/components/layout/section.d.ts +20 -0
- package/dist/components/layout/section.js +143 -0
- package/dist/components/layout/sidebar-toggle-button.d.ts +26 -0
- package/dist/components/layout/sidebar-toggle-button.js +137 -0
- package/dist/components/layout/split-view.d.ts +19 -0
- package/dist/components/layout/split-view.js +157 -0
- package/dist/components/navigation/accordion.d.ts +25 -0
- package/dist/components/navigation/accordion.js +253 -0
- package/dist/components/navigation/tabs.d.ts +27 -0
- package/dist/components/navigation/tabs.js +289 -0
- package/dist/components/overlays/dialog.d.ts +26 -0
- package/dist/components/overlays/dialog.js +267 -0
- package/dist/components/overlays/drawer.d.ts +32 -0
- package/dist/components/overlays/drawer.js +323 -0
- package/dist/components/overlays/popover.d.ts +35 -0
- package/dist/components/overlays/popover.js +317 -0
- package/dist/components/overlays/tooltip.d.ts +26 -0
- package/dist/components/overlays/tooltip.js +204 -0
- package/dist/components/visuals/illustration.d.ts +26 -0
- package/dist/components/visuals/illustration.js +319 -0
- package/dist/core/controller.d.ts +11 -0
- package/dist/core/controller.js +23 -0
- package/dist/core/element.d.ts +22 -0
- package/dist/core/element.js +28 -0
- package/dist/core/event-emitter.d.ts +9 -0
- package/dist/core/event-emitter.js +33 -0
- package/dist/core/form-associated.d.ts +63 -0
- package/dist/core/form-associated.js +218 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +4 -0
- package/dist/core/json-schema.d.ts +1 -0
- package/dist/core/json-schema.js +1 -0
- package/dist/foundations/a11y/focus.d.ts +17 -0
- package/dist/foundations/a11y/focus.js +94 -0
- package/dist/foundations/a11y/heading.d.ts +26 -0
- package/dist/foundations/a11y/heading.js +40 -0
- package/dist/foundations/a11y/index.d.ts +5 -0
- package/dist/foundations/a11y/index.js +3 -0
- package/dist/foundations/a11y/keyboard.d.ts +28 -0
- package/dist/foundations/a11y/keyboard.js +77 -0
- package/dist/foundations/geometry/index.d.ts +1 -0
- package/dist/foundations/geometry/index.js +1 -0
- package/dist/foundations/geometry/tokens.d.ts +123 -0
- package/dist/foundations/geometry/tokens.js +154 -0
- package/dist/foundations/icons/box-iconography.d.ts +479 -0
- package/dist/foundations/icons/box-iconography.generated.d.ts +2370 -0
- package/dist/foundations/icons/box-iconography.generated.js +4010 -0
- package/dist/foundations/icons/box-iconography.js +39 -0
- package/dist/foundations/icons/index.d.ts +1 -0
- package/dist/foundations/icons/index.js +1 -0
- package/dist/foundations/motion/index.d.ts +2 -0
- package/dist/foundations/motion/index.js +1 -0
- package/dist/foundations/motion/tokens.d.ts +39 -0
- package/dist/foundations/motion/tokens.js +43 -0
- package/dist/foundations/tokens/box-dark.d.ts +11 -0
- package/dist/foundations/tokens/box-dark.js +46 -0
- package/dist/foundations/tokens/box-defaults.d.ts +5 -0
- package/dist/foundations/tokens/box-defaults.js +52 -0
- package/dist/foundations/tokens/index.d.ts +5 -0
- package/dist/foundations/tokens/index.js +4 -0
- package/dist/foundations/tokens/interaction.d.ts +28 -0
- package/dist/foundations/tokens/interaction.js +72 -0
- package/dist/foundations/tokens/registry.d.ts +14 -0
- package/dist/foundations/tokens/registry.js +92 -0
- package/dist/foundations/tokens/types.d.ts +16 -0
- package/dist/foundations/tokens/types.js +1 -0
- package/dist/foundations/typography/index.d.ts +2 -0
- package/dist/foundations/typography/index.js +1 -0
- package/dist/foundations/typography/tokens.d.ts +76 -0
- package/dist/foundations/typography/tokens.js +27 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +98 -0
- package/dist/patterns/content-explorer/actions/controller.d.ts +12 -0
- package/dist/patterns/content-explorer/actions/controller.js +36 -0
- package/dist/patterns/content-explorer/actions/index.d.ts +2 -0
- package/dist/patterns/content-explorer/actions/index.js +1 -0
- package/dist/patterns/content-explorer/actions/types.d.ts +13 -0
- package/dist/patterns/content-explorer/actions/types.js +1 -0
- package/dist/patterns/content-explorer/adapters/action-menu.d.ts +24 -0
- package/dist/patterns/content-explorer/adapters/action-menu.js +312 -0
- package/dist/patterns/content-explorer/adapters/breadcrumbs.d.ts +15 -0
- package/dist/patterns/content-explorer/adapters/breadcrumbs.js +161 -0
- package/dist/patterns/content-explorer/adapters/item-summary.d.ts +11 -0
- package/dist/patterns/content-explorer/adapters/item-summary.js +72 -0
- package/dist/patterns/content-explorer/adapters/items.d.ts +4 -0
- package/dist/patterns/content-explorer/adapters/items.js +12 -0
- package/dist/patterns/content-explorer/adapters/list.d.ts +28 -0
- package/dist/patterns/content-explorer/adapters/list.js +527 -0
- package/dist/patterns/content-explorer/adapters/table.d.ts +23 -0
- package/dist/patterns/content-explorer/adapters/table.js +467 -0
- package/dist/patterns/content-explorer/adapters/toolbar.d.ts +19 -0
- package/dist/patterns/content-explorer/adapters/toolbar.js +234 -0
- package/dist/patterns/content-explorer/box-transport.d.ts +44 -0
- package/dist/patterns/content-explorer/box-transport.js +229 -0
- package/dist/patterns/content-explorer/collection/controller.d.ts +17 -0
- package/dist/patterns/content-explorer/collection/controller.js +67 -0
- package/dist/patterns/content-explorer/collection/index.d.ts +2 -0
- package/dist/patterns/content-explorer/collection/index.js +1 -0
- package/dist/patterns/content-explorer/collection/types.d.ts +20 -0
- package/dist/patterns/content-explorer/collection/types.js +1 -0
- package/dist/patterns/content-explorer/content-explorer.d.ts +85 -0
- package/dist/patterns/content-explorer/content-explorer.js +745 -0
- package/dist/patterns/content-explorer/contracts.d.ts +32 -0
- package/dist/patterns/content-explorer/contracts.js +114 -0
- package/dist/patterns/content-explorer/controller.d.ts +34 -0
- package/dist/patterns/content-explorer/controller.js +399 -0
- package/dist/patterns/content-explorer/host-bindings.d.ts +50 -0
- package/dist/patterns/content-explorer/host-bindings.js +76 -0
- package/dist/patterns/content-explorer/index.d.ts +18 -0
- package/dist/patterns/content-explorer/index.js +24 -0
- package/dist/patterns/content-explorer/navigation/controller.d.ts +10 -0
- package/dist/patterns/content-explorer/navigation/controller.js +48 -0
- package/dist/patterns/content-explorer/navigation/index.d.ts +2 -0
- package/dist/patterns/content-explorer/navigation/index.js +1 -0
- package/dist/patterns/content-explorer/navigation/types.d.ts +20 -0
- package/dist/patterns/content-explorer/navigation/types.js +1 -0
- package/dist/patterns/content-explorer/schemas.d.ts +6 -0
- package/dist/patterns/content-explorer/schemas.js +120 -0
- package/dist/patterns/content-explorer/selection/controller.d.ts +12 -0
- package/dist/patterns/content-explorer/selection/controller.js +54 -0
- package/dist/patterns/content-explorer/selection/index.d.ts +2 -0
- package/dist/patterns/content-explorer/selection/index.js +1 -0
- package/dist/patterns/content-explorer/selection/types.d.ts +14 -0
- package/dist/patterns/content-explorer/selection/types.js +1 -0
- package/dist/patterns/content-explorer/types.d.ts +209 -0
- package/dist/patterns/content-explorer/types.js +10 -0
- package/dist/patterns/file-request/file-request-builder.d.ts +36 -0
- package/dist/patterns/file-request/file-request-builder.js +344 -0
- package/dist/patterns/file-request/index.d.ts +1 -0
- package/dist/patterns/file-request/index.js +1 -0
- package/dist/patterns/governance/governance-panel.d.ts +40 -0
- package/dist/patterns/governance/governance-panel.js +351 -0
- package/dist/patterns/governance/index.d.ts +1 -0
- package/dist/patterns/governance/index.js +1 -0
- package/dist/patterns/insights/bar-chart.d.ts +43 -0
- package/dist/patterns/insights/bar-chart.js +462 -0
- package/dist/patterns/insights/chart-panel.d.ts +43 -0
- package/dist/patterns/insights/chart-panel.js +436 -0
- package/dist/patterns/insights/donut-chart.d.ts +43 -0
- package/dist/patterns/insights/donut-chart.js +535 -0
- package/dist/patterns/insights/index.d.ts +5 -0
- package/dist/patterns/insights/index.js +5 -0
- package/dist/patterns/insights/line-chart.d.ts +46 -0
- package/dist/patterns/insights/line-chart.js +511 -0
- package/dist/patterns/insights/metric-card.d.ts +36 -0
- package/dist/patterns/insights/metric-card.js +278 -0
- package/dist/patterns/item/bulk-action-bar.d.ts +35 -0
- package/dist/patterns/item/bulk-action-bar.js +325 -0
- package/dist/patterns/item/index.d.ts +4 -0
- package/dist/patterns/item/index.js +4 -0
- package/dist/patterns/item/item-details-panel.d.ts +61 -0
- package/dist/patterns/item/item-details-panel.js +429 -0
- package/dist/patterns/item/item-form.d.ts +54 -0
- package/dist/patterns/item/item-form.js +485 -0
- package/dist/patterns/item/preview-header.d.ts +46 -0
- package/dist/patterns/item/preview-header.js +323 -0
- package/dist/patterns/metadata/contracts.d.ts +75 -0
- package/dist/patterns/metadata/contracts.js +91 -0
- package/dist/patterns/metadata/index.d.ts +4 -0
- package/dist/patterns/metadata/index.js +4 -0
- package/dist/patterns/metadata/metadata-filter-builder.d.ts +43 -0
- package/dist/patterns/metadata/metadata-filter-builder.js +362 -0
- package/dist/patterns/metadata/metadata-inspector.d.ts +31 -0
- package/dist/patterns/metadata/metadata-inspector.js +245 -0
- package/dist/patterns/metadata/schemas.d.ts +5 -0
- package/dist/patterns/metadata/schemas.js +66 -0
- package/dist/patterns/preview/annotation-inspector.d.ts +44 -0
- package/dist/patterns/preview/annotation-inspector.js +380 -0
- package/dist/patterns/preview/annotation-thread.d.ts +37 -0
- package/dist/patterns/preview/annotation-thread.js +338 -0
- package/dist/patterns/preview/annotation-toolbar.d.ts +42 -0
- package/dist/patterns/preview/annotation-toolbar.js +393 -0
- package/dist/patterns/preview/content-preview-adapter.d.ts +13 -0
- package/dist/patterns/preview/content-preview-adapter.js +30 -0
- package/dist/patterns/preview/index.d.ts +6 -0
- package/dist/patterns/preview/index.js +6 -0
- package/dist/patterns/preview/preview-element.d.ts +41 -0
- package/dist/patterns/preview/preview-element.js +429 -0
- package/dist/patterns/preview/provider-adapter.d.ts +36 -0
- package/dist/patterns/preview/provider-adapter.js +29 -0
- package/dist/patterns/search/filter-bar.d.ts +50 -0
- package/dist/patterns/search/filter-bar.js +379 -0
- package/dist/patterns/search/index.d.ts +3 -0
- package/dist/patterns/search/index.js +3 -0
- package/dist/patterns/search/saved-view-picker.d.ts +25 -0
- package/dist/patterns/search/saved-view-picker.js +239 -0
- package/dist/patterns/search/search-results-header.d.ts +34 -0
- package/dist/patterns/search/search-results-header.js +288 -0
- package/dist/patterns/share/access-stats.d.ts +19 -0
- package/dist/patterns/share/access-stats.js +204 -0
- package/dist/patterns/share/collaborator-avatars.d.ts +22 -0
- package/dist/patterns/share/collaborator-avatars.js +214 -0
- package/dist/patterns/share/contracts.d.ts +65 -0
- package/dist/patterns/share/contracts.js +75 -0
- package/dist/patterns/share/index.d.ts +14 -0
- package/dist/patterns/share/index.js +14 -0
- package/dist/patterns/share/invite-collaborators-contracts.d.ts +38 -0
- package/dist/patterns/share/invite-collaborators-contracts.js +1 -0
- package/dist/patterns/share/invite-collaborators-controller.d.ts +40 -0
- package/dist/patterns/share/invite-collaborators-controller.js +86 -0
- package/dist/patterns/share/invite-collaborators-modal.d.ts +46 -0
- package/dist/patterns/share/invite-collaborators-modal.js +465 -0
- package/dist/patterns/share/permission-matrix.d.ts +37 -0
- package/dist/patterns/share/permission-matrix.js +360 -0
- package/dist/patterns/share/presence-contracts.d.ts +26 -0
- package/dist/patterns/share/presence-contracts.js +1 -0
- package/dist/patterns/share/presence-controller.d.ts +31 -0
- package/dist/patterns/share/presence-controller.js +47 -0
- package/dist/patterns/share/presence.d.ts +32 -0
- package/dist/patterns/share/presence.js +255 -0
- package/dist/patterns/share/schemas.d.ts +4 -0
- package/dist/patterns/share/schemas.js +41 -0
- package/dist/patterns/share/share-panel.d.ts +75 -0
- package/dist/patterns/share/share-panel.js +565 -0
- package/dist/patterns/share/unified-share-controller.d.ts +52 -0
- package/dist/patterns/share/unified-share-controller.js +97 -0
- package/dist/patterns/share/unified-share-modal.d.ts +50 -0
- package/dist/patterns/share/unified-share-modal.js +646 -0
- package/dist/patterns/task/index.d.ts +2 -0
- package/dist/patterns/task/index.js +2 -0
- package/dist/patterns/task/review-queue-item.d.ts +45 -0
- package/dist/patterns/task/review-queue-item.js +403 -0
- package/dist/patterns/task/task-assignment-panel.d.ts +50 -0
- package/dist/patterns/task/task-assignment-panel.js +450 -0
- package/package.json +151 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { FormAssociatedElement, boeFormFieldErrorStyles, formDataFromNamedValues, formErrorMessageMarkup, stringValuesFromFormValue, } from "../../core/index.js";
|
|
2
|
+
import { applyRovingTabindex, handleRovingKeydown } from "../../foundations/a11y/index.js";
|
|
3
|
+
import { boeMotionDuration, boeMotionEasing } from "../../foundations/motion/index.js";
|
|
4
|
+
import { boeRadius } from "../../foundations/geometry/index.js";
|
|
5
|
+
const DEFAULT_TAG_NAME = "box-dual-listbox";
|
|
6
|
+
const escapeHtml = (value) => value
|
|
7
|
+
.replaceAll("&", "&")
|
|
8
|
+
.replaceAll("<", "<")
|
|
9
|
+
.replaceAll(">", ">")
|
|
10
|
+
.replaceAll('"', """)
|
|
11
|
+
.replaceAll("'", "'");
|
|
12
|
+
const dualListboxStyles = `
|
|
13
|
+
:host {
|
|
14
|
+
display: block;
|
|
15
|
+
/* Fill the host container so the two panels get their full width; as a bare
|
|
16
|
+
block this collapses to content width in flex/inline parents, cramping the
|
|
17
|
+
panels and clipping option labels. */
|
|
18
|
+
inline-size: 100%;
|
|
19
|
+
color: inherit;
|
|
20
|
+
font: inherit;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[part="field"] {
|
|
24
|
+
margin: 0;
|
|
25
|
+
padding: 0;
|
|
26
|
+
border: none;
|
|
27
|
+
min-inline-size: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[part="label"] {
|
|
31
|
+
margin: 0 0 0.55rem;
|
|
32
|
+
padding: 0;
|
|
33
|
+
font-size: 0.8rem;
|
|
34
|
+
font-weight: 700;
|
|
35
|
+
letter-spacing: 0.08em;
|
|
36
|
+
text-transform: uppercase;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[part="layout"] {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: stretch;
|
|
42
|
+
gap: 0.65rem;
|
|
43
|
+
min-inline-size: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[part="available-panel"],
|
|
47
|
+
[part="selected-panel"] {
|
|
48
|
+
flex: 1 1 0;
|
|
49
|
+
min-inline-size: 0;
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: 0.4rem;
|
|
53
|
+
padding: 0.55rem;
|
|
54
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 82%, transparent);
|
|
55
|
+
border-radius: ${boeRadius.large};
|
|
56
|
+
background: var(--boe-token-surface-surface-secondary, #fbfbfb);
|
|
57
|
+
box-shadow: 0 12px 24px rgba(15, 23, 42, 0.04);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[part="list-label"] {
|
|
61
|
+
display: block;
|
|
62
|
+
font-size: 0.78rem;
|
|
63
|
+
font-weight: 700;
|
|
64
|
+
letter-spacing: 0.06em;
|
|
65
|
+
text-transform: uppercase;
|
|
66
|
+
opacity: 0.75;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[part="list"] {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
gap: 0.35rem;
|
|
73
|
+
min-block-size: 10rem;
|
|
74
|
+
max-block-size: 18rem;
|
|
75
|
+
overflow: auto;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
[part="option"] {
|
|
79
|
+
width: 100%;
|
|
80
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 64%, transparent);
|
|
81
|
+
border-radius: ${boeRadius.med};
|
|
82
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
83
|
+
color: inherit;
|
|
84
|
+
font: inherit;
|
|
85
|
+
text-align: left;
|
|
86
|
+
padding: 0.5rem 0.65rem;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
transition:
|
|
89
|
+
border-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
90
|
+
background ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
91
|
+
transform ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
[part="option"]:hover:not(:disabled) {
|
|
95
|
+
border-color: color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 100%, transparent);
|
|
96
|
+
background: color-mix(in srgb, var(--boe-token-surface-item-surface-hover, #eef4fb) 52%, var(--boe-token-surface-surface, #ffffff) 48%);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
[part="option"][aria-selected="true"] {
|
|
100
|
+
border-color: color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 22%, transparent);
|
|
101
|
+
background: color-mix(in srgb, var(--boe-token-surface-item-surface-selected, #f2f7fd) 72%, var(--boe-token-surface-surface, #ffffff) 28%);
|
|
102
|
+
box-shadow: inset 0 0 0 1px rgba(0, 97, 213, 0.06);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
[part="option"]:focus-visible,
|
|
106
|
+
[part="move-right"]:focus-visible,
|
|
107
|
+
[part="move-left"]:focus-visible {
|
|
108
|
+
outline: 2px solid var(--boe-token-surface-surface-brand, #0061d5);
|
|
109
|
+
outline-offset: 2px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[part="option"]:disabled,
|
|
113
|
+
[part="move-right"]:disabled,
|
|
114
|
+
[part="move-left"]:disabled {
|
|
115
|
+
cursor: not-allowed;
|
|
116
|
+
opacity: 0.55;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
[part="actions"] {
|
|
120
|
+
flex: 0 0 auto;
|
|
121
|
+
display: flex;
|
|
122
|
+
flex-direction: column;
|
|
123
|
+
justify-content: center;
|
|
124
|
+
gap: 0.45rem;
|
|
125
|
+
padding-block: 0.55rem 0;
|
|
126
|
+
padding-inline: 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
[part="move-right"],
|
|
130
|
+
[part="move-left"] {
|
|
131
|
+
inline-size: 1.65rem;
|
|
132
|
+
block-size: 1.65rem;
|
|
133
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 88%, transparent);
|
|
134
|
+
border-radius: ${boeRadius.med};
|
|
135
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
136
|
+
color: inherit;
|
|
137
|
+
font: inherit;
|
|
138
|
+
font-size: 0.8rem;
|
|
139
|
+
font-weight: 700;
|
|
140
|
+
cursor: pointer;
|
|
141
|
+
transition:
|
|
142
|
+
border-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
143
|
+
background ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
144
|
+
transform ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
[part="move-right"]:hover:not(:disabled),
|
|
148
|
+
[part="move-left"]:hover:not(:disabled) {
|
|
149
|
+
border-color: color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 22%, transparent);
|
|
150
|
+
background: var(--boe-token-surface-item-surface-hover, #eef4fb);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
[part="empty"] {
|
|
154
|
+
display: grid;
|
|
155
|
+
place-items: center;
|
|
156
|
+
min-block-size: 100%;
|
|
157
|
+
border: 1px dashed rgba(214, 224, 234, 0.72);
|
|
158
|
+
border-radius: ${boeRadius.med};
|
|
159
|
+
padding: 0.65rem;
|
|
160
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
161
|
+
background: color-mix(in srgb, var(--boe-token-surface-surface, #ffffff) 65%, transparent);
|
|
162
|
+
text-align: center;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@media (max-width: 720px) {
|
|
166
|
+
[part="layout"] {
|
|
167
|
+
flex-direction: column;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
[part="actions"] {
|
|
171
|
+
flex-direction: row;
|
|
172
|
+
justify-content: center;
|
|
173
|
+
padding-block: 0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
${boeFormFieldErrorStyles}
|
|
178
|
+
`;
|
|
179
|
+
export class BoxDualListboxElement extends FormAssociatedElement {
|
|
180
|
+
static get observedAttributes() {
|
|
181
|
+
return [
|
|
182
|
+
...FormAssociatedElement.formObservedAttributes,
|
|
183
|
+
"disabled",
|
|
184
|
+
"label",
|
|
185
|
+
"options",
|
|
186
|
+
"value",
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
availableSelection = new Set();
|
|
190
|
+
chosenSelection = new Set();
|
|
191
|
+
valueInternal = [];
|
|
192
|
+
legendEl;
|
|
193
|
+
availableListEl;
|
|
194
|
+
selectedListEl;
|
|
195
|
+
moveRightEl;
|
|
196
|
+
moveLeftEl;
|
|
197
|
+
errorEl;
|
|
198
|
+
listsSignature = "";
|
|
199
|
+
selectionOnlyUpdate = false;
|
|
200
|
+
get disabled() {
|
|
201
|
+
return this.hasAttribute("disabled");
|
|
202
|
+
}
|
|
203
|
+
set disabled(value) {
|
|
204
|
+
if (value) {
|
|
205
|
+
this.setAttribute("disabled", "");
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
this.removeAttribute("disabled");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
get label() {
|
|
212
|
+
return this.getAttribute("label") ?? "Dual Listbox";
|
|
213
|
+
}
|
|
214
|
+
set label(value) {
|
|
215
|
+
this.setAttribute("label", value);
|
|
216
|
+
}
|
|
217
|
+
get options() {
|
|
218
|
+
const raw = this.getAttribute("options");
|
|
219
|
+
if (!raw) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const parsed = JSON.parse(raw);
|
|
224
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
set options(value) {
|
|
231
|
+
this.setAttribute("options", JSON.stringify(value));
|
|
232
|
+
}
|
|
233
|
+
get value() {
|
|
234
|
+
return [...this.valueInternal];
|
|
235
|
+
}
|
|
236
|
+
set value(nextValue) {
|
|
237
|
+
this.valueInternal = [...nextValue];
|
|
238
|
+
this.setAttribute("value", JSON.stringify(nextValue));
|
|
239
|
+
this.syncFormAssociation();
|
|
240
|
+
}
|
|
241
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
242
|
+
if (name === "value") {
|
|
243
|
+
const raw = this.getAttribute("value");
|
|
244
|
+
if (!raw) {
|
|
245
|
+
this.valueInternal = [];
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(raw);
|
|
250
|
+
this.valueInternal = Array.isArray(parsed) ? parsed : [];
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
this.valueInternal = [];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
258
|
+
}
|
|
259
|
+
getFormValue() {
|
|
260
|
+
return formDataFromNamedValues(this.name, this.valueInternal);
|
|
261
|
+
}
|
|
262
|
+
restoreFormValue(value) {
|
|
263
|
+
const next = stringValuesFromFormValue(value, this.name);
|
|
264
|
+
this.valueInternal = next;
|
|
265
|
+
this.setAttribute("value", JSON.stringify(next));
|
|
266
|
+
this.syncFormAssociation();
|
|
267
|
+
if (this.isRendered) {
|
|
268
|
+
this.update();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
emitValueChanged(nextValue) {
|
|
272
|
+
this.valueInternal = [...nextValue];
|
|
273
|
+
this.setAttribute("value", JSON.stringify(nextValue));
|
|
274
|
+
this.syncFormAssociation();
|
|
275
|
+
this.dispatchEvent(new CustomEvent("value-changed", {
|
|
276
|
+
bubbles: true,
|
|
277
|
+
composed: true,
|
|
278
|
+
detail: { value: [...nextValue] },
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
moveSelected(direction) {
|
|
282
|
+
if (this.disabled) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (direction === "to-selected") {
|
|
286
|
+
const moving = this.options
|
|
287
|
+
.filter(option => this.availableSelection.has(option.value) && !option.disabled)
|
|
288
|
+
.map(option => option.value);
|
|
289
|
+
if (moving.length === 0) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const nextValue = this.options
|
|
293
|
+
.map(option => option.value)
|
|
294
|
+
.filter(value => this.valueInternal.includes(value) || moving.includes(value));
|
|
295
|
+
this.availableSelection.clear();
|
|
296
|
+
this.emitValueChanged(nextValue);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const moving = this.options
|
|
300
|
+
.filter(option => this.chosenSelection.has(option.value) && !option.disabled)
|
|
301
|
+
.map(option => option.value);
|
|
302
|
+
if (moving.length === 0) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const nextValue = this.valueInternal.filter(value => !moving.includes(value));
|
|
306
|
+
this.chosenSelection.clear();
|
|
307
|
+
this.emitValueChanged(nextValue);
|
|
308
|
+
}
|
|
309
|
+
toggleSelection(list, value) {
|
|
310
|
+
const set = list === "available" ? this.availableSelection : this.chosenSelection;
|
|
311
|
+
if (set.has(value)) {
|
|
312
|
+
set.delete(value);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
set.add(value);
|
|
316
|
+
}
|
|
317
|
+
if (this.isRendered) {
|
|
318
|
+
this.selectionOnlyUpdate = true;
|
|
319
|
+
this.update();
|
|
320
|
+
this.selectionOnlyUpdate = false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
patchSelectionState() {
|
|
324
|
+
const patchList = (listEl, selection) => {
|
|
325
|
+
listEl.querySelectorAll('[part="option"]').forEach(node => {
|
|
326
|
+
const button = node;
|
|
327
|
+
const selected = selection.has(button.dataset.value ?? "");
|
|
328
|
+
button.setAttribute("aria-selected", String(selected));
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
patchList(this.availableListEl, this.availableSelection);
|
|
332
|
+
patchList(this.selectedListEl, this.chosenSelection);
|
|
333
|
+
}
|
|
334
|
+
listsKey(availableItems, selectedItems) {
|
|
335
|
+
return JSON.stringify({
|
|
336
|
+
available: availableItems.map(option => [option.value, option.label, Boolean(option.disabled)]),
|
|
337
|
+
selected: selectedItems.map(option => [option.value, option.label, Boolean(option.disabled)]),
|
|
338
|
+
disabled: this.disabled,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
renderListItems(list, items) {
|
|
342
|
+
const selection = list === "available" ? this.availableSelection : this.chosenSelection;
|
|
343
|
+
if (!items.length) {
|
|
344
|
+
return `<div part="empty">No items</div>`;
|
|
345
|
+
}
|
|
346
|
+
return items
|
|
347
|
+
.map(option => `
|
|
348
|
+
<button
|
|
349
|
+
type="button"
|
|
350
|
+
part="option"
|
|
351
|
+
role="option"
|
|
352
|
+
data-list="${list}"
|
|
353
|
+
data-value="${escapeHtml(option.value)}"
|
|
354
|
+
aria-selected="${String(selection.has(option.value))}"
|
|
355
|
+
${option.disabled || this.disabled ? "disabled" : ""}
|
|
356
|
+
>
|
|
357
|
+
${escapeHtml(option.label)}
|
|
358
|
+
</button>
|
|
359
|
+
`)
|
|
360
|
+
.join("");
|
|
361
|
+
}
|
|
362
|
+
renderTemplate() {
|
|
363
|
+
if (!this.shadowRoot) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
this.shadowRoot.innerHTML = `
|
|
367
|
+
<style>${dualListboxStyles}</style>
|
|
368
|
+
<fieldset part="field">
|
|
369
|
+
<legend part="label"></legend>
|
|
370
|
+
<div part="layout">
|
|
371
|
+
<div part="available-panel">
|
|
372
|
+
<strong part="list-label">Available</strong>
|
|
373
|
+
<div part="list" role="listbox" aria-label="Available" aria-multiselectable="true" data-list="available"></div>
|
|
374
|
+
</div>
|
|
375
|
+
<div part="actions">
|
|
376
|
+
<button type="button" part="move-right" aria-label="Move selected items to chosen list">></button>
|
|
377
|
+
<button type="button" part="move-left" aria-label="Move selected items to available list"><</button>
|
|
378
|
+
</div>
|
|
379
|
+
<div part="selected-panel">
|
|
380
|
+
<strong part="list-label">Chosen</strong>
|
|
381
|
+
<div part="list" role="listbox" aria-label="Chosen" aria-multiselectable="true" data-list="selected"></div>
|
|
382
|
+
</div>
|
|
383
|
+
</div>
|
|
384
|
+
${formErrorMessageMarkup()}
|
|
385
|
+
</fieldset>
|
|
386
|
+
`;
|
|
387
|
+
this.legendEl = this.shadowRoot.querySelector('[part="label"]');
|
|
388
|
+
this.availableListEl = this.shadowRoot.querySelector('[data-list="available"]');
|
|
389
|
+
this.selectedListEl = this.shadowRoot.querySelector('[data-list="selected"]');
|
|
390
|
+
this.moveRightEl = this.shadowRoot.querySelector('[part="move-right"]');
|
|
391
|
+
this.moveLeftEl = this.shadowRoot.querySelector('[part="move-left"]');
|
|
392
|
+
this.errorEl = this.shadowRoot.querySelector('[part="error-message"]');
|
|
393
|
+
}
|
|
394
|
+
setupListeners() {
|
|
395
|
+
const handleListClick = (event) => {
|
|
396
|
+
const button = event.target.closest('[part="option"]');
|
|
397
|
+
if (!button) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const list = button.dataset.list ?? "available";
|
|
401
|
+
const value = button.dataset.value ?? "";
|
|
402
|
+
if (!value || this.disabled || button.disabled) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this.toggleSelection(list, value);
|
|
406
|
+
};
|
|
407
|
+
const handleListKeydown = (event) => {
|
|
408
|
+
const keyboardEvent = event;
|
|
409
|
+
const listEl = keyboardEvent.currentTarget;
|
|
410
|
+
const options = Array.from(listEl.querySelectorAll('[part="option"]:not([disabled])'));
|
|
411
|
+
if (handleRovingKeydown(keyboardEvent, options, { orientation: "vertical" })) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (keyboardEvent.key !== " " && keyboardEvent.key !== "Enter") {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const button = keyboardEvent.target.closest('[part="option"]');
|
|
418
|
+
if (!button || button.disabled || this.disabled) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
keyboardEvent.preventDefault();
|
|
422
|
+
const list = button.dataset.list ?? "available";
|
|
423
|
+
this.toggleSelection(list, button.dataset.value ?? "");
|
|
424
|
+
};
|
|
425
|
+
this.availableListEl.addEventListener("click", handleListClick);
|
|
426
|
+
this.selectedListEl.addEventListener("click", handleListClick);
|
|
427
|
+
this.availableListEl.addEventListener("keydown", handleListKeydown);
|
|
428
|
+
this.selectedListEl.addEventListener("keydown", handleListKeydown);
|
|
429
|
+
this.moveRightEl.addEventListener("click", () => this.moveSelected("to-selected"));
|
|
430
|
+
this.moveLeftEl.addEventListener("click", () => this.moveSelected("to-available"));
|
|
431
|
+
}
|
|
432
|
+
syncListRoving(listEl) {
|
|
433
|
+
const options = Array.from(listEl.querySelectorAll('[part="option"]:not([disabled])'));
|
|
434
|
+
const selectedIndex = Math.max(0, options.findIndex(button => button.getAttribute("aria-selected") === "true"));
|
|
435
|
+
applyRovingTabindex(options, selectedIndex);
|
|
436
|
+
}
|
|
437
|
+
update() {
|
|
438
|
+
if (!this.legendEl || !this.availableListEl || !this.selectedListEl || !this.errorEl) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
this.legendEl.textContent = this.label;
|
|
442
|
+
if (this.selectionOnlyUpdate) {
|
|
443
|
+
this.patchSelectionState();
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const selectedSet = new Set(this.valueInternal);
|
|
447
|
+
const availableItems = this.options.filter(option => !selectedSet.has(option.value));
|
|
448
|
+
const selectedItems = this.options.filter(option => selectedSet.has(option.value));
|
|
449
|
+
const nextSignature = this.listsKey(availableItems, selectedItems);
|
|
450
|
+
if (nextSignature !== this.listsSignature || this.availableListEl.childElementCount === 0) {
|
|
451
|
+
this.listsSignature = nextSignature;
|
|
452
|
+
this.availableListEl.innerHTML = this.renderListItems("available", availableItems);
|
|
453
|
+
this.selectedListEl.innerHTML = this.renderListItems("selected", selectedItems);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
this.patchSelectionState();
|
|
457
|
+
}
|
|
458
|
+
this.syncListRoving(this.availableListEl);
|
|
459
|
+
this.syncListRoving(this.selectedListEl);
|
|
460
|
+
if (this.disabled) {
|
|
461
|
+
this.moveRightEl.setAttribute("disabled", "");
|
|
462
|
+
this.moveLeftEl.setAttribute("disabled", "");
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
this.moveRightEl.removeAttribute("disabled");
|
|
466
|
+
this.moveLeftEl.removeAttribute("disabled");
|
|
467
|
+
}
|
|
468
|
+
const focusableControls = [
|
|
469
|
+
...Array.from(this.availableListEl.querySelectorAll('[part="option"]')),
|
|
470
|
+
...Array.from(this.selectedListEl.querySelectorAll('[part="option"]')),
|
|
471
|
+
this.moveRightEl,
|
|
472
|
+
this.moveLeftEl,
|
|
473
|
+
];
|
|
474
|
+
this.applyInvalidStateToControls(focusableControls, this.errorEl);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
export const defineBoxDualListboxElement = (tagName = DEFAULT_TAG_NAME) => {
|
|
478
|
+
const existingElement = customElements.get(tagName);
|
|
479
|
+
if (existingElement) {
|
|
480
|
+
return existingElement;
|
|
481
|
+
}
|
|
482
|
+
customElements.define(tagName, BoxDualListboxElement);
|
|
483
|
+
return BoxDualListboxElement;
|
|
484
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseElement } from "../../core/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* A generic form grouping: a `<legend>`, an optional description, and slotted
|
|
4
|
+
* controls. Because slotted controls live in light DOM (outside the shadow
|
|
5
|
+
* `<fieldset>`), native `fieldset[disabled]` propagation cannot reach them, so
|
|
6
|
+
* `disabled` is mirrored onto the light-DOM controls directly. Groups arbitrary
|
|
7
|
+
* fields; use `box-checkbox-group`/`box-radio-group` for option lists.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BoxFieldsetElement extends BaseElement {
|
|
10
|
+
static get observedAttributes(): string[];
|
|
11
|
+
private fieldsetEl;
|
|
12
|
+
private bodyEl;
|
|
13
|
+
private legendEl;
|
|
14
|
+
private descriptionEl;
|
|
15
|
+
get label(): string;
|
|
16
|
+
set label(value: string);
|
|
17
|
+
get description(): string;
|
|
18
|
+
set description(value: string);
|
|
19
|
+
get disabled(): boolean;
|
|
20
|
+
set disabled(value: boolean);
|
|
21
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
22
|
+
/**
|
|
23
|
+
* Reflect the group's disabled state onto the slotted (light-DOM) controls,
|
|
24
|
+
* which the shadow `<fieldset disabled>` cannot reach. Tracks which controls
|
|
25
|
+
* this element disabled so re-enabling never clobbers a control the consumer
|
|
26
|
+
* disabled on its own.
|
|
27
|
+
*/
|
|
28
|
+
private syncDisabledControls;
|
|
29
|
+
protected renderTemplate(): void;
|
|
30
|
+
protected update(): void;
|
|
31
|
+
}
|
|
32
|
+
export declare const defineBoxFieldsetElement: (tagName?: string) => typeof BoxFieldsetElement;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { BaseElement } from "../../core/index.js";
|
|
2
|
+
const DEFAULT_TAG_NAME = "box-fieldset";
|
|
3
|
+
const DESCRIPTION_ID = "box-fieldset-description";
|
|
4
|
+
const fieldsetStyles = `
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
color: inherit;
|
|
8
|
+
font: inherit;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
[part="fieldset"] {
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
border: none;
|
|
15
|
+
min-inline-size: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[part="fieldset"][data-disabled="true"] {
|
|
19
|
+
opacity: 0.6;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[part="legend"] {
|
|
23
|
+
margin: 0 0 0.35rem;
|
|
24
|
+
padding: 0;
|
|
25
|
+
font-size: 0.8rem;
|
|
26
|
+
font-weight: 700;
|
|
27
|
+
letter-spacing: 0.06em;
|
|
28
|
+
text-transform: uppercase;
|
|
29
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[part="description"] {
|
|
33
|
+
margin: 0 0 0.5rem;
|
|
34
|
+
font-size: 0.86rem;
|
|
35
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
[part="body"] {
|
|
39
|
+
display: grid;
|
|
40
|
+
gap: 0.55rem;
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
/**
|
|
44
|
+
* A generic form grouping: a `<legend>`, an optional description, and slotted
|
|
45
|
+
* controls. Because slotted controls live in light DOM (outside the shadow
|
|
46
|
+
* `<fieldset>`), native `fieldset[disabled]` propagation cannot reach them, so
|
|
47
|
+
* `disabled` is mirrored onto the light-DOM controls directly. Groups arbitrary
|
|
48
|
+
* fields; use `box-checkbox-group`/`box-radio-group` for option lists.
|
|
49
|
+
*/
|
|
50
|
+
export class BoxFieldsetElement extends BaseElement {
|
|
51
|
+
static get observedAttributes() {
|
|
52
|
+
return ["description", "disabled", "label"];
|
|
53
|
+
}
|
|
54
|
+
fieldsetEl;
|
|
55
|
+
bodyEl;
|
|
56
|
+
legendEl = null;
|
|
57
|
+
descriptionEl = null;
|
|
58
|
+
get label() {
|
|
59
|
+
return this.getAttribute("label") ?? "";
|
|
60
|
+
}
|
|
61
|
+
set label(value) {
|
|
62
|
+
this.setAttribute("label", value);
|
|
63
|
+
}
|
|
64
|
+
get description() {
|
|
65
|
+
return this.getAttribute("description") ?? "";
|
|
66
|
+
}
|
|
67
|
+
set description(value) {
|
|
68
|
+
this.setAttribute("description", value);
|
|
69
|
+
}
|
|
70
|
+
get disabled() {
|
|
71
|
+
return this.hasAttribute("disabled");
|
|
72
|
+
}
|
|
73
|
+
set disabled(value) {
|
|
74
|
+
this.toggleAttribute("disabled", value);
|
|
75
|
+
}
|
|
76
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
77
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
78
|
+
if (name === "disabled" && this.isRendered) {
|
|
79
|
+
this.syncDisabledControls();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Reflect the group's disabled state onto the slotted (light-DOM) controls,
|
|
84
|
+
* which the shadow `<fieldset disabled>` cannot reach. Tracks which controls
|
|
85
|
+
* this element disabled so re-enabling never clobbers a control the consumer
|
|
86
|
+
* disabled on its own.
|
|
87
|
+
*/
|
|
88
|
+
syncDisabledControls() {
|
|
89
|
+
const controls = this.querySelectorAll("input, select, textarea, button, [disabled], [aria-disabled]");
|
|
90
|
+
for (const control of Array.from(controls)) {
|
|
91
|
+
if (this.disabled) {
|
|
92
|
+
if (!control.hasAttribute("disabled")) {
|
|
93
|
+
control.setAttribute("disabled", "");
|
|
94
|
+
control.setAttribute("data-box-fieldset-disabled", "");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (control.hasAttribute("data-box-fieldset-disabled")) {
|
|
98
|
+
control.removeAttribute("disabled");
|
|
99
|
+
control.removeAttribute("data-box-fieldset-disabled");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
renderTemplate() {
|
|
104
|
+
if (!this.shadowRoot) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.shadowRoot.innerHTML = `
|
|
108
|
+
<style>${fieldsetStyles}</style>
|
|
109
|
+
<fieldset part="fieldset">
|
|
110
|
+
<div part="body">
|
|
111
|
+
<slot></slot>
|
|
112
|
+
</div>
|
|
113
|
+
</fieldset>
|
|
114
|
+
`;
|
|
115
|
+
this.fieldsetEl = this.shadowRoot.querySelector('[part="fieldset"]');
|
|
116
|
+
this.bodyEl = this.shadowRoot.querySelector('[part="body"]');
|
|
117
|
+
}
|
|
118
|
+
update() {
|
|
119
|
+
if (!this.fieldsetEl || !this.bodyEl) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const label = this.label;
|
|
123
|
+
const description = this.description;
|
|
124
|
+
if (label) {
|
|
125
|
+
if (!this.legendEl) {
|
|
126
|
+
this.legendEl = document.createElement("legend");
|
|
127
|
+
this.legendEl.setAttribute("part", "legend");
|
|
128
|
+
this.fieldsetEl.insertBefore(this.legendEl, this.bodyEl);
|
|
129
|
+
}
|
|
130
|
+
this.legendEl.textContent = label;
|
|
131
|
+
}
|
|
132
|
+
else if (this.legendEl) {
|
|
133
|
+
this.legendEl.remove();
|
|
134
|
+
this.legendEl = null;
|
|
135
|
+
}
|
|
136
|
+
if (description) {
|
|
137
|
+
if (!this.descriptionEl) {
|
|
138
|
+
this.descriptionEl = document.createElement("p");
|
|
139
|
+
this.descriptionEl.setAttribute("part", "description");
|
|
140
|
+
this.descriptionEl.id = DESCRIPTION_ID;
|
|
141
|
+
this.fieldsetEl.insertBefore(this.descriptionEl, this.bodyEl);
|
|
142
|
+
}
|
|
143
|
+
this.descriptionEl.textContent = description;
|
|
144
|
+
this.fieldsetEl.setAttribute("aria-describedby", DESCRIPTION_ID);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.descriptionEl?.remove();
|
|
148
|
+
this.descriptionEl = null;
|
|
149
|
+
this.fieldsetEl.removeAttribute("aria-describedby");
|
|
150
|
+
}
|
|
151
|
+
this.fieldsetEl.dataset.disabled = this.disabled ? "true" : "false";
|
|
152
|
+
if (this.disabled) {
|
|
153
|
+
this.fieldsetEl.setAttribute("disabled", "");
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
this.fieldsetEl.removeAttribute("disabled");
|
|
157
|
+
}
|
|
158
|
+
this.syncDisabledControls();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export const defineBoxFieldsetElement = (tagName = DEFAULT_TAG_NAME) => {
|
|
162
|
+
const existingElement = customElements.get(tagName);
|
|
163
|
+
if (existingElement) {
|
|
164
|
+
return existingElement;
|
|
165
|
+
}
|
|
166
|
+
customElements.define(tagName, BoxFieldsetElement);
|
|
167
|
+
return BoxFieldsetElement;
|
|
168
|
+
};
|