No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:

  1. Missing Context/Providers: You can use decorators to supply specific contexts or providers, which are sometimes necessary for components to render correctly. For detailed instructions on using decorators, please visit the Decorators documentation.
  2. Misconfigured Webpack or Vite: Verify that Storybook picks up all necessary settings for loaders, plugins, and other relevant parameters. You can find step-by-step guides for configuring Webpack or Vite with Storybook.
  3. Missing Environment Variables: Your Storybook may require specific environment variables to function as intended. You can set up custom environment variables as outlined in the Environment Variables documentation.

ColorMode

Semantic color palette configuration

We've created several color modes by default for light and dark context.

Each color mode consists of a set of aliased color tokens. Each alias has semantic meaning for how the color is used throughout our design system:

  • text: The standard text color for all type.
  • background: The base background color.
  • primary: The color used for interactive elements with a primary action.
  • secondary: The color used for interactive elements with a secondary action.

Note: This set is not final and is likely to expand as our needs grow.

Gamut components are built using these aliases instead of referring to specific tokens directly, guaranteeing that:

  • Components can be used in ANY context without configuration and work correctly.
  • Consistent color scheme and accessibility between contexts.
  • Colors usage more meaningful when reading through code as aliases hint to usage.
  • Dead simple configuration.

Light mode

Prop
Path
Swatch
text
theme.colors.text
var(--color-navy-800)
text-accent
theme.colors['text-accent']
var(--color-navy-900)
text-disabled
theme.colors['text-disabled']
var(--color-navy-500)
text-secondary
theme.colors['text-secondary']
var(--color-navy-600)
feedback-error
theme.colors['feedback-error']
var(--color-red-600)
feedback-success
theme.colors['feedback-success']
var(--color-green-700)
feedback-warning
theme.colors['feedback-warning']
var(--color-yellow)
background
theme.colors.background
var(--color-white)
background-contrast
theme.colors['background-contrast']
var(--color-white)
background-current
theme.colors['background-current']
var(--color-white)
background-primary
theme.colors['background-primary']
var(--color-beige)
background-selected
theme.colors['background-selected']
var(--color-navy-100)
background-disabled
theme.colors['background-disabled']
var(--color-navy-200)
background-hover
theme.colors['background-hover']
var(--color-navy-200)
background-success
theme.colors['background-success']
var(--color-green-0)
background-warning
theme.colors['background-warning']
var(--color-yellow-0)
background-error
theme.colors['background-error']
var(--color-red-0)
shadow-primary
theme.colors['shadow-primary']
var(--color-navy-800)
shadow-secondary
theme.colors['shadow-secondary']
var(--color-navy-600)
primary
theme.colors.primary
var(--color-hyper-500)
primary-hover
theme.colors['primary-hover']
var(--color-hyper-400)
primary-inverse
theme.colors['primary-inverse']
var(--color-yellow-500)
secondary
theme.colors.secondary
var(--color-navy-800)
secondary-hover
theme.colors['secondary-hover']
var(--color-navy-700)
danger
theme.colors.danger
var(--color-red-500)
danger-hover
theme.colors['danger-hover']
var(--color-red-600)
interface
theme.colors.interface
var(--color-hyper-500)
interface-hover
theme.colors['interface-hover']
var(--color-hyper-400)
border-primary
theme.colors['border-primary']
var(--color-navy-800)
border-secondary
theme.colors['border-secondary']
var(--color-navy-600)
border-tertiary
theme.colors['border-tertiary']
var(--color-navy-300)
border-disabled
theme.colors['border-disabled']
var(--color-navy-500)

Dark mode

