Giter Club home page Giter Club logo

Comments (6)

Mokshit06 avatar Mokshit06 commented on May 27, 2024

@ncknuna This should be fixed in release 1.1.3. The issue was that macaron tries to extract every call of styled functions, but it was unable to do so because of a variable reference that it couldn't resolve. In this case you want to opt out of macaron's extraction since you know you will only call it inside macaron$ and it will be extracted later. So you can add a leading comment to the function calls with macaron-ignore like

const Component = /* macaron-ignore */ styled("button", {});
/* macaron-ignore */ globalStyle(selector, styles)

macaron will skip extracting these functions and will directly extract where you've called macaron$. Just add these comments inside sampleFn and it should work

from macaron.

Mokshit06 avatar Mokshit06 commented on May 27, 2024

Another thing, you can't return a styled component from macaron$() because the return value needs to be serialised and component declarations are functions and can't be serialised.

from macaron.

ncknuna avatar ncknuna commented on May 27, 2024

Thanks for the quick fix! I forked and modified the previous stackblitz and now it works: https://stackblitz.com/edit/macaron-css-macaron-tj3yss?file=src/App.tsx

The main concern I have now is that it's a bit verbose, needing to be wrapped by both macaron$ and sampleFn:

const MyComponent = getStyledPrimativeComponent(
  'div',
  macaron$(() =>
    sampleFn({
      fontSize: 24,
      backgroundColor: 'green',
      '& .inner': {
        backgroundColor: 'blue',
      },
    })
  )
);

Can you think of any way to make this a bit more elegant? Also happy to take this to a discussion now that the original issue was fixed, and close this one.

from macaron.

Mokshit06 avatar Mokshit06 commented on May 27, 2024

I have a few ideas on how this can be made less verbose. Lets move this to a discussion

from macaron.

Mokshit06 avatar Mokshit06 commented on May 27, 2024

Vanilla-extract also has a concept of function serialisers that it uses to serialise recipes etc, which allow them to be returned from macaron$. Maybe styled can also be made into a serialisable function, so you can just return it directly

from macaron.

ncknuna avatar ncknuna commented on May 27, 2024

Started disccusion here: #26

Closing this as completed

from macaron.

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.