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

Card: Improving CardItem and adding CardSection to allow Card children to fill the Card's margins #8813

Merged
merged 23 commits into from
May 9, 2019

Conversation

khmakoto
Copy link
Member

@khmakoto khmakoto commented Apr 23, 2019

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ npm run change

Description of changes

This PR enhances the Card component API to allow for sections and items inside the Card to fully bleed into the Card margins. This is achieved via the use of CardItem and CardSection. The logic provided allows the things to bleed into the correct margins depending on the type of Card (vertical/compact) and the position of the item/section in the Card (first, middle or last item/section).

As part of this PR, a couple of tokens have been added to both Stack and StackItem that were shown to be needed.

Snapshot tests have also been written for Card, CardItem and CardSection as part of this PR.

Finally, this PR adds an interactive example for people to play with that illustrates how Card, CardSection and CardItem work in tandem.

Below is how the new example looks like:

image

Focus areas to test

(optional)

Microsoft Reviewers: Open in CodeFlow

@msft-github-bot
Copy link
Contributor

msft-github-bot commented Apr 23, 2019

Component perf results:

Scenario Target branch avg total (ms) PR avg total (ms) Target branch avg per item (ms) PR avg per item (ms) Is significant change Is regression
PrimaryButton 84.963 89.316 0.850 0.893 false false
BaseButton 33.857 35.348 0.339 0.353 false false
NewButton 117.414 134.152 1.174 1.342 true true
button 5.921 5.999 0.059 0.060 false false
DetailsRows without styles 194.000 185.026 1.940 1.850 false false
DetailsRows 212.316 218.446 2.123 2.185 false false
Toggles 52.744 56.955 0.527 0.570 false false
NewToggle 72.424 70.988 0.724 0.710 false false
DocumentCardTitle with truncation 27.820 27.556 0.278 0.276 false false

/**
* Defines the padding to be applied to the Stack contents relative to its border.
*/
padding?: number | string;
Copy link
Member

Choose a reason for hiding this comment

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

Should the corresponding props be deprecated?

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 warnDeprecations but not @deprecated markup...

Copy link
Member Author

Choose a reason for hiding this comment

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

@deprecated markup is not on the tokens but on the props above.

const CardSectionType = (<CardSection /> as React.ReactElement<ICardSectionProps>).type;

const childrenGap = tokens && (tokens as ICardTokens).childrenGap;
const childrenMargin = tokens && (tokens as ICardTokens).childrenMargin;
Copy link
Member

Choose a reason for hiding this comment

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

Opened #8829.

<ExampleCard title="Basic Card" code={CardBasicExampleCode}>
<CardBasicExample />
<ExampleCard title="Vertical Card" code={CardVerticalExampleCode}>
<CardVerticalExample />
Copy link
Member

Choose a reason for hiding this comment

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

With regards to Card documentation, the first questions I had revolved around CardItem vs. CardSection, whether or not they are interchangeable (which is yes, but by looking at code), and whether or not they have to be nested when used.

/**
* Determines if the CardItem should disregard the children margin specified by Card.
*/
fill?: boolean;
Copy link
Member

@JasonGore JasonGore Apr 24, 2019

Choose a reason for hiding this comment

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

Is fill a prop that StackItem would never have?

Copy link
Member Author

@khmakoto khmakoto Apr 24, 2019

Choose a reason for hiding this comment

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

Well, fill is specifically for bleeding into the edge of the Card, which I think is a concept inherently for CardItem/CardSection and not StackItem, since Card has a say in its children's margin while Stack does not.

Pick<
IStackProps,
'as' | 'horizontal' | 'reversed' | 'horizontalAlign' | 'verticalAlign' | 'verticalFill' | 'disableShrink' | 'grow' | 'wrap'
>,
Copy link
Member

Choose a reason for hiding this comment

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

Would this be easier if it just extends all of IStackProps? I'm thinking that would be the better default, unless there are props we specifically want to exclude.

Copy link
Member Author

@khmakoto khmakoto Apr 24, 2019

Choose a reason for hiding this comment

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

Just extending IStackProps won't work since things like styles and tokens would be defined twice in the interface. Additionally, I'm specifically excluding deprecated props.

let marginTokens = fill ? { margin: 0 } : { margin };

if (child.type === CardSectionType) {
marginTokens = { ...marginTokens, ...{ childrenGap } };
Copy link
Member

Choose a reason for hiding this comment

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

I'm still parsing this function and trying to make sense of it. I think a few scattered comments explaining "why" could help here. Why is childrenGap only applied to CardSections and not CardItems? Is that intuitive and symmetric with StackItem behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

childrenGap is only applied to CardSections because the childrenGap token does not exist in ICardItemTokens. This is symmetric behavior I think because childrenGap applies specifically to children, which makes sense since a CardSection is made to hold multiple children while CardItem is made to hold only one, just like StackItem.

}

const marginItemProps: ICardItemProps | ICardSectionProps = {
tokens: { ...marginTokens, ...childTokens }
Copy link
Member

@JasonGore JasonGore Apr 24, 2019

Choose a reason for hiding this comment

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

There seem to be a lot of spreads here for what ultimately just devolve into two props: margin and childrenGap. Is it possible to store them as primitives and use less spreads?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed some of the spreads, however, specifically the one you're pointing out here is overwriting whatever calculation we've made with the user provided tokens, which I think is the expected behavior.

@khmakoto khmakoto requested a review from JasonGore April 25, 2019 22:11
@micahgodbolt micahgodbolt mentioned this pull request Apr 25, 2019
12 tasks
Copy link
Contributor

@natalieethell natalieethell left a comment

Choose a reason for hiding this comment

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

The Separator examples look good! This actually helped me catch something I need to fix in one of them, thanks :)

/**
* Defines the padding to be applied to the Stack contents relative to its border.
*/
padding?: number | string;
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 warnDeprecations but not @deprecated markup...

packages/react-cards/src/components/Card/Card.view.tsx Outdated Show resolved Hide resolved

/* If childrenMargin has been specified and the fill property is not present, make the appropriate calculations to get the resolved
* margin for this specific child depending on the type of Card (vertical vs compact) and the child position in the card (first
* child, in-between child or last child). */
Copy link
Member

Choose a reason for hiding this comment

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

👍

/**
* Defines the padding to be applied to the Stack contents relative to its border.
*/
padding?: number | string;
Copy link
Member Author

Choose a reason for hiding this comment

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

@deprecated markup is not on the tokens but on the props above.

*/
maxHeight?: number | string;

/**
* Defines the inner padding of the Stack.
* @deprecated Use 'padding' token instead.
Copy link
Member Author

Choose a reason for hiding this comment

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

@JasonGore Here is the deprecated markup.

@khmakoto khmakoto closed this May 7, 2019
@khmakoto khmakoto reopened this May 7, 2019
@msft-github-bot
Copy link
Contributor

Hello @khmakoto!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me and give me an instruction to get started! Learn more here.

@msft-github-bot msft-github-bot merged commit 77a9195 into microsoft:fabric-7 May 9, 2019
@khmakoto khmakoto deleted the fabric7 branch May 9, 2019 20:47
@msft-github-bot
Copy link
Contributor

🎉@uifabric/[email protected] has been released which incorporates this pull request.:tada:

Handy links:

@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants