Repository: lizashkod/react-timeline-range-slider Branch: master Commit: 7a328a0d8f0c Files: 13 Total size: 21.6 KB Directory structure: gitextract_e_2xsxx2/ ├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── src/ │ ├── components/ │ │ ├── Handle.js │ │ ├── KeyboardHandle.js │ │ ├── SliderRail.js │ │ ├── Tick.js │ │ └── Track.js │ ├── index.js │ └── styles/ │ └── index.scss └── webpack.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets": ["@babel/preset-env"], "plugins": [ "transform-object-rest-spread", "transform-react-jsx", "@babel/plugin-proposal-class-properties" ] } ================================================ FILE: .gitignore ================================================ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies /node_modules /.pnp .pnp.js /.idea /dist # testing /coverage # production /build # misc .DS_Store .env.local .env.development.local .env.test.local .env.production.local npm-debug.log* yarn-debug.log* yarn-error.log* ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 Elizaveta Shkodkina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ ### react-timeline-range-slider ![demo gif](./demo.gif) ### Installation npm i react-timeline-range-slider ### Props | Prop | Type | Default | Description| |--|--|--|--| | timelineInterval | array |[startOfToday(), endOfToday()]|Interval to display| |selectedInterval|array|[new Date(), addHours(new Date(), 1)]|Selected interval inside the timeline| |disabledIntervals|array|[]|Array of disabled intervals inside the timeline| |containerClassName|string||ClassName of the wrapping container| |step|number|1800000|Number of milliseconds between steps (the default value is 30 minutes)| |ticksNumber|number|48|Number of steps on the timeline (the default value is 30 minutes)| |error|bool|false|Is the selected interval is not valid| |mode|int/function|3|The interaction mode. Value of 1 will allow handles to cross each other. Value of 2 will keep the sliders from crossing and separated by a step. Value of 3 will make the handles pushable and keep them a step apart. ADVANCED: You can also supply a function that will be passed the current values and the incoming update. Your function should return what the state should be set as.| |formatTick|function|ms => format(new Date(ms), 'HH:mm')|Function that determines the format in which the date will be displayed| |onUpdateCallback|function||| |onChangeCallback|function||| ### Example [Live demo](https://codesandbox.io/s/react-timeline-range-slider-ve7w2?file=/src/App.js) ```javascript import React from 'react' import { endOfToday, set } from 'date-fns' import TimeRange from 'react-timeline-range-slider' const now = new Date() const getTodayAtSpecificHour = (hour = 12) => set(now, { hours: hour, minutes: 0, seconds: 0, milliseconds: 0 }) const selectedStart = getTodayAtSpecificHour() const selectedEnd = getTodayAtSpecificHour(14) const startTime = getTodayAtSpecificHour(7) const endTime = endOfToday() const disabledIntervals = [ { start: getTodayAtSpecificHour(16), end: getTodayAtSpecificHour(17) }, { start: getTodayAtSpecificHour(7), end: getTodayAtSpecificHour(12) }, { start: getTodayAtSpecificHour(20), end: getTodayAtSpecificHour(24) } ] class App extends React.Component { state = { error: false, selectedInterval: [selectedStart, selectedEnd], } errorHandler = ({ error }) => this.setState({ error }) onChangeCallback = selectedInterval => this.setState({ selectedInterval }) render() { const { selectedInterval, error } = this.state return ( ) } } export default App ``` ================================================ FILE: package.json ================================================ { "name": "react-timeline-range-slider", "version": "1.4.1", "description": "Time Slider component for React", "author": "Elizaveta Shkodkina ", "main": "dist/index.js", "license": "MIT", "homepage": "https://github.com/lizashkod/react-time-range-slider", "repository": { "type": "git", "url": "https://github.com/lizashkod/react-time-range-slider" }, "keywords": [ "react-component", "react", "slider", "component", "time-picker", "react-slider", "range-slider", "range" ], "peerDependencies": { "react": "^17.0.2", "react-dom": "^17.0.2" }, "scripts": { "start": "webpack --watch", "build": "webpack" }, "eslintConfig": { "extends": "react-app" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "dependencies": { "prop-types": "^15.7.2", "d3-scale": "^3.2.3", "date-fns": "^2.19.0", "node-sass": "^5.0.0", "react-compound-slider": "^3.3.1" }, "devDependencies": { "@babel/core": "^7.13.10", "@babel/plugin-proposal-class-properties": "^7.13.0", "@babel/preset-env": "^7.13.12", "@babel/preset-react": "^7.12.13", "babel-loader": "^8.2.2", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-react-jsx": "^6.24.1", "css-loader": "^5.1.3", "sass-loader": "^10.0.0", "style-loader": "^2.0.0", "webpack": "^4.43.0", "webpack-cli": "^3.3.12" } } ================================================ FILE: src/components/Handle.js ================================================ import PropTypes from 'prop-types' import React from 'react' const Handle = ({ error, domain: [min, max], handle: { id, value, percent = 0 }, disabled, getHandleProps, }) => { const leftPosition = `${percent}%` 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, style: PropTypes.object, } Handle.defaultProps = { disabled: false } export default Handle ================================================ FILE: src/components/KeyboardHandle.js ================================================ import PropTypes from 'prop-types' import React from 'react' const KeyboardHandle = ({ domain: [min, max], handle: { id, value, percent = 0 }, disabled, getHandleProps }) => (