Skip to content

Commit 847e7ef

Browse files
committed
Working DatePresetPicker with demo
0 parents  commit 847e7ef

20 files changed

+38624
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ['es2015', 'stage-0', 'react']
3+
}

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = false
9+
insert_final_newline = true
10+
indent_style = tab
11+
12+
[*.json]
13+
indent_style = space
14+
indent_size = 2

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.publish/*
2+
dist/*
3+
example/dist/*
4+
lib/*
5+
node_modules/*

.eslintrc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"browser": true,
5+
"node": true
6+
},
7+
"plugins": [
8+
"react"
9+
],
10+
"rules": {
11+
"curly": [2, "multi-line"],
12+
"quotes": [2, "single", "avoid-escape"],
13+
"react/display-name": 0,
14+
"react/jsx-boolean-value": 1,
15+
"react/jsx-quotes": 1,
16+
"react/jsx-no-undef": 1,
17+
"react/jsx-sort-props": 0,
18+
"react/jsx-sort-prop-types": 1,
19+
"react/jsx-uses-react": 1,
20+
"react/jsx-uses-vars": 1,
21+
"react/no-did-mount-set-state": 1,
22+
"react/no-did-update-set-state": 1,
23+
"react/no-multi-comp": 1,
24+
"react/no-unknown-property": 1,
25+
"react/prop-types": 1,
26+
"react/react-in-jsx-scope": 1,
27+
"react/self-closing-comp": 1,
28+
"react/wrap-multilines": 1,
29+
"semi": 2,
30+
"strict": 0
31+
}
32+
}

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Coverage tools
11+
lib-cov
12+
coverage
13+
coverage.html
14+
.cover*
15+
16+
# Dependency directory
17+
node_modules
18+
19+
# Example build directory
20+
example/dist
21+
.publish
22+
23+
# Editor and other tmp files
24+
*.swp
25+
*.un~
26+
*.iml
27+
*.ipr
28+
*.iws
29+
*.sublime-*
30+
.idea/
31+
*.DS_Store

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# react-dates-presets
2+
3+
Preset picker based on `react-dates` - allows you to define preset ranges like `today`, `last week`, etc.
4+
5+
![demo gif](http://streamfoundations.github.io/react-dates-presets/demo/demo.gif)
6+
7+
## Demo & Examples
8+
9+
Live demo: [streamfoundations.github.io/react-dates-presets/demo](http://streamfoundations.github.io/react-dates-presets/demo/)
10+
11+
## Usage
12+
13+
```
14+
render() {
15+
const ranges = [
16+
{ id: 'today', range: { startDate: moment(), endDate: moment() }, label: 'Today' },
17+
{ id: '7_days', range: { startDate: moment().subtract(7, 'days'), endDate: moment() }, label: 'Last 7 days' },
18+
{ id: '1_month', range: { startDate: moment().subtract(1, 'month'), endDate: moment() }, label: 'Last month' },
19+
{ id: '2_months', range: { startDate: moment().subtract(2, 'months'), endDate: moment() }, label: 'Last 2 months' },
20+
];
21+
22+
return (
23+
<DatePresetPicker
24+
value={this.props.value}
25+
onChange={this.onChange}
26+
ranges={ranges}
27+
isOutsideRange={(date) => date >= moment().add(1, 'days') /* allow past dates */}
28+
/>
29+
);
30+
}
31+
```
32+
33+
You can also check out working code in [/demo/App.jsx](https://github.com/streamfoundations/react-dates-presets/blob/master/demo/App.jsx).

demo/App.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import moment from 'moment';
4+
import 'react-dates/lib/css/_datepicker.css';
5+
import DatePresetPicker from '../lib/index.js';
6+
import '../lib/styles.css';
7+
8+
class App extends React.Component {
9+
onChange(vals) {
10+
console.log('onChange called with args: ', vals);
11+
};
12+
13+
render() {
14+
const initialState = { startDate: moment().format('YYYY-MM-DD'), endDate: moment().format('YYYY-MM-DD') };
15+
16+
const ranges = [
17+
{ id: 'today', range: { startDate: moment(), endDate: moment() }, label: 'Today' },
18+
{ id: '7_days', range: { startDate: moment().subtract(7, 'days'), endDate: moment() }, label: 'Last 7 days' },
19+
{ id: '1_month', range: { startDate: moment().subtract(1, 'month'), endDate: moment() }, label: 'Last month' },
20+
{ id: '2_months', range: { startDate: moment().subtract(2, 'months'), endDate: moment() }, label: 'Last 2 months' },
21+
];
22+
23+
return (
24+
<DatePresetPicker
25+
value={initialState}
26+
onChange={this.onChange}
27+
ranges={ranges}
28+
isOutsideRange={() => false /* allow future & past dates */}
29+
/>
30+
);
31+
}
32+
}
33+
34+
ReactDOM.render(<App />, document.getElementById('react'));

demo/app.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/demo.gif

396 KB
Loading

demo/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="user-scalable=yes, width=device-width" />
6+
<title>React Popover demo</title>
7+
<link href="./styles.css" media="all" rel="stylesheet" />
8+
<style>
9+
html, body, #react, #react > div {
10+
height: 100%;
11+
margin: 0;
12+
padding: 0;
13+
background-color: #E9F1F7;
14+
}
15+
body {
16+
padding: 15px 30px;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<div id="react"></div>
22+
<script src="./vendor.js"></script>
23+
<script src="./app.js"></script>
24+
</body>
25+
</html>

demo/styles.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/vendor.js

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)