diff --git a/components/optional/index.js b/components/optional/index.js deleted file mode 100644 index 7e5656ef..00000000 --- a/components/optional/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import PropTypes from 'prop-types'; -import { useBlockEditContext } from '@wordpress/block-editor'; - -export const Optional = ({ value, children }) => { - const { isSelected } = useBlockEditContext(); - return (isSelected || !!value) && children; -}; - -Optional.defaultProps = { - value: '', -}; - -Optional.propTypes = { - value: PropTypes.string || PropTypes.bool || PropTypes.number, - children: PropTypes.node.isRequired, -}; diff --git a/components/optional/index.ts b/components/optional/index.ts new file mode 100644 index 00000000..ba8ded85 --- /dev/null +++ b/components/optional/index.ts @@ -0,0 +1,21 @@ +import { useBlockEditContext } from '@wordpress/block-editor'; + +interface OptionalProps { + /** + * The value to check for truthiness. + */ + value?: string | number | boolean; + + /** + * The children to render if the value is truthy. + */ + children: React.ReactNode; +} + +export const Optional: React.FC = ({ + value = '', + children, +}) => { + const { isSelected } = useBlockEditContext(); + return (isSelected || !!value) && children; +};