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

refactor: Destructure default props #525

Merged
merged 51 commits into from
Apr 7, 2020
Merged

refactor: Destructure default props #525

merged 51 commits into from
Apr 7, 2020

Conversation

mannycarrera4
Copy link
Contributor

@mannycarrera4 mannycarrera4 commented Mar 18, 2020

Summary

Fixes: #486
This PR touches a lot of our files, except our internal components like static states.

TODO

  • move default props to the top of the definition

@NicholasBoll
Copy link
Member

I'm confused. The issue referenced is to change Modal and the PR description says it changes Modal.tsx, but the only file changed is ComboBox.tsx

@cypress
Copy link

cypress bot commented Mar 19, 2020



Test summary

206 0 0 0


Run details

Project canvas-kit
Status Passed
Commit fd2481c ℹ️
Started Apr 7, 2020 5:36 PM
Ended Apr 7, 2020 5:38 PM
Duration 02:17 💡
OS Linux Ubuntu Linux - 16.04
Browser Electron 78

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@anicholls
Copy link
Contributor

@mannycarrera4 This will be a problem with all components - not just Modal. Modal was just an example used in the issue. I thought we agreed in planning that this was going to be done for every component?

@anicholls anicholls added the breaking-change A change that will break something for consumers label Mar 19, 2020
@mannycarrera4
Copy link
Contributor Author

@anicholls Yep yep, just opened up as a draft to work my way through and document it.

Copy link
Contributor

@anicholls anicholls left a comment

Choose a reason for hiding this comment

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

Getting close!

Do you mind targeting prerelease/v4 with this? It doesn't look like it's a breaking change, but I'd just like to bundle it with that stuff in case any uncaught problems make it in.

/**
* Type to Pick props from an interface, making some required and leaving others as is
*/
export type PickRequired<T, Req extends keyof T, AsIs extends keyof T> = Required<Pick<T, Req>> &
Copy link
Contributor

Choose a reason for hiding this comment

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

@NicholasBoll Thoughts on using this to avoid setting the default twice? (it was needed a second time for styled components)

Copy link
Member

Choose a reason for hiding this comment

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

I think I get it. The external interface says some props are optional and will be defaulted, but the Styled function doesn't know about any defaults and requires an override to tell Typescript the props aren't undefined.

Interesting problem. I think this is fine, but it is another interface that has to be learned to keep Typescript + Styled API happy.

It makes the css prop more interesting as it won't suffer from this problem.

@@ -11,12 +11,12 @@ export interface ModalContentProps extends React.HTMLAttributes<HTMLDivElement>
* The padding of the Modal. Accepts `zero`, `s`, or `l`.
* @default PopupPadding.l
Copy link
Contributor

Choose a reason for hiding this comment

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

Still waiting on this one. Need to make sure we update the JSDoc and readme as well.

@mannycarrera4 mannycarrera4 changed the base branch from master to prerelease/v4 April 2, 2020 16:26
public render() {
const {
icon = checkIcon as CanvasSystemIcon, // needed for TS2742 - https://github.com/microsoft/TypeScript/issues/29808
Copy link
Member

Choose a reason for hiding this comment

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

Interesting... Thank you for providing a link to the issue!

@anicholls anicholls changed the title chore: Destructure default props refactor: Destructure default props Apr 7, 2020
@anicholls anicholls merged commit 0edde1d into Workday:prerelease/v4 Apr 7, 2020
const {children, gutter, capWidth, ...elemProps} = this.props;
const {
gutter = canvas.spacing.xs,
spacing = spacingNumbers.xs,
Copy link
Member

Choose a reason for hiding this comment

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

This default will not be set in the renderChild function.

backgroundColor = SidePanelBackgroundColor.White,
openNavigationLabel = 'open navigation',
closeNavigationLabel = 'close navigation',
openDirection = SidePanelOpenDirection.Left,
Copy link
Member

Choose a reason for hiding this comment

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

This default won't be picked up in the private toggleButtonDirection function below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A change that will break something for consumers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider Using Destructuring With Default Assignment for Default Prop Values
5 participants