UNPKG

@ebay/ebayui-core

Version:

Collection of core eBay components; considered to be the building blocks for all composite structures, pages & apps.

31 lines (30 loc) 883 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class SegmentedButtons { onCreate() { this.state = { selectedIndex: 0, }; } onInput(input) { let selectedIndex = (input.button || []).findIndex((button) => button.selected); if (selectedIndex === -1) { selectedIndex = 0; } this.state.selectedIndex = selectedIndex; } onButtonClick(index, ev) { if (index !== this.state.selectedIndex) { this.state.selectedIndex = index; const value = this.input.button ? [...this.input.button][index].value || undefined : undefined; this.emit("change", { index, value, originalEvent: ev, }); } } } module.exports = SegmentedButtons;