-
Notifications
You must be signed in to change notification settings - Fork 350
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
Conversation
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)
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (8766cc7) and published it to npm. You 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 |
Size Change: 0 B Total Size: 1.29 MB ℹ️ View Unchanged
|
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
There was a problem hiding this 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.
.storybook/story-wrapper.tsx
Outdated
/** | ||
* Wrapper for Storybook stories that | ||
* 1. Renders the story inside of a .framework-perseus container | ||
* 2. Includes the global styles from webapp |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
.storybook/webapp-styles.less
Outdated
@@ -0,0 +1,136 @@ | |||
/** | |||
* This file contains styles that are used in webapp that ultimately |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
.storybook/global.less
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
.storybook/global.less
Outdated
@wonderBlocksFontFamily: "Lato", "Noto Sans", "Helvetica", "Corbel", sans-serif; | ||
|
||
// Layers | ||
@layer reset, shared; |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
.storybook/global.less
Outdated
margin: 0; | ||
color: @offBlack; | ||
line-height: 1.4; | ||
min-width: 0 !important; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
.storybook/story-wrapper.tsx
Outdated
return ( | ||
<div className="framework-perseus box-sizing-border-box-reset"> | ||
{props.children} | ||
</div> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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. 👍
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:
framework-perseus
class.box-sizing: border-box
in particular affects all thespacing (margins and padding)
Issue: none
Test plan:
"mini", "small", and "normal" stories show different sizes.
(previously 336px)
Screenshots: