/** * Tick slider — a single-row slider over a small, named set of steps (e.g. * spacing: Small / Medium / Large / Extra Large), with every step labelled * underneath the track rather than just the current one. * * Deliberately not `@wordpress/components`' `RangeControl` with `marks`: its * mark labels are positioned for a full-width settings page, and inside the * ~250px Customizer panel this control also renders in, a 4th long label * ("Extra Large") collides with its neighbour and runs off the edge. This * lays the labels out as a flex row instead, so they always divide the * available width evenly regardless of how narrow the host is. */ interface TickOption { value: string; label: string; } interface TickSliderProps { label: string; value: string; options: TickOption[]; onChange: ( value: string ) => void; help?: string; } export default function TickSlider( { label, value, options, onChange, help, }: TickSliderProps ) { const index = Math.max( 0, options.findIndex( ( option ) => option.value === value ) ); const lastIndex = Math.max( 0, options.length - 1 ); const percent = lastIndex > 0 ? ( index / lastIndex ) * 100 : 0; return (
{ help }
) }