|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { withStyles, makeStyles } from '@material-ui/core/styles'; |
| 4 | +import Slider from '@material-ui/core/Slider'; |
| 5 | +import Typography from '@material-ui/core/Typography'; |
| 6 | +import Tooltip from '@material-ui/core/Tooltip'; |
| 7 | + |
| 8 | +const useStyles = makeStyles((theme) => ({ |
| 9 | + root: { |
| 10 | + width: 300 + theme.spacing(3) * 2, |
| 11 | + }, |
| 12 | + margin: { |
| 13 | + height: theme.spacing(3), |
| 14 | + }, |
| 15 | +})); |
| 16 | + |
| 17 | +function ValueLabelComponent(props) { |
| 18 | + const { children, open, value } = props; |
| 19 | + |
| 20 | + return ( |
| 21 | + <Tooltip open={open} enterTouchDelay={0} placement="top" title={value}> |
| 22 | + {children} |
| 23 | + </Tooltip> |
| 24 | + ); |
| 25 | +} |
| 26 | + |
| 27 | +ValueLabelComponent.propTypes = { |
| 28 | + children: PropTypes.element.isRequired, |
| 29 | + open: PropTypes.bool.isRequired, |
| 30 | + value: PropTypes.number.isRequired, |
| 31 | +}; |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +const AirbnbSlider = withStyles({ |
| 37 | + root: { |
| 38 | + color: '#3a8589', |
| 39 | + height: 3, |
| 40 | + padding: '13px 0', |
| 41 | + }, |
| 42 | + thumb: { |
| 43 | + height: 27, |
| 44 | + width: 27, |
| 45 | + backgroundColor: '#fff', |
| 46 | + border: '1px solid currentColor', |
| 47 | + marginTop: -12, |
| 48 | + marginLeft: -13, |
| 49 | + boxShadow: '#ebebeb 0 2px 2px', |
| 50 | + '&:focus, &:hover, &$active': { |
| 51 | + boxShadow: '#ccc 0 2px 3px 1px', |
| 52 | + }, |
| 53 | + '& .bar': { |
| 54 | + // display: inline-block !important; |
| 55 | + height: 9, |
| 56 | + width: 1, |
| 57 | + backgroundColor: 'currentColor', |
| 58 | + marginLeft: 1, |
| 59 | + marginRight: 1, |
| 60 | + }, |
| 61 | + }, |
| 62 | + active: {}, |
| 63 | + track: { |
| 64 | + height: 3, |
| 65 | + }, |
| 66 | + rail: { |
| 67 | + color: '#ffffff', |
| 68 | + opacity: 1, |
| 69 | + height: 3, |
| 70 | + }, |
| 71 | +})(Slider); |
| 72 | + |
| 73 | +function AirbnbThumbComponent(props) { |
| 74 | + return ( |
| 75 | + <span {...props}> |
| 76 | + <span className="bar" /> |
| 77 | + <span className="bar" /> |
| 78 | + <span className="bar" /> |
| 79 | + </span> |
| 80 | + ); |
| 81 | +} |
| 82 | + |
| 83 | +export default function CustomizedSlider() { |
| 84 | + const classes = useStyles(); |
| 85 | + |
| 86 | + return ( |
| 87 | + <div className={classes.root}> |
| 88 | + <Typography gutterBottom>Airbnb</Typography> |
| 89 | + <AirbnbSlider |
| 90 | + ThumbComponent={AirbnbThumbComponent} |
| 91 | + getAriaLabel={(index) => (index === 0 ? 'Minimum price' : 'Maximum price')} |
| 92 | + defaultValue={[20, 40]} |
| 93 | + valueLabelDisplay="on" |
| 94 | + /> |
| 95 | + </div> |
| 96 | + ); |
| 97 | +} |
0 commit comments