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

[MediaQueryProvider] Add media query provider #2117

Merged
merged 2 commits into from
Sep 24, 2019

Conversation

AndrewMusgrave
Copy link
Member

@AndrewMusgrave AndrewMusgrave commented Sep 10, 2019

WHY are these changes introduced?

Reduce duplicated logic and add a location where we can easily add to it

WHAT is this pull request doing?

  • Create MediaQueryProvider, hooks, and context
  • Add it to AppProvider, withAppProvider, PolarisTestProvider
  • Add tests
  • Replace all occurrences of navigationBarCollapsed() with useMediaQuery or mediaQuery

How to 🎩

You'll want to check Filters, Frame, Navigation, Page and Sheet in the deployment across screen sizes to ensure navigation collapsed is still working correctly.

🎩 checklist

@AndrewMusgrave AndrewMusgrave force-pushed the add-media-query-provider branch 2 times, most recently from 9ad816a to 821f784 Compare September 11, 2019 21:48
@AndrewMusgrave AndrewMusgrave changed the title [WIP] Add media query provider [MediaQueryProvider] Add media query provider Sep 11, 2019
import {LinkContext} from '../../../utilities/link';
import {AppProvider} from '../AppProvider';

describe('<AppProvider />', () => {
beforeEach(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

AppProvider renders MediaQueryProvider now which uses matchMedia and since jsdom doesn't provide it, we'll need it mock it.

const navigation = <div />;
const frame = mountWithAppProvider(
<Frame showMobileNavigation navigation={navigation} />,
{mediaQuery: {isNavigationCollapsed: true}},
Copy link
Member Author

Choose a reason for hiding this comment

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

This passes the value to PolarisTestProvider which passes it to MediaQueryContext.Provider to mock isNavigationCollapsed

children?: React.ReactNode;
}

export const MediaQueryProvider = function MediaQueryProvider({
Copy link
Member Author

Choose a reason for hiding this comment

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

We check the breakpoint, when the state is initialized, after the first render and during resize.

interface State {
mobileView?: boolean;
}
export function Header({
Copy link
Member Author

Choose a reason for hiding this comment

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

After removing the breakpoint logic I was able to convert Header into a functional component 😄

Copy link
Contributor

@dleroux dleroux left a comment

Choose a reason for hiding this comment

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

🎉 😅

codecov so close!

@AndrewMusgrave AndrewMusgrave force-pushed the add-media-query-provider branch from a5807d2 to d8c0d1c Compare September 24, 2019 17:02
@AndrewMusgrave AndrewMusgrave merged commit b16c134 into master Sep 24, 2019
@AndrewMusgrave AndrewMusgrave deleted the add-media-query-provider branch September 24, 2019 17:29
@dleroux dleroux temporarily deployed to production October 3, 2019 13:16 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants