Skip to content

Commit

Permalink
[typescript] Fix InputProps typing error & add dependency for @types/…
Browse files Browse the repository at this point in the history
…react-text-mask (mui#831)

* [mui#822] Add @types/react-text-mask to dependencies

* [mui#826] Properly type InputProps, InputAdornmentProps props

* Fix datetext field typings

* Move extending wrapper to separate shared type
  • Loading branch information
dmtrKovalenko authored Jan 2, 2019
1 parent 9a5c6fc commit f55d990
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class InlineDateTimePickerDemo extends PureComponent {
value={selectedDate}
onChange={this.handleDateChange}
format={this.props.getFormatString({
moment: 'YYYY/MM/DD hh:mm A',
dateFns: 'yyyy/MM/dd hh:mm A',
moment: 'YYYY/MM/DD hh:mm a',
dateFns: 'yyyy/MM/dd hh:mm a',
})}
mask={[
/\d/,
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"react-dom": "^16.3.0"
},
"dependencies": {
"@types/react-text-mask": "^5.4.2",
"classnames": "^2.2.6",
"keycode": "^2.2.0",
"react-event-listener": "^0.6.4",
Expand Down Expand Up @@ -89,7 +90,6 @@
"@types/react": "^16.7.17",
"@types/react-dom": "^16.0.11",
"@types/react-event-listener": "^0.4.7",
"@types/react-text-mask": "^5.4.2",
"@types/react-transition-group": "^2.0.15",
"classnames": "^2.2.6",
"codecov": "^3.1.0",
Expand Down
3 changes: 2 additions & 1 deletion lib/src/DatePicker/DatePickerInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import * as React from 'react';
import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import { ExtendWrapper } from '../wrappers/ExtendWrapper';
import InlineWrapper, { OuterInlineWrapperProps } from '../wrappers/InlineWrapper';
import Calendar from './components/Calendar';
import DatePicker, { BaseDatePickerProps } from './DatePicker';

export interface DatePickerInlineProps
extends Omit<BasePickerProps, 'ampm'>,
BaseDatePickerProps,
Omit<OuterInlineWrapperProps, 'onChange' | 'value'> {
ExtendWrapper<OuterInlineWrapperProps> {
onlyCalendar?: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/DatePicker/DatePickerModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';

import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import { ExtendWrapper } from '../wrappers/ExtendWrapper';
import ModalWrapper, { ModalWrapperProps } from '../wrappers/ModalWrapper';
import DatePicker, { BaseDatePickerProps } from './DatePicker';

export interface DatePickerModalProps
extends BasePickerProps,
BaseDatePickerProps,
Omit<ModalWrapperProps, 'onChange' | 'value'> {}
ExtendWrapper<ModalWrapperProps> {}

export const DatePickerModal: React.SFC<DatePickerModalProps> = props => {
const {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/DateTimePicker/DateTimePickerInline.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';

import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import { ExtendWrapper } from '../wrappers/ExtendWrapper';
import InlineWrapper, { OuterInlineWrapperProps } from '../wrappers/InlineWrapper';
import DateTimePicker, { BaseDateTimePickerProps } from './DateTimePicker';

export interface DateTimePickerInlineProps
extends BasePickerProps,
BaseDateTimePickerProps,
Omit<OuterInlineWrapperProps, 'onChange' | 'value'> {}
ExtendWrapper<OuterInlineWrapperProps> {}

export const DateTimePickerInline: React.SFC<DateTimePickerInlineProps> = props => {
const {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/DateTimePicker/DateTimePickerModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';

import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import { ExtendWrapper } from '../wrappers/ExtendWrapper';
import ModalWrapper, { ModalWrapperProps } from '../wrappers/ModalWrapper';
import DateTimePicker, { BaseDateTimePickerProps } from './DateTimePicker';

export interface DateTimePickerModalProps
extends BasePickerProps,
BaseDateTimePickerProps,
Omit<ModalWrapperProps, 'onChange' | 'value'> {}
ExtendWrapper<ModalWrapperProps> {}

export const DateTimePickerModal: React.SFC<DateTimePickerModalProps> = props => {
const {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/TimePicker/TimePickerInline.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';

import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import { ExtendWrapper } from '../wrappers/ExtendWrapper';
import InlineWrapper, { OuterInlineWrapperProps } from '../wrappers/InlineWrapper';
import TimePicker, { BaseTimePickerProps } from './TimePicker';

export interface TimePickerInlineProps
extends BasePickerProps,
BaseTimePickerProps,
Omit<OuterInlineWrapperProps, 'onChange' | 'value'> {}
ExtendWrapper<OuterInlineWrapperProps> {}

export const TimePickerInline: React.SFC<TimePickerInlineProps> = props => {
const { value, format, onChange, ampm, forwardedRef, seconds, ...other } = props;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/TimePicker/TimePickerModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as PropTypes from 'prop-types';
import * as React from 'react';

import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import { ExtendWrapper } from '../wrappers/ExtendWrapper';
import ModalWrapper, { ModalWrapperProps } from '../wrappers/ModalWrapper';
import TimePicker, { BaseTimePickerProps } from './TimePicker';

export interface TimePickerModalProps
extends BasePickerProps,
BaseTimePickerProps,
Omit<ModalWrapperProps, 'onChange' | 'value'> {}
ExtendWrapper<ModalWrapperProps> {}

export const TimePickerModal: React.SFC<TimePickerModalProps> = props => {
const { value, format, autoOk, onChange, ampm, forwardedRef, seconds, ...other } = props;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/__tests__/e2e/DatePicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IconButton, InputAdornment } from '@material-ui/core';
import { ReactWrapper } from 'enzyme';
import * as React from 'react';
import DatePickerModal from '../../DatePicker';
Expand Down Expand Up @@ -64,6 +65,16 @@ describe('e2e -- DatePicker keyboard input', () => {
mask={[/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/]}
value={'2018-01-01T00:00:00.000Z'}
onChange={onChangeMock}
InputAdornmentProps={{
disableTypography: true,
}}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton>date_range</IconButton>
</InputAdornment>
),
}}
/>
);
});
Expand Down
2 changes: 2 additions & 0 deletions lib/src/__tests__/wrappers/ModalWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('ModalWrapper', () => {
onDismiss={jest.fn()}
onAccept={jest.fn()}
onClear={jest.fn()}
onChange={jest.fn()}
format="mm dd"
>
<div>foo</div>
</ModalWrapper>
Expand Down
15 changes: 8 additions & 7 deletions lib/src/_shared/DateTextField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Icon from '@material-ui/core/Icon';
import IconButton from '@material-ui/core/IconButton';
import InputAdornment from '@material-ui/core/InputAdornment';
import InputAdornment, {
InputAdornmentProps as MuiInputAdornmentProps,
} from '@material-ui/core/InputAdornment';
import TextField, { BaseTextFieldProps, TextFieldProps } from '@material-ui/core/TextField';
import * as PropTypes from 'prop-types';
import * as React from 'react';
Expand Down Expand Up @@ -78,7 +80,7 @@ export interface DateTextFieldProps
ExtendMui<BaseTextFieldProps, 'onError' | 'onChange' | 'value'> {
// Properly extend different variants from mui textfield
variant?: TextFieldProps['variant'];
InputProps?: Partial<TextFieldProps>;
InputProps?: TextFieldProps['InputProps'];
inputProps?: TextFieldProps['inputMode'];
value: DateType;
minDate?: DateType;
Expand Down Expand Up @@ -118,9 +120,9 @@ export interface DateTextFieldProps
| React.ComponentType<TextFieldProps>
| React.ReactType<React.HTMLAttributes<any>>;
/** Props to pass to keyboard input adornment */
InputAdornmentProps?: object;
InputAdornmentProps?: Partial<MuiInputAdornmentProps>;
/** Specifies position of keyboard button adornment */
adornmentPosition?: 'start' | 'end';
adornmentPosition?: MuiInputAdornmentProps['position'];
onClick: (e: React.SyntheticEvent) => void;
/* Callback firing when date that applied in the keyboard is invalid **/
onError?: (newValue: MaterialUiPickersDate, error: React.ReactNode) => void;
Expand Down Expand Up @@ -194,7 +196,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
maxDateMessage: 'Date should not be after maximal date',
TextFieldComponent: TextField,
InputAdornmentProps: {},
adornmentPosition: 'end',
adornmentPosition: 'end' as MuiInputAdornmentProps['position'],
pipe: undefined,
keepCharPositions: false,
};
Expand Down Expand Up @@ -358,7 +360,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
localInputProps[`${adornmentPosition}Adornment`] = (
<InputAdornment position={adornmentPosition!} {...InputAdornmentProps}>
<IconButton disabled={disabled} onClick={this.openPicker}>
<Icon> {keyboardIcon} </Icon>
<Icon>{keyboardIcon}</Icon>
</IconButton>
</InputAdornment>
);
Expand Down Expand Up @@ -388,5 +390,4 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
}
}

// @ts-ignore ts requires to duplicate proptypes of textfield
export default withUtils()(DateTextField);
8 changes: 8 additions & 0 deletions lib/src/wrappers/ExtendWrapper.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Omit } from '@material-ui/core';
import { InlineWrapperProps } from './InlineWrapper';
import { ModalWrapperProps } from './ModalWrapper';

export type ExtendWrapper<T extends InlineWrapperProps | ModalWrapperProps> = Omit<
T,
'onChange' | 'value' | 'format'
>;
3 changes: 2 additions & 1 deletion lib/src/wrappers/InlineWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Omit } from '@material-ui/core';
import Popover, { PopoverProps as PopoverPropsType } from '@material-ui/core/Popover';
import withStyles, { WithStyles } from '@material-ui/core/styles/withStyles';
import keycode from 'keycode';
Expand All @@ -7,7 +8,7 @@ import EventListener from 'react-event-listener';
import DateTextField, { DateTextFieldProps } from '../_shared/DateTextField';
import DomainPropTypes from '../constants/prop-types';

export interface OuterInlineWrapperProps extends Partial<DateTextFieldProps> {
export interface OuterInlineWrapperProps extends Omit<DateTextFieldProps, 'utils' | 'onClick'> {
/** On open callback */
onOpen?: () => void;
/** On close callback */
Expand Down
2 changes: 1 addition & 1 deletion lib/src/wrappers/ModalWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DateTextField, { DateTextFieldProps } from '../_shared/DateTextField';
import ModalDialog from '../_shared/ModalDialog';
import DomainPropTypes from '../constants/prop-types';

export interface ModalWrapperProps extends Partial<DateTextFieldProps> {
export interface ModalWrapperProps extends Omit<DateTextFieldProps, 'utils' | 'onClick'> {
onAccept?: () => void;
onDismiss?: () => void;
onClear?: () => void;
Expand Down

0 comments on commit f55d990

Please sign in to comment.