import React, { ChangeEvent } from "react"; import classnames from "classnames"; import { FILL_COLOR_MAP } from "../../utils/accessibility"; const DEFAULT_FILL_COLOR_NAME = "default"; interface RangeSliderProps { /** CSS class names. */ className?: string; /** Custom color for slider **/ fillColorName?: keyof typeof FILL_COLOR_MAP; /** Whether it is disabled, will render as greyscale if so **/ isDisabled?: boolean; /** onChange function */ onChange: (event: ChangeEvent) => void; /** Hook for automated JavaScript tests */ testSection?: string; /** When true, uses 'Off' instead of '0%' */ useOffForLabel?: boolean; /** The value */ value: number; } const RangeSlider: React.FC = ({ className, fillColorName = DEFAULT_FILL_COLOR_NAME, isDisabled = false, onChange, testSection, useOffForLabel = false, value, ...props }: RangeSliderProps) => { const rangeClasses = classnames({ "oui-rangeslider": true, "oui-rangeslider--disabled": isDisabled, }, className); // ensure valid fillColor name (in the case that propType errors are ignored) const validFillColorName = (Object.keys(FILL_COLOR_MAP) as Array).includes( fillColorName ) ? fillColorName : DEFAULT_FILL_COLOR_NAME; const fillColor = FILL_COLOR_MAP[validFillColorName]; return (
); }; export default RangeSlider;