Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
### Dependency upgrades

### Code quality

- Improve `withAppProvider`, `withSticky`, `withRef`, and `withContext` types to allow them to infer a components props ([#805](https://github.com/Shopify/polaris-react/pull/805))
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export interface WithAppProviderProps {
};
}

export default function withAppProvider<OwnProps>() {
return function addProvider<C>(
export default function withAppProvider() {
return function addProvider<OriginalProps, C>(
Copy link
Contributor

Choose a reason for hiding this comment

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

C is Context in this case correct?

Copy link
Member Author

@AndrewMusgrave AndrewMusgrave Jan 3, 2019

Choose a reason for hiding this comment

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

I believe it's for inferring the typeof component. So for example

withSticky()(Scrollable);

will infer React.ComponentClass<Props, React.ComponentState> & typeof Scrollable. typeof Scrollable will be inferred from & C

WrappedComponent:
| React.ComponentClass<OwnProps & WithAppProviderProps> & C
| React.SFC<OwnProps & WithAppProviderProps> & C,
): React.ComponentClass<OwnProps> & C {
class WithProvider extends React.Component<OwnProps, never> {
| React.ComponentClass<OriginalProps & WithAppProviderProps> & C
| React.SFC<OriginalProps & WithAppProviderProps> & C,
): React.ComponentClass<OriginalProps> & C {
class WithProvider extends React.Component<OriginalProps, never> {
static contextTypes = WrappedComponent.contextTypes
? merge(WrappedComponent.contextTypes, polarisAppProviderContextTypes)
: polarisAppProviderContextTypes;
Expand Down Expand Up @@ -90,6 +90,6 @@ export default function withAppProvider<OwnProps>() {
WrappedComponent as React.ComponentClass<any>,
);

return FinalComponent as React.ComponentClass<OwnProps> & C;
return FinalComponent as React.ComponentClass<OriginalProps> & C;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function withSticky() {
WrappedComponent:
| React.ComponentClass<OwnProps & WithAppProviderProps> & C
| React.SFC<OwnProps & WithAppProviderProps> & C,
): any & C {
): React.ComponentClass<OwnProps> & C {
// eslint-disable-next-line shopify/react-initialize-state
class WithStickyManager extends React.Component<
{},
Expand Down Expand Up @@ -50,6 +50,6 @@ export default function withSticky() {
WithStickyManager,
WrappedComponent as React.ComponentClass<any>,
);
return FinalComponent as React.ComponentClass<any> & C;
return FinalComponent as React.ComponentClass<OwnProps> & C;
};
}
2 changes: 1 addition & 1 deletion src/components/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ export class Autocomplete extends React.PureComponent<CombinedProps, never> {
}
}

export default withAppProvider<Props>()(Autocomplete);
export default withAppProvider()(Autocomplete);
2 changes: 1 addition & 1 deletion src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@ function customerPlaceholder(name?: string) {
: AVATAR_IMAGES[0];
}

export default withAppProvider<Props>()(Avatar);
export default withAppProvider()(Avatar);
2 changes: 1 addition & 1 deletion src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ function Badge({
);
}

export default withAppProvider<Props>()(Badge);
export default withAppProvider()(Badge);
2 changes: 1 addition & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ function isIconSource(x: any): x is IconSource {
return typeof x === 'string' || (typeof x === 'object' && x.body);
}

export default withAppProvider<Props>()(Button);
export default withAppProvider()(Button);
2 changes: 1 addition & 1 deletion src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ function Checkbox({
);
}

export default withAppProvider<Props>()(Checkbox);
export default withAppProvider()(Checkbox);
2 changes: 1 addition & 1 deletion src/components/ChoiceList/ChoiceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ function updateSelectedChoices(
return selected.filter((selectedChoice) => selectedChoice !== value);
}

export default withAppProvider<Props>()(ChoiceList);
export default withAppProvider()(ChoiceList);
2 changes: 1 addition & 1 deletion src/components/Collapsible/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,4 @@ function collapsibleHeight(
return `${height || 0}px`;
}

export default withAppProvider<Props>()(Collapsible);
export default withAppProvider()(Collapsible);
2 changes: 1 addition & 1 deletion src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,4 @@ export class DataTable extends React.PureComponent<
}
}

export default withAppProvider<Props>()(DataTable);
export default withAppProvider()(DataTable);
2 changes: 1 addition & 1 deletion src/components/DataTable/components/Cell/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ function Cell({
return cellMarkup;
}

export default withAppProvider<Props>()(Cell);
export default withAppProvider()(Cell);
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ function Navigation({
);
}

export default withAppProvider<Props>()(Navigation);
export default withAppProvider()(Navigation);
2 changes: 1 addition & 1 deletion src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,4 @@ function deriveRange(selected?: Date | Range) {
return selected instanceof Date ? {start: selected, end: selected} : selected;
}

export default withAppProvider<Props>()(DatePicker);
export default withAppProvider()(DatePicker);
2 changes: 1 addition & 1 deletion src/components/DatePicker/components/Day/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ export class Day extends React.PureComponent<CombinedProps, never> {
}
}

export default withAppProvider<Props>()(Day);
export default withAppProvider()(Day);
2 changes: 1 addition & 1 deletion src/components/DropZone/DropZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,4 @@ function handleDragStart(event: React.DragEvent<HTMLDivElement>) {
event.stopPropagation();
}

export default withAppProvider<Props>()(DropZone);
export default withAppProvider()(DropZone);
6 changes: 3 additions & 3 deletions src/components/DropZone/components/FileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class FileUpload extends React.Component<CombinedProps, State> {
}

export default compose<Props>(
withContext<Props, WithAppProviderProps, DropZoneContext>(Consumer),
withAppProvider<Props>(),
withRef<Props>(),
withContext<DropZoneContext>(Consumer),
withAppProvider(),
withRef(),
)(FileUpload);
2 changes: 1 addition & 1 deletion src/components/EmptySearchResult/EmptySearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export class EmptySearchResult extends React.PureComponent<
}
}

export default withAppProvider<Props>()(EmptySearchResult);
export default withAppProvider()(EmptySearchResult);
2 changes: 1 addition & 1 deletion src/components/Frame/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,4 @@ function isMobileView() {
return navigationBarCollapsed().matches;
}

export default withAppProvider<Props>()(Frame);
export default withAppProvider()(Frame);
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ class ContextualSaveBar extends React.PureComponent<CombinedProps, State> {
}
}

