theme-ui#useColorMode TypeScript Examples

The following examples show how to use theme-ui#useColorMode. 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: ToggleMode.tsx    From use-comments with MIT License 6 votes vote down vote up
ToggleMode = () => {
  const [colorMode, setColorMode] = useColorMode();

  return (
    <div className="js-only" sx={{ display: 'flex' }}>
      <DarkModeSwitch
        onChange={() =>
          setColorMode(colorMode === 'default' ? 'dark' : 'default')
        }
        checked={colorMode !== 'default'}
        sunColor="currentColor"
        moonColor="currentColor"
        /** @ts-ignore */
        size="calc(1.25rem + 1px)"
        speed={2.5}
      />
      <noscript>
        <style
          dangerouslySetInnerHTML={{ __html: '.js-only { display: none }' }}
        />
      </noscript>
    </div>
  );
}
Example #2
Source File: header.tsx    From carlosazaustre.es with MIT License 5 votes vote down vote up
Header = () => {
  const { siteTitle } = useSiteMetadata()
  const { navigation: nav, externalLinks, basePath } = useMinimalBlogConfig()
  const [colorMode, setColorMode] = useColorMode()
  const isDark = colorMode === `dark`
  const toggleColorMode = (e: any) => {
    e.preventDefault()
    setColorMode(isDark ? `light` : `dark`)
  }

  return (
    <header sx={{ mb: [4, 5] }}>
      <Flex sx={{ alignItems: `center`, justifyContent: `space-between` }}>
        <Link
          to={replaceSlashes(`/${basePath}`)}
          aria-label={`${siteTitle} - Back to home`}
          sx={{ color: `heading`, textDecoration: `none` }}
        >
          <div sx={{ my: 0, fontWeight: `medium`, fontSize: [3, 4] }}>
              <img src={logo} width={32} alt={siteTitle} />&nbsp; 
              {siteTitle}
         </div>
        </Link>
        <ColorModeToggle isDark={isDark} toggle={toggleColorMode} />
      </Flex>
      <div
        sx={{
          boxSizing: `border-box`,
          display: `flex`,
          variant: `dividers.bottom`,
          alignItems: `center`,
          justifyContent: `space-between`,
          mt: 3,
          color: `secondary`,
          a: { color: `secondary`, ":hover": { color: `heading` } },
          flexFlow: `wrap`,
        }}
      >
        <Navigation nav={nav} />

        {externalLinks && externalLinks.length > 0 && (
          <div sx={{ "a:not(:first-of-type)": { ml: 3 }, fontSize: [1, `18px`] }}>
            {externalLinks.map(link => (
              <ExternalLink key={link.url} href={link.url} text={link.name} />
            ))}
          </div>
        )}
      </div>
    </header>
  )
}