Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing prop types #1761

Merged
merged 7 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"build/dist/material-ui-pickers.esm.js": {

"bundled": 189105,
"minified": 101411,
"gzipped": 26429,
Expand Down
9 changes: 9 additions & 0 deletions lib/src/DateRangePicker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { date } from '../constants/prop-types';
import { useUtils } from '../_shared/hooks/useUtils';
import { MobileWrapper } from '../wrappers/MobileWrapper';
import { DateRangeInputProps } from './DateRangePickerInput';
Expand Down Expand Up @@ -128,6 +130,13 @@ export function makeRangePicker<TWrapper extends SomeWrapper>(Wrapper: TWrapper)
);
}

RangePickerWithStateAndWrapper.propTypes = {
value: PropTypes.arrayOf(date).isRequired,
onChange: PropTypes.func.isRequired,
startText: PropTypes.node,
endText: PropTypes.node,
};

return React.forwardRef<
HTMLDivElement,
React.ComponentProps<typeof RangePickerWithStateAndWrapper>
Expand Down
3 changes: 3 additions & 0 deletions lib/src/DateRangePicker/DateRangePickerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RangeInput, DateRange } from './RangeTypes';
import { useUtils } from '../_shared/hooks/useUtils';
import { makeStyles } from '@material-ui/core/styles';
import { MaterialUiPickersDate } from '../typings/date';
import { inputPropTypes } from '../constants/prop-types';
import { CurrentlySelectingRangeEndProps } from './RangeTypes';
import { useMaskedInput } from '../_shared/hooks/useMaskedInput';
import { DateRangeValidationError } from '../_helpers/date-utils';
Expand Down Expand Up @@ -183,3 +184,5 @@ export const DateRangePickerInput: React.FC<DateRangeInputProps> = ({
</div>
);
};

DateRangePickerInput.propTypes = inputPropTypes;
Copy link
Member

@oliviertassinari oliviertassinari May 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the inputPropTypes import pruned from the bundle?
What do you think of duplicating the information in the propTypes (no imports)? This could be one step closer to how we automatically generate the prop types from the typescript definitions in the main repository.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.NODE_ENV !== "production" ? PureDateInput.propTypes = inputPropTypes : void 0;

From build code. Do you think we should duplicate it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking because, in the core, we are from time to time using prop-types helpers:

  • exactProp
  • chainPropTypes
  • elementAcceptingRef
  • elementTypeAcceptingRef
  • refType
  • deprecatedPropType
  • requiredPropFactory
  • unsupportedProp

It seems that none of the imports are pruned in people bundle (removing X.propTypes = Y not being enough). But to be confirmed.

6 changes: 6 additions & 0 deletions lib/src/DateRangePicker/DateRangePickerView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { isRangeValid } from '../_helpers/date-utils';
import { MaterialUiPickersDate } from '../typings/date';
import { BasePickerProps } from '../typings/BasePicker';
Expand Down Expand Up @@ -212,3 +213,8 @@ export const DateRangePickerView: React.FC<DateRangePickerViewProps> = ({
</div>
);
};

DateRangePickerView.propTypes = {
disableAutoMonthSwitching: PropTypes.bool,
calendars: PropTypes.oneOf([1, 2, 3]),
};
2 changes: 1 addition & 1 deletion lib/src/Picker/Picker.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import clsx from 'clsx';
import KeyboardDateInput from '../_shared/KeyboardDateInput';
import { useViews } from '../_shared/hooks/useViews';
import { makeStyles } from '@material-ui/core/styles';
import { DateTimePickerView } from '../DateTimePicker';
import { ParsableDate } from '../constants/prop-types';
import { BasePickerProps } from '../typings/BasePicker';
import { MaterialUiPickersDate } from '../typings/date';
import { DatePickerView } from '../DatePicker/DatePicker';
import { KeyboardDateInput } from '../_shared/KeyboardDateInput';
import { useIsLandscape } from '../_shared/hooks/useIsLandscape';
import { DIALOG_WIDTH, VIEW_HEIGHT } from '../constants/dimensions';
import { WrapperVariantContext } from '../wrappers/WrapperVariantContext';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/_shared/KeyboardDateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import InputAdornment from '@material-ui/core/InputAdornment';
import { useUtils } from './hooks/useUtils';
import { CalendarIcon } from './icons/CalendarIcon';
import { useMaskedInput } from './hooks/useMaskedInput';
import { inputPropTypes } from '../constants/prop-types';
import { DateInputProps, DateInputRefs } from './PureDateInput';
import { getTextFieldAriaText } from '../_helpers/text-field-helper';

Expand Down Expand Up @@ -50,4 +51,4 @@ export const KeyboardDateInput: React.FC<DateInputProps & DateInputRefs> = ({
});
};

export default KeyboardDateInput;
KeyboardDateInput.propTypes = inputPropTypes;
4 changes: 2 additions & 2 deletions lib/src/_shared/PureDateInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';
import { onSpaceOrEnter } from '../_helpers/utils';
import { ParsableDate } from '../constants/prop-types';
import { MaterialUiPickersDate } from '../typings/date';
import { TextFieldProps } from '@material-ui/core/TextField';
import { IconButtonProps } from '@material-ui/core/IconButton';
import { useUtils, MuiPickersAdapter } from './hooks/useUtils';
import { ParsableDate, inputPropTypes } from '../constants/prop-types';
import { InputAdornmentProps } from '@material-ui/core/InputAdornment';
import { getDisplayDate, getTextFieldAriaText } from '../_helpers/text-field-helper';

Expand Down Expand Up @@ -136,4 +136,4 @@ export const PureDateInput: React.FC<DateInputProps & DateInputRefs> = ({
});
};

PureDateInput.displayName = 'PureDateInput';
PureDateInput.propTypes = inputPropTypes;
12 changes: 11 additions & 1 deletion lib/src/constants/prop-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as PropTypes from 'prop-types';
import { MaterialUiPickersDate } from '../typings/date';

const date = PropTypes.oneOfType([
export const date = PropTypes.oneOfType([
PropTypes.object,
PropTypes.string,
PropTypes.number,
Expand All @@ -17,3 +17,13 @@ export const DomainPropTypes = { date, datePickerView };
export const defaultMinDate = new Date('1900-01-01');

export const defaultMaxDate = new Date('2100-01-01');

export const inputPropTypes = {
renderInput: PropTypes.func.isRequired,
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
mask: PropTypes.string,
rifmFormatter: PropTypes.func,
openPickerIcon: PropTypes.node,
OpenPickerButtonProps: PropTypes.object,
acceptRegex: PropTypes.instanceOf(RegExp),
getOpenDialogAriaText: PropTypes.func,
};
2 changes: 1 addition & 1 deletion lib/src/wrappers/DesktopWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import KeyboardDateInput from '../_shared/KeyboardDateInput';
import Popover, { PopoverProps } from '@material-ui/core/Popover';
import { WrapperProps } from './Wrapper';
import { StaticWrapperProps } from './StaticWrapper';
import { makeStyles } from '@material-ui/core/styles';
import { InnerMobileWrapperProps } from './MobileWrapper';
import { WrapperVariantContext } from './WrapperVariantContext';
import { IS_TOUCH_DEVICE_MEDIA } from '../constants/dimensions';
import { KeyboardDateInput } from '../_shared/KeyboardDateInput';
import { InnerDesktopPopperWrapperProps } from './DesktopPopperWrapper';

export interface InnerDesktopWrapperProps {
Expand Down