@php use Illuminate\Support\Js; $statePath = $getStatePath(); $options = $getNormalizedOptions(); $optionKeys = array_keys($options); $size = $getSize(); $variant = $getVariant(); $hasSeparators = $hasSeparators(); $isFullWidth = $isFullWidth(); $isIconOnly = $isIconOnly(); $expandSelectedLabel = $shouldExpandSelectedLabel(); $isDisabled = $isDisabled(); @endphp
mapWithKeys(fn (array $option, string | int $key): array => [(string) $key => $option['disabled']])->all()) }}, separators: @js($hasSeparators), disabled: @js($isDisabled), indicatorStyle: '', resizeObserver: null, normalize(value) { return value === null || value === undefined ? null : String(value); }, isSelected(value) { return this.normalize(this.state) === this.normalize(value); }, isOptionDisabled(value) { return this.disabledOptions[this.normalize(value)] ?? false; }, canSelect(value) { return ! this.disabled && ! this.isOptionDisabled(value); }, select(value) { if (! this.canSelect(value)) { return; } this.state = value; this.$nextTick(() => this.updateIndicator()); }, selectedIndex() { const current = this.normalize(this.state); return this.optionKeys.findIndex((key) => this.normalize(key) === current); }, showSeparator(separatorIndex) { if (! this.separators) { return false; } const selectedIndex = this.selectedIndex(); if (selectedIndex === -1) { return true; } return separatorIndex !== selectedIndex - 1 && separatorIndex !== selectedIndex; }, updateIndicator() { const track = this.$refs.track; if (! track) { return; } const selected = track.querySelector('[data-segment-selected=true]'); if (! selected) { this.indicatorStyle = 'opacity: 0;'; return; } this.indicatorStyle = 'width: ' + selected.offsetWidth + 'px;' + 'height: ' + selected.offsetHeight + 'px;' + 'transform: translate3d(' + selected.offsetLeft + 'px, ' + selected.offsetTop + 'px, 0);' + 'opacity: 1;'; }, init() { this.$watch('state', () => this.$nextTick(() => this.updateIndicator())); this.$nextTick(() => this.updateIndicator()); if (typeof ResizeObserver === 'undefined') { return; } this.resizeObserver = new ResizeObserver(() => this.updateIndicator()); this.resizeObserver.observe(this.$refs.track); }, }" x-init="init()" @class([ 'fsu-segment-control', 'w-full' => $isFullWidth, 'opacity-60 pointer-events-none' => $isDisabled, ]) role="radiogroup" aria-label="{{ $getLabel() }}" >
$variant === 'ghost', ]) > @foreach ($options as $value => $option) @if (! $loop->first && $hasSeparators) @endif @endforeach