import * as React from "react"; import { get } from "lodash"; import Grid from "@material-ui/core/Grid"; import IconButton from "@material-ui/core/IconButton"; import Slider from "@material-ui/core/Slider"; import RemoveIcon from "@material-ui/icons/Remove"; import AddIcon from "@material-ui/icons/Add"; import { ButtonSliderGroupProps } from "./types"; /** * Renders two buttons and an optional slider * * Used for use cases like incrementing/decrementing a property, or setting a precise value (using the slider) */ export const ButtonSliderGroup: React.FC = ({ value = 0, minValue = 0, maxValue, showSlider = false, label, toolTip, button1 = { command: "SHRINK", style: {}, }, button2 = { command: "GROW", style: {}, }, children, __testSliderValue = 111, onValueChange = () => false, }) => { // const [sliderValue, setSliderValue] = React.useState(value); const handleChange = ( command: any, newValue: number | number[] | React.ReactText ) => { // console.log(newValue); onValueChange(command, newValue); }; return (
{label} handleChange(button1.command, value)} style={{ ...button1.style }} > {get(button1, "icon") || } {showSlider && ( handleChange(null, v)} aria-labelledby="continuous-slider" max={maxValue} min={minValue} /> )} handleChange(button2.command, value)} style={{ ...button2.style }} > {get(button2, "icon") || } {children} {/* This is for (jest) testing purposes */} {__testSliderValue && (
handleChange(null, __testSliderValue)} /> )}
); }; export default ButtonSliderGroup;