-
Notifications
You must be signed in to change notification settings - Fork 212
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
chore(storybook) update storybook format and add ltr/rtl support #12911
Conversation
I got u millsoper. 💯 |
import { Account } from '../../models/Account'; | ||
import { MOCK_LINKED_ACCOUNTS } from '../LinkedAccounts/mocks'; | ||
|
||
const defaultStory = { title: 'Components/Nav', component: Nav }; |
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.
Updated format per this comment #12870 (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 think it might be more ideal to format this like:
export default {
title: 'Components/Nav',
component: Nav,
} as Meta;
// or "Basic" as you have it further below, I personally prefer "Default" since it's slightly more clear (my opinion)
export const Default = () => <Nav />;
This is more similar to how they recommend it in the docs and how we've done all of our other modern default story SB formatting in the few fxa-settings
files as well as our email stories.
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.
Thank you so much for fixing this 🙌
I just had some nits/suggestions, but then a couple of notes as I've dug a little here.
I noticed in the package description, it states:
A storybook addons that lets your users toggle between ltr and rtl.
But I'm not sure I see the toggle shown there, and I know you noted in your description:
Long-term there is probably future work to be done regularizing some of the styles (so that similar elements have similar styles) and possibly adding a knob so that users can toggle the rtl/ltr in Storybook, but that feels outside of the scope of this ticket.
... I actually forgot that we added a toggle for this in fxa-auth-server
storybook:
I don't think this throws a wrench into your PR (as in, I don't believe you need to uninstall this package and reference auth-server's SB), since I don't think we have any actual RTL specific styles in our emails since they're all centered and pretty basic. I didn't dig further into how that package can toggle vs what we're doing, but I wanted to note that just for consistency's sake whether you do something here with it or we do so in the future.
I noticed we actually have a duplicate ticket for this - #9195 - I didn't realize when I filed the ticket your PR fixes that this was an RTL/LTR problem, and forgot about that ticket until now. We could cancel it in favor of the ticket this closes, but since that ticket actually references a toggle, we could instead slightly modify the title and leave a comment over there saying the style problem was fixed but we'd still like to have an option to switch from RTL/LTR, with maybe a reference to this comment or with just a summary of it so we can make sure whatever we do we're consistent.
import { Account } from '../../models/Account'; | ||
import { MOCK_LINKED_ACCOUNTS } from '../LinkedAccounts/mocks'; | ||
|
||
const defaultStory = { title: 'Components/Nav', component: Nav }; |
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 it might be more ideal to format this like:
export default {
title: 'Components/Nav',
component: Nav,
} as Meta;
// or "Basic" as you have it further below, I personally prefer "Default" since it's slightly more clear (my opinion)
export const Default = () => <Nav />;
This is more similar to how they recommend it in the docs and how we've done all of our other modern default story SB formatting in the few fxa-settings
files as well as our email stories.
const accountWithLinkedAccounts = Object.assign({}, account, { | ||
linkedAccounts: MOCK_LINKED_ACCOUNTS, | ||
}); | ||
|
||
const configWithoutNewsletterLink = Object.assign({}, getDefault(), { | ||
marketingEmailPreferencesUrl: '', | ||
}); |
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.
It's fine to leave these as-is since this is just an opinion but I personally prefer this syntax since it reads more clear to me and we're doing similar stuff in emails Storybooks:
const accountWithLinkedAccounts = {
...account,
linkedAccounts: MOCK_LINKED_ACCOUNTS,
});
const configWithoutNewsletterLink = {
...getDefault(),
marketingEmailPreferencesUrl: '',
});
Do you prefer explicitly using Object.assign
?
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 don't, this is way clearer to me also! 👍
|
||
const account = { | ||
primaryEmail: { | ||
email: 'johndope@example.com', | ||
}, | ||
subscriptions: [{ created: 1, productName: 'x' }], | ||
linkedAccounts: [], | ||
} as any; |
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.
Slightly better typing here than any
is as unknown as Account
.
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 really cool thank you!!
marketingEmailPreferencesUrl: '', | ||
}); | ||
|
||
const storyWithAccount = ( |
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 named a similar wrapper in Security
this (storyWithAccount
) since account
was the only param needed. This might be better named to something like storyWithContext
since that's what the story is providing, but I'm open to other name suggestions and it's not a big deal to leave it as-is.
Also, I think you can use the type Config
for config.
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.
Excellent, great idea!
@@ -26,6 +27,7 @@ storiesOf('Pages/Settings', module) | |||
recoveryKey: false, | |||
totp: { exists: false, verified: false }, | |||
attachedClients: SERVICES_NON_MOBILE, | |||
linkedAccounts: MOCK_LINKED_ACCOUNTS, |
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.
Not necessary for this PR but it would also be super nice for this file to get reformatted to the new Storybook since it was touched 🙈
I think maybe for "Cold start" story (this one), we might want to not show linkedAccounts
. That story is supposed to be a "bare minimum" example if someone just created an account - I think in fact it would be nice for attachedClients
to just show one session, but that again isn't part of the issue you fixed, so 🤷♀️
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 thinking, will do!
d734ccf
to
811c520
Compare
I got u millsoper. 💯 |
eecf753
to
ca1616e
Compare
I got u millsoper. 💯 |
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.
LGTM! Let's be sure to address this comment as I know you said you were going to in Slack 🙂 Also, don't forget to fixup your 2nd commit too and tweak the commit message to follow that because/this commit format.
I'm also fine with us closing that ticket (#9195) saying it's fixed with this PR and you could file a new one with context from this PR, the ticket it closes, and #9195 noting the consistency bit between our SBs. That gives us the advantage of triaging it in our next meeting, but again I'm also personally fine with just tweaking the title and leaving a comment over there since it was part of the issue anyway and I know we'll just backlog it.
return story; | ||
}; | ||
|
||
export const basic = () => <Nav />; |
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.
Nit: this should be capitalized conventionally, e.g. Basic
component: PageSettings, | ||
} as Meta; | ||
|
||
const coldStartAccount = { |
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.
Yaaaaas thank you for the refactor 😍
linkedAccounts: MOCK_LINKED_ACCOUNTS, | ||
} | ||
|
||
const storyWithContext = ( |
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.
Just thinking outloud; if we end up using storyWithContext
in our other SB refactors, we should definitely consider pulling this out into a helper function to use across stories, we can have it take a children
prop.
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.
Mm I like that idea. It would feel nice to do a big sweep refactoring all of these and refactor it out then
|
||
export const ColdStart = storyWithContext( | ||
coldStartAccount, | ||
'cold start', |
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 don't mind either way, but you could take out the story names here. They'll just show up in SB as Cold Start
vs cold start
. 🤷♀️
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.
oh interesting hmmmmm. I liked seeing them in the example I was modeling this on just because it was a little more explicit/less mysterious, but I think that confusion will become less and less frequent the more of these that we transition. Good with going either way!
Unrelated, but... Should we add this to all the Storybook projects?
|
Because: * RTL/LTR styles weren't showing up in storybook. This commit: * Uses an addon to add the `dir` value so that rtl/ltr styles are applied * Adds in Linked Accounts to some of the stories * Update the format for files that were changed Closes: #12848
b08224d
to
6b92c6a
Compare
chore(storybook) add LinkedAccounts to stories
chore(storybook) refactor nav stories
fix(storybook) use addon to get ltr/rtl in storybook
Because
This pull request
Issue that this pull request solves
Closes: #12848
Checklist
Put an
x
in the boxes that applyScreenshots (Optional)
Before (no linked accounts stories):
After (with linked accounts stories):
Before (without rtl/ltr addon):
After (with rtl/ltr addon):
Other information (Optional)
The reason why the styles in storybook looked wrong, even thought they looked fine when rendered outside of storybook, is because some of our styles were only being applied in the case of (under the hood in our CSS), the property selectors
[dir='rtl']
or[dir='ltr']
being true. Storybook doesn't have a value for that property available out of the box, so those styles were not being applied. Adding in thestorybook-addon-rtl
addon, and callinginitializeRTL()
inpreview.js
provided that property and fixed the styles. Long-term there is probably future work to be done regularizing some of the styles (so that similar elements have similar styles) and possibly adding a knob so that users can toggle the rtl/ltr in Storybook, but that feels outside of the scope of this ticket.Testing
Elements where you can see the rtl/ltr fixes in storybook are: the
Checkbox
story, and the space between theEmail Communications
label and its associated "link" button, visible in the "basic" story under theNav
story.