@material-ui/styles#StylesProvider TypeScript Examples

The following examples show how to use @material-ui/styles#StylesProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.tsx    From master-frontend-lemoncode with MIT License 6 votes vote down vote up
App: React.FunctionComponent = () => {
  return (
    <StylesProvider injectFirst>
      <ThemeProviderComponent>
        <AuthProvider>
          <SnackbarProvider>
            <SpinnerComponent />
            <RouterComponent />
            <SnackbarComponent />
          </SnackbarProvider>
        </AuthProvider>
      </ThemeProviderComponent>
    </StylesProvider>
  );
}
Example #2
Source File: theme-provider.component.tsx    From master-frontend-lemoncode with MIT License 6 votes vote down vote up
ThemeProviderComponent = (props) => {
  const { children } = props;

  return (
    <StylesProvider injectFirst>
      <ThemeProvider theme={theme}>
        <CssBaseline />
        {children}
      </ThemeProvider>
    </StylesProvider>
  );
}
Example #3
Source File: _app.tsx    From Teyvat.moe with GNU General Public License v3.0 6 votes vote down vote up
_app: FunctionComponent<AppProps> = ({ Component, pageProps }) => {
  // TODO: Remove server-side JSS styles.
  // Normally you'd call 'useEffect' to call jssStyles.parentElement.removeChild(jssStyles);
  // However, I was experiencing an unknown bug where the old class names weren't being replaced
  // with the new ones, so I just got rid of the call so that the old class names would work.

  return (
    <>
      {/* StoreProvider allows hooks and components to access the Redux store. */}
      <StoreProvider store={store}>
        {/* ThemeProvider allows for child components to access the Material UI theme. */}
        <ThemeProvider theme={Theme}>
          {/* CSSBaseline injects a basic cascading style sheet for use by Material UI styling. */}
          <CssBaseline />
          {/* NotificationProvider handles the Notistack.
              Must be a child of StoreProvider since Redux handles notifications. */}
          <StylesProvider generateClassName={generateClassName}>
            <NotificationProvider>
              {/* ErrorHandler provides a fallback interface to use if the web page crashes. */}
              <ErrorHandler errorHandler={FullPageErrorHandler}>
                {/* Component provides the actual map content. */}
                <Component {...pageProps} />
              </ErrorHandler>
            </NotificationProvider>
          </StylesProvider>
        </ThemeProvider>
      </StoreProvider>
    </>
  );
}
Example #4
Source File: Root.tsx    From office-booker with MIT License 6 votes vote down vote up
Root: React.FC = () => (
  <StylesProvider injectFirst>
    <StyledThemeProvider theme={MaterialTheme}>
      <MaterialThemeProvider theme={MaterialTheme}>
        <CssBaseline />
        <StyledGlobal />

        <MuiPickersUtilsProvider utils={DateFnsUtils}>
          <ErrorBoundary>
            <AppProvider>
              <Structure>
                <Routes />
              </Structure>
            </AppProvider>
          </ErrorBoundary>
        </MuiPickersUtilsProvider>
      </MaterialThemeProvider>
    </StyledThemeProvider>
  </StylesProvider>
)
Example #5
Source File: TestContext.tsx    From office-booker with MIT License 6 votes vote down vote up
TestContext: React.FC<{ user?: User; config?: Config }> = ({
  children,
  user,
  config,
}) => (
  <StylesProvider injectFirst>
    <StyledThemeProvider theme={MaterialTheme}>
      <MaterialThemeProvider theme={MaterialTheme}>
        <MuiPickersUtilsProvider utils={DateFnsUtils}>
          <AppProvider initialState={{ user, config }}>
            <Structure>{children}</Structure>
          </AppProvider>
        </MuiPickersUtilsProvider>
      </MaterialThemeProvider>
    </StyledThemeProvider>
  </StylesProvider>
)
Example #6
Source File: component.tsx    From backstage with Apache License 2.0 5 votes vote down vote up
TechDocsShadowDom = ({
  element,
  onAppend,
  children,
}: TechDocsShadowDomProps) => {
  const [jss, setJss] = useState(
    create({
      ...jssPreset(),
      insertionPoint: undefined,
    }),
  );

  useShadowDomStylesEvents(element);
  const loading = useShadowDomStylesLoading(element);

  const ref = useCallback(
    (shadowHost: HTMLDivElement) => {
      if (!element || !shadowHost) return;

      setJss(
        create({
          ...jssPreset(),
          insertionPoint: element.querySelector('head') || undefined,
        }),
      );

      let shadowRoot = shadowHost.shadowRoot;

      if (!shadowRoot) {
        shadowRoot = shadowHost.attachShadow({ mode: 'open' });
      }

      shadowRoot.replaceChildren(element);

      if (typeof onAppend === 'function') {
        onAppend(shadowRoot);
      }
    },
    [element, onAppend],
  );

  return (
    <>
      {loading && <Progress />}
      {/* The sheetsManager={new Map()} is needed in order to deduplicate the injection of CSS in the page. */}
      <StylesProvider jss={jss} sheetsManager={new Map()}>
        <div ref={ref} data-testid="techdocs-native-shadowroot" />
        {children}
      </StylesProvider>
    </>
  );
}
Example #7
Source File: test.tsx    From baleen3 with Apache License 2.0 5 votes vote down vote up
LightTheme: React.FC<{ readonly children?: React.ReactNode }> = ({
  children,
}) => (
  <StylesProvider generateClassName={generateClassName}>
    <ThemeProvider choice="light">{children}</ThemeProvider>
  </StylesProvider>
)
Example #8
Source File: test.tsx    From baleen3 with Apache License 2.0 5 votes vote down vote up
DarkTheme: React.FC<{ readonly children?: React.ReactNode }> = ({
  children,
}) => (
  <StylesProvider generateClassName={generateClassName}>
    <ThemeProvider choice="dark">{children}</ThemeProvider>
  </StylesProvider>
)