Skip to content
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

[EuiEmptyPrompt] Create Storybook Stories for EuiEmptyPrompt & Import Sass Styles for Components Not Using Emotion #7057

Merged
merged 8 commits into from
Aug 10, 2023

Conversation

breehall
Copy link
Contributor

@breehall breehall commented Aug 8, 2023

Summary

  1. Creates Storybook stories for EuiEmptyPrompt. This creates three stories:
  • Playground
  • An EmptyPrompt with multiple actions
  • An EmptyPrompt inside of a PageTemplate

I chose not to create stories for the panel options, title sizes, icon colors, and loading/error states as these can be replicated with toggles within the Playground.

  1. Imports the light theme so can use Sass to style components that haven't been converted to Emotion yet

This is my first set of stories, so I would love feedback / recommendations on how the stories are created.

QA

Sass Import Exploration Summary

Problem Statement: EUI components are currently styled in two different formats (CSS-in-JS with Emotion and Sass). For components that have not been converted to Emotion, we need a way to dynamically import light and dark theme Sass styles to Storybook.

I time-boxed myself to two hours of research and testing. Here are a few resources I used to attempt to solve this problem.

@storybook/addon-styling
addon-styling is a package created by the Storybook team that simplifies styling components. This felt like the most promising option because the implementation only requires a few line of configuration within our storybook/main.js.

After installing and completing configuration steps, I found that the Sass components still weren't being styled properly. The components would show in Storybook, but wouldn't update when props were changed. Upon additional research, I found that using this configuration would look for Sass styling for each of our components.

My next search led me to creating a custom decorator by using withThemeFromJSXProvider. This decorator allows you to specify your themes and global styles. I this is where I paused my research as I was continuing to dig into rabbit holes. If I were to pick up research again, this is likely the place I would start.

Additional Links & Research:

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_7057_buildkite/

@breehall breehall added skip-changelog documentation Issues or PRs that only affect documentation - will not need changelog entries labels Aug 8, 2023
@breehall breehall requested a review from cee-chen August 8, 2023 19:10
@breehall breehall marked this pull request as ready for review August 8, 2023 19:10
@cee-chen
Copy link
Contributor

cee-chen commented Aug 9, 2023

@breehall We discussed a timeboxed exploration of dynamically swapping the imported CSS file based on the light/dark mode global. Can you write up a short summary of the approaches and invesigations you took to try and get this working?

.storybook/preview.tsx Outdated Show resolved Hide resolved
breehall and others added 2 commits August 9, 2023 16:05
…nt stories

- Remove Multiple Actions story in favor of displaying this in the Playground
@breehall breehall requested a review from cee-chen August 9, 2023 20:24
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_7057_buildkite/

Comment on lines 25 to 28
element: { control: 'text' },
body: {
control: 'text',
},
Copy link
Contributor

@cee-chen cee-chen Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: see below comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually let's go ahead and remove the body control completely. I don't think this needs configuration personally, it flips just fine between text vs JSX.

Suggested change
element: { control: 'text' },
body: {
control: 'text',
},
element: { control: 'text' },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should body in the playground remain a string? Or should we move it back to a <p> since the Page Template story is using multiple paragraphs?

Copy link
Contributor

@cee-chen cee-chen Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The playground should have as editable of controls as possible, so the body there should remain a string.

Other stories that are not the playground do not (necessarily) need to have this concern. They could only care about a certain subset of props being editable, or they could be simply demonstrating a state that is difficult to obtain with Storybook's controls, and not need to have any editable controls.

So body should be a string for the playground, and JSX for the page template demo.

},
};

export const PageTemplate: Story = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This story ended up changing too much with the changes implemented. The PageTemplate story was fine as-is and in fact shouldn't be too similar to the Playground - if it is, what's the point of it?

Let's move the ...componentDefaults to the start of the args and then override args as necessary (e.g. layout="horizontal") to get this demo back to parity with where it was / the example on EUI docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PageTemplate story was fine as-is and in fact shouldn't be too similar

I think the direction to DRY out the defaults caused a little confusion on my part here.

… used and does not affect the component. This was realized in the creation of the Storybook documentation for EuiEmptyPropmt
…ove custom argTypes for the body and element props
 into storybook/empty-prompt

Merging in changes made in Github UI
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_7057_buildkite/

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great! I have one minor/optional order nit left, but overall feel like these stories are in solid shape. I know there was some back and forth here, so I just want to TL;DR some of the items we discussed:

  • Playground stories should have as editable of controls as possible
    • For some props that take React nodes, this means preferring strings instead, as Storybook has no JSX editing.
  • Storybook unfortunately does not inherit default props information. For playground stories, we should manually set those default prop values via args, to indicate to viewing devs what the component defaults are at a glance.
  • If a playground control is not working or doesn't belong in the component, investigate why - the prop may need a different control type, or should be removed
  • Additional stories should have a distinct reason for being separate from the playground. They typically demonstrate a visual state that is difficult to obtain from Storybook's controls alone. Their controls do not need to be as editable as the playground.

If I've missed anything in the above, please feel free to add on!

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_7057_buildkite/

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@breehall breehall merged commit d9557c1 into elastic:main Aug 10, 2023
@breehall breehall deleted the storybook/empty-prompt branch October 6, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues or PRs that only affect documentation - will not need changelog entries skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants