facebook / stylex

StyleX is the styling system for ambitious user interfaces.
https://stylexjs.com
MIT License
8.21k stars 304 forks source link

Referencing static assets #539

Open hauxir opened 2 months ago

hauxir commented 2 months ago

Description

How can i reference static assets within stylex definitions?

Example

I apologize if I overlooked this in the docs, but I didn't seem to find anything regarding injecting static files into style definitions with Stylex. Is there a recommended method for handling such scenarios?

Example:


import exampleImage from "./example.png"

const styles = stylex.create({
    background: {
        backgroundImage: `url(${exampleImage})`, // This is not allowed currently
    },
});
necolas commented 2 months ago

StyleX can't know how an image import is resolved by a bundler. At the moment you can probably use the dynamic styles syntax and pass in the value during render.

https://stylexjs.com/docs/learn/styling-ui/defining-styles/#dynamic-styles