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.

Any chance of support outside of a `.treat.ts` file?

See original GitHub issue

First off, I love treat! Thanks for building it!

Instead of:

// component.treat.ts
import { style } from 'treat';

export const green = style({
  color: 'green'
});

// component.ts
import { green } from './component.treat.ts';

export function MyComponent() {
  return <div className={green}>This is green</div>;
}

It would be awesome to be able to do:

// component.ts
import { style } from 'treat';

const green = style({
  color: 'green'
});

export function MyComponent() {
  return <div className={green}>This is green</div>;
}

or even better:

// component.ts
import { style } from 'treat';

export function MyComponent() {
  return <div className={style({color: 'green'})}>This is green</div>;
}

I’ve really come to enjoy the css prop in emotion and glamor. My ideal (working) solution for CSS is to have a css toolkit library like tailwindcss or basscss (or it could be exported classes from a toolkit treat file) and then to use a prop on the component for everything that falls outside of the toolkit.

Creating an extra file seems like more overhead than is needed for a couple of properties… Using the style prop is fine but sometimes these components are re-used all over the application so it would be nice to abstract it as a class.

There are other zero-runtime css-in-js libraries that support this type of thing… but they don’t have the other upsides of treat (as you talk about in the documentation).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
mattcompilescommented, Feb 20, 2020

No, the only technical limitation is creating a style that is only known at runtime, theming is not the concern. e.g.

// This could work
import { style } from 'treat';

export function MyComponent() {
  return <div className={style({color: 'green'})}>This is green</div>;
}
// This won't
import { style } from 'treat';

export function MyComponent(props) {
  return <div className={style({color: props.color})}>This is green</div>;
}

I am interested in supporting inline styles but am not sure whether to allow use in dynamic contexts (like react render) as it may be confusing for people why some things work and others don’t. One way around this, which is the way facebooks stylex seems to work, is to only allow treat style calls at the top level of the file (kinda like imports).

e.g.

// This could work
import { style } from 'treat';

const green = style({color: 'green'});

export function MyComponent() {
  return <div className={green}>This is green</div>;
}

I am currently investigating lots of changes to treat which may become treat v2. Moving away from a separate file approach and towards inline styles is one thing I’m considering and I do have a semi-working prototype of this. Once I get a better idea of what will be in the next major version I will post an issue here detailing the proposed changes and hopefully release an alpha/beta version on npm.

4reactions
kripodcommented, Mar 22, 2020

In the last few days, I’ve been working on a CSS-in-JS framework called glaze, built upon treat. More details are available in these tweets.

Sneak peeks at the API (heavily inspired by Theme UI):

image

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
This includes generating a type for the import based on the static JSON shape. TypeScript does not support resolving JSON files by default:...
Read more >
Typescript: Cannot use import statement outside a module
The error means Node found an import statement in a file that it does not consider an ECMAScript (ES) module. Adding "type": "module"...
Read more >
Support to Run TypeScript test file(.ts) directly without ... - GitHub
My current thinking (once the extraction of Babel matures) is to support a TypeScript integration which knows how to load the pre-compiled files...
Read more >
Telehealth for the Treatment of Serious Mental Illness and ...
Despite these variations, however, there is substantial evidence to inform the types of resources that can help reduce substance use, lessen symptoms of...
Read more >
Template type checking - Angular
Disabling type checking using $any() link ... Disable checking of a binding expression by surrounding the expression in a call to the $any()...
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