Panda CSS: build time and type-safe CSS-in-JS
panda-css.com
panda-css.com
One thing that bugs me about this (and Tailwind) is the number of dependencies they pull in. Panda has 152 nodes (239, if you count their dev-dependencies)[0].
Tailwind has 98 (594 if you count their dev-dependencies).
I know they're only dev-dependencies, but still... I've got all of that code running on my machine, just to process CSS. I really don't love it.
I am not arguing for using sass, et al, but CSS preprocessors still have their place for those who wish to utilize them.
How much do they care about simplicity, bloat, efficiency, security? The number of dependencies is a signal. Maybe not an important one, though.
As far as I can tell installing a package will also pull down all of its dev dependencies. This unfortunately leads to many typescript related annoyances such as jest typescript global types being pulled in despite not needing them.
<Block
backgroundColor = 'red'
hoverBackgroundColor = 'blue'
marginH = { 4 }
marginV = { 12 }
padding = { 16 }
Works in both React and Preact. It's designed to support generating styles at build time, but I've never bothered. For the sorts of things I work on, being able to quickly bang out a component is more important than golfing the bundle size or maintaining a design system.jsxstyle feels like I can sculpt in code. It's really satisfying to hammer out some props and see a component come to life, especially when you've got hot module replacement working.
Based on a quick perusal of linked page, Panda seems like perhaps a more mature version of jsxstyle, but also more fidgety. As an army of one, I'm happy to optimize for iteration speed, but if I needed to maintain a system, maybe I'd consider switching to Panda.
Can you just use inline style in this case ?
Plus, they all get their own class names, so it's a bit more efficient than the naked style prop, and if you edit one in DevTools, all its siblings are updated to match.
<button
bg="blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600"
text="sm white"
font="mono light"
p="y-2 x-4"
border="2 rounded blue-200"
>
https://unocss.dev/presets/attributifyBetter off learning CSS and using it more effectively rather than single attributes
Touch either side, you have to understand the entire codependencies, inheritance rules and edges cases to make any predictions on what will actually happen.
You always can do edit/fix fast cycles, but it always ends up complicating initial code while eroding overall quality.
Good practices to make to whole thing predictable generally fails on edges cases.
Long story short, having each attributes defined, used and moved around independently really really simplify the whole experience, without leaving much things to regret.
Essentially the discussion is around how should you use it
- define it as inline attributes on individual elements - use some thing like Andy Bell’s CUBE approach to define styles for layout and components
With something like Andy’s approach you’ll end up with far less CSS, it’ll adapt to devices and you won’t actually have to write much CSS for new components
I am speaking in principle. Im am not even sure if inline styles are correctly referred to as CSS, as there is no cascading and no sheet. Aren’t they just styles?
With templates/components, I do not find myself writing a lot of style code at all, plus they remain more composable. The segregation into CSS, despite its inevitable coupling to the structure of the document, has no value to me.
I also do not buy the adaptation argument. I can adapt in code just fine, in fact it is necessary because proper adaptation needs more than just styling.
but since using tailwind, i far prefer this
class="bg-red-500 hover:bg-blue-500 mx-4 my-12 p-4"
Imba allows you to write CSS anywhere in a component definition using CSS-like syntax (rather than Javascript object syntax).
The syntax for adding a quick inline style is so simple:
<div [width:20px]>
You can even do hover states in an inline style: <div [color:red @hover:blue]>
And interpolation is easy too: <div [width:{someValue}px]>
Putting a CSS block at any level of your tag hierarchy scopes it to that tag. <div.foo>
<div.bar>
css color:red # this applies to div.bar
em color:blue # this applies to div.bar em
"hello"
<em> "world"
CSS blocks declared in a component definition but outside of the markup, apply to the whole tag. CSS declared in a file, outside of a component definition, apply to all components defined in that file. There is also a global keyword to apply styles globally.and there's a whole range of other useful features, a favorite of mind is the shorthand syntax for things like this:
c:red # same as color:red
d:vtc # same as display:flex flex-direction:column justify-content:center
x:10px rotate:30deg # same as transform:translateX(10px), rotate(30deg)I've considered porting it to JS into a Vite plugin so the same syntax can be used anywhere else. I would have done it already if I had the time.
Source: https://github.com/segunadebayo/chakra-ui/blob/master/README...
[1]: https://github.com/jxom/fannypack/blob/c7046c5f58cc68ee756be...
Seems like ‘fannypack’ went to ‘bum-bag’ as its successor. I wonder how much naming has to do with popularity of libraries, and if chakra took off because it was more appealing to larger tech companies. Satirical names never seem to get too big from what I’ve seen.
But such naming is niche, and a new project making it big like that is too. I'm sure it would make for an awkward conversation getting it approved, but ultimately it doesn't really matter does it. Funding/sponsorship on the other hand, I can definitely see it being a consideration.
See top of readme: https://github.com/jxom/bumbag-ui
So not sure what controversy you're trying to stir. Fannypack didn't have dark mode, Accordions, Alerts, Breadcrumbs, responsive containers, and a whole slew of components that Chakra had.
In fact if you look at the Avatar component from Chakra 5 yrs ago vs the Fannypack Avatar you'll see the code is completely different.
https://github.com/segunadebayo/chakra-ui/blob/master/src/Av...
https://github.com/jxom/fannypack/blob/c7046c5f58cc68ee756be...
The most likely story is he was just using Fannypack's docs as a reference for how to format his own.
"Build your next idea even faster."
I always thought the biggest influence on Chakra was actually Styled System. I really doubt there's anything nefarious happening here given that the Panda docs have a whole acknowledgement section that lists the projects that influenced it: https://panda-css.com/docs/overview/getting-started#acknowle...
Most of these React styling libraries were influenced by their predecessors. Emotion essentially copied styled components entire api: https://emotion.sh/docs/styled
Then again I'm one of those few engineers who actually enjoys CSS so my opinion may not be representative.
And it's not hard to get them working in Webpack...if you're like me.. maintaining the same app for 10 years and see no reason to switch to the new hotness.
Why does react makes this the developer’s problem to figure out? It feels a bit like a missed opportunity.
For a long time React was advertised and regarded as "just a UI library", so not having anything bundled with it was a conscious design decision.
End result is that you have an average of three popular solutions for stuff that's normally already included in other frameworks and no two React projects are the same.
If you want something less flexible, more opinionated, restricted to rendering in DOM but with more respective batteries included (such as styling, etc.), you should look at a framework instead. Some popular examples are Gatsby, Next, Docusaurus, etc. (Non-React alternatives in the same category include Vue and Svelte.)
That being said, one of the things Tailwind got right is that it's even faster to type out than normal CSS _or_ JS objects.
When you know what you want from Tailwind you write it and see it very quickly. Subjectively, there would have to be some very strong benefits to get me to go back to writing plain CSS rather than a bunch of class names.
I can knock out a responsive grid layout taking advantage of pseudo elements and :is() selectors quickly with CSS. Doing so with Tailwind is a nightmare for me, I end up searching docs for classes for every style I want and combinatorial classes for pseudo selectors will never click for me...why bother when simple things like spaces before a :has() selector or `margin-block` isn't even available?
Some things just don't work well or at all in a class-based utility system. There's nothing wrong with that, but personally I'd rather stay with one styling paradigm and avoid having to decide when to break out of the "do everything in utility classes" model. The context switching isn't worth it for me and I still lose the benefit of colocation.
Best of both worlds IMO.
I get that react didn't really have a clean answer for styling, but that's more a reason to not use react than a reason to invent a new DSL for styles on the web.
CSS modules still run through a build and bundling step which, in my opinion, kicks it out of the "I'm just using CSS" camp.
Modern frontend is increasingly depressing. Don't get me wrong, there are lots of great things that solve real engineering problems, then there are things that really don't solve a real problem.
CSS is neither of these.