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.

`transformers` middleware for theme values

See original GitHub issue

In our custom theme implementation on our team at work, we used functions to get tokens. for example:

<div
  css={theme => ({
    color: theme.color('red')
  })}
>
  This is our token red
</div>

This enabled us to do some cool things, for example, to use https://github.com/VinSpee/alpha-string-to-rgba so we could do this:

<div
  css={theme => ({
    color: theme.color('red.5')
  })}
>
  This is our token red, transformed to 50% opacity by `aRGB`.
</div>

Maybe the API could look like something like this (just spitballing here):

const theme = {
  colors: {
    red: '#E62A1E'
  },
  transformers: {
    colors: currentTheme => val => aRGB(currentTheme.colors)(val),
  },
};

any thoughts on something like this? It’s like a middleware for tokens. It could (optionally, and simply) open up a lot of possibilities.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
hennessyevancommented, Mar 13, 2020

For anyone else coming here wanting to stick to theme-ui’s API but want to change some of the ways theme data is stored you can use a Proxy

For example, my theme operates on a base-8 scale. So if I want spacing to act like <Box margin={3}/> to give me { margin: 24px; } I can set a Proxy for the space prop.

const theme = {
  space: new Proxy([], {
    get: (_, num) => num * 8,
  }),
}

Note Be aware of the support for Proxy: https://caniuse.com/#search=proxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy

0reactions
jxnblkcommented, Sep 17, 2019

Going to close this out, since I think @johno covered some of the rationale with how we’re approaching theming here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Routing in ASP.NET Core - Microsoft Learn
When a routing middleware executes, it sets an Endpoint and route values to a request feature on the HttpContext from the current request:....
Read more >
Condition in actix_web::middleware - Rust - UCSD CSE
Middleware for conditionally enabling other middleware. ... ConditionMiddleware<T::Transform, S>. The TransformService value created by this factory ...
Read more >
Configuration - Scribe documentation - Read the Docs
Default: /docs . middleware : List of middleware to be attached to the documentation endpoint ... By default, this will be the value...
Read more >
A Lightweight XML-based Middleware Architecture - CiteSeerX
of platform and language, support both value and reference ... in parsers [12] and transformers [13, 14]. ... quently, this topic is not...
Read more >
Plugins
An open source Traefik Middleware that enables Authentication via LDAP in a ... Apply themes from [theme.park](theme-park.dev) to supported applications.
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