Tokens
You can import Base Web design tokens from baseui/tokens. A token is just an alias for a value in your design system, such as a hex or pixel value. For example:
const acmeBlue = '#00F';
Anytime someone needs to reference the blue for Acme Co. there is a single place it is defined and exported. Note, this is a little different from a theme, which assigns semantic meaning to colors. A token is just a consistent way to reference an immutable value in a design system.
Currently we only export colors from baseui/tokens. In the future, we may add more types of values to the module such as typography and spacing values. Eventually we may even move tokens into a separate package entirely- to better support other platforms and keep baseui focused on components.
Colors
Not every color listed here is used in a baseui component. This is simply the complete set of official Base Web colors. Ideally these are the only colors you would need to use in a Base Web project.
Usage
So what do you do with a token? Should you import it wherever you need to use the color? Should you alias it in your theme object?
In a pinch you could certainly employ either of those strategies. However, we think the best way to use tokens with baseui is to assign them to your theme's primitive variables. Here is what that might look like:
// myTheme.jsimport {createTheme, lightThemePrimitives} from 'baseui/themes';import {colors} from 'baseui/tokens';const myThemePrimitives = {...lightThemePrimitives,primary: colors.blue400,primary50: colors.blue50,primary100: colors.blue100,primary200: colors.blue200,primary300: colors.blue300,primary400: colors.blue400,primary500: colors.blue500,primary600: colors.blue600,primary700: colors.blue700,};const myTheme = createTheme(myThemePrimitives);export default myTheme;
You could also assign tokens as overrides on the theme if the primitives don't cover your use case. Sometimes our default mapping of primitives to theme properties may differ from your own intentions.
// myTheme.jsimport {createTheme, lightThemePrimitives} from 'baseui/themes';import {colors} from 'baseui/tokens';const myThemeOverrides = {colors: {borderFocus: colors.yellow200,},};const myTheme = createTheme(lightThemePrimitives, myThemeOverrides);export default myTheme;
It is best to assign things at the primitives level, with overrides as a backup. This will generally insulate you from future changes in baseui. When you assign tokens directly in component code or alias them on the theme object you are opting out of the baseui way of doing things. We will try to support those use cases the best we can, but our priority will always be supporting theme primitives and overrides first.
For more on baseui theming check out the documentation.