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

feat(react-card): add orientation prop #23037

Merged
merged 12 commits into from
Jun 3, 2022
Merged

feat(react-card): add orientation prop #23037

merged 12 commits into from
Jun 3, 2022

Conversation

andrefcdias
Copy link
Contributor

@andrefcdias andrefcdias commented May 17, 2022

New Behavior

Added the orientation property which will control:

  • flex container direction
  • center alignment of content for horizontal layouts

a horizontal card example

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 17, 2022

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:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@fabricteam
Copy link
Collaborator

fabricteam commented May 18, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-card
Card - All
61.945 kB
17.662 kB
63.222 kB
17.946 kB
1.277 kB
284 B
react-card
Card
57.23 kB
16.48 kB
58.378 kB
16.819 kB
1.148 kB
339 B
react-card
CardPreview
7.709 kB
3.286 kB
7.838 kB
3.316 kB
129 B
30 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-card
CardFooter
7.737 kB
3.264 kB
react-card
CardHeader
9.302 kB
3.779 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
183.617 kB
50.924 kB
react-components
react-components: FluentProvider & webLightTheme
33.988 kB
11.108 kB
🤖 This report was generated against 143f4ac9fb4eef165e4975bcf3b113bc00680e03

@size-auditor
Copy link

size-auditor bot commented May 18, 2022

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 143f4ac9fb4eef165e4975bcf3b113bc00680e03 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented May 18, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

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

@github-actions github-actions bot added this to the June Project Cycle Q2 2022 milestone Jun 2, 2022
@andrefcdias andrefcdias marked this pull request as ready for review June 2, 2022 09:39
@andrefcdias andrefcdias requested review from a team as code owners June 2, 2022 09:39
marginTop: `calc(var(${cardCSSVars.cardSizeVar}) * -1)`,
marginBottom: `calc(var(${cardCSSVars.cardSizeVar}) * -1)`,
},
[`> :not([aria-hidden="true"]):first-of-type.${cardPreviewClassNames.root}`]: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunate necessity due to Tabster's injected elements

Copy link
Contributor

Choose a reason for hiding this comment

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

Im usually against adding comments to codebase, but I think this is the exception. can we document this pls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's warranted 😓 Will do 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and added a little explanation to the other styles too. Let me know if you would change something.

Copy link
Contributor

Choose a reason for hiding this comment

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

all good lets get this in!

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@andrefcdias andrefcdias Jun 3, 2022

Choose a reason for hiding this comment

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

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.

Comment on lines +42 to +44
[`> .${cardHeaderClassNames.root}, > .${cardFooterClassNames.root}`]: {
flexShrink: 0,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensuring header and footer won't go below the required sizes.

Comment on lines +45 to +47
[`> :not(.${cardPreviewClassNames.root}):not(.${cardHeaderClassNames.root}):not(.${cardFooterClassNames.root})`]: {
flexGrow: 1,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allow content to grow before Card components.

@@ -16,6 +16,7 @@ const useStyles = makeStyles({

'> *': {
display: 'block',
height: '100%',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now necessary to adjust CardPreview's content for horizontal cards.

Comment on lines +36 to +50
<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>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom example that fits better the horizontal use case. Will start reusing more of design's templates going forward.

@@ -14,8 +14,9 @@ const useStyles = makeStyles({
root: {
position: 'relative',

'> *': {
[`> :not(.${cardPreviewClassNames.logo})`]: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously wrongfully applying to any child element, which would include the floating logo slot.

Copy link
Contributor

Choose a reason for hiding this comment

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

also improves paint perf, nice catch

@@ -38,7 +38,7 @@ const SampleCardContent = () => (
storiesOf('Card Converged', module)
.addDecorator(story => (
<Screener steps={new Screener.Steps().snapshot('normal', { cropTo: '.testWrapper' }).end()}>
<div className="testWrapper" style={{ width: '300px' }}>
<div className="testWrapper" style={{ width: '600px' }}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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}`]: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Im usually against adding comments to codebase, but I think this is the exception. can we document this pls?

@@ -14,8 +14,9 @@ const useStyles = makeStyles({
root: {
position: 'relative',

'> *': {
[`> :not(.${cardPreviewClassNames.logo})`]: {
Copy link
Contributor

Choose a reason for hiding this comment

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

also improves paint perf, nice catch

@andrefcdias andrefcdias requested a review from Hotell June 2, 2022 13:40
@andrefcdias andrefcdias merged commit 06030b7 into microsoft:master Jun 3, 2022
@andrefcdias andrefcdias deleted the card-orientation branch June 3, 2022 10:56
marwan38 pushed a commit to marwan38/fluentui that referenced this pull request Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants