by bsimpson · 2y ago · 0 comments
<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.
<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
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.
but since using tailwind, i far prefer this
class="bg-red-500 hover:bg-blue-500 mx-4 my-12 p-4"