/** * @file * @copyright 2020 Aleksej Komarov * @license MIT */ import { clamp01, keyOfMatchingRange, scale } from 'common/math'; import { classes } from 'common/react'; import { computeBoxClassName, computeBoxProps } from './Box'; import { DraggableControl } from './DraggableControl'; import { NumberInput } from './NumberInput'; export const Slider = (props) => { // IE8: I don't want to support a yet another component on IE8. if (Byond.IS_LTE_IE8) { return ; } const { // Draggable props (passthrough) animated, format, maxValue, minValue, onChange, onDrag, step, stepPixelSize, suppressFlicker, unit, value, // Own props className, fillValue, color, ranges = {}, children, ...rest } = props; const hasContent = children !== undefined; return ( {(control) => { const { dragging, editing, value, displayValue, displayElement, inputElement, handleDragStart } = control; const hasFillValue = fillValue !== undefined && fillValue !== null; const scaledValue = scale(value, minValue, maxValue); const scaledFillValue = scale(fillValue ?? displayValue, minValue, maxValue); const scaledDisplayValue = scale(displayValue, minValue, maxValue); const effectiveColor = color || keyOfMatchingRange(fillValue ?? value, ranges) || 'default'; return (
{dragging &&
{displayElement}
}
{hasContent ? children : displayElement}
{inputElement}
); }} ); };