Giter Club home page Giter Club logo

theme-ui's Introduction

Theme UI logo Theme UI logo

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

📖

CJ

📖 💻

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

theme-ui's People

Contributors

alexanderchan avatar appsparkler avatar atanasster avatar beerose avatar braaar avatar colebemis avatar dburles avatar dcastil avatar deckchairlabs avatar dependabot-preview[bot] avatar dependabot[bot] avatar dev-cj avatar draekien avatar ekafyi avatar fcisio avatar flo-sch avatar hasparus avatar hoobdeebla avatar jletey avatar johno avatar jordanoverbye avatar julianbenegas avatar jxnblk avatar lachlanjc avatar lekoarts avatar mxstbr avatar sammarxz avatar simenandre avatar wkovacs64 avatar yurm04 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

theme-ui's Issues

Consider alternatives to `theme.styles`

Currently the theme.styles object is used as a shortcut to style components that are used in MDX. Each key in this object maps to a component that is passed to the MDXProvider's context. This allows the styles used in MDX to be generated and/or defined in multiple ways, including using Typography.js as an input. There might be alternative, more component-based approaches to handling this.

Currently, Theme UI passes components like the following to MDX context:

// mdx components
{
  h1: styled('h1')(props => props.theme.styles.h1)
}

And the styles for this component can be defined in the theme.styles object like this:

theme: {
  styles: {
    h1: {
      color: 'tomato',
    }
  }
}

Schema validation package

A schema validation for Theme UI objects could help with other packages and libraries built on top of the core. Leveraging a library like yup or joi, this validator should be able to detect whether a theme object is valid and detect typos among other things

Accessible layout components

The docs site currently includes a skip nav link and some handling of the focus state for the sidebar menu. Layout components could be added to the core library to make building accessible page layouts easier

Add style guide components

Having a few built in style guide components to show demonstrate parts of the theme would be a great addition. For example:

  • Type specimen component to show fonts
  • Font-size/typographic scale visualization
  • Color palette components with support for color modes

Support for styles in interpolated strings?

Most of my existing styles are written using emotion, however they're written using interpolated strings, as in:

<h1 css={css`color: red`}>Hi</h1>

I was unable to find a way to make this work using theme-ui. Is there existing / planned support for this method of writing styles?

Thanks for your help!

Theme UI vs Styled System

In simple terms, I'm just wondering why you'd choose this over styled system? My understanding so far is its a layer on top of style system to help streamline a few things such as general layout creation, as well as offering the ability to style certain components from the context of a theme file?

Cheers!

MDX navigation components

The docs site's sidebar navigation is a styled MDX document, with a list of links. The pagination component uses the same MDX to render previous and next links. A similar approach is used in the official MDX docs and the Styled System docs. It'd be great to abstract these navigation components out into a new package in the monorepo for reuse.

  • Accessibility should be kept in mind, and this navigation should work well with keyboard navigation
  • The ThemeProvider can be used to provide a custom wrapper component through MDX context and include theme.styles
  • Nice to have: accordion for nested link lists
  • The Pagination component should accept a current pathname prop, but not be coupled to Reach Router
  • A breadcrumbs component could also be added using the same source MDX document
  • A mobile layout and open/closed state could probably be handled outside of the sidebar component
  • Note: I noticed an issue with refs not working correctly in the sidebar nav when using the ThemeProvider, so currently the MDXProvider is used. This was something related to focus management IIRC

[gatsby-theme-ui] required theme location breaks if module resolvers include `/src`

The problem, in brief: If you are using src as a relative module lookup directory, the location of the theme file shadows the actual gatsby-theme-ui module because they have the same name. Could we set the path to the theme file in the plugin options?

// gatsby-node.js

exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    resolve: {
      modules: [path.resolve(__dirname, "src"), "node_modules"],
    },
  })
}
// src/gatsby-theme-ui/index.js
import baseTheme from 'gatsby-theme-ui'  /* Uh oh */

export default {
  ... baseTheme.
  colors: { ...
}

Should the wrapper component be included by default?

Currently theme-ui has a default wrapper component that's used to add base styles (typography, color, etc) to an MDX doc. It's also used in the typography.js transform in place of setting styled on the body and html elements. This wrapper component can easily be overridden/removed when using the export default syntax in an MDX file, but it also might be the kind of thing that is a little too magical in how it works – i.e. it seems like an easy thing for someone to get tripped up with

[idea] Quick-and-dirty shorthand parsing idea

Right now, there's no support for shorthand properties. This means that I can't set something like this:

{
  Container: {
   border: '1px solid primary'
  }
}

One idea for allowing this could be to split the shorthand into string tokens using .split, then look for tokens and replace.

// assumes the value is border shorthand: '1px solid primary'
border.split(' ').map(replaceThemeUITokensWithValues).join(' ')

The edge case here would be comma-separated values (e.g. multiple backgrounds):

{
  Container: {
    background: 'primary, rgba(0, 0, 0, 0.75)'
  }
}

This could be worked around with regex 😱 (e.g. /([,\s]*)(\w+)([,\s]*)/) to capture non-word characters and drop them back in:

const handleNonWordCharacters = str => {
  const [_, pre, maybeToken, post] = str.match(/([,\s]*)(\w+)([,\s]*)/);

  return pre + replaceThemeUITokensWithValues(maybeToken) + post;
}

There are probably a large number of dragons to consider with this approach, but if it's limited to only a few shorthand properties (e.g. border, background) maybe it's manageable?

VS Code plugin

Similar to the idea of a Chrome extension (#86), it would be nice to have a plugin for VS Code and/or other IDEs with graphical interfaces for editing things like colors and typography

`useLayoutEffect` and SSR mismatch

Hi! This is looking great.

I ran into an issue while setting up theme-ui in a Next.js project which is rendered on the server.

error:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://fb.me/react-uselayouteffect-ssr for common fixes.

useLayoutEffect(() => {
// initialize
const stored = storage.get()
const dark = getMediaQuery()
if (dark) {
setMode('dark')
return
}
document.body.classList.remove('theme-ui-' + stored)
if (!stored || stored === mode) return
setMode(stored)
}, [])
appears to be the culprit.

According to the link referenced in the error, we'd either need to push this to useEffect (sounds undesirable), or, similar to what redux does, create a useIsomorphicLayoutEffect like this:

const useIsomorphicLayoutEffect =
  typeof window !== 'undefined' ? useLayoutEffect : useEffect

thoughts?

Looking for additional preset themes

Theme UI includes a @theme-ui/presets package, which is intended to serve as a base for creating custom themes on top of. It'd be great to have more presets added to the package. Presets can be as minimal as a basic color palette and typographic styles, or include MDX element styles, syntax highlighting, or any other useful design tokens.

If you'd like to contribute a new preset, but aren't sure how to get started, feel free to leave a comment here, and we'll try to help you out

top, bottom, left, right negative values

Hi!

Maybe the top, bottom, left, and right properties should follow the same negative value rules as margins?

Personally, I find myself often doing something like this:

<Card>
  <Box
    css={{
      position: 'relative',
      top: `-${theme.sizes[1]}`,
    }}
  >
    <Avatar size="2" />
  </Box>
  <Content />
</Card>

Is this a common enough occurrence to warrant an API breaking change?

codesandbox starter

Hi!

I spun up a codesandbox starter for Theme UI

features:

  • Theme UI and its dependencies
  • imports the base theme
  • example of using Styled
  • uses @emotion/babel-plugin-jsx-pragmatic to insert the jsx pragma and point it at theme-ui
  • uses babel-plugin-emotion for smartness

I mirrored the prettier settings from this project and tried to keep the sandbox free of my own opinions, but feel free to offer feedback, and if you like it, fork it and add it to the docs or readme - letting people get up and running quickly.

Splitting out root ThemeProvider and nested ThemeProviders

Currently the ThemeProvider component can be nested to create theming contexts inside of a parent theme. This allows components like the experimental MDX Blocks to work and is a powerful feature that probably isn't leveraged much yet.

That said, there are a few issues with this in its current implementation:

  • Color mode state is only kept at the root-level ThemeProvider
  • ThemeProvider deeply merges theme objects, which can easily cause styling bugs and unreadable text when combined with things like syntax highlighting in pre tags
  • The gatsby-theme-ui package is geared towards having one, single root theme
  • The Chrome extension is also geared towards having a single root theme provider

This is a proposal to split the functionality of the ThemeProvider into two separate components.

  1. The top-level, root ThemeProvider:
  • Handles the base theme object
  • Provides the styled MDX components in context
  • Includes hooks for stateful theme object changes which could be leveraged in the Chrome extension and other editing tools
  • Would not pick up outer context
  • Would warn when nested in another ThemeProvider
  1. A nested context provider (name TBD):
  • Only includes a nested emotion context (no MDX)
  • Does not handle color modes
  • Can deep merge the base theme object (ignoring theme.styles)
  • Only shallow merges theme.styles

With the two separate components, an application tree could look something like the following:

<ThemeProvider theme={theme}>
  <div>root-level context available</div>
  <NestedTheme theme={subTheme}>
    <div>nested context available</div>
  </NestedTheme>
</ThemeProvider>

Responsive styles using objects

Does theme-ui support responsive styles using objects, as in styled-system? Or are you moving away from this approach?

Theme UI

<div
  css={css({
    width: [ '100%', '50%', '25%' ],
  })}
/>

Styled System

<div
  width={{ _: '100%', sm: '100%', md: '50%', lg: '25%' }}
/>

CSS prop unable to override responsive theme config

When the developer sets the value only for the first viewport, The CSS props function is unable to override all viewport values of the theme config .

//theme.js
const breakpoints = ["52em"];
const styles = {
  h1: {
    color: ["red", "blue"]
  }
};
<Styled.h1 css={css({ color: ["rebeccapurple" ]})}>
  {props.children}
</Styled.h1>

I expected this to override the the larger viewports as well. But i had to explicitly set the value for all viewports.

<Styled.h1 css={css({ color: ["rebeccapurple", 'rebeccapurple'] })}>
  {props.children}
</Styled.h1>

I have reproduced the issue in this codesanbox. you can reproduce the issue by resizing

Is this the intended behaviour? If not, can we filter the props and merge in jsx function/pragma?

thoughts on arrays of colors

any thoughts on doing something like this?


colors: {
  grays: ['#424445', '#666666', '#999999', '#CCCCCC', '#e0e3e6', '#e6e6e6'],
  reds: [
    '#a00',
    '#e62b1e',
    '#fF5041',
  ],
};

 

<h1 color="grays[1]">fairly dark</h1> 

i know passing something like that as a string sucks and is not the best option, but do you have any ideas around this in general?

Optional CSS custom properties support for color modes

Currently the color mode flash prevention only handles foreground and background colors for the <body> element, which means that colors used in other elements will still flash on page load. The styles generated by the ColorMode component could optionally include all values as CSS custom properties, and the ThemeProvider component could map the values used in context to their relevant custom properties instead of raw color values.

This should be an opt-in feature since custom properties are not supported in IE 11.

Typescript support

I used rebass before and really like this new idea, especially since it allows even more flexibility.

Not sure if you prefer adding definition files only or refactoring into typescript? I can make pr for either approach 🤔

Chrome devtools extension

An optional Chrome devtools extension could allow someone to inspect and live edit a site built with Theme UI could make adjusting the style of a site easier by providing a GUI for editing things like color values, which can be difficult to assess when editing raw values in code.

Ideas/questions

  • The extension could be either a panel (tab) or sidebar in the elements tab
  • Changes in the inspector should show live updates in the site
  • This could be flagged as a development-only feature or enabled for production sites as well
  • The extension could offer a JSON export of changes made in the browser
  • This should support multiple theme shapes, but would likely benefit from a separate Theme UI schema package (#85)
  • The UI components used in the extension should be a separate package that can be used in other applications (#59 #60)

Rough proof of concept: #79

Similar concepts & prior art:

The css prop doesn’t pick up space values for gap, gridGap, gridColumnGap, gridRowGap

my theme.js file:

export default {
  space: {
    '1': '0.25rem',
    '2': '0.5rem',
  }
}

my Header.js file:

<div
  css={{
    display: 'grid',
    gridGap: 2, // returns 2px, instead of 0.5rem
    p: 2, // works as intended, return 0.5rem
  }}
></div>

As you can see none of the grid gap properties pick up the correct value.
Is this a bug, or is my configuration wrong? Thanks!

Gatsby Plugin

Add a Gatsby plugin to control how theme and component context is handled when using multiple Gatsby themes in a site.

This plugin should:

  • Provide a zero-config way to add a src/theme module to the theme context
  • Merge multiple themes into a single theme object
  • Allow the site author to completely override any value in a child theme
  • Provide an option for enabling and disabling color mode state (or handle this with a separate plugin)
  • Allow MDX components to be defined (or provide this as a separate plugin)

Breaking changes for v0.2

Based on a few issues and discussion, it might be worth bumping to v0.2 with some small breaking changes. Currently, I'm thinking the following:

  • Rename the css prop in the JSX pragma to not collide with Emotion (#69)
  • Remove some (or all) styled-system props in favor of using the css prop (#65)
  • Split the ThemeProvider into two separate components (#89)
  • Consider ditching @emotion/styled as a dependency and creating all built-in components with the css prop, which would help reduce the core bundle size (This could cause issues when certain props get accidentally passed through to MDX elements, but docs could be added to show some common pitfalls)
  • Remove the toStyle API from theme-ui-typography in favor of using toTheme – this should reduce the overall bundle size
  • Rename subpackages to use @theme-ui scope

Add docs for debugging context

This should include at least:

  • Advice for debugging multiple versions of Emotion or MDX in the dependency graph (npm ls yarn list)
  • Notes on using the internal, Emotion, and MDX contexts for debugging
  • A note about nested ThemeProvider components

[docs] possible missing information for it to work with gatsby

Hi Jackson! Awesome stuff as usual.

Just gave this a test run while making a gatsby theme.

I was following one of the examples on how to use it with gatsby. (not as a plugin)

And I got stuck with a dom attribute error saying css shouldn't be there. Turns out
you need to have gatsby-plugin-emotion installed as well

I guess just a heads up to anyone who might encounter the same issue.

Rationale behind using emotion

Mind asking what made you choose emotion for this project? You seemed to use styled-components in the past (e.g. rebass) since this is a relatively new project and now that you've worked on a bunch of css-in-js libraries, do you personally prefer emotion at this point?

Handle flash when loading pages using non-white background colors

When loading a page that uses color modes, any page that uses a non-white background color will show a flash of the default color mode styles before picking up a stored color mode value from localStorage. The useDarkMode library uses an inline script to set classnames on the <body> element before rendering the page. If we do something similar for Theme UI, this should be based on values from the theme context and not be added as global CSS

Issue with MDXRenderer

Hey @johno, theme-ui is looking awesome!

I'm getting a following error after importing MDXRenderer:

Failed to compile

./node_modules/gatsby-mdx/context.js 11:2
Module parse failed: Unexpected token (11:2)
You may need an appropriate loader to handle this file type.
| 
| export const MDXScopeProvider = ({ __mdxScope, children }) => (
>   <GatsbyMDXScopeContext.Provider value={__mdxScope}>
|     {children}
|   </GatsbyMDXScopeContext.Provider>

Do you think it could be because of ThemeProvider? It works fine for mdx in /pages, but I'd like to render eg. articles which is when MDXRenderer would come handy.

Example repo

🙏

Referencing theme colors in border and boxShadow

I expected I could use theme colors like this, but primary is not replaced with the theme color:

import styled from '@emotion/styled';
import { Box, css } from 'theme-ui';

const Box1 = styled(Box)(css({
  borderBottom: '4px solid primary', // results in '4px solid primary'
}));

const Box2 = styled(Box)(css({
  boxShadow: '0 0 0 4px primary',
}));

Border bottom color can be achieved like this (but it took a while to realize that borderColor must be defined after borderBottom in order it to work):

const Box3 = styled(Box)(css({
  borderBottom: '4px solid', // results in 'border-bottom-color: initial';
  borderColor: 'primary', // overrides border colors with theme color
}));

For boxShadow, on the other hand, there isn't a separate property to define the color in.

It would be really handy being able to use theme colors inside border and boxShadow definitions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.