-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for CSS in JS / modular styling API #248
Comments
@basarat always a pleasure to hear your input and see what you're working on! Let's say we do decide to use typestyle. Doesn't this essentially force all of our downstream consumers to also use typestyle? With meaningful class names removed, users couldn't write regular CSS that gets along well with Blueprint. I'd be a little concerned about forcing this on users |
Mutual respect for all your OSS efforts as well 🌹 ❤️ and Thanks!
Not quite. Few reasons:
They can write regular CSS with their choice of classNames and they get to chose even the framework e.g. aphrodite or CSS modules and pass in the generated or hand-written classNames More Notes
|
Sass is pretty great and indeed there's no clear winner for CSS in JS yet, but a solution like TypeStyle is very much something we want to research in the near-ish future |
Consider Styled Components please! |
I saw in the readme that you are considering using tools for css generation, I really hope you will not move to css-modules or worst styled-components. My arguments/opinions :
When I fist saw blueprint I thought, "yet another react framework", but when I saw how you keep things simple, I though "Ahh finally some people think about the developers and designers that will use the tool everyday", "Finally developers that don't think only about the purity of their code, but also about the great things we will build with it". I hope this (very opinionated) post will help you to take the right decision. Cheers, |
I really love the blueprint library, but really hoping to see CSS in JS used here at some point so not having to add two stylesheets. Importing a component would bring its styles, and only its styles, in at a time. Is this on the roadmap? Thanks! |
@graysonhicks CSS in JS is not "on the roadmap" because it amounts to a holistic rewrite of each component. it's a future consideration and certainly something we're discussing internally, but i wouldn't hold your breath. |
Something to consider is following the way that MUI does things, which has changed a lot over time, but I think they have settled on a pretty decent approach: |
Interesting set of libraries in this vein: https://theme-ui.com/ |
If at some point you are looking to revamp/rewrite blueprintjs components with CSS-in-JS ii suggest using styled-components and styled-system If you added these it would be much easier to make blueprint "themeable". theme.ui is great but import things you don't need as library authors from my point of view. |
+1, styled-system has nailed it. Theme UI has been great to work with.
|
If it is useful to anyone, styled-components support styling of any component: https://styled-components.com/docs/basics#styling-any-component import { Card } from '@blueprintjs/core';
import styled from 'styled-components';
const StyledCard = styled(Card)`
background-color: lightsteelblue;
`;
const MyComponent = () => (
<div>
{/* default */}
<Card>Blip blop dippeti doo</Card>
{/* modified */}
<StyledCard>Dippe dabbe hippeti hop</StyledCard>
</div>
); The problem that remains, though, is that Blueprint components can't be used in isolation since they depend on a global stylesheet. I wonder if it would be possible (relatively easily) to create a stripped down version of the global stylesheet, which can be applied to a import styled from 'styled-components';
import { strippedStyles } from '@blueprintjs/core'; // raw text
const BlueprintWrapper = styled.div`
${strippedStyles}
`;
const MyModularComponent = () => (
<BlueprintWrapper>
{/* blueprint components */}
</BlueprintWrapper>
); |
some thoughts on theming Blueprint from an original author of this library (I left the company in early 2019) who has recently attempted this himself in a non-Palantir codebase. apologies for length (my first github essay!) but i have a lot of thoughts here and this is possibly the most contentious feature request in this project, so buckle up.
@ViggoV this suggestion of (an aside: this layout/presentation dichotomy actually also applies to the list of components— so here are a few things you can do to customize Blueprint today: change the Sass variableschanging the note that this approach requires compiling it's just CSSthe brute force approach is to simply write your own CSS in your own stylesheet and apply it on top of the sanest way to do this is to add your own the ✨magic of CSS✨allows you to override/clobber any and all styles, although i can't promise it'll be fun. you're going to write some gross styles. your main enemy will be specificity because blueprint involves some highly specific CSS selectors. an appropriate use of make your own
|
I can't speak for other people but in my case the problem is not really related with Blueprint Component behaviour. It's pretty easy in fact to override Blueprint component even using styled-components. Problems come when you try to build a new component for your project and you want to make him look alike blueprints one in terms of color or margin. The real problem is that there only a few documentation and for example you can't know that a button minimal background hover is |
@giladgray Thank you for the detailed answer. If I understand you correctly it seems that you misunderstood me. In the The exact reason I was looking into this is that we are slowly working towards migrating our massive applications frontend to a I am sorry if this goes a little off the path for issue, but I was directed here after adding a new issue on the topic. |
I am having some partial luck with a dirty, hackish solution. I import the raw contents of the global stylesheets and import styled from 'styled-components';
import bp_css from '@blueprintjs/core/lib/css/blueprint.css';
const unwrap_rex = new RegExp('^(html|body)\s?{([^}]*)}', 'gms');
const unwrapped_bp_css = bp_css.replace(unwrap_rex, '$2');
// doing the same with the icons css and normalize
const StyleWrapper = styled.div`
*, *:before, *:after {
all: unset;
}
${unwrapped_bp_css};
`;
const MyIsolatedApp = () => (
<>
<h1>This is styled by the global styles</h1>
<StyledWrapper>
...everything in here has Blueprint styles
</StyledWrapper>
</>
); The above does apply Blueprint styles within the wrapper as expected, but something is wrong with the box-model. Even though everything I've put in there has had PS: sorry for the nasty "this is a test - do not use" styling |
A lot has change in the React ecosystem since this issue was opened back in 2016. Specifically, React Server Components (RSC) are now a thing, which are being implemented in popular frameworks like Next.js. However, RSCs do not work with CSS-in-JS solutions (at least none that I'm currently aware of). As such, many UI component libraries are starting to move away from this approach in favor of purse CSS approaches that can be supported by server rendering. I think it would be prudent to consider this when evaluating a new approach for Blueprint. |
Reading through the FAQ : https://github.com/palantir/blueprint/wiki/Frequently-Asked-Questions Specifically
Blueprint with a traditional global CSS stylesheet for a few reasons
I would like to argue against the reasons presented using typestyle as an example.With TypeStyle you get to use TypeScript tooling for CSS just like you use TypeScript tooling for JSX for HTML.
Note the case, e.g. You should't need to go into a CSS specificity war to customise components : #184. With TypeStyle you just take a className in your props and use
classes
to compose the final style. This is mentioned here : http://typestyle.io/#/core And demonstrated below (and you can play with it here : http://bit.ly/2fpylJl) :Note: Using
className
like TypeStyle, gives you all the power of CSS, something that cannot be done with thestyle
attribute.Hope that helps, this trick will work even without TypeStyle. This is definitely a learning area, and I present more reasons here as well http://typestyle.io/#/why 🌹 ❤️
The text was updated successfully, but these errors were encountered: