From b0ba985fc3f84eed9f6dd426903b26dc2d40db39 Mon Sep 17 00:00:00 2001 From: Luciano Graziani Date: Tue, 4 Jun 2019 17:32:40 -0300 Subject: [PATCH 1/2] Fix `content` and `children` props type Instead of limiting the elements to one string or one react element, would be better if it allows one (string, number, or react element) or an array of them. Which, actually, it already works. --- index.d.ts | 2 +- src/Tippy.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 811a125..7668aad 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,7 +4,7 @@ import { Instance, Options, GroupOptions } from 'tippy.js' type Omit = Pick> export interface TippyProps extends Omit { - content: React.ReactElement | string + content: React.ReactChild | React.ReactChild[] children: React.ReactElement onCreate?: (instance: Instance) => void /** @deprecated Use `visible` instead */ diff --git a/src/Tippy.js b/src/Tippy.js index 7e3b582..54bd259 100644 --- a/src/Tippy.js +++ b/src/Tippy.js @@ -126,8 +126,13 @@ function Tippy({ ) } +const ContentType = PropTypes.oneOfType([ + PropTypes.number, + PropTypes.string, + PropTypes.element, +]) Tippy.propTypes = { - content: PropTypes.oneOfType([PropTypes.string, PropTypes.element]) + content: PropTypes.oneOf([ContentType, PropTypes.arrayOf(ContentType)]) .isRequired, children: PropTypes.element.isRequired, onCreate: PropTypes.func, From d306d743a0e5af2d679c300098e49c8eaf471eb5 Mon Sep 17 00:00:00 2001 From: Luciano Graziani Date: Thu, 6 Jun 2019 10:52:10 -0300 Subject: [PATCH 2/2] fix(prod): Wrap proptypes with a env check This will prevent adding PropTypes to production! --- src/Tippy.js | 32 +++++++++++++++++--------------- src/TippyGroup.js | 6 ++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Tippy.js b/src/Tippy.js index 54bd259..64125ac 100644 --- a/src/Tippy.js +++ b/src/Tippy.js @@ -126,21 +126,23 @@ function Tippy({ ) } -const ContentType = PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - PropTypes.element, -]) -Tippy.propTypes = { - content: PropTypes.oneOf([ContentType, PropTypes.arrayOf(ContentType)]) - .isRequired, - children: PropTypes.element.isRequired, - onCreate: PropTypes.func, - isVisible: PropTypes.bool, // deprecated - isEnabled: PropTypes.bool, // deprecated - visible: PropTypes.bool, - enabled: PropTypes.bool, - className: PropTypes.string, +if (process.env.NODE_ENV !== 'production') { + const ContentType = PropTypes.oneOfType([ + PropTypes.number, + PropTypes.string, + PropTypes.element, + ]) + Tippy.propTypes = { + content: PropTypes.oneOf([ContentType, PropTypes.arrayOf(ContentType)]) + .isRequired, + children: PropTypes.element.isRequired, + onCreate: PropTypes.func, + isVisible: PropTypes.bool, // deprecated + isEnabled: PropTypes.bool, // deprecated + visible: PropTypes.bool, + enabled: PropTypes.bool, + className: PropTypes.string, + } } export default forwardRef(function TippyWrapper({ children, ...props }, ref) { diff --git a/src/TippyGroup.js b/src/TippyGroup.js index c36b0b3..3267575 100644 --- a/src/TippyGroup.js +++ b/src/TippyGroup.js @@ -21,6 +21,8 @@ export default function TippyGroup({ children, ...props }) { }) } -TippyGroup.propTypes = { - children: PropTypes.arrayOf(PropTypes.element).isRequired, +if (process.env.NODE_ENV !== 'production') { + TippyGroup.propTypes = { + children: PropTypes.arrayOf(PropTypes.element).isRequired, + } }