Prop
Path
Swatch
text
theme.colors.text
var(--color-white)
text-accent
theme.colors['text-accent']
var(--color-beige)
text-disabled
theme.colors['text-disabled']
var(--color-white-500)
text-secondary
theme.colors['text-secondary']
var(--color-white-600)
feedback-error
theme.colors['feedback-error']
var(--color-red-300)
feedback-success
theme.colors['feedback-success']
var(--color-green-400)
feedback-warning
theme.colors['feedback-warning']
var(--color-yellow-0)
background
theme.colors.background
var(--color-navy-800)
background-contrast
theme.colors['background-contrast']
var(--color-black)
background-current
theme.colors['background-current']
var(--color-navy-800)
background-primary
theme.colors['background-primary']
var(--color-navy-900)
background-selected
theme.colors['background-selected']
var(--color-white-100)
background-disabled
theme.colors['background-disabled']
var(--color-white-200)
background-hover
theme.colors['background-hover']
var(--color-white-200)
background-success
theme.colors['background-success']
var(--color-green-900)
background-warning
theme.colors['background-warning']
var(--color-yellow-900)
background-error
theme.colors['background-error']
var(--color-red-900)
shadow-primary
theme.colors['shadow-primary']
var(--color-white)
shadow-secondary
theme.colors['shadow-secondary']
var(--color-white-600)
primary
theme.colors.primary
var(--color-yellow-500)
primary-hover
theme.colors['primary-hover']
var(--color-yellow-400)
primary-inverse
theme.colors['primary-inverse']
var(--color-hyper-500)
secondary
theme.colors.secondary
var(--color-white)
secondary-hover
theme.colors['secondary-hover']
var(--color-white-700)
danger
theme.colors.danger
var(--color-red-300)
danger-hover
theme.colors['danger-hover']
var(--color-red-400)
interface
theme.colors.interface
var(--color-yellow-500)
interface-hover
theme.colors['interface-hover']
var(--color-yellow-400)
border-primary
theme.colors['border-primary']
var(--color-white)
border-secondary
theme.colors['border-secondary']
var(--color-white-600)
border-tertiary
theme.colors['border-tertiary']
var(--color-white-300)
border-disabled
theme.colors['border-disabled']
var(--color-white-500)

<ColorMode />

Here's an example using components in context. By toggling dark mode you can see all the colors map to a new color that is accessible for the mode by default.

Light Mode

Cool Feature

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

i am a large label, but something is wrong. (optional)
this is still not updog...
ah yes, a radio group (optional)
you can't type here. (optional)
a humble checkbox (optional)

Usage

import { ColorMode } from '@codecademy/gamut-styles'; const Page = ({ children }) => ( <ColorMode mode="light">{children}</ColorMode>; );

system Color Mode

You can also provide ColorMode with mode="system" and it will automatically set the color mode based on the users preference.

system color mode: light mode

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Usage

import { ColorMode } from '@codecademy/gamut-styles'; const Page = ({ children }) => ( <ColorMode mode="system">{children}</ColorMode>; );

<Background />

There are many cases where you may need a specific background color for a section of a page, like a card or a landing page. Instead of having to guess the right mode for the background, we've added a <Background /> component to detect if contrast of the background and current mode's text color meet an accessible standard. If not, we will automatically change the mode to an accessible one, allowing you to be sure that all components inside your background will meet contrast requirements and designs without any configuration!

Current background

When you use Background the selected background color is set to a theme variable background-current. This is useful to reference when you need access to an ancestors background color (e.g. simulating transparency + masking content).

Usage

import { Background } from '@codecademy/gamut-styles'; const Page = ({ children }) => ( <Background bg="hyper">{children}</Background>; );

useCurrentMode | useColorMode

For situations where you need to access the current mode in JS, the value of always present on the emotion theme context. If you need the full theme you may use the built in useTheme hook from @emotion/react. However for cases that are specific to modes only we expose 2 hooks to help.

  • useColorMode(): If you need access to all modes and their variables this hook will return a tuple of [mode, modeColors, modes].
  • useCurrentMode(): For simpler usages where you want to get the default mode, this hook returns the key of the active mode.
import { useColorMode, useCurrentMode } from '@codecademy/gamut-styles'; const [current, currentColors, modes] = useColorMode(); const current = useCurrentMode();

Examples

Sometimes you may just want to wrap a page in a different background color than the base color mode.

hyper

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

beige

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

In some cases you may want to use multiple areas with different backgrounds. <Background /> makes this a simple task by provisioning a new color context for all components inside.

black

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

paleGreen

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

navy-900

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

white-500

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

green

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

white-500

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

usePrefersDarkMode

If you want to check which color mode the user prefers, you can use usePrefersDarkMode and it will return a boolean value using window.matchMedia('(prefers-color-scheme: dark)') media query.

user prefers dark mode: false

Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore et dolore . Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.