-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Conversation
…n to fill the Card's margins.
Component perf results:
|
packages/office-ui-fabric-react/src/components/Stack/Stack.styles.ts
Outdated
Show resolved
Hide resolved
/** | ||
* Defines the padding to be applied to the Stack contents relative to its border. | ||
*/ | ||
padding?: number | string; |
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.
Should the corresponding props be deprecated?
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 see warnDeprecations
but not @deprecated
markup...
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.
@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; |
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.
Opened #8829.
<ExampleCard title="Basic Card" code={CardBasicExampleCode}> | ||
<CardBasicExample /> | ||
<ExampleCard title="Vertical Card" code={CardVerticalExampleCode}> | ||
<CardVerticalExample /> |
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.
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; |
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.
Is fill
a prop that StackItem would never have?
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.
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.
packages/react-cards/src/components/Card/CardItem/CardItem.view.tsx
Outdated
Show resolved
Hide resolved
Pick< | ||
IStackProps, | ||
'as' | 'horizontal' | 'reversed' | 'horizontalAlign' | 'verticalAlign' | 'verticalFill' | 'disableShrink' | 'grow' | 'wrap' | ||
>, |
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.
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.
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 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.
packages/react-cards/src/components/Card/CardSection/CardSection.view.tsx
Outdated
Show resolved
Hide resolved
packages/react-cards/src/components/Card/examples/Card.Vertical.Example.tsx
Outdated
Show resolved
Hide resolved
let marginTokens = fill ? { margin: 0 } : { margin }; | ||
|
||
if (child.type === CardSectionType) { | ||
marginTokens = { ...marginTokens, ...{ childrenGap } }; |
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'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?
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.
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 } |
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.
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?
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 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.
…make use of deprecated props
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.
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; |
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 see warnDeprecations
but not @deprecated
markup...
...ages/office-ui-fabric-react/src/components/Stack/examples/Stack.Horizontal.Basic.Example.tsx
Outdated
Show resolved
Hide resolved
packages/office-ui-fabric-react/src/components/Stack/examples/Stack.Vertical.Basic.Example.tsx
Outdated
Show resolved
Hide resolved
packages/office-ui-fabric-react/src/components/Stack/examples/Stack.Vertical.Grow.Example.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). */ |
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.
👍
/** | ||
* Defines the padding to be applied to the Stack contents relative to its border. | ||
*/ | ||
padding?: number | string; |
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.
@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. |
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.
@JasonGore Here is the deprecated markup.
Hello @khmakoto! Because this pull request has the 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. |
🎉 Handy links: |
Pull request checklist
$ npm run change
Description of changes
This PR enhances the
Card
component API to allow for sections and items inside theCard
to fully bleed into theCard
margins. This is achieved via the use ofCardItem
andCardSection
. The logic provided allows the things to bleed into the correct margins depending on the type ofCard
(vertical/compact) and the position of the item/section in theCard
(first, middle or last item/section).As part of this PR, a couple of tokens have been added to both
Stack
andStackItem
that were shown to be needed.Snapshot tests have also been written for
Card
,CardItem
andCardSection
as part of this PR.Finally, this PR adds an interactive example for people to play with that illustrates how
Card
,CardSection
andCardItem
work in tandem.Below is how the new example looks like:
Focus areas to test
(optional)
Microsoft Reviewers: Open in CodeFlow