Skip to content

Migrate Badge to TS #937

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

Merged
merged 8 commits into from
Sep 17, 2020
Merged

Migrate Badge to TS #937

merged 8 commits into from
Sep 17, 2020

Conversation

ArnonZ
Copy link
Contributor

@ArnonZ ArnonZ commented Sep 14, 2020

WOAUILIB-1070

type LabelFormatterValues = typeof LABEL_FORMATTER_VALUES[number]
export type BadgeSizes = keyof typeof BADGE_SIZES

export type BadgePropTypes = ViewProps & TouchableOpacityProps & {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep the name as BadgeProp instead of BadgePropTypes, I wanted to have a shorter name
(I know we already have some components with xxxPropTypes, we'll change them eventually).

/**
* the badge size (default, small)
*/
size: BadgeSizes | number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be optional as the rest of the props?
Otherwise it will require user to pass it (even though it has a default value)

Copy link
Contributor Author

@ArnonZ ArnonZ Sep 16, 2020

Choose a reason for hiding this comment

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

I've checked the example screen and it doesn't require since it knows to use the defaultProp (I left some examples where size is not passed).
As far as I know this is the only way to make TS take into account defaultProps:
size: 'default'.
Also, TS doesn't like it as optional, it yells at me for methods that use size and assume that it can be undefined and fall back to defaultProp.

Same thing we did in Avatar btw: https://github.com/wix/react-native-ui-lib/blob/master/src/components/avatar/index.tsx#L121

@ArnonZ ArnonZ requested a review from ethanshar September 16, 2020 18:42
@ethanshar ethanshar merged commit b0bc97c into master Sep 17, 2020
@ArnonZ ArnonZ deleted the infra/TS_badge branch September 21, 2020 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants