feat(react-card): add orientation prop#23037
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 203dbb6:
|
📊 Bundle size reportUnchanged fixtures
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: 143f4ac9fb4eef165e4975bcf3b113bc00680e03 (build) |
Perf Analysis (
|
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| Avatar | mount | 883 | 900 | 5000 | |
| Button | mount | 566 | 569 | 5000 | |
| FluentProvider | mount | 1847 | 1861 | 5000 | |
| FluentProviderWithTheme | mount | 256 | 292 | 10 | |
| FluentProviderWithTheme | virtual-rerender | 222 | 232 | 10 | |
| FluentProviderWithTheme | virtual-rerender-with-unmount | 304 | 305 | 10 | |
| MakeStyles | mount | 1605 | 1593 | 50000 |
| marginTop: `calc(var(${cardCSSVars.cardSizeVar}) * -1)`, | ||
| marginBottom: `calc(var(${cardCSSVars.cardSizeVar}) * -1)`, | ||
| }, | ||
| [`> :not([aria-hidden="true"]):first-of-type.${cardPreviewClassNames.root}`]: { |
There was a problem hiding this comment.
Unfortunate necessity due to Tabster's injected elements
There was a problem hiding this comment.
Im usually against adding comments to codebase, but I think this is the exception. can we document this pls?
There was a problem hiding this comment.
I think that's warranted 😓 Will do 👍🏻
There was a problem hiding this comment.
I went ahead and added a little explanation to the other styles too. Let me know if you would change something.
There was a problem hiding this comment.
I don't have any concrete numbers I can share here or guidance on what to do instead but I want to share some potential issues with this selector.
Attribute selectors and pseudo-classes are some of the slowest selectors: source. Sadly it's difficult to substantiate this with numbers as devtools have dropped CSS selector profilers :(
Is it at all possible to refactor this selector to, say, drop the attribute selector? Does Tabster apply classes to its hidden elements? Could it be updated to if not?
There was a problem hiding this comment.
thanks for reaching out @spmonahan ! The thing with Tabster DOM insertions is it can break at any time (which happened already). IMO would be best if tabster could expose a hook (css selector?) as part of its public API to give use solid contract. Can we reach out to folks @andrefcdias ? WDYT
There was a problem hiding this comment.
Thank you for sharing your concerns, @spmonahan. I agree that this approach is not ideal, but please keep in mind that there will be some work put into optimization after all implementation is finished as not to keep delaying the implementation.
As @Hotell said, Tabster updates tends to be breaking and this was the lesser evil approach.
I'll keep this in mind for the future before finalizing Card.
| [`> .${cardHeaderClassNames.root}, > .${cardFooterClassNames.root}`]: { | ||
| flexShrink: 0, | ||
| }, |
There was a problem hiding this comment.
Ensuring header and footer won't go below the required sizes.
| [`> :not(.${cardPreviewClassNames.root}):not(.${cardHeaderClassNames.root}):not(.${cardFooterClassNames.root})`]: { | ||
| flexGrow: 1, | ||
| }, |
There was a problem hiding this comment.
Allow content to grow before Card components.
|
|
||
| '> *': { | ||
| display: 'block', | ||
| height: '100%', |
There was a problem hiding this comment.
Now necessary to adjust CardPreview's content for horizontal cards.
| <Card size="small" orientation="horizontal"> | ||
| <CardPreview className={styles.horizontalPreview}> | ||
| <img src={Logo} alt="company logo template" /> | ||
| </CardPreview> | ||
| <CardHeader | ||
| image={<Avatar badge={{ status: 'available' }} image={{ src: avatarElviaURL }} />} | ||
| header={ | ||
| <Body1> | ||
| <b>Strategy 2021</b> | ||
| </Body1> | ||
| } | ||
| description={<Caption1>https://aka.ms/fluentui</Caption1>} | ||
| action={<Button appearance="transparent" icon={<MoreHorizontal24Regular />} />} | ||
| /> | ||
| </Card> |
There was a problem hiding this comment.
Custom example that fits better the horizontal use case. Will start reusing more of design's templates going forward.
| position: 'relative', | ||
|
|
||
| '> *': { | ||
| [`> :not(.${cardPreviewClassNames.logo})`]: { |
There was a problem hiding this comment.
Previously wrongfully applying to any child element, which would include the floating logo slot.
There was a problem hiding this comment.
also improves paint perf, nice catch
| .addDecorator(story => ( | ||
| <Screener steps={new Screener.Steps().snapshot('normal', { cropTo: '.testWrapper' }).end()}> | ||
| <div className="testWrapper" style={{ width: '300px' }}> | ||
| <div className="testWrapper" style={{ width: '600px' }}> |
There was a problem hiding this comment.
300px crops the horizontal example.
| marginTop: `calc(var(${cardCSSVars.cardSizeVar}) * -1)`, | ||
| marginBottom: `calc(var(${cardCSSVars.cardSizeVar}) * -1)`, | ||
| }, | ||
| [`> :not([aria-hidden="true"]):first-of-type.${cardPreviewClassNames.root}`]: { |
There was a problem hiding this comment.
Im usually against adding comments to codebase, but I think this is the exception. can we document this pls?
| position: 'relative', | ||
|
|
||
| '> *': { | ||
| [`> :not(.${cardPreviewClassNames.logo})`]: { |
There was a problem hiding this comment.
also improves paint perf, nice catch

New Behavior
Added the
orientationproperty which will control:The 6 changes in Screener are due to the change in the viewport size, so they're expected.
#23037 (comment)
I plan on refactoring these stories in the future to use design templates, so for now I'm keeping changes simple to facilitate reviews.
Related Issue(s)
#19336