From a3485d0329107521d194b93dc26abca479d1381f Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 1 Mar 2024 18:36:36 +0530 Subject: [PATCH 1/6] move Optional component to TS --- components/optional/{index.js => index.ts} | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename components/optional/{index.js => index.ts} (65%) diff --git a/components/optional/index.js b/components/optional/index.ts similarity index 65% rename from components/optional/index.js rename to components/optional/index.ts index 7e5656ef..f67dc864 100644 --- a/components/optional/index.js +++ b/components/optional/index.ts @@ -1,7 +1,12 @@ import PropTypes from 'prop-types'; import { useBlockEditContext } from '@wordpress/block-editor'; -export const Optional = ({ value, children }) => { +interface OptionalProps { + value?: string|number|boolean; + children: React.ReactNode; +} + +export const Optional: React.FC = ({ value, children }): boolean | React.ReactNode => { const { isSelected } = useBlockEditContext(); return (isSelected || !!value) && children; }; From 8b862f4c893dd40514dfcd0d0f23a1dbd67cf2b3 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 1 Mar 2024 19:10:03 +0530 Subject: [PATCH 2/6] eslint fix --- components/optional/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/optional/index.ts b/components/optional/index.ts index f67dc864..a8f441b3 100644 --- a/components/optional/index.ts +++ b/components/optional/index.ts @@ -2,11 +2,14 @@ import PropTypes from 'prop-types'; import { useBlockEditContext } from '@wordpress/block-editor'; interface OptionalProps { - value?: string|number|boolean; + value?: string | number | boolean; children: React.ReactNode; } -export const Optional: React.FC = ({ value, children }): boolean | React.ReactNode => { +export const Optional: React.FC = ({ + value, + children, +}): boolean | React.ReactNode => { const { isSelected } = useBlockEditContext(); return (isSelected || !!value) && children; }; From 1cab61d8f23bf71f61a1c84c8c0eb8279f495f96 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 1 Mar 2024 20:53:26 +0530 Subject: [PATCH 3/6] remove proptypes --- components/optional/index.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/components/optional/index.ts b/components/optional/index.ts index a8f441b3..0360fba3 100644 --- a/components/optional/index.ts +++ b/components/optional/index.ts @@ -1,4 +1,3 @@ -import PropTypes from 'prop-types'; import { useBlockEditContext } from '@wordpress/block-editor'; interface OptionalProps { @@ -9,7 +8,7 @@ interface OptionalProps { export const Optional: React.FC = ({ value, children, -}): boolean | React.ReactNode => { +}) => { const { isSelected } = useBlockEditContext(); return (isSelected || !!value) && children; }; @@ -17,8 +16,3 @@ export const Optional: React.FC = ({ Optional.defaultProps = { value: '', }; - -Optional.propTypes = { - value: PropTypes.string || PropTypes.bool || PropTypes.number, - children: PropTypes.node.isRequired, -}; From 229c1f33a016b26884df312d577f885ea1734c70 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 1 Mar 2024 21:49:58 +0530 Subject: [PATCH 4/6] add doc --- components/optional/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/optional/index.ts b/components/optional/index.ts index 0360fba3..8a3cb607 100644 --- a/components/optional/index.ts +++ b/components/optional/index.ts @@ -1,7 +1,14 @@ 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; } From 36308239393917f5925e4979dd75aa0655dc92db Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Sun, 3 Mar 2024 15:35:06 +0530 Subject: [PATCH 5/6] Update components/optional/index.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fabian Kägy --- components/optional/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/optional/index.ts b/components/optional/index.ts index 8a3cb607..78d3f4ba 100644 --- a/components/optional/index.ts +++ b/components/optional/index.ts @@ -13,7 +13,7 @@ interface OptionalProps { } export const Optional: React.FC = ({ - value, + value = '', children, }) => { const { isSelected } = useBlockEditContext(); From dc65fef1408b2d90e6ed216fd2cca0394a7dd71a Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 11 Mar 2024 15:25:27 +0530 Subject: [PATCH 6/6] remove default props --- components/optional/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/optional/index.ts b/components/optional/index.ts index 78d3f4ba..ba8ded85 100644 --- a/components/optional/index.ts +++ b/components/optional/index.ts @@ -19,7 +19,3 @@ export const Optional: React.FC = ({ const { isSelected } = useBlockEditContext(); return (isSelected || !!value) && children; }; - -Optional.defaultProps = { - value: '', -};