component ButtonGroup { outputs { click(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object }) select(payload: { value: string | number | boolean | null | object; previousValue: string | number | boolean | null | object; item: string | number | boolean | null | object; index: number }) change(payload: { value: string | number | boolean | null | object; previousValue: string | number | boolean | null | object; item: string | number | boolean | null | object; index: number }) } props { items: unknown[] = [] value: string = "" size: string = "md" color: string = "primary" variant: string = "default" orientation: string = "horizontal" responsive: boolean = false attached: boolean = true selectable: boolean = false toolbar: boolean = false disabled: boolean = false ariaLabel: string = "Button group" class: string = "" } state selectedValue = value functions { shared function itemValue(item, index) { return item.value || item.label || String(index) } client function selectItem(item, index) { previousValue = selectedValue nextValue = itemValue(item, index) output.select({ value: nextValue, previousValue: previousValue, item: item, index: index }) if (selectable && previousValue !== nextValue) { selectedValue = nextValue output.change({ value: nextValue, previousValue: previousValue, item: item, index: index }) } } } view {
} style { .wire-next--button-group { display: inline-flex; align-items: stretch; width: fit-content; max-width: 100%; isolation: isolate; } .wire-next--button-group[data-orientation="vertical"] { flex-direction: column; } .wire-next--button-group[data-attached="false"] { gap: 0.5rem; } .wire-next--button-group[data-disabled="true"] { cursor: not-allowed; opacity: 0.6; } .wire-next--button-group[data-attached="true"] > :is(.wire-btn, .wire-action) { position: relative; margin: 0; } .wire-next--button-group[data-attached="true"] > .wire-action { display: flex; } .wire-next--button-group[data-attached="true"] > :is(.wire-btn, .wire-action) :is(.wire-btn) { height: 100%; } .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > :is(.wire-btn, .wire-action):not(:first-child) { margin-inline-start: -1px; } .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > .wire-btn:not(:first-child):not(:last-child), .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > .wire-action:not(:first-child):not(:last-child) > .wire-btn { border-radius: 0; } .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > .wire-btn:first-child:not(:last-child), .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > .wire-action:first-child:not(:last-child) > .wire-btn { border-start-end-radius: 0; border-end-end-radius: 0; } .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > .wire-btn:last-child:not(:first-child), .wire-next--button-group[data-attached="true"][data-orientation="horizontal"] > .wire-action:last-child:not(:first-child) > .wire-btn { border-start-start-radius: 0; border-end-start-radius: 0; } .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > :is(.wire-btn, .wire-action):not(:first-child) { margin-top: -1px; } .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > .wire-btn:not(:first-child):not(:last-child), .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > .wire-action:not(:first-child):not(:last-child) > .wire-btn { border-radius: 0; } .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > .wire-btn:first-child:not(:last-child), .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > .wire-action:first-child:not(:last-child) > .wire-btn { border-end-start-radius: 0; border-end-end-radius: 0; } .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > .wire-btn:last-child:not(:first-child), .wire-next--button-group[data-attached="true"][data-orientation="vertical"] > .wire-action:last-child:not(:first-child) > .wire-btn { border-start-start-radius: 0; border-start-end-radius: 0; } .wire-next--button-group > :is(.wire-btn, .wire-action):focus-within, .wire-next--button-group > .wire-btn:focus-visible { z-index: 2; } .wire-next--button-group[data-selectable="true"] > .wire-btn[data-selected="true"] { z-index: 1; border-color: var(--wire-component-color); background: color-mix(in srgb, var(--wire-component-color) 16%, var(--wire-color-surface)); color: var(--wire-component-color); } @media (max-width: 480px) { .wire-next--button-group[data-responsive="true"] > :is(.wire-btn, .wire-action) { display: flex; width: 100%; flex-direction: column; } .wire-next--button-group[data-responsive="true"] > .wire-action > .wire-btn { width: 100%; } .wire-next--button-group[data-responsive="true"][data-attached="true"] > :is(.wire-btn, .wire-action) { margin-top: -1px; margin-inline-start: 0; } .wire-next--button-group[data-responsive="true"][data-attached="true"] > :is(.wire-btn, .wire-action):first-child { margin-top: 0; } .wire-next--button-group[data-responsive="true"][data-attached="true"] > .wire-btn, .wire-next--button-group[data-responsive="true"][data-attached="true"] > .wire-action > .wire-btn { border-radius: 0; } .wire-next--button-group[data-responsive="true"][data-attached="true"] > .wire-btn:first-child, .wire-next--button-group[data-responsive="true"][data-attached="true"] > .wire-action:first-child > .wire-btn { border-start-start-radius: var(--wire-radius-sm); border-start-end-radius: var(--wire-radius-sm); } .wire-next--button-group[data-responsive="true"][data-attached="true"] > .wire-btn:last-child, .wire-next--button-group[data-responsive="true"][data-attached="true"] > .wire-action:last-child > .wire-btn { border-end-start-radius: var(--wire-radius-sm); border-end-end-radius: var(--wire-radius-sm); } } /* Shared component foundation. */ .wire-component { --wire-component-color: var(--wire-color-primary); --wire-component-scale: 1; margin: 0; color: var(--wire-color-text); font-family: var(--wrn-font-sans, inherit); } .wire-component--color-primary { --wire-component-color: var(--wire-color-primary); } .wire-component--color-secondary { --wire-component-color: var(--wire-color-secondary); } .wire-component--color-success { --wire-component-color: var(--wire-color-success); } .wire-component--color-warning { --wire-component-color: var(--wire-color-warning); } .wire-component--color-danger { --wire-component-color: var(--wire-color-danger); } .wire-component--color-info { --wire-component-color: var(--wire-color-info); } .wire-component--size-xs { --wire-component-scale: 0.78; } .wire-component--size-sm { --wire-component-scale: 0.88; } .wire-component--size-default, .wire-component--size-md { --wire-component-scale: 1; } .wire-component--size-lg { --wire-component-scale: 1.14; } .wire-component--size-xl { --wire-component-scale: 1.28; } .wire-component:not(.wire-btn) { font-size: calc(1em * var(--wire-component-scale)); } .wire-component :is(a, button, input, select, textarea):focus-visible { outline-color: var(--wire-component-color); } .wire-component p { margin: 0; color: var(--wire-color-muted); line-height: 1.6; } } }