Skip to content

Configuration

Global Styles

Global styles consist of a basic set of CSS rules designed to reset certain browser behaviors. Both CherryThemeProvider and ClientThemeProvider inject the Cherry global styles automatically. If your app ships its own global styles, pass $globalStyles={false} to ClientThemeProvider and render yours as a child instead. Outside the providers, include them manually:

tsx
import { ThemedGlobalStyles } from "cherry-styled-components";

ThemedGlobalStyles is a global-style component that reads the theme from the styled-components ThemeProvider, so render it inside one. Under Cherry's providers that theme's colors are CSS variables, so a mode switch repaints the global styles without rendering them again. This minimal wrapper renders them for one fixed theme with real values; unlike the real CherryThemeProvider, it skips the CSS variables, dark mode and the toggle context:

tsx
"use client";
import React from "react";
import { ThemeProvider as StyledThemeProvider } from "styled-components";
import { ThemedGlobalStyles, Theme } from "cherry-styled-components";

function ManualThemeProvider({
  children,
  theme,
}: {
  children: React.ReactNode;
  theme: Theme;
}) {
  return (
    <StyledThemeProvider theme={theme}>
      <ThemedGlobalStyles />
      {children}
    </StyledThemeProvider>
  );
}

export { ManualThemeProvider };

GlobalStyles(theme) is still exported. It takes a Theme and returns a new global-style component built with createGlobalStyle for that one theme. Call it once at module level, never during render or inside useMemo: in development, styled-components calls a React hook whenever a styled component is created, and React throws "Rendered fewer hooks than expected" when that happens inside another hook.

tsx
import { GlobalStyles, theme } from "cherry-styled-components";

const LightGlobalStyles = GlobalStyles(theme);

The Actual Global Styles

Adjust the global styles according to your project's requirements:

src/lib/utils/global.tsx
"use client";
import { createGlobalStyle, css } from "styled-components";
import { Theme } from "./theme";
import { linkColor } from "./mixins";

const globalStyles = (theme: Theme) => css`
html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  scroll-behavior: smooth;
  background-color: ${theme.colors.light};
}

body {
  font-family: "Inter", sans-serif;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

pre,
code,
kbd,
samp {
  font-family: monospace, monospace;
}

pre,
code,
kbd,
samp,
blockquote,
p,
a,
h1,
h2,
h3,
h4,
h5,
h6,
ul li,
ol li {
  margin: 0;
  padding: 0;
  color: ${theme.colors.dark};
}

a {
  color: ${linkColor(theme)};
}

ol,
ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

figure {
  margin: 0;
}

fieldset {
  appearance: none;
  border: none;
}

button,
input,
a,
img,
svg,
svg * {
  transition: all 0.3s ease;
}

strong,
b {
  font-weight: 700;
}

hr {
  margin: 20px 0;
  border: none;
  border-bottom: 1px solid ${theme.colors.grayLight};
}
`;

// One fixed theme. Call once at module level, never during render.
const GlobalStyles = (theme: Theme) => createGlobalStyle`
  ${globalStyles(theme)}
`;

// Reads the active theme from the ThemeProvider; what the providers render.
const ThemedGlobalStyles = createGlobalStyle`
  ${({ theme }) => globalStyles(theme as Theme)}
`;

export { GlobalStyles, ThemedGlobalStyles };