question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strict type tokens for other theme variables

See original GitHub issue

Description

https://github.com/chakra-ui/chakra-ui/pull/5243 added support for generating strict types for variants and sizes

I’d like to be able to extend that to other properties (e.g. colors, space etc.)

Problem Statement/Justification

We’d like to ensure that only known colours/sizes etc are used in the app to ensure consistency.

For example, colors supports | (string & {}), so any colour can be provided. This includes HTML named colours, which make it hard to tell from looking at some code whether it is using known theme values or just arbitrary values.

<Text color="red">Hello world</Text>

This would display as red, but if I don’t have a red colour defined in my theme it is doing it based on the HTML colour, which undermines using the theme for consistency.

Proposed Solution or API

A new flag for Chakra CLI, maybe --strict-theme-tokens.

When provided, the unions in the output wouldn’t include | (string & {}).

At runtime, custom strings would still be allowed, but the typechecker would enforce correctness.

Alternatives

No response

Additional Information

I can look at doing a PR for this if it would be likely to get merged.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
lexanthcommented, Aug 1, 2022

@TimKolberger Anything I can do to get the attached PR moving forward?

2reactions
lexanthcommented, Apr 19, 2022

Not stale - attached PR is approved

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theming: an abstraction for design tokens - Benoit Rajalu
Theming is, eventually, coming to our apps in a shape or another. ... Simply put, a theme is a collection of design tokens,...
Read more >
What Are Design Tokens? | CSS-Tricks
As I understand it, the general idea is this: design tokens are an agnostic way to store variables such as typography, color, and...
Read more >
How to manage your Design Tokens with Style Dictionary
Another possible way to build the tokens is using a Node script. Here as well you can build all the platforms with a...
Read more >
Themes - Carbon Design System
With tokens, the code only needs to be changed in one place to see the effect system-wide. Tokens are used across all components...
Read more >
Customize Theme - Chakra UI
To extend or override a token in the default theme, import the extendTheme function and add the keys you'd like to override. You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found