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: add card mode outlined #2512

Merged
merged 1 commit into from
May 14, 2021
Merged

feat: add card mode outlined #2512

merged 1 commit into from
May 14, 2021

Conversation

brunohkbx
Copy link
Collaborator

@brunohkbx brunohkbx commented Jan 19, 2021

Summary

Implement MD outlined card.

https://material.io/components/cards

Resolves #2130

Elevated Outlined
light-elevated light-outlined
Elevated Outlined
dark-elevated dark-outlined

Test plan

  1. Open the example app
  2. Check the example showing an outlined card

@callstack-bot
Copy link

callstack-bot commented Jan 19, 2021

Hey @brunohkbx, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

@github-actions
Copy link

The mobile version of example app from this branch is ready! You can see it here

.

* - `elevated` - Card with elevation, elevation defaults to 1.
* - `outlined` - Card with an outline.
*/
mode?: 'elevated' | 'outlined';
Copy link
Contributor

@Trancever Trancever Jan 19, 2021

Choose a reason for hiding this comment

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

I don't like the way it's typed currently. The outlined card shouldn't accept elevation prop. Could you try something like that:

type OutlinedCardProps = {
  mode: 'outlined';
  elevation: never;
};

type ElevatedCardProps = {
  mode?: 'elevated';
  elevation?: number;
};

type Props = (OutlinedCardProps | ElevatedCardProps) & { Common Props };

I haven't tried that, so it might not work, but I would like to explore this way of handling conditional types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Trancever I tried your approach and it wasn't working at first. So after some time debugging, I found a problem in the HOC withTheme. I removed it and it worked as follow:

Raises error
<Card mode="outlined" elevation={3} />

Works
<Card mode="elevated" elevation={3} />

After looking up the issue in withTheme I found a problem in its type declaration here
$Without it's not working as expected because Pick doesn't distribute over discriminated union types and you can read more about here

Should we fix the type declaration first?
type $Without<T, K extends keyof any> = T extends any ? Pick<T, Exclude<keyof T, K>> : never;
works for me

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should first fix the type of the withTheme HOC. Could you submit a PR? 🙏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@github-actions
Copy link

Hello 👋, this pull request has been open for more than 2 months with no activity on it. If you think this is still necessary with the latest version, please comment and ping a maintainer to get this reviewed, otherwise it will be closed automatically in 7 days.

@brunohkbx
Copy link
Collaborator Author

brunohkbx commented Apr 23, 2021

@lukewalczak I added a switch at the top to toggle the mode. WDYT?

@lukewalczak
Copy link
Member

Hey @brunohkbx, thanks for updating the PR! I like the idea of switch and the whole feature 🎉 . I will test it a bit, ping the theme provider lib one more time and go through the code. Anyway I guess we're close to ship it!

@souhe
Copy link
Member

souhe commented May 6, 2021

@brunohkbx I just published a new version of theme-provider with your fix. Sorry for the lag.
The new version is now v3.0.6 I had to bump it a lot since we did a mistake with the previous release ;)

@brunohkbx
Copy link
Collaborator Author

@souhe thanks. I will update this PR

@brunohkbx
Copy link
Collaborator Author

brunohkbx commented May 12, 2021

TS now complains when using mode outlined + elevation cc @Trancever @lukewalczak

Screenshot from 2021-05-12 14-51-14

@lukewalczak
Copy link
Member

lukewalczak commented May 12, 2021

TS now complains when using mode outlined + elevation

Isn't a correct behavior since you typed:

type OutlinedCardProps = {
  mode: 'outlined';
  elevation: never;
};

?

@brunohkbx
Copy link
Collaborator Author

@lukewalczak yeah it is. I'm just showing it. Works now with callstack/react-theme-provider 3.0.6

@lukewalczak
Copy link
Member

yeah it is. I'm just showing it. Works now with callstack/react-theme-provider 3.0.6

Ahhh ok I see, sorry for misunderstanding 😅 thanks @brunohkbx!

@lukewalczak
Copy link
Member

Awesome feature, thanks @brunohkbx for your work!

@lukewalczak lukewalczak merged commit 20080c4 into main May 14, 2021
@lukewalczak lukewalczak deleted the feat/add-card-mode-outline branch May 14, 2021 19:12
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.

Outlined cards
5 participants