Skip to content

Commit d644c96

Browse files
committed
change luxon to date-fns
1 parent 0c0a64a commit d644c96

File tree

9 files changed

+428
-411
lines changed

9 files changed

+428
-411
lines changed

API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ All [material-ui-pickers](https://github.com/dmtrKovalenko/material-ui-pickers)
7373
| maxDate | false | Date | |
7474
| disablePast | false | boolean | |
7575
| disableFuture | false | boolean | |
76-
| format | false | string | luxon string format |
76+
| format | false | string | date fns string format |
7777
| locale | false | string | use dateLocale as default |
7878
| onChange | true | Function(date) | |
7979

components/Date.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
22
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
3-
import FieldCoreBase from '@react-form-fields/core/components/FieldCoreBase';
4-
import { DateTime } from 'luxon';
3+
import FieldCoreBase, { IPropsFieldBase } from '@react-form-fields/core/components/FieldCoreBase';
54
import DatePicker from 'material-ui-pickers/DatePicker';
65
import { DatePickerWrapperProps } from 'material-ui-pickers/DatePicker/DatePickerWrapper';
7-
import DateUtils from 'material-ui-pickers/utils/luxon-utils';
6+
import DateUtils from 'material-ui-pickers/utils/date-fns-utils';
87
import MuiPickersUtilsProvider from 'material-ui-pickers/utils/MuiPickersUtilsProvider';
98
import * as React from 'react';
109

1110
import { getConfig } from '../config';
1211

13-
interface IProps extends DatePickerWrapperProps {
12+
type PropsResolver = {
13+
[K in Exclude<keyof IPropsFieldBase, keyof DatePickerWrapperProps | 'mask'>]?: IPropsFieldBase[K]
14+
};
15+
16+
interface IProps extends DatePickerWrapperProps, PropsResolver {
1417
value: Date;
1518
onChange: (value: Date) => void;
1619
minDate?: Date;
@@ -21,9 +24,7 @@ interface IProps extends DatePickerWrapperProps {
2124
}
2225

2326
export default class FieldDate extends FieldCoreBase<IProps> {
24-
onChange = (value: DateTime) => {
25-
const date = value ? value.toJSDate() : null;
26-
27+
onChange = (date?: Date) => {
2728
getConfig().validationOn === 'onChange' && this.setState({ showError: true });
2829
this.props.onChange(date);
2930
}
@@ -49,7 +50,7 @@ export default class FieldDate extends FieldCoreBase<IProps> {
4950
cancelLabel={'Cancelar'}
5051
label={label}
5152
value={value || null}
52-
format={format || 'D'}
53+
format={format || getConfig().dateFormat}
5354
fullWidth={true}
5455
margin={'normal'}
5556
leftArrowIcon={<ChevronLeftIcon />}

components/Select.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ITextFieldProps } from '../interfaces/props';
1010

1111
interface IProps extends ITextFieldProps {
1212
options?: { value: string | number, label: string }[];
13+
emptyOption?: boolean;
1314
loading?: boolean;
1415
onChange: (value: any) => void;
1516
}
@@ -28,7 +29,7 @@ export default class FieldSelect extends FieldCoreBase<IProps> {
2829
}
2930

3031
render() {
31-
const { value, options, children, loading } = this.props;
32+
const { value, options, children, loading, emptyOption } = this.props;
3233

3334
return (
3435
<React.Fragment>
@@ -58,9 +59,9 @@ export default class FieldSelect extends FieldCoreBase<IProps> {
5859
)
5960
}}
6061
>
61-
<MenuItem value={''}>
62-
Selecione...
63-
</MenuItem>
62+
{emptyOption &&
63+
<MenuItem value={''}>Selecione...</MenuItem>
64+
}
6465
{(options || []).map(option => (
6566
<MenuItem key={option.value} value={option.value}>
6667
{option.label}

config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import * as coreConfig from '@react-form-fields/core/config';
22

33
declare module '@react-form-fields/core/config' {
44
interface IConfig {
5-
dateLocale?: string;
5+
dateLocale?: any;
6+
dateFormat?: string;
67
validationOn?: 'onChange' | 'onBlur' | 'onSubmit';
78
}
89
}
910

1011
const defaultConfig: coreConfig.IConfig = {
11-
validationOn: 'onChange'
12+
validationOn: 'onChange',
13+
dateFormat: 'dd/MM/yyyy'
1214
}
1315

1416
export function getConfig(): coreConfig.IConfig {

docs/project/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dependencies": {
77
"@material-ui/core": "^1.2.0",
88
"@react-form-fields/core": "1.1.0",
9-
"@react-form-fields/material-ui": "1.6.0",
9+
"@react-form-fields/material-ui": "1.8.7",
1010
"mdi-react": "^3.4.0",
1111
"react": "^16.4.0",
1212
"react-dom": "^16.4.0",
@@ -23,6 +23,6 @@
2323
"@types/node": "^10.3.1",
2424
"@types/react": "^16.4.1",
2525
"@types/react-dom": "^16.0.6",
26-
"typescript": "2.9"
26+
"typescript": "3"
2727
}
2828
}

0 commit comments

Comments
 (0)