import React, { Component, Fragment } from 'react'; import { Slider, Rail, Handles, Tracks, Ticks } from 'react-compound-slider'; import PropTypes from 'prop-types'; const sliderStyle: any = { position: 'relative', margin: 'auto', width: '80%', touchAction: 'none' }; const defaultDomain: any = [0, 100]; const defaultValues: any = [0]; class SimpleSlider extends Component { constructor(props: any) { super(props); } state = { values: defaultValues.slice(), update: defaultValues.slice() }; onUpdate = (update) => { this.props.onUpdate(update[0]); this.setState({ update }); }; onChange = (values) => { this.props.onChange(values[0]); this.setState({ values }); }; render() { const { state: { values, update } } = this; return (
{({ getRailProps }) => } {({ handles, getHandleProps }) => (
{handles.map((handle) => ( ))}
)}
{({ tracks, getTrackProps }) => (
{tracks.map(({ id, source, target }) => ( ))}
)}
{({ ticks }) => (
{ticks.map((tick) => ( ))}
)}
); } } // ******************************************************* // RAIL // ******************************************************* const railOuterStyle = { position: 'absolute', width: '100%', height: 42, transform: 'translate(0%, -50%)', borderRadius: 7, cursor: 'pointer' // border: '1px solid white', }; const railInnerStyle: any = { position: 'absolute', width: '100%', height: 14, transform: 'translate(0%, -50%)', borderRadius: 7, pointerEvents: 'none', backgroundColor: 'rgb(155,155,155)' }; export function SliderRail({ getRailProps }) { return (
); } SliderRail.propTypes = { getRailProps: PropTypes.func.isRequired }; // ******************************************************* // HANDLE COMPONENT // ******************************************************* export function Handle({ domain: [min, max], handle: { id, value, percent }, disabled, getHandleProps }) { return (
); } Handle.propTypes = { domain: PropTypes.array.isRequired, handle: PropTypes.shape({ id: PropTypes.string.isRequired, value: PropTypes.number.isRequired, percent: PropTypes.number.isRequired }).isRequired, getHandleProps: PropTypes.func.isRequired, disabled: PropTypes.bool }; Handle.defaultProps = { disabled: false }; // ******************************************************* // KEYBOARD HANDLE COMPONENT // Uses a button to allow keyboard events // ******************************************************* export function KeyboardHandle({ domain: [min, max], handle: { id, value, percent }, disabled, getHandleProps }) { return (