export default withAppProvider<Props>()(ContextualSaveBar);
export default withAppProvider()(ContextualSaveBar);
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ function DiscardConfirmationModal({
);
}

export default withAppProvider<Props>()(DiscardConfirmationModal);
export default withAppProvider()(DiscardConfirmationModal);
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@ function isBundledIcon(key: string | BundledIcon): key is BundledIcon {
return Object.keys(BUNDLED_ICONS).includes(key);
}

export default withAppProvider<Props>()(Icon);
export default withAppProvider()(Icon);
2 changes: 1 addition & 1 deletion src/components/Loading/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export class Loading extends React.PureComponent<ComposedProps, never> {
}
}

export default withAppProvider<Props>()(Loading);
export default withAppProvider()(Loading);
2 changes: 1 addition & 1 deletion src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ function isIframeModal(
);
}

export default withAppProvider<Props>()(Modal);
export default withAppProvider()(Modal);
2 changes: 1 addition & 1 deletion src/components/Navigation/components/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,6 @@ function matchStateForItem(
return matchesUrl ? MatchState.MatchUrl : MatchState.NoMatch;
}

export const Item = withAppProvider<Props>()(BaseItem);
export const Item = withAppProvider()(BaseItem);

export default Item;
2 changes: 1 addition & 1 deletion src/components/OptionList/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,4 @@ function testSectionsPropEquality(
return optionsAreEqual && titlesAreEqual;
}

export default withAppProvider<Props>()(OptionList);
export default withAppProvider()(OptionList);
Loading