Skip to content

Provide a way to control UI states #6403

Closed
@unional

Description

@unional

Provide a general summary of the feature here

When creating component documentation, e.g. using storybook,
I want to create a story that show the component in various states.

For example, creating a story for a button, and showing how it looks like normally, when pressed, when hover, when focused, etc.

I couldn't do that write now because using css selector doesn't change the state object in:

<Button className={(state) => ...}/>

And the ButtonContext doesn't seem to work with UI states:

<ButtonContext.Provider value={{ isPressed: true, isDisabled: true }}>
  <Button
    className={(state) => {
      console.log('state', state)
      return ''
    }}
  >
    Click me
  </Button>
</ButtonContext.Provider>

It prints isDisabled: true but isPressed: false. Also it does not have other states (like isFocusVisible).

I can do it if I break it down to one story per component per state, and use user.event() to cause the state change.

But the number of stories will explode and it is very hard to navigate.

🤔 Expected Behavior?

Have a way to do that.

😯 Current Behavior

No good way to do that statically.

💁 Possible Solution

Maybe provide a <UIStateContext.Provider/>

🔦 Context

Creating a nice documentation

💻 Examples

No response

🧢 Your Company/Team

Palo Alto Networks

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions