• Stars
    star
    5,291
  • Rank 7,804 (Top 0.2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build consistent, themeable React apps based on constraint-based design principles

Theme UI

The Design Graph Framework

ย 

GitHub GitHub Stars npm (latest) npm (develop)
Contributors
Size Tree Shaking MIT license Join our Discord community
This project is using Cypress for end-to-end tests. This project is using Percy.io for visual regression testing.


Theme UI is a library for creating themeable user interfaces based on constraint-based design principles. Build custom component libraries, design systems, web applications, Gatsby themes, and more with a flexible API for best-in-class developer ergonomics.

stable docs: https://theme-ui.com
develop (prerelease) docs: https://dev.theme-ui.com


Built for design systems, white-labels, themes, and other applications where customizing colors, typography, and layout are treated as first-class citizens and based on a standard Theme Specification, Theme UI is intended to work in a variety of applications, libraries, and other UI components. Colors, typography, and layout styles derived from customizable theme-based design scales help you build UI rooted in constraint-based design principles.

  • The next evolution of Styled System
  • From the creators of utility-based, atomic CSS methodologies
  • Theme-based styling with the sx prop
  • Compatible with virtually any UI component library
  • Works with existing Styled System components
  • Quick mobile-first responsive styles
  • Built-in support for dark modes
  • Primitive page layout components
  • Completely customizable with robust theming
  • Built with a standard Theme Specification for interoperability
  • Built with Emotion for scoped styles
  • Plugin for use in Gatsby sites and themes
  • Style MDX content with a simple, expressive API
  • Works with Typography.js themes

Getting Started

npm install theme-ui @emotion/react

If you don't need color modes or components you can install @theme-ui/core.

Any styles in your app can reference values from the global theme object. To provide the theme in context, wrap your application with the ThemeUIProvider component and pass in a custom theme object.

// basic usage
import { ThemeUIProvider } from 'theme-ui'
import theme from './theme'

export default (props) => (
  <ThemeUIProvider theme={theme}>{props.children}</ThemeUIProvider>
)

The theme object follows the System UI Theme Specification, which lets you define custom color palettes, typographic scales, fonts, and more. Read more about theming.

// example theme.js
export default {
  fonts: {
    body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif',
    heading: '"Avenir Next", sans-serif',
    monospace: 'Menlo, monospace',
  },
  colors: {
    text: '#000',
    background: '#fff',
    primary: '#33e',
  },
}

sx prop

The sx prop works similarly to Emotion's css prop, accepting style objects to add CSS directly to an element in JSX, but includes extra theme-aware functionality. Using the sx prop for styles means that certain properties can reference values defined in your theme object. This is intended to make keeping styles consistent throughout your app the easy thing to do.

The sx prop only works in modules that have defined a custom pragma at the top of the file, which replaces the default React JSX functions. This means you can control which modules in your application opt into this feature without the need for a Babel plugin or additional configuration.

/** @jsxImportSource theme-ui */

export default (props) => (
  <div
    sx={{
      fontWeight: 'bold',
      fontSize: 4, // picks up value from `theme.fontSizes[4]`
      color: 'primary', // picks up value from `theme.colors.primary`
    }}
  >
    Hello
  </div>
)

Read more about how the custom pragma works.

Responsive styles

The sx prop also supports using arrays as values to change properties responsively with a mobile-first approach. This API originated in Styled System and is intended as a terser syntax for applying responsive styles across a singular dimension.

/** @jsxImportSource theme-ui */

export default (props) => (
  <div
    sx={{
      // applies width 100% to all viewport widths,
      // width 50% above the first breakpoint,
      // and 25% above the next breakpoint
      width: ['100%', '50%', '25%'],
    }}
  />
)

Documentation

MIT License

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Brent Jackson

๐Ÿค” ๐Ÿ’ป ๐ŸŽจ ๐Ÿ“– ๐Ÿ’ก โš ๏ธ ๐Ÿ‘€

Piotr Monwid-Olechnowicz

๐Ÿ’ป ๐Ÿ“– โš ๏ธ ๐Ÿ‘€

Dany Castillo

๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก โš ๏ธ

Jordan Overbye

๐Ÿ’ป ๐Ÿ’ก โš ๏ธ

Lachlan Campbell

๐Ÿ’ป ๐Ÿ’ก โš ๏ธ ๐Ÿ‘€ ๐Ÿ“– ๐Ÿ’ฌ

John Otander

๐Ÿ’ป ๐Ÿ‘€ ๐Ÿ“– โš ๏ธ ๐Ÿค”

David Burles

๐Ÿ’ป ๐Ÿ‘€ โš ๏ธ ๐Ÿ“–

Max Stoiber

๐Ÿ’ป ๐Ÿ‘€ โš ๏ธ ๐Ÿ’ก

Atanas Stoyanov

๐Ÿ’ป ๐Ÿ’ฌ โš ๏ธ ๐Ÿ› ๐Ÿ“–

Lennart

๐Ÿ’ป ๐Ÿ› ๐Ÿ“– ๐Ÿ’ก

Aleksandra Sikora

๐Ÿ’ป

LB

๐Ÿ’ป โš ๏ธ

Francis Champagne

๐Ÿ’ป ๐Ÿ› โš ๏ธ ๐Ÿ“–

Alex Page

๐Ÿ’ป ๐Ÿ“–

Adam Schay

๐Ÿ’ป

Alex

๐Ÿ’ป ๐Ÿ“–

James Edmonds

๐Ÿ’ป ๐Ÿ“–

Florent SCHILDKNECHT

๐Ÿ’ป ๐Ÿ“–

Cole Bemis

๐Ÿ’ป โš ๏ธ ๐Ÿ“–

John Letey

๐Ÿ“–

Yuraima Estevez

๐Ÿ’ป

Allan Pope

๐Ÿ’ป ๐Ÿ“–

Emmanuel Pilande

๐Ÿ’ป

Justin Hall

๐Ÿ’ป

Marek

๐Ÿ’ป ๐Ÿ›

Bjรถrn Clees

๐Ÿ“– ๐Ÿ’ป

Iurii Kucherov

๐Ÿ“–

Joe Strouth

๐Ÿ’ป ๐Ÿ›

Stewart Everett

๐Ÿ’ป

Travis Arnold

๐Ÿ’ป ๐Ÿ“–

Ivo Reis

๐Ÿ’ป

Benedikt Rรถtsch

๐Ÿ› ๐Ÿ“–

Jacob Cofman

๐Ÿ“–

John Letey

๐Ÿ“–

Lawrence Gosset

๐Ÿ“–

Markos Konstantopoulos

๐Ÿ“–

Robin Millette

๐Ÿ’ป

Rodney Folz

๐Ÿ’ป

Rodrigo Pombo

๐Ÿ’ป โš ๏ธ ๐Ÿ“–

Scott Silvi

๐Ÿ“–

Shawn Allen

๐Ÿ“–

Tomas Carnecky

๐Ÿ’ป ๐Ÿ›

John Polacek

๐Ÿ’ป ๐Ÿ›

mackie

๐Ÿ’ป

Aaron Adams

๐Ÿ’ป ๐Ÿ› ๐Ÿ“–

Amberley

๐Ÿ’ป

Andreea Nฤƒstase

๐Ÿ“–

Anson Low Z.F

๐Ÿ› ๐Ÿ“–

Bernhard Gschwantner

๐Ÿ’ป

Bhanu Prakash Korthiwada

๐Ÿ“–

Bruno Lemos

๐Ÿ“–

Bryce Fischer

๐Ÿ’ป

Dan Wood

๐Ÿ“–

Debs

๐Ÿ“–

Edward O'Reilly

๐Ÿ’ป ๐Ÿ›

Eric Schaefer

๐Ÿ’ป

Felix Green

๐Ÿ“–

Gerhard Bliedung

๐Ÿ’ป ๐Ÿ›

Guayo Mena

๐Ÿ’ก

Guilherme Lima

๐Ÿ“–

Herb Caudill

๐Ÿ“–

Jacob Bolda

๐Ÿ’ป ๐Ÿ›

Jason Lengstorf

๐Ÿ› ๐Ÿ“–

Jason Rundell (he/him)

๐Ÿ’ก

Joe Race

๐Ÿ“–

Kanstantsin Klimashevich

๐Ÿ“–

Eka

๐Ÿ“– ๐Ÿ›

Keir Williams

๐Ÿ“–

Kristรณf Poduszlรณ

๐Ÿ’ป ๐Ÿ› ๐Ÿค”

Kyle Gill

๐Ÿ“–

Kyle Holmberg

๐Ÿ“–

Jay Laiche

๐Ÿ’ป

Marc Wiest

๐Ÿ’ป

Matheus Teixeira

๐Ÿ’ป

matt-cratebind

๐Ÿ“–

Matt Zabriskie

๐Ÿ’ป

Maxime Khoy

๐Ÿ’ป

Michael Friedman

๐Ÿ“–

Michael Zetterberg fd. Lopez

๐Ÿ’ป

Nathan Knowler

๐Ÿ’ป

Neeraj Lagwankar

๐Ÿ“–

Owen Young

๐Ÿ’ป

Patrick Arminio

๐Ÿ’ป ๐Ÿ›

Pedro Duarte

๐Ÿ’ป

Ray Clanan

๐Ÿ’ป

Rich Werden

๐Ÿ“–

Rob Phoenix

๐Ÿ“– ๐Ÿ›

Robert Moggach

๐Ÿ’ป ๐Ÿ›

Anand Narayan

๐Ÿ’ป ๐Ÿ›

Sam Poder

๐Ÿ“–

Sam Rose

๐Ÿ“–

Sohrab

๐Ÿ’ป

Spencer Rinehart

๐Ÿ’ป

Steve

๐Ÿ“–

Steve Barton

๐Ÿ“–

Tim Reynolds

๐Ÿ’ป ๐Ÿ›

Vinรญcius Lemes

๐Ÿ“–

Yihwan Kim

๐Ÿ’ป ๐Ÿ›

Yuriy Burychka

๐Ÿ“–

Zolwiastyl

๐Ÿ’ป

Amrish Kushwaha

๐Ÿ’ป

Joe Bell

๐Ÿ’ป ๐Ÿ›

kenny-loveholidays

๐Ÿ’ป

โฆ‡โฆ€โˆ™ห‡โˆŽห‡โˆ™โฆ€โฆˆ

๐Ÿ’ป ๐Ÿ›

navsgh

๐Ÿ“–

Shane O'Neill

๐Ÿ“–

ๆฑช็ฃŠ

๐Ÿ’ป ๐Ÿ›

Carolin Maisenbacher

๐Ÿ’ป ๐Ÿ“– โš ๏ธ

Alex Chan

๐Ÿ“– ๐Ÿ’ก โš ๏ธ ๐Ÿ’ป

Kenny

๐Ÿ’ป

Jordie Bodlay

๐Ÿ“–

Matt Gleich

๐Ÿ“–

William Pei

๐Ÿ“– ๐Ÿ’ก ๐Ÿ’ป โš ๏ธ

Greg Poole

๐Ÿ“–

Akash

๐Ÿ“– ๐Ÿ’ป

Cannon Lock

๐Ÿ“–

kamatte

๐Ÿ“– ๐Ÿ’ป

Simen A. W. Olsen

๐Ÿ“– ๐Ÿ’ก โš ๏ธ ๐Ÿ’ป

Wahid Rahim

๐Ÿ“– ๐Ÿ’ก ๐Ÿ’ป

Justin Cooper

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!