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

fix: make require props optional #737

Merged
merged 3 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/checkbox/NativeControl.tsx
Expand Up @@ -24,13 +24,13 @@ import * as React from 'react';
export interface NativeControlProps extends React.HTMLProps<HTMLInputElement>{
checked: boolean;
disabled: boolean;
id: string;
id?: string;
rippleActivatorRef: React.RefObject<HTMLInputElement>;
onChange: (evt: React.ChangeEvent<HTMLInputElement>) => void;
};

export class NativeControl extends React.Component<NativeControlProps, {}> {
static defaultProps: Partial<NativeControlProps> = {
static defaultProps = {
checked: false,
disabled: false,
onChange: () => {},
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/index.tsx
Expand Up @@ -62,7 +62,7 @@ export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
};
}

static defaultProps: Partial<CheckboxProps> = {
static defaultProps = {
checked: false,
className: '',
disabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/chips/Chip.tsx
Expand Up @@ -53,7 +53,7 @@ export class Chip extends React.Component<ChipProps, ChipState> {
chipElement: HTMLDivElement | null = null;
foundation?: MDCChipFoundation;

static defaultProps: Partial<ChipProps> = {
static defaultProps = {
id: '',
label: '',
className: '',
Expand Down
24 changes: 12 additions & 12 deletions packages/chips/ChipSet.tsx
Expand Up @@ -29,13 +29,13 @@ import {ChipProps} from './Chip'; // eslint-disable-line no-unused-vars
type ChipType = React.ReactElement<ChipProps>;

export interface ChipSetProps {
className: string;
selectedChipIds: string[];
handleSelect: (selectedChipIds: string[]) => void;
updateChips: (chips: Partial<ChipProps>[]) => void;
choice: boolean;
filter: boolean;
input: boolean;
className?: string;
selectedChipIds?: string[];
handleSelect?: (selectedChipIds: string[]) => void;
updateChips?: (chips: Partial<ChipProps>[]) => void;
choice?: boolean;
filter?: boolean;
input?: boolean;
children: ChipType | ChipType[];
};

Expand All @@ -50,13 +50,13 @@ export default class ChipSet extends React.Component<ChipSetProps, ChipSetState>
constructor(props: ChipSetProps) {
super(props);
this.state = {
selectedChipIds: props.selectedChipIds,
selectedChipIds: props.selectedChipIds!,
foundation: null,
hasInitialized: false,
};
}

static defaultProps: Partial<ChipSetProps> = {
static defaultProps = {
className: '',
selectedChipIds: [],
handleSelect: () => {},
Expand All @@ -78,7 +78,7 @@ export default class ChipSet extends React.Component<ChipSetProps, ChipSetState>
this.initChipSelection();
}
if (selectedChipIds !== prevProps.selectedChipIds) {
this.setState({selectedChipIds});
this.setState({selectedChipIds: selectedChipIds!});
}
}

Expand All @@ -101,7 +101,7 @@ export default class ChipSet extends React.Component<ChipSetProps, ChipSetState>
setSelected: () => {
const selectedChipIds = this.state.foundation.getSelectedChipIds().slice();
this.setState({selectedChipIds}, () => {
this.props.handleSelect(selectedChipIds);
this.props.handleSelect!(selectedChipIds);
});
},
removeChip: this.removeChip,
Expand Down Expand Up @@ -143,7 +143,7 @@ export default class ChipSet extends React.Component<ChipSetProps, ChipSetState>
}
}
const chipsArray = chips.length ? chips.map((chip) => chip.props) : [];
updateChips(chipsArray);
updateChips!(chipsArray);
};

setCheckmarkWidth = (checkmark: ChipCheckmark | null) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dialog/index.tsx
Expand Up @@ -94,7 +94,7 @@ class Dialog<T extends HTMLElement = HTMLElement> extends React.Component<
labelledBy?: string;
describedBy?: string;

static defaultProps: Partial<DialogProps<HTMLElement>> = {
static defaultProps = {
autoStackButtons: true,
className: '',
onOpening: () => {},
Expand Down
22 changes: 10 additions & 12 deletions packages/drawer/index.tsx
Expand Up @@ -40,15 +40,13 @@ import {FocusTrap} from 'focus-trap';
const {cssClasses: listCssClasses} = MDCListFoundation;

export interface DrawerProps extends React.HTMLProps<HTMLElement>{
className: string;
open: boolean;
onOpen: () => void;
onClose: () => void;
onTransitionEnd: React.TransitionEventHandler<HTMLElement>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed these since they are duplicates covered in HTMLProps.

onKeyDown: React.KeyboardEventHandler<HTMLElement>;
tag: string;
dismissible: boolean;
modal: boolean;
className?: string;
open?: boolean;
onOpen?: () => void;
onClose?: () => void;
tag?: string;
dismissible?: boolean;
modal?: boolean;
};

interface DrawerState {
Expand All @@ -63,7 +61,7 @@ class Drawer extends React.Component<DrawerProps, DrawerState> {

state: DrawerState = {classList: new Set()};

static defaultProps: Partial<DrawerProps> = {
static defaultProps = {
className: '',
children: null,
open: false,
Expand Down Expand Up @@ -184,13 +182,13 @@ class Drawer extends React.Component<DrawerProps, DrawerState> {
}

handleKeyDown = (evt: React.KeyboardEvent<HTMLElement>) => {
this.props.onKeyDown(evt);
this.props.onKeyDown!(evt);
if (!this.foundation) return;
this.foundation.handleKeydown(evt);
};

handleTransitionEnd = (evt: React.TransitionEvent<HTMLElement>) => {
this.props.onTransitionEnd(evt);
this.props.onTransitionEnd!(evt);
if (!this.foundation) return;
this.foundation.handleTransitionEnd(evt);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/floating-label/index.tsx
Expand Up @@ -42,7 +42,7 @@ export default class FloatingLabel extends React.Component<
foundation_?: MDCFloatingLabelFoundation;
labelElement_: React.RefObject<HTMLLabelElement> = React.createRef();

static defaultProps: Partial<FloatingLabelProps> = {
static defaultProps = {
className: '',
float: false,
};
Expand Down
18 changes: 9 additions & 9 deletions packages/linear-progress/index.tsx
Expand Up @@ -26,14 +26,14 @@ import * as React from 'react';
import {MDCLinearProgressFoundation} from '@material/linear-progress/dist/mdc.linearProgress';

export interface LinearProgressProps<T> extends React.HTMLProps<T> {
buffer: number;
bufferingDots: boolean;
className: string;
closed: boolean;
indeterminate: boolean;
progress: number;
reversed: boolean;
tag: string;
buffer?: number;
bufferingDots?: boolean;
className?: string;
closed?: boolean;
indeterminate?: boolean;
progress?: number;
reversed?: boolean;
tag?: string;
};

interface LinearProgressState {
Expand All @@ -57,7 +57,7 @@ class LinearProgress<T extends {} = HTMLDivElement> extends React.Component<
};
}

static defaultProps: LinearProgressProps<HTMLDivElement> = {
static defaultProps = {
buffer: 0,
bufferingDots: true,
className: '',
Expand Down
6 changes: 1 addition & 5 deletions packages/list/ListItem.tsx
Expand Up @@ -32,10 +32,6 @@ export interface ListItemProps<T> extends React.HTMLProps<T> {
shouldFocus: boolean;
shouldFollowHref: boolean;
shouldToggleCheckbox: boolean;
onKeyDown: React.KeyboardEventHandler<T>;
onClick: React.MouseEventHandler<T>;
onFocus: React.FocusEventHandler<T>;
onBlur: React.FocusEventHandler<T>;
tag: string;
children: React.ReactNode;
};
Expand All @@ -54,7 +50,7 @@ export default class ListItem<T extends {} = HTMLElement> extends React.Componen
> {
listItemElement_: React.RefObject<T> = React.createRef();

static defaultProps: Partial<ListItemProps<HTMLElement>> = {
static defaultProps = {
className: '',
classNamesFromList: [],
attributesFromList: {},
Expand Down
34 changes: 17 additions & 17 deletions packages/list/index.tsx
Expand Up @@ -36,16 +36,16 @@ const VERTICAL = 'vertical';
const CHECKBOX_TYPE = 'checkbox';

export interface ListProps<T> extends React.HTMLProps<HTMLElement> {
className: string;
nonInteractive: boolean;
dense: boolean;
avatarList: boolean;
twoLine: boolean;
singleSelection: boolean;
selectedIndex: number;
handleSelect: (selectedIndex: number) => void;
wrapFocus: boolean;
tag: string;
className?: string;
nonInteractive?: boolean;
dense?: boolean;
avatarList?: boolean;
twoLine?: boolean;
singleSelection?: boolean;
selectedIndex?: number;
handleSelect?: (selectedIndex: number) => void;
wrapFocus?: boolean;
tag?: string;
children: ListItem<T> | ListItem<T>[] | React.ReactNode;
};

Expand Down Expand Up @@ -90,7 +90,7 @@ export default class List<T extends HTMLElement = HTMLElement> extends React.Com
listItemChildrenTabIndex: {},
};

static defaultProps: Partial<ListProps<HTMLElement>> = {
static defaultProps = {
'className': '',
'nonInteractive': false,
'dense': false,
Expand Down Expand Up @@ -240,7 +240,7 @@ export default class List<T extends HTMLElement = HTMLElement> extends React.Com
e.key === 'Space' ||
e.keyCode === 32)
) {
this.props.handleSelect(index);
this.props.handleSelect!(index);
}
};

Expand All @@ -251,7 +251,7 @@ export default class List<T extends HTMLElement = HTMLElement> extends React.Com
// Work around until MDC Web issue is resolved:
// https://github.com/material-components/material-components-web/issues/4053
if (index >= 0) {
this.props.handleSelect(index);
this.props.handleSelect!(index);
}
};

Expand Down Expand Up @@ -320,19 +320,19 @@ export default class List<T extends HTMLElement = HTMLElement> extends React.Com
const props = {
...otherProps,
onKeyDown: (e: React.KeyboardEvent<T>) => {
onKeyDown(e);
onKeyDown!(e);
this.handleKeyDown(e, index);
},
onClick: (e: React.MouseEvent<T>) => {
onClick(e);
onClick!(e);
this.handleClick(e, index);
},
onFocus: (e: React.FocusEvent<T>) => {
onFocus(e);
onFocus!(e);
this.handleFocus(e, index);
},
onBlur: (e: React.FocusEvent<T>) => {
onBlur(e);
onBlur!(e);
this.handleBlur(e, index);
},
shouldFocus: focusListItemAtIndex === index,
Expand Down
2 changes: 1 addition & 1 deletion packages/material-icon/index.tsx
Expand Up @@ -55,7 +55,7 @@ export const RippleMaterialIcon = Ripple.withRipple<MaterialIconProps, HTMLEleme
export default class MaterialIcon extends React.Component<
MaterialIconProps, {}
> {
static defaultProps: Partial<MaterialIconProps> = {
static defaultProps = {
icon: '',
className: '',
hasRipple: false,
Expand Down
26 changes: 13 additions & 13 deletions packages/menu-surface/index.tsx
Expand Up @@ -26,26 +26,26 @@ import * as classnames from 'classnames';
import {MDCMenuSurfaceFoundation, MDCMenuSurfaceAdapter, Corner} from '@material/menu-surface/dist/mdc.menuSurface';

export interface MenuSurfaceProps extends React.HTMLProps<HTMLDivElement> {
className: string;
className?: string;
anchorElement?: HTMLElement;
anchorCorner: number;
anchorCorner?: number;
anchorMargin?: {
top?: number;
left?: number;
bottom?: number;
right?: number;
};
styles: React.CSSProperties;
styles?: React.CSSProperties;
coordinates?: {
x: number;
y: number;
};
onClose: () => void;
onOpen: () => void;
onKeyDown: (event: React.KeyboardEvent) => void;
quickOpen: boolean;
open: boolean;
fixed: boolean;
onClose?: () => void;
onOpen?: () => void;
onKeyDown?: (event: React.KeyboardEvent) => void;
quickOpen?: boolean;
open?: boolean;
fixed?: boolean;
};

export interface MenuSurfaceState {
Expand Down Expand Up @@ -85,7 +85,7 @@ class MenuSurface extends React.Component<MenuSurfaceProps, MenuSurfaceState> {
classList: new Set(),
};

static defaultProps: Partial<MenuSurfaceProps> = {
static defaultProps = {
className: '',
styles: {},
anchorCorner: 0,
Expand Down Expand Up @@ -289,13 +289,13 @@ class MenuSurface extends React.Component<MenuSurfaceProps, MenuSurfaceState> {
if (this.registerWindowClickListener) {
this.registerWindowClickListener();
}
this.props.onOpen();
this.props.onOpen!();
},
notifyClose: () => {
if (this.deregisterWindowClickListener) {
this.deregisterWindowClickListener();
}
this.props.onClose();
this.props.onClose!();
},
isElementInContainer: (el: HTMLElement) => {
if (!this.menuSurfaceElement.current) return false;
Expand Down Expand Up @@ -337,7 +337,7 @@ class MenuSurface extends React.Component<MenuSurfaceProps, MenuSurfaceState> {
};

handleKeydown = (evt: React.KeyboardEvent) => {
this.props.onKeyDown(evt);
this.props.onKeyDown!(evt);
this.foundation.handleKeydown(evt);
};

Expand Down
10 changes: 5 additions & 5 deletions packages/notched-outline/index.tsx
Expand Up @@ -25,10 +25,10 @@ import * as classnames from 'classnames';
import {MDCNotchedOutlineFoundation} from '@material/notched-outline/dist/mdc.notchedOutline';

export interface NotchedOutlineProps {
className: string,
isRtl: boolean,
notch: boolean,
notchWidth: number
className?: string,
isRtl?: boolean,
notch?: boolean,
notchWidth?: number
};

interface NotchedOutlineState {
Expand All @@ -44,7 +44,7 @@ export default class NotchedOutline extends React.Component<
pathElement_: React.RefObject<SVGPathElement> = React.createRef();
idleElement_: React.RefObject<HTMLDivElement> = React.createRef();

static defaultProps: Partial<NotchedOutlineProps> = {
static defaultProps = {
className: '',
isRtl: false,
notch: false,
Expand Down