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 conditional propType #113

Merged
merged 1 commit into from
Mar 27, 2020
Merged

feat: add conditional propType #113

merged 1 commit into from
Mar 27, 2020

Conversation

Mohammer5
Copy link
Contributor

This is the counterpiece to oneOfType. While oneOfType allows all supplied propTypes, conditional will pick a propType based on the result of a condition callback.

const Component = ({ multiple, selected, optons }) => {
  const selectedOptions = multiple ? selected : [selected]

  return // jsx
}

Component.propTypes = {
  multiple: propTypes.bool,
  selected: conditional(({ multiple }) => multiple
    ? propTypes.arrayOf(propTypes.string)
    : propTypes.string
  ),
}

@Mohammer5 Mohammer5 requested review from a team March 27, 2020 11:02
Copy link
Contributor

@varl varl left a comment

Choose a reason for hiding this comment

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

Nice. Looks good to me. This could probably be used for the Select components for ui@5, @HendrikThePendric, if we move to string values.

@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@HendrikThePendric
Copy link
Contributor

Nice one 😄

This could probably be used for the Select components for ui@5, @HendrikThePendric, if we move to string values.

Yup I can 👍

@HendrikThePendric
Copy link
Contributor

@Mohammer5 Very sorry.... I should have reviewed this much sooner.... But there are a few things missing:

  • This new prop-validator should be attached to the propTypes object in ./src/index.js
  • It should get added to the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

4 participants