Skip to content

Commit cd9a465

Browse files
authored
Merge pull request #30 from y0c/dev
D2M
2 parents a95f1ac + effc3f2 commit cd9a465

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3601
-3831
lines changed

.storybook/webpack.config.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
// load the default config generator.
22
const path = require('path');
33

4-
module.exports = (baseConfig, env, defaultConfig) => {
4+
module.exports = ({ config }) => {
55
// Extend it as you need.
66
// For example, add typescript loader:
7-
defaultConfig.module.rules.push({
7+
config.module.rules.push({
88
test: /\.(ts|tsx)$/,
99
use: [
1010
require.resolve('awesome-typescript-loader'),
1111
require.resolve('react-docgen-typescript-loader'),
1212
],
1313
});
1414

15-
defaultConfig.module.rules.push({
15+
config.module.rules.push({
1616
test: /\.scss$/,
17-
loaders: ['style-loader', 'css-loader', 'sass-loader'],
17+
use: [
18+
require.resolve('style-loader'),
19+
require.resolve('css-loader'),
20+
require.resolve('sass-loader'),
21+
],
1822
});
1923

20-
defaultConfig.resolve.modules.push(path.join(__dirname, '../'));
21-
defaultConfig.resolve.extensions.push('.ts', '.tsx');
22-
return defaultConfig;
24+
config.resolve.modules.push(path.join(__dirname, '../'));
25+
config.resolve.extensions.push('.ts', '.tsx');
26+
return config;
2327
};

README.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ React DatePicker
3434

3535
![datepicker](https://user-images.githubusercontent.com/2585676/52909193-a8992400-32c7-11e9-9266-7735c0e6e705.gif)
3636

37+
3738
### RangeDatePicker
3839

3940
![rangedatepicker](https://user-images.githubusercontent.com/2585676/52909117-d7ae9600-32c5-11e9-902a-4df671e82611.gif)
4041

41-
### TimePicker
42-
43-
![timepicker](https://user-images.githubusercontent.com/2585676/52909206-fd3c9f00-32c7-11e9-983e-94594c9847f4.gif)
4442

4543
[Demo in Storybook](https://y0c.github.io/react-datepicker)
4644

@@ -51,7 +49,6 @@ React DatePicker
5149
* RangeDatePicker
5250
* DatePicker
5351
* Standalone Calendar
54-
* TimePicker
5552

5653
The components that you can use are as follows: If you want to configure the `DatePicker` yourself, you can configure it any way you want through the `Default Calendar component`.
5754

@@ -63,11 +60,13 @@ The components that you can use are as follows: If you want to configure the `Da
6360

6461
## 📦 Dependency
6562

66-
> In the next version v1.0.0, moment.js will be replaced by day.js or date-fns
63+
* Moment.js
6764

68-
* [Moment](https://momentjs.com)
65+
In previous versions, moment.js were used. but now it is changed to `Day.js` to because of bundle size issue (#14)
6966

70-
`Moment` is a javascript library for Parse, validate, manipulate, and display dates and times. this component use moment library to globalize and control date. You can check the locale list through this [link](https://github.com/moment/moment/tree/develop/locale).
67+
* [Day.js](https://github.com/iamkun/dayjs)
68+
69+
`Day.js` is a javascript library for Parse, validate, manipulate, and display dates and times. this component use `Day.js` library to globalize and control date. You can check the locale list through this [link](https://github.com/iamkun/dayjs/tree/dev/src/locale).
7170

7271
## 📲 Installation
7372

@@ -89,26 +88,55 @@ import { DatePicker } from '@y0c/react-datepicker';
8988
// You can customize style by copying asset folder.
9089
import '@y0c/react-datepicker/assets/styles/calendar.scss';
9190

92-
// Please include the locale you want to use.
93-
// and delivery props to calendar component
94-
// See locale list https://github.com/moment/moment/tree/develop/locale
95-
import 'moment/locale/ko';
96-
9791
class DatePickerExample extends Component {
9892

9993
onChange = (date) => {
94+
// Day.js object
10095
console.log(date);
96+
97+
// to normal Date object
98+
console.log(date.toDate());
10199
}
102100

103101
render() {
104102
return (
105-
<DatePicker locale="ko" onChange={this.onChange}/>
103+
<DatePicker onChange={this.onChange}/>
106104
)
107105
}
108106
}
109107
```
108+
110109
You can find more Exmaples and Demo in story book link
111110

111+
## 🌎 i18n
112+
113+
Features for i18n are provided by Day.js by default.
114+
115+
see locale list https://github.com/iamkun/dayjs/tree/dev/src/
116+
117+
and you can customize the locale object
118+
119+
```javascript
120+
// use day.js locale
121+
import 'dayjs/locale/ko'
122+
123+
// delivery prop locale string
124+
<DatePicker locale="ko" />
125+
126+
// or define customize locale object
127+
const locale = {
128+
name: 'ko',
129+
weekdays: '일요일_월요일_화요일_수요일_목요일_금요일_토요일'.split('_'),
130+
weekdaysShort: '일_월_화_수_목_금_토'.split('_'),
131+
months: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
132+
};
133+
134+
// delivery propr locale object
135+
<DatePicker locale={locale} />
136+
```
137+
138+
Defaults locale `en`
139+
112140
### 🎨 Themeing
113141

114142
1. Copy this project asset folder under scss file
@@ -167,6 +195,10 @@ Please fork and use [https://codesandbox.io/s/pw6n17pk57](https://codesandbox.io
167195
* Open a new issue(Bug or Feature) on [Github](https://github.com/y0c/react-datepicker/issues/new/choose)
168196
* Join the [Gitter room](https://gitter.im/react-datepicker/community) to chat with other developers.
169197

198+
## 👨‍👦‍👦 Contribution
199+
200+
Issue and Pull Request are always welcome!
201+
170202
## 📝 License
171203
MIT
172204

assets/styles/app.scss

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,25 @@
7575
left: 50%;
7676
transform: translateX(-50%) translateY(-50%);
7777
}
78-
&.include__time {
79-
padding: 10px;
78+
&__include-time {
8079
border: 1px solid $divider-color;
81-
background: white;
80+
.calendar__item,
81+
.time__container {
82+
border: none;
83+
}
8284
}
8385
&__tab {
8486
& button {
8587
padding: 5px 10px;
8688
outline: none;
8789
display: inline-flex;
8890
align-items: center;
89-
background: $primary-color;
90-
color:white;
91+
background: none;
92+
border:none;
93+
border-bottom: 2px solid $divider-color;
9194
&.active {
92-
background: $primary-color-dark;
95+
color: $primary-color-dark;
96+
border-bottom: 2px solid $primary-color-dark;
9397
}
9498
&:first-child {
9599
border-right: none;
@@ -98,7 +102,7 @@
98102
margin-right: 5px;
99103
}
100104
}
101-
margin-bottom: 10px;
105+
margin: 10px 0;
102106
}
103107
}
104108
}
@@ -158,7 +162,6 @@
158162
display:inline-block;
159163
background: white;
160164
font-size: $base-font-size;
161-
box-shadow: 1px 1px 0px #eee;
162165
*, *:before, *:after {
163166
box-sizing: border-box;
164167
}

examples/CalendarSelectedController.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import * as moment from 'moment';
2+
import * as dayjs from 'dayjs';
33
import Calendar, { Props as ICalendarProps } from '../src/components/Calendar';
44
import { Omit, Merge } from '../src/utils/TypeUtil';
55

@@ -16,7 +16,7 @@ interface IProps {
1616
}
1717

1818
interface State {
19-
selected: moment.Moment[];
19+
selected: dayjs.Dayjs[];
2020
}
2121

2222
type Props = CalendarProps & IProps;
@@ -29,7 +29,7 @@ class CalendarSelectedController extends React.Component<Props, State> {
2929
selected: [],
3030
};
3131

32-
public handleChange = (date: moment.Moment) => {
32+
public handleChange = (date: dayjs.Dayjs) => {
3333
const { multiple } = this.props;
3434
this.setState({
3535
selected: multiple ? [...this.state.selected, date] : [date],

package.json

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@y0c/react-datepicker",
33
"version": "0.3.7",
4-
"description": "React Datepicker Component",
4+
"description": "Flexible, Reusable, Mobile friendly DatePicker Component",
55
"author": "y0c",
66
"license": "MIT",
77
"main": "lib/index.js",
@@ -34,8 +34,7 @@
3434
},
3535
"dependencies": {
3636
"classnames": "^2.2.6",
37-
"lodash": "4.17.11",
38-
"moment": "^2.22.2",
37+
"dayjs": "^1.8.12",
3938
"react": "^16.8.4",
4039
"react-dom": "^16.8.4"
4140
},
@@ -76,22 +75,22 @@
7675
]
7776
},
7877
"devDependencies": {
79-
"@babel/core": "^7.2.2",
80-
"@storybook/addon-actions": "^4.1.11",
81-
"@storybook/addon-info": "^4.1.11",
82-
"@storybook/addon-jest": "^4.1.11",
83-
"@storybook/addon-knobs": "^4.1.11",
84-
"@storybook/addon-links": "^4.1.11",
85-
"@storybook/addon-options": "^4.1.11",
86-
"@storybook/addons": "^4.1.11",
87-
"@storybook/cli": "^4.1.11",
88-
"@storybook/react": "^4.1.11",
78+
"@babel/core": "^7.4.3",
79+
"@emotion/core": "^10.0.10",
80+
"@storybook/addon-actions": "^5.0.6",
81+
"@storybook/addon-info": "^5.0.6",
82+
"@storybook/addon-jest": "^5.0.6",
83+
"@storybook/addon-knobs": "^5.0.6",
84+
"@storybook/addon-links": "^5.0.6",
85+
"@storybook/addon-options": "^5.0.6",
86+
"@storybook/addons": "^5.0.6",
87+
"@storybook/cli": "^5.0.6",
88+
"@storybook/react": "^5.0.6",
8989
"@storybook/storybook-deployer": "^2.8.1",
9090
"@types/classnames": "^2.2.6",
9191
"@types/enzyme": "^3.1.15",
92-
"@types/jest": "^23.3.12",
92+
"@types/jest": "^24.0.11",
9393
"@types/lodash": "^4.14.118",
94-
"@types/moment": "^2.13.0",
9594
"@types/react": "^16.7.13",
9695
"@types/react-dom": "^16.0.11",
9796
"@types/sinon": "^7.0.3",
@@ -100,7 +99,7 @@
10099
"@types/storybook__react": "^4.0.0",
101100
"awesome-typescript-loader": "^5.2.1",
102101
"babel-loader": "^8.0.5",
103-
"clean-webpack-plugin": "0.1.19",
102+
"clean-webpack-plugin": "2.0.1",
104103
"cross-env": "5.2.0",
105104
"css-loader": "2.1.0",
106105
"enzyme": "^3.8.0",
@@ -109,7 +108,7 @@
109108
"file-loader": "3.0.1",
110109
"html-webpack-plugin": "3.2.0",
111110
"husky": "^1.3.1",
112-
"jest": "^23.6.0",
111+
"jest": "^24.7.0",
113112
"lint-staged": "^8.1.0",
114113
"node-sass": "4.11.0",
115114
"prettier": "^1.15.3",
@@ -119,13 +118,13 @@
119118
"sass-loader": "7.1.0",
120119
"sinon": "^7.2.2",
121120
"style-loader": "0.23.1",
122-
"ts-jest": "^23.10.5",
121+
"ts-jest": "^24.0.1",
123122
"ts-loader": "^5.3.3",
124123
"ts-mockito": "^2.3.1",
125124
"tslint": "^5.12.1",
126125
"tslint-config-airbnb": "^5.11.1",
127126
"tslint-config-prettier": "^1.17.0",
128-
"tslint-react": "^3.6.0",
127+
"tslint-react": "^4.0.0",
129128
"typescript": "^3.2.2",
130129
"url-loader": "^1.1.2",
131130
"webpack": "4.28.4",
@@ -139,7 +138,6 @@
139138
"keywords": [
140139
"react",
141140
"datepicker",
142-
"timepicker",
143141
"calendar",
144142
"rangepicker",
145143
"rangedatepicker"

src/common/@types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export namespace IDatePicker {
2+
export type Locale = string | { name: string; [key: string]: any };
23
export enum PickerDirection {
34
TOP,
45
BOTTOM,

src/common/Constant.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const DatePickerDefaults = {
22
dateFormat: 'YYYY-MM-DD',
3-
locale: 'en-ca',
3+
dateTimeFormat: 'YYYY-MM-DD HH:mm A',
4+
timeFormat: 'HH:mm A',
5+
locale: 'en',
46
};

src/components/Calendar.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { range } from 'lodash';
2-
import * as moment from 'moment';
1+
import { range } from '../utils/ArrayUtil';
2+
import * as dayjs from 'dayjs';
33
import * as React from 'react';
44
import CalendarContainer, { InheritProps as ContainerProps } from './CalendarContainer';
55

66
export interface Props extends ContainerProps {
77
/** Calendar Initial Date Parameters */
8-
base: moment.Moment;
8+
base: dayjs.Dayjs;
99
/** Number of months to show at once */
1010
showMonthCnt: number;
1111
}
1212

1313
export interface State {
14-
base: moment.Moment;
14+
base: dayjs.Dayjs;
1515
}
1616

1717
class Calendar extends React.Component<Props, State> {
1818
public static defaultProps = {
19-
base: moment(),
19+
base: dayjs(),
2020
showMonthCnt: 1,
2121
showToday: false,
2222
};
@@ -28,7 +28,7 @@ class Calendar extends React.Component<Props, State> {
2828
};
2929
}
3030

31-
public setBase = (base: moment.Moment) => {
31+
public setBase = (base: dayjs.Dayjs) => {
3232
this.setState({ base });
3333
};
3434

@@ -44,7 +44,7 @@ class Calendar extends React.Component<Props, State> {
4444
<CalendarContainer
4545
{...this.props}
4646
base={this.state.base}
47-
current={base.clone().add(idx, 'months')}
47+
current={dayjs(base).add(idx, 'month')}
4848
prevIcon={idx === 0}
4949
nextIcon={idx === showMonthCnt! - 1}
5050
setBase={this.setBase}

0 commit comments

Comments
 (0)