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

[Storybook] Update styles to be more accurate to prod #1945

Merged
merged 8 commits into from
Dec 5, 2024
Merged

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Dec 4, 2024

Summary:

Perseus Storybook in its current state does not accurately
reflect how these component look in prod.

A couple things are added here to fix this:

  1. Stories are wrapped with the framework-perseus class.
  2. Webapp styles are imported
  • box-sizing: border-box in particular affects all the
    spacing (margins and padding)

Issue: none

Test plan:

Screenshots:

Before After
Screenshot 2024-12-03 at 6 03 03 PM Screenshot 2024-12-03 at 6 02 37 PM
Screenshot 2024-12-03 at 6 02 56 PM Screenshot 2024-12-03 at 6 02 47 PM

Perseus Storybook in its current state does not accurately
reflect how these component look in prod.

A couple things are added here to fix this:
1. Stories are wrapped with the `framework-perseus` class.
2. Webapp styles are imported
  - `box-sizing: border-box` in particular affects all the
    spacing (margins and padding)

Issue: none

Test plan:
- Go to http://localhost:6006/?path=/docs/perseus-components-number-input--docs
- Confirm that the inputs have rounded bordersa, and the
  "mini", "small", and "normal" stories show different sizes.
- Go to http://localhost:6006/?path=/story/perseuseditor-widgets-interactive-graph--interactive-graph-ray
- Scroll to the start coordinates panels
- Use the dev tools to confirm that the width is 308px
  (previously 336px)
@nishasy nishasy self-assigned this Dec 4, 2024
@nishasy nishasy requested review from jeremywiebe, a team and benchristel December 4, 2024 02:02
Copy link
Contributor

github-actions bot commented Dec 4, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (8766cc7) and published it to npm. You
can install it using the tag PR1945.

Example:

yarn add @khanacademy/perseus@PR1945

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1945

Copy link
Contributor

github-actions bot commented Dec 4, 2024

Size Change: 0 B

Total Size: 1.29 MB

ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 697 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/index.js 425 kB
packages/perseus/dist/es/strings.js 3.7 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@nishasy nishasy marked this pull request as ready for review December 4, 2024 02:53
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Dec 4, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/shiny-sloths-obey.md, .storybook/preview.tsx, packages/perseus/src/styles/global.less, packages/perseus/src/styles/perseus-renderer.less, packages/perseus/src/styles/reset.css

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

I'm going to hold off approving. I'd love to find a way to set these styles as part of the Perseus bundle we deliver instead of mimicking things in Storybook.

/**
* Wrapper for Storybook stories that
* 1. Renders the story inside of a .framework-perseus container
* 2. Includes the global styles from webapp
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would love it if we could isolate Perseus from these types of resets that trickle down into Perseus from outside. It makes sense to try to align styling with that of our primary consumer (webapp), but, if possible, could we make these styles/resets explicit in our Perseus styling system instead of mimicking them in Storybook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where would you propose adding this styles? We could do Renderer, but I don't think that would apply to our editors.

@@ -0,0 +1,136 @@
/**
* This file contains styles that are used in webapp that ultimately
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to avoid, if possible, references to projects outside of Perseus. I realize that might be pedantic, but Perseus is open source and although webapp is our primary consumer, I think it's worthwhile to stay at least somewhat agnostic of where Perseus is used.

Also, as stated in story-wrapper.tsx, I'm loathe to copy this much styling from an outside consumer just in Storybook. It gives us a false sense of what final styling will be in any given location if we've duplicated the styles only in Storybook, but not in our production styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great points. I'll remove the reference to webapp. Maybe I can just say "prod"?

The other thing I was thinking of doing is just including the box-sizing: border-box style since that's where most of the spacing discrepancy is coming from. I added the other styles in case I missed something else, but I think it should be fine without those.

@khan-actions-bot khan-actions-bot requested a review from a team December 4, 2024 19:39
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a great place to put this. Then you can include it in perseus-renderer.less. That file is imported in renderer.tsx (which is our core renderer the all articles and exercises use). That should guarantee that these global styles are always included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeremywiebe but maybe not in the .storybook folder, right? I can move it where perseus-renderer.less is?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct. This will become a part of our production Perseus CSS so it should go alongside the perseus-renderer.less file.

@wonderBlocksFontFamily: "Lato", "Noto Sans", "Helvetica", "Corbel", sans-serif;

// Layers
@layer reset, shared;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to include legacy. The rest of our PROD site show:

@layer reset, shared, legacy;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but I left it out since @legacy isn't defined anywhere in perseus styles. Should I add it anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please add it. Although legacy is last in the list, and "shouldn't" affect anything when imported due to definition order, we should be consistent with how it is declared in other parts in PROD.

That said, since this is the first time that we have declared and used layers in Perseus, we should verify how this comes across in PROD. Perhaps a ZND would help? I want to make sure that we aren't making sub-layers due to how these styles are imported.

margin: 0;
color: @offBlack;
line-height: 1.4;
min-width: 0 !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really need !important?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that was already there in webapp with the comment

/* Needs !important because we might load shared.css later */

But I don't think that's relevant anymore? I don't see a shared.css anywhere. I'll remove the !important.

return (
<div className="framework-perseus box-sizing-border-box-reset">
{props.children}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a separate file for this? Could we not just wrap the preview.tsx content in this <div> directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah. Now that I removed the import, I'll change it back to how it was before.

Copy link
Contributor

@mark-fitzgerald mark-fitzgerald left a comment

Choose a reason for hiding this comment

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

I like the call-outs that Jeremy made. I added a couple additional items, but all else looks good.

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

Thanks for doing this Nisha. Hoping this will reduce inconsistencies between Storybook and prod even further. 👍

@nishasy nishasy merged commit e69ca31 into main Dec 5, 2024
9 checks passed
@nishasy nishasy deleted the storybook-styles branch December 5, 2024 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants