How do you give library components project-specific colors? Idea: match tokens by name

We keep our design system in its own WeWeb project and link it as a library to our other projects. The library holds the components and the color tokens. Brand colors (primary, secondary, tertiary) are different in every project, and we want the library components to pick up the project’s own colors without detaching them from the library.

What we see today: our library components reference color tokens by uid with a hardcoded fallback, like `var(–, #hex)`. A project that uses the library gets the library’s colors. We can create color tokens in the project, but the library components don’t use them.

A workaround that works

Give the component optional color props (for example “project primary”) and fall back to the library token when the prop is empty. The component stays linked to the library. The downside: every component that uses a brand color (buttons, labels, checkboxes) needs such a prop, and the project has to pass the value in each time. Typography and fonts have the same problem.

Our idea

Match tokens by name (or something). If a project has a token with exactly the same name (and folder) as a token in the library, the library component would use the project’s token instead of the library’s. Then the library can define everything once, and a project only overrides the colors it wants to change.

Questions:

  • Does something like this exist, or is there an equivalent?
  • How do you theme library components per project or brand?
  • What problems did you run into, for example detached copies that drift out of sync with the library?

Thanks! Happy to share more details.

I used this approach in two projects for the same client to ‘stay organised’, but I wouldn’t recommend it as, over time, it becomes unsustainable what with the variants, properties, logic, and types that are created for each element. Before long, it becomes so vast that making a single change requires checking through too many options to avoid breaking something in the other linked projects.

I had to split them up and use them individually in each project.

Our currect decision is to limit it to adding a project-primairy and project-secundairy colour to the library component where a project specific colour is required (example: tabbar, btn component). Any modifications beyond that means we copy the component to the project itself and adjust it there.

I know we’re going to run into a client where their primary colour just doesn;t quite match with the library colours used for warning, success and danger. And when that happens it means the design system tokens need to be switched for project tokens.

And since adding colours for all the swatches to alle the components is a good way to start down a road that ends in purgatory we’re not going to be doing that.