-
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: Adding first prototype for Basic Card component #7954
Conversation
Size Auditor did not detect a change in bundle size for any component! |
packages/experiments/src/components/Card/CardItem/CardItem.types.ts
Outdated
Show resolved
Hide resolved
* Defines if the default padding applies to this CardItem or not. | ||
* @defaultvalue false | ||
*/ | ||
preventPadding?: 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.
Hmm, I wondering about this prop in architecturally descending order 😆
-
Is there a strong reason not to just use a
padding
orpaddingHorizontal
token? It seems that this is used to display images nicely aligned to the Card. Wouldn't it be reasonable to let consumers handle the styling to eliminate padding (a relatively common scenario) rather than introduce a prop to do it? -
I wonder if this should be a token somehow? It's similar to top level props like
disabled
andprimary
(argument against being a token), but it is also used only in the styles function (argument for being a token?) -
I'm also not clear on what "default padding" here means because when this prop is TRUE the negative padding is applied. What default padding is being prevented?
-
I'm not sure about the name. Is this an existing prop in OUFR?
disablePadding
seems more consistent with our naming conventions.
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.
In order:
-
Not really a strong reason to have this like we this, just taking inspiration from the
preventShrink
prop inStack
, but happy to just use apadding
orpaddingHorizontal
token. Don't really have a strong preference here. Maybe @dzearing, @micahgodbolt and @mikewheaton could share their opinions about this. -
Definitely should be a token if we decide to go for a
padding
orpaddingHorizontal
approach. -
Maybe I should improve the comments here but the default padding in the
Card
is12px
in every direction. So when we prevent this default padding for just a child, we apply a negative margin to make up for this. -
It's not an existing prop, again, was going of the
preventShrink
prop inStack
but happy to take suggestions on naming.disablePadding
could definitely work.
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.
Good point on preventShrink
, I wish I would have thought to call it out as disableShrink
earlier. I would still lean towards disablePadding
though. 😆
Better yet (per our chat), perhaps disableChildPadding
to indicate it applies to the children. Any input we can get from others would help, too.
}, | ||
preventPadding && { | ||
marginLeft: '-12px', | ||
marginRight: '-13px' |
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 there rationale for these values and why they differ?
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.
12px
is the default padding on the Card
. The marginRight
adds one extra pixel to compensate for the boxShadow
on the right being 1px
wide.
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 chatted with the designers this morning and they'll be sending along designs soon. The final version will have a symmetrical shadow so we can adjust this when it comes in.
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.
Hmm, I wonder if we should be linking these values. Like make a const inside this function:
const defaultPadding = '12px';
And then using defaultPadding
in styling vs. hardcoded values. I know that's not typically our standard but it might help prevent regressions over time.
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.
Actually the '12px` is scattered across two styles files, which is even more likely to regress if Card's value changes yet CardItem's does not. There are a couple of ways we could do this.. if not by linking a shared const value, then perhaps some kind of unit test.
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.
After trying for almost a full-day to get a way to compare the padding
and margin
of Card
and CardItem
respectively via a unit testing approach I've found that its pretty much impossible via jest/enzyme.
Given that, I finally chose to use a defaultPadding
const to link both. I've added a couple of snapshots for it.
Not feeling very confident about this change though, so it would be great if I could get some feedback on it.
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.
How about just setting up a unit test on the styles functions?
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.
Leveraged the styles functions to write a unit test. I would still like feedback on this approach though, as I'm not 100% confident on the way I did it.
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.
It is more complicated than I was hoping. Per our discussion, I think it's worth exploring this just a bit more as a future example with possible use of concatStyleSets
to simplify the test.
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.
Per our discussion it seems that there is no utility that completely fits our needs here to simplify the test. We'll go with our approach here for now, but maybe it would be good to have such a utility in the future.
packages/experiments/src/components/Card/examples/Card.Basic.Example.tsx
Outdated
Show resolved
Hide resolved
… the changes made in StackItem.tsx.
…ty from both Card and CardItem.
…s linked across both Card and CardItem.
…th unit test that leverages styling functions of the components.
Hello @khmakoto! Because this pull request has the |
🎉 Handy links: |
Pull request checklist
$ npm run change
Description of changes
This PR is the first attempt at prototyping a
Card
component while leveragingStack
. As part of this, the following changes are included:Card
types and styles.CardItem
types and styles.Card
page inexperiments
.Basic Card
example.margins
when setting thedisableChildPadding
to true inCardItem
correspond correctly to thepadding
values used inCard
.A screenshot of the
Basic Card
example is provided below:Focus areas to test
(optional)
Microsoft Reviewers: Open in CodeFlow