Code Monkey home page Code Monkey logo

Comments (4)

aacotroneo avatar aacotroneo commented on May 27, 2024 1

yep! when I import my colors for direct use I need to look for the current theme as well, but nothing more serious than that.. (ie. a few lines) so no need to change anything in the library. thanks!

from react-with-styles.

lencioni avatar lencioni commented on May 27, 2024

Hi @aacotroneo! Thanks for the question. 😀

When using external libraries that require styles (this example is an actual snackbar from material-ui)

Although I don't have any experience with material-ui, I'm not sure it makes sense to run these styles through withStyles in this case. Depending on the interface you are using, it may generate inline styles or CSS classNames (while injecting styles onto the page for those classNames). Instead, it seems like you could just pass the styles directly to your material-ui snackbar. What do you hope to get by passing these styles through withStyles?

In some cases I find it better to only decorate the top level containers/components and pass a few props (like colors) to children and have them decoupled from any other dependencies.

Here again, I don't think I really understand what you are trying to accomplish. How does running these styles through withStyles limit what props you can pass to children?

Do you think that exposing that in a tidy way may cause any problems, or that will go against maintainability/encapsulation?

The idea behind react-with-styles is to provide an abstraction layer so you don't have to think as much about how your styles are being handled. The interface determines whether you are using inline styles, CSS classNames, or a mixture of both. I think that exposing direct access to the styles will likely not be a great idea because of the added complexity to the library and the types of patterns that it would enable would likely hurt the maintainability of your app code.

But, it is quite possible that I don't actually understand your use-case. It would be much easier to discuss this concretely if you could provide some code examples of what you are hoping to do.

from react-with-styles.

aacotroneo avatar aacotroneo commented on May 27, 2024

Thanks for answering :)

I've been playing a little more and have a different perspective. May be what I'd want is to have access to the raw theme components through this library, so I can take advantage of all the theme management and to keep all that at one place.

Whenever I decorate my component with the withStyles, the theme structure and location is nicely hidden from it, as it's just injected.

But whenever I need to access (say a color from) the theme I end up requiring the theme files directly which spoils some of the magic.

import { withStyles, css } from './styles/with-styles'; // this is the main app theme
import {colors} from './styles/theme/colors'; // this is breaking encapsulation a bit

@withStyles(styles)
default class Component extends Component {

  // I need colors.blue here from my theme to style a 3rd party component.
  // I can't use withStyles because my component requires specific formats 
  // for its style related props (like color={xxx})

So, the specific usecase here would be - how'd you recommend to get such a reference to the current theme's blue color? (so I can pass it to a 3rd party component that requires a color prop). Shouldn't this library be responsible for locating that color somehow as well?

Thanks!

PS: I understand this would break some opaqueness on the other hand.. so I don't know how the API should be changed to allow something like this.

from react-with-styles.

ljharb avatar ljharb commented on May 27, 2024

You can still use withStyles only for the theme, no?

from react-with-styles.

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.