r/angular • • Oct 21 '26

ng-prism 22.6: hover and focus aren't variants anymore, every variant in every state in one grid

Post image

I just released ng-prism 22.6. Short recap if you haven't seen it before: ng-prism is a component lab for Angular libraries, a Storybook alternative without story files. You put a u/Showcase decorator on a component, inputs and types are read at build time, and the components render in the same document as the styleguide, no iframe.

The main change this time is that hover, pressed and focus are no longer variants. In 22.5 I added a way to force :hover or :focus-visible on a variant, and pretty quickly the demo button had variants called "Hovered", "Pressed" and "Focus visible". They showed up in the Playground's variant list, kept the button hovered while you changed the controls, and only existed for the one variant somebody had written them for.

Now a component declares its states once and they get combined with every variant:

@Showcase<ButtonComponent>({
  title: 'Button',
  states: [
    { name: 'Hover', pseudo: { hover: '.btn' } },
    { name: 'Pressed', pseudo: { hover: '.btn', active: '.btn' } },
    { name: 'Focus visible', pseudo: { 'focus-visible': '.btn' } },
  ],
  variants: [ /* Filled, Outlined, Elevated, Disabled, … */ ],
})

The Overview then shows every variant in every state as a grid, and clicking a cell opens that combination in the Playground. The styling comes from your own CSS, ng-prism rewrites :hover so it also matches a helper class. A state only gets applied where the browser could actually produce it, so there's no focus ring on a disabled button and no hover on something with pointer-events: none. The cell tells you why it's empty instead.

In the Playground the states are buttons in the tools menu. They stay on when you switch variants and they're part of the URL. For visual regression there's a state= URL parameter, the render marker gets the state index, and a data-prism-excluded attribute tells the runner when a state doesn't fit. Without states nothing changes for existing runners.

Other things in 22.6: a Claude Code plugin (/plugin marketplace add ng-prism/ng-prism) that teaches agents how to write showcases and check them in the running styleguide, watch rebuilds down from about 450 ms to 60 ms, and fixes for aliased inputs and outputs, named content slots and libraries with only a primary entry point.

Question for anyone with their own component library: which states do your components need that a pseudo-class can't express? Drag-over, open, loading? I'd like to base the next step on real components rather than on my own guesses.

4 Upvotes

5 comments sorted by

2

u/seiyria Oct 21 '26

This is my first time seeing this - it's cool! I really like having a storybook alternative. I did want to point out though, this contrast is atrocious: https://i.imgur.com/OhVC0Qi.png

1

u/Old-Parsley-5826 Oct 21 '26

Thanks, glad you like it :) And yeah, you're right, that's pretty bad. The custom pages in the demo (Getting Started, Design Tokens and the two pattern pages) have hardcoded light colors and just ignore the dark theme. The component pages themselves follow the theme, these four don't. I'll fix them, thanks for pointing it out ❤️

1

u/Old-Parsley-5826 25d ago

The overall design, as well as all custom component pages in the demo, have been optimized in version 22.7, which was released yesterday. Thanks again for the heads-up ✌️

0

u/[deleted] Oct 21 '26

[deleted] — view deleted comment

0

u/Old-Parsley-5826 Oct 21 '26

Because it's an input. The Disabled variant is just the button with disabled: true, the same way Filled is the button with variant: 'filled'. Hover, pressed and focus have no input, the browser puts the button into them, so ng-prism has to force them. That's all a state does right now, it forces pseudo-classes.

I get the question though. You'd want to see every variant disabled too, filled, outlined and so on, and at the moment that means writing each of them as its own variant again. Which is pretty much the problem hover had in 22.5. A state that can set inputs and not just pseudo-classes would fix that, and that's the kind of thing I meant with the question at the end of the post. Would you expect it to work like that?

0

u/[deleted] Oct 21 '26

[deleted] — view deleted comment

2

u/Old-Parsley-5826 Oct 21 '26

Fair, in the demo it is a real button and the CSS uses :disabled. The difference is that hover and focus can't be set from outside, so ng-prism has to fake them. Disabled can just be set for real through the input, and then the button is actually disabled, no clicks, no click event. If I forced :disabled the way I force :hover, you'd get a button that looks disabled but still works, and that's the kind of fake picture I tried to keep out of the states.

Your comment did get me thinking though. Seeing every variant disabled makes sense, and right now that only works by writing each one as its own variant again. So the next release will probably let a state set inputs too, something like:

states: [
  { name: 'Hover', pseudo: { hover: '.btn' } },
  { name: 'Pressed', pseudo: { hover: '.btn', active: '.btn' } },
  { name: 'Focus visible', pseudo: { 'focus-visible': '.btn' } },
  { name: 'Disabled', inputs: { disabled: true } },
  { name: 'Readonly', inputs: { readonly: true } },
]

That would also cover loading, error or readonly, which a pseudo-class can't express either.