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 size prop #22915

Merged
merged 10 commits into from
May 31, 2022
Merged

feat(react-card): add size prop #22915

merged 10 commits into from
May 31, 2022

Conversation

andrefcdias
Copy link
Contributor

New Behavior

Added the size property which will control:

  • Container padding
  • Padding in-between children
  • Border radius

Related Issue(s)

#19336

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 10, 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 0a0b94c:

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

@fabricteam
Copy link
Collaborator

fabricteam commented May 10, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-card
Card - All
60.746 kB
17.41 kB
62.033 kB
17.718 kB
1.287 kB
308 B
react-card
Card
56.031 kB
16.147 kB
57.318 kB
16.528 kB
1.287 kB
381 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-card
CardFooter
7.793 kB
3.327 kB
react-card
CardHeader
9.363 kB
3.841 kB
react-card
CardPreview
7.765 kB
3.35 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
181.217 kB
50.609 kB
react-components
react-components: FluentProvider & webLightTheme
34.148 kB
11.124 kB
🤖 This report was generated against ecb991eff272bc8ed5d3f23ccf21e2b8cbf0dc6b

@fabricteam
Copy link
Collaborator

fabricteam commented May 10, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1282 1286 5000
Button mount 790 815 5000
FluentProvider mount 2362 2371 5000
FluentProviderWithTheme mount 396 444 10
FluentProviderWithTheme virtual-rerender 368 331 10
FluentProviderWithTheme virtual-rerender-with-unmount 440 444 10
MakeStyles mount 2020 1988 50000

@size-auditor
Copy link

size-auditor bot commented May 10, 2022

Asset size changes

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

Baseline commit: ecb991eff272bc8ed5d3f23ccf21e2b8cbf0dc6b (build)

@andrefcdias
Copy link
Contributor Author

/azp run

@andrefcdias andrefcdias mentioned this pull request May 17, 2022
37 tasks
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@andrefcdias andrefcdias changed the title feat(react-card): implement size prop feat(react-card): add size prop May 17, 2022
@andrefcdias
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@andrefcdias andrefcdias marked this pull request as ready for review May 19, 2022 13:55
@andrefcdias andrefcdias requested a review from a team as a code owner May 19, 2022 13:55
@andrefcdias andrefcdias requested a review from Hotell May 19, 2022 14:52
@andrefcdias andrefcdias enabled auto-merge (squash) May 19, 2022 14:52
@andrefcdias andrefcdias requested a review from a team as a code owner May 24, 2022 14:14
auto-merge was automatically disabled May 25, 2022 13:00

Pull request was closed

@andrefcdias andrefcdias reopened this May 25, 2022
// TODO: Extract this to separate styles when tackling the `size` prop
...shorthands.margin('12px'),
...shorthands.padding(`var(${cardSizeVar})`),
...shorthands.gap(`var(${cardSizeVar})`),
Copy link
Member

Choose a reason for hiding this comment

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

have you considered passing the size down the react tree through context so that the relevant component can own the style ? It will also be easier to override for users because they are less specific

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we've considered that possibility before, as well as other alternatives to spacing, but chose to go with the simplest solution for now as conversations kept delaying implementation.
Each solution has its own pros and cons. For that one, users who add non Card components to a Card would get a bad DX as they get no padding by default and would need to consume a context to apply something as trivial as a padding. Another problem is the fact that we can't have doubled paddings in between elements and flex displays do not allow for collapsible margins, which would mean a complex logic to apply the proper padding.
I'm 100% open to suggestions to these cons however.

Copy link
Member

Choose a reason for hiding this comment

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

Oh this is also for non-card components ? I don't see this var being used in any styles targeting non-card components here

Is the intended ussage something like this?

import { makeStyles, cardSizeVar } from '@fluentui/react-components`;

const useStyles = makeStyles({
  cardPadding: {
    ...shorthands.padding(`var(${cardSizeVar})`)
  }
})

function NonCardComponent() {
  const styles = useStyles();
  return <div className={styles.cardPadding} />
}

Copy link
Contributor Author

@andrefcdias andrefcdias May 27, 2022

Choose a reason for hiding this comment

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

Not particularly but it's also a possibility we open for our users, especially if we end up not using gap.
However, the reason we put this in a var is to simplify any overwriting of the value as changing the var will affect both padding and gap, and these two need to be aligned.

Copy link
Member

Choose a reason for hiding this comment

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

and these two need to be aligned

This point makes sense to me. I do wonder if we will consider this cssVar a part of our public API, once feature engineers do a devtools inspect and see it, they can certainly use it in overrides. If we ever rename/remove this var it could break those overrides

Copy link
Member

Choose a reason for hiding this comment

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

I see that slider already does this, if we will stick with the cssvar approach we should export it for users at least

export const sliderCSSVars = {
sliderDirectionVar: `--fui-Slider--direction`,
sliderProgressVar: `--fui-Slider--progress`,
sliderStepsPercentVar: `--fui-Slider--steps-percent`,
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. My approach was not to export until we're sure we want to for the reasons you mentioned (avoiding misuse or name changes).
Thanks for sharing the slider example though. I'll align the usage and export it to avoid possible problems.

@andrefcdias andrefcdias requested a review from a team as a code owner May 30, 2022 14:15
@andrefcdias andrefcdias removed the request for review from a team May 30, 2022 15:11
[`> *:not(.${cardPreviewClassNames.root})`]: {
// TODO: Extract this to separate styles when tackling the `size` prop
...shorthands.margin('12px'),
...shorthands.padding(`var(${cardCSSVars.cardSizeVar})`),
Copy link
Contributor

Choose a reason for hiding this comment

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

😍 using css vars the rite way yay !

@@ -177,6 +201,7 @@ export const useCardStyles_unstable = (state: CardState): CardState => {
state.root.className = mergeClasses(
cardClassNames.root,
styles.root,
sizeMap[state.size],
Copy link
Contributor

Choose a reason for hiding this comment

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

fancyness

@andrefcdias andrefcdias merged commit 8caa7bb into microsoft:master May 31, 2022
@andrefcdias andrefcdias deleted the card-size branch May 31, 2022 12:16
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.

4 participants