Summary
Visual editor for splitting 100% across 2–5 draggable segments (traffic allocation, weighted distribution).| Class | Bjanczak\FilamentFlexFields\Filament\Forms\Components\TrafficSplit |
| State type | array<int, int> — weights summing to 100 |
| Model cast | 'split' => 'array' or 'json' |
| FieldType | traffic_split |
[40, 35, 25].
Basic usage
Validation
No automatic Laravel rules. Ensure segment weights sum to 100 in application logic if persisted outside the component. The component normalizes state on hydration vianormalizeWeights().
Default state
Equal split across segments (equalSplit()), e.g. three segments → [34, 33, 33].
Configuration API
linkedToRepeater(string|Closure $repeaterPath)
Links the split control dynamically to a Repeater state path. The number of split segments will automatically match the items in the Repeater, syncing weights.
State normalization
On load, weights are passed throughnormalizeWeights():
- Ensures segment count matches
segmentCount() - Enforces
minWeight - Respects
lockedSegments - Rebalances unlocked segments so the total equals 100
InvalidArgumentException when minWeight × segmentCount > 100.
FlexField schema config
| Config key | Maps to |
|---|---|
segment_count | segmentCount() |
min_weight | minWeight() |
value_threshold | valueThreshold() |
size | size() |
variant | variant() |
labels | labels() |
locked_segments | lockedSegments() |
Public helper methods
| Method | Returns | Description |
|---|---|---|
equalSplit() | list<int> | Equal weight distribution across segmentCount() summing to 100 (remainder distributed to first segments). Default state source. |
normalizeWeights(?array $weights) | list<int> | Normalizes weights to segment count, enforces minWeight, respects lockedSegments, rebalances to total 100. Returns equalSplit() when input is invalid. |
CSS / stacking
Drag handles use a local stacking context (z-index: 2 inside .fff-traffic-split__track with isolation: isolate) so grey divider bars do not paint above the Filament sticky header when scrolling.