styled-components#ThemeProvider TypeScript Examples

The following examples show how to use styled-components#ThemeProvider. 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: utils.stories.tsx    From panvala with Apache License 2.0 7 votes vote down vote up
StoryWrapper = ({ children, proposals, slates, ballot }: any) => {
  return (
    <EthereumProvider>
      <MainContext.Provider
        value={{
          proposals: proposals || [],
          slates: slates || [],
          slatesByID: !!slates ? keyBy(slates, 'id') : {},
          proposalsByID: !!proposals ? keyBy(proposals, 'id') : {},
          currentBallot: ballot || currentBallot,
          onRefreshProposals: () => null,
          onRefreshSlates: () => null,
          onRefreshCurrentBallot: () => null,
        }}
      >
        <ThemeProvider theme={theme}>{children}</ThemeProvider>
      </MainContext.Provider>
    </EthereumProvider>
  );
}
Example #2
Source File: _app.tsx    From website with Apache License 2.0 7 votes vote down vote up
function MyApp({ Component, pageProps }: AppProps) {
  /* niceeeee */
  console.log(`
       __            __        __  __             ______    ______  
      /  |          /  |      /  |/  |           /      \  /      \ 
  ____$$ |  ______  $$ |____  $$ |$$/   ______  /$$$$$$  |/$$$$$$  |
 /    $$ | /      \ $$      \ $$ |/  | /      \ $$ |  $$ |$$ \__$$/ 
/$$$$$$$ | $$$$$$  |$$$$$$$  |$$ |$$ | $$$$$$  |$$ |  $$ |$$      \ 
$$ |  $$ | /    $$ |$$ |  $$ |$$ |$$ | /    $$ |$$ |  $$ | $$$$$$  |
$$ \__$$ |/$$$$$$$ |$$ |  $$ |$$ |$$ |/$$$$$$$ |$$ \__$$ |/  \__$$ |
$$    $$ |$$    $$ |$$ |  $$ |$$ |$$ |$$    $$ |$$    $$/ $$    $$/ 
 $$$$$$$/  $$$$$$$/ $$/   $$/ $$/ $$/  $$$$$$$/  $$$$$$/   $$$$$$/  
  `);

  const preferredTheme = usePreferredTheme();

  return (
    <StyledEngineProvider injectFirst>
      <SWRConfig
        value={{
          fetcher,
          refreshInterval: 12000000,
          revalidateOnFocus: false,
        }}
      >
        <ThemeProvider theme={preferredTheme === "dark" ? Theme : LightTheme}>
          <GlobalStyles />
          <Component {...pageProps} />
        </ThemeProvider>
      </SWRConfig>
    </StyledEngineProvider>
  );
}
Example #3
Source File: utils.tsx    From safe-apps-sdk with MIT License 7 votes vote down vote up
AllTheProviders: FC = ({ children }) => {
  return (
    <ThemeProvider theme={theme}>
      <SafeProvider
        loader={
          <>
            <Title size="md">Waiting for Safe...</Title>
          </>
        }
      >
        {children}
      </SafeProvider>
    </ThemeProvider>
  )
}
Example #4
Source File: _app.tsx    From 35d-blog with MIT License 6 votes vote down vote up
App = ({ Component, pageProps }) => {
  const router = useRouter()

  let defaultTheme
  if (process.browser) {
    defaultTheme = window.localStorage.getItem('35d_theme') || 'LIGHT'
  }
  const [theme, setTheme] = useState(defaultTheme)

  const toggleDarkMode = () => {
    if (process.browser) {
      window.localStorage.setItem('35d_theme', theme === 'LIGHT' ? 'DARK' : 'LIGHT')
    }
    theme === 'LIGHT' ? setTheme('DARK') : setTheme('LIGHT')
  }

  return (
    <ThemeProvider theme={theme === 'LIGHT' ? lightTheme : darkTheme}>
      <>
        <DarkModeContext.Provider value={{ theme, toggleDarkMode }}>
          <div className="w-full max-w-3xl mx-auto flex flex-wrap items-start overflow-hidden">
            <Navigation />
            <main className="w-full sm:w-3/4 ml-0 sm:ml-1/4 min-h-screen">
              <Breadcrumbs route={router.route} />
              <Component {...pageProps} className="w-full sm:w-3/4 sm:-mt-1 ml-0 sm:ml-1/4" />
            </main>
            <Footer />
          </div>
        </DarkModeContext.Provider>
      </>
    </ThemeProvider>
  )
}
Example #5
Source File: index.tsx    From react-doc-viewer with Apache License 2.0 6 votes vote down vote up
DocViewer: FC<DocViewerProps> = (props) => {
  const { documents, theme } = props;

  if (!documents || documents === undefined) {
    throw new Error(
      "Please provide an array of documents to DocViewer.\ne.g. <DocViewer documents={[ { uri: 'https://mypdf.pdf' } ]} />"
    );
  }

  return (
    <AppProvider {...props}>
      <ThemeProvider
        theme={theme ? { ...defaultTheme, ...theme } : defaultTheme}
      >
        <Container
          id="react-doc-viewer"
          data-testid="react-doc-viewer"
          {...props}
        >
          <HeaderBar />
          <ProxyRenderer />
        </Container>
      </ThemeProvider>
    </AppProvider>
  );
}
Example #6
Source File: App.tsx    From gobarber-mobile with MIT License 6 votes vote down vote up
App: React.FC = () => {
  return (
    <ThemeProvider theme={defaultTheme}>
      <NavigationContainer>
        <StatusBar barStyle="light-content" translucent />
        <AppProvider>
          <View style={{ backgroundColor: '#312e38', flex: 1 }}>
            <Routes />
          </View>
        </AppProvider>
      </NavigationContainer>
    </ThemeProvider>
  );
}
Example #7
Source File: index.tsx    From taskcafe with MIT License 6 votes vote down vote up
App = () => {
  const [user, setUser] = useState<string | null>(null);

  return (
    <>
      <UserContext.Provider value={{ user, setUser }}>
        <ThemeProvider theme={theme}>
          <NormalizeStyles />
          <BaseStyles />
          <BrowserRouter>
            <PopupProvider>
              <Routes />
            </PopupProvider>
          </BrowserRouter>
          <ToastedContainer
            position="bottom-right"
            autoClose={5000}
            hideProgressBar
            newestOnTop
            closeOnClick
            rtl={false}
            pauseOnFocusLoss
            draggable
            pauseOnHover
            limit={5}
          />
        </ThemeProvider>
      </UserContext.Provider>
    </>
  );
}
Example #8
Source File: Main.tsx    From SpaceEye with MIT License 6 votes vote down vote up
/**
 *
 */
function Main() {
    return (
        <HashRouter>
            <ThemeProvider theme={DarkTheme}>
                <MuiThemeProvider theme={theme}>
                    <div>
                        <Route exact path="/" component={ImagePickerPage} />
                        <Route path="/settings" component={Settings} />
                    </div>
                </MuiThemeProvider>
            </ThemeProvider>
        </HashRouter>
    )
}
Example #9
Source File: App.tsx    From GraphAV with MIT License 6 votes vote down vote up
App: React.FC<{}> = (): ReactElement => {
  const [globalTheme, setGlobalTheme] = useState<Theme>(themes.light);
  const [isTutorialVisible, setIsTutorialVisible] = useState<boolean>(
    (localStorage.getItem('isFirstTime') ?? 'true') === 'true'
  );

  const onTutorialExit = () => {
    setIsTutorialVisible(false);
    localStorage.setItem('isFirstTime', 'false');
  };

  const onTutorialOpen = () => {
    setIsTutorialVisible(true);
  };

  return (
    <ThemeProvider theme={globalTheme}>
      <Home onHelpClick={onTutorialOpen} changeTheme={setGlobalTheme}></Home>
      <Tutorial onExit={onTutorialExit} isVisible={isTutorialVisible} />
    </ThemeProvider>
  );
}
Example #10
Source File: App.tsx    From github-explorer with MIT License 6 votes vote down vote up
export default function App() {
  return (
    <>
      <ThemeProvider theme={theme}>
        <QueryClientProvider client={queryClient}>
          <Routes />
        </QueryClientProvider>
      </ThemeProvider>
      <GlobalStyles />
    </>
  );
}
Example #11
Source File: index.tsx    From react-memory-game with MIT License 6 votes vote down vote up
App: React.FC = () => {
  const themeType = useTypedSelector(({ Theme }) => Theme.type)
  const themeColors = THEME_COLORS[themeType || ThemeTypes.dark]

  return (
    <ThemeProvider theme={themeColors}>
      <GlobalStyles />
      <HashRouter basename={process.env.PUBLIC_URL}>
        <Switch>
          <Route exact path="/" component={DificultyChooser} />
          <Route exact path="/game" component={Game} />
        </Switch>
      </HashRouter>
    </ThemeProvider>
  )
}
Example #12
Source File: Announcement.test.cypress.tsx    From metaflow-ui with Apache License 2.0 6 votes vote down vote up
describe('Announcements test', () => {
  it('Announcements basic', () => {
    cy.viewport(1000, 600);
    // mock notifications fetching
    cy.intercept({ method: 'get', url: '**/notifications**' }, (req) => {
      req.reply({
        statusCode: 200,
        body: NotificationsResponse,
      });
    }).as('NotificationsMockData');

    mount(
      <ThemeProvider theme={theme}>
        <Router>
        <QueryParamProvider ReactRouterRoute={Route}>
          <Announcements />
        </QueryParamProvider>
        </Router>
      </ThemeProvider>
    );

    // test that the notifications are rendered correctly
    cy.get('[data-testid="announcements-container"]').children().should('have.length', 3);

    // test that notifications can be removed
    cy.get('[data-testid="announcements-container"]').children().eq(2)
      .then($elem => 
        cy.wrap($elem).find('.icon.icon-times').click()
      );
    cy.get('[data-testid="announcements-container"]').children().should('have.length', 2);
  });
});
Example #13
Source File: A.test.tsx    From panvala with Apache License 2.0 6 votes vote down vote up
describe('A', () => {
  test('loads and displays greeting', async () => {
    const utils = render(
      <ThemeProvider theme={theme}>
        <A>TEST ANCHOR</A>
      </ThemeProvider>
    );
    const testA = utils.getByText('TEST ANCHOR');
    expect(testA).toBeTruthy();
  });
});
Example #14
Source File: index.tsx    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
ReactDOM.render(
  <React.StrictMode>
    <NotificationsWithPortal />
    <ApolloProvider client={client}>
      <ThemeProvider theme={theme}>
        <App />
      </ThemeProvider>
    </ApolloProvider>
  </React.StrictMode>,
  document.getElementById("root")
);
Example #15
Source File: index.tsx    From safe-airdrop with MIT License 6 votes vote down vote up
ReactDOM.render(
  <React.StrictMode>
    <ThemeProvider theme={theme}>
      <GlobalStyle />
      <SafeProvider
        loader={
          <>
            <Title size="md">Waiting for Safe...</Title>
            <Loader size="md" />
          </>
        }
      >
        <MessageContextProvider>
          <App />
        </MessageContextProvider>
      </SafeProvider>
    </ThemeProvider>
  </React.StrictMode>,
  document.getElementById("root"),
);
Example #16
Source File: AppProvider.tsx    From Wern-Fullstack-Template with MIT License 6 votes vote down vote up
AppProvider: React.FC = ({ children }) => {
  const [themeMode, setThemeMode] = useState<string>('dark')
  const currentTheme = (theme as any)[themeMode]

  useEffect(() => {
    setThemeMode(localStorage.getItem('theme') || 'dark')
  }, [])

  useEffect(() => {
    localStorage.setItem('theme', themeMode)
  }, [themeMode])

  const toggleTheme = () => {
    setThemeMode((oldTheme) => {
      if (oldTheme === 'light') return 'dark'
      else return 'light'
    })
  }

  //  combine into one object for global ThemeContext state
  const value = useMemo(() => ({ themeMode, toggleTheme }), [themeMode])
  return (
    <ThemeContext.Provider value={value}>
      <ThemeProvider theme={currentTheme}>
        <GlobalStyles />
        {children}
      </ThemeProvider>
    </ThemeContext.Provider>
  )
}
Example #17
Source File: App.tsx    From covidex with MIT License 6 votes vote down vote up
App = () => {
  return (
    <ThemeProvider theme={Theme}>
      {/* Dynamically load metadata for HTML header */}
      <Helmet>
        <meta charSet="utf-8" />
        <title>{Configuration[METADATA]['title']}</title>
        <meta name="description" content={Configuration[METADATA]['description']} />
        <link rel="icon" href={`/${Configuration[METADATA]['favicon']}`} />
      </Helmet>
      <Router>
        <AppContainer>
          <Navbar />
          <Switch>
            <Route exact path={HOME_ROUTE}>
              <HomePage />
            </Route>
            <Route path={`${RELATED_ROUTE}/:articleId`}>
              <RelatedPage />
            </Route>
            <Route>
              <NotFoundPage />
            </Route>
          </Switch>
          <Footer />
        </AppContainer>
      </Router>
    </ThemeProvider>
  );
}
Example #18
Source File: App.tsx    From web-show with Apache License 2.0 6 votes vote down vote up
App: React.FC = () => {
    return (
        <ThemeProvider theme={theme}>
            <AppStyles className="App">
                <Banner />
                <BodyStyles className="body">
                    <Row>
                        <TrafficChartContainer title="Ping kube-system Pod" />
                    </Row>
                </BodyStyles>
            </AppStyles>
        </ThemeProvider>
    )
}
Example #19
Source File: CreateAccount.slow.spec.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
renderAccounts = () => {
  const memoryStore = new MemoryStore();

  return render(
    <MemoryRouter>
      <ThemeProvider theme={lightTheme}>
        <Api store={memoryStore}
          url={`ws://127.0.0.1:${SUBSTRATE_PORT}`}>
          <WaitForApi>
            <div>
              <AccountsApp basePath='/accounts'
                onStatusChange={() => { /* */
                }}/>
            </div>
          </WaitForApi>
        </Api>
      </ThemeProvider>
    </MemoryRouter>
  );
}
Example #20
Source File: App.tsx    From PolkaBridge-Farming with MIT License 6 votes vote down vote up
Providers: React.FC = ({ children }) => {
  return (
    <ThemeProvider theme={theme}>
      <UseWalletProvider
        chainId={config.chainId}
        connectors={{
          walletconnect: { rpcUrl: config.ankrEthereumRpc },
        }}
      >
        <PolkaBridgeProvider>
          <TransactionProvider>
            <FarmsProvider>
              <Router>
                <ModalsProvider>{children}</ModalsProvider>
              </Router>
            </FarmsProvider>
          </TransactionProvider>
        </PolkaBridgeProvider>
      </UseWalletProvider>
    </ThemeProvider>
  )
}
Example #21
Source File: App.tsx    From rocketredis with MIT License 6 votes vote down vote up
App = () => {
  return (
    <RecoilRoot>
      <ThemeProvider theme={defaultTheme}>
        <AppProvider>
          <Screen />
        </AppProvider>
        <GlobalStyle />
      </ThemeProvider>
    </RecoilRoot>
  )
}
Example #22
Source File: Ages.spec.tsx    From covid19map with MIT License 6 votes vote down vote up
describe('Age graph', () => {
  const wrapper = mount(
    <ThemeProvider theme={theme}>
      <Ages ages={data.ageRows} />
    </ThemeProvider>
  );
  it('displays an age graph', () => {
    setTimeout(() => {
      expect(wrapper.find('.recharts-bar-rectangle').length).toBeGreaterThan(0);
    }, 10);
  });
});
Example #23
Source File: AccordionGroup.tsx    From halstack-react with Apache License 2.0 6 votes vote down vote up
DxcAccordionGroup = ({
  defaultIndexActive,
  indexActive,
  disabled = false,
  onActiveChange,
  margin,
  children,
}: AccordionGroupPropsType): JSX.Element => {
  const colorsTheme = useTheme();
  const [innerIndexActive, setInnerIndexActive] = useState(defaultIndexActive ?? -1);
  const handlerActiveChange = useCallback(
    (index) => {
      indexActive ?? setInnerIndexActive((prev) => (index === prev ? -1 : index));
      !disabled && onActiveChange?.(index);
    },
    [disabled, indexActive, onActiveChange]
  );
  const contextValue = useMemo(
    () => ({ activeIndex: indexActive ?? innerIndexActive, handlerActiveChange, disabled }),
    [indexActive, innerIndexActive, handlerActiveChange, disabled]
  );

  return (
    <ThemeProvider theme={colorsTheme.accordion}>
      <AccordionGroupContainer margin={margin} disabled={disabled}>
        {(Array.isArray(children) ? children : [children])
          .filter((child) => child.type === AccordionGroupAccordion)
          .map((accordion, index) => (
            <AccordionGroupAccordionContext.Provider value={{ index, ...contextValue }}>
              {accordion}
            </AccordionGroupAccordionContext.Provider>
          ))}
      </AccordionGroupContainer>
    </ThemeProvider>
  );
}
Example #24
Source File: App.tsx    From react-weather-app with GNU General Public License v3.0 6 votes vote down vote up
App: React.FC = () => {
  const darkMode = useSelector((state: AppStore) => state.app.darkMode);
  return (
    <ThemeProvider theme={darkMode ? darkTheme : lightTheme}>
      <GlobalStyles />
      <Home />
    </ThemeProvider>
  );
}
Example #25
Source File: index.tsx    From safe-app-template with MIT License 6 votes vote down vote up
ReactDOM.render(
  <React.StrictMode>
    <ThemeProvider theme={theme}>
      <GlobalStyle />
      <SafeProvider loading={(
          <>
            <Title size="md">Waiting for Safe...</Title>
            <Loader size="md" />
          </>
        )}>
        <App />
      </SafeProvider>
    </ThemeProvider>
  </React.StrictMode>,
  document.getElementById("root")
);
Example #26
Source File: index.tsx    From multisig-react with MIT License 6 votes vote down vote up
Root = (): React.ReactElement => (
  <ThemeProvider theme={styledTheme}>
    <Provider store={store}>
      <MuiThemeProvider theme={theme}>
        <ConnectedRouter history={history}>
          <Sentry.ErrorBoundary fallback={GlobalErrorBoundary}>
            <App>{wrapInSuspense(<AppRoutes />, <Loader />)}</App>
          </Sentry.ErrorBoundary>
        </ConnectedRouter>
      </MuiThemeProvider>
    </Provider>
  </ThemeProvider>
)
Example #27
Source File: App.tsx    From vagasExplorer with MIT License 6 votes vote down vote up
App: React.FC = () => {
  const [theme, setTheme] = usePeristedState<DefaultTheme>('theme', light);

  const toggleTheme = () => {
    setTheme(theme.title === 'light' ? dark : light);
  };

  return (
    <ThemeProvider theme={theme}>
      <BrowserRouter>
        <Routes toggleTheme={toggleTheme} />
        <GlobalStyle />
      </BrowserRouter>
    </ThemeProvider>
  );
}
Example #28
Source File: Layout.tsx    From nyxo-website with MIT License 6 votes vote down vote up
Layout: FC<Props> = ({ children }) => {
  useEffect(() => {
    // generateAscii()
  }, [])

  return (
    <>
      <ThemeProvider theme={lightTheme}>
        <Header />
        <main>{children}</main>
        <footer>
          <Footer />
        </footer>
      </ThemeProvider>
    </>
  )
}
Example #29
Source File: App.tsx    From jobsgowhere with MIT License 6 votes vote down vote up
App: React.FC = function () {
  return (
    <Auth0Provider>
      <ProfileProvider>
        <PostProvider>
          <MobileViewProvider>
            <ThemeProvider theme={theme}>
              <GlobalStyle />
              <BrowserRouter>
                <Layout>
                  <Switch>
                    <Route exact path="/" component={JobsScreen} />
                    <Route path="/auth0/authorize" component={AuthorizeScreen} />
                    <Route path="/jobs" component={JobsScreen} />
                    <Route path="/talents" component={TalentsScreen} />
                    <Route path="/faq" component={FAQScreen} />
                    <Route path="/about" component={AboutUsScreen} />
                    <ProtectedRoute path="/posts/new" component={PostScreen} />
                    <ProtectedRoute path="/posts/edit" component={PostScreen} />
                    <ProtectedRoute path="/profile" component={ProfileScreen} />
                  </Switch>
                </Layout>
              </BrowserRouter>
            </ThemeProvider>
          </MobileViewProvider>
        </PostProvider>
      </ProfileProvider>
    </Auth0Provider>
  );
}