Giter Site home page Giter Site logo

Comments (7)

damianstasik avatar damianstasik commented on August 21, 2024 3

@markdalgleish thank you! I think we can close this issue.

from vanilla-extract.

markdalgleish avatar markdalgleish commented on August 21, 2024 1

We could potentially also provide runtime APIs for setting vanilla vars on elements.

from vanilla-extract.

mattcompiles avatar mattcompiles commented on August 21, 2024 1

@duarten I think your use-case is already catered to by the createInlineTheme API?

from vanilla-extract.

markdalgleish avatar markdalgleish commented on August 21, 2024

I'd probably model this as something like getVarName that accepts a var created by vanilla-extract.

from vanilla-extract.

markdalgleish avatar markdalgleish commented on August 21, 2024

On that last point, thinking we could provide APIs like this:

setElementVar(el, themeVars.mode, 'dark')

assignElementVars(el, themeVars.space, {
  small: '4px',
  medium: '8px',
  large: '12px'
})

from vanilla-extract.

duarten avatar duarten commented on August 21, 2024

I think I have another use case for such an API. Consider a Responsive<Height>>, given

interface Responsive<T> { mobile: T, tablet: T, desktop: T }

type Height = 1 | 2 | 3 ... | "full"

To minimize the amount of classes generated, we could want to generate the following styles:

export const heightMobileVar = createVar();
export const heightTabletVar = createVar();
// ...
export const responsiveHeight = style({
  '@media': {
    'screen': {
      height: heightMobileVar,
    },
    'screen and (min-width: 768px)': {
      height: heightTabletVar 
    },
    // ...
  },
});

In my component, I would map from Responsive<Height> to an assignment of theme values to those height variables. Something like the following:

// Theme values
const heights = {
  1: "1px",
  2: "2px",
  // ...
  fill: "100%",
} as const;

// createVars would be a new API
const heightVars: Record<screens, string> = createVars({ ... });

// assignVars would return a CSSProperties object.
<Component style={assignVars(heightVars, mapResponsive(heightProp, asLookup(heights))) ... />

from vanilla-extract.

markdalgleish avatar markdalgleish commented on August 21, 2024

Opened a PR for imperatively setting vars on elements at runtime: #25

from vanilla-extract.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.