From 678d156c0d4daf36ba7653553de4a6f8dda1659a Mon Sep 17 00:00:00 2001 From: Daniel Tschinder <231804+danez@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:57:17 +0100 Subject: [PATCH] remove prop-types for the most part --- src/components/Tab.js | 6 +++--- src/components/TabList.js | 7 ++++--- src/components/TabPanel.js | 6 ++++-- src/components/Tabs.js | 12 +++++++----- src/components/UncontrolledTabs.js | 9 +++++---- src/components/__tests__/Tabs-errors-test.js | 3 --- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/components/Tab.js b/src/components/Tab.js index b9d023e01f..91401a9268 100644 --- a/src/components/Tab.js +++ b/src/components/Tab.js @@ -1,4 +1,3 @@ -import PropTypes from 'prop-types'; import React, { useEffect, useRef } from 'react'; import cx from 'clsx'; @@ -12,6 +11,8 @@ const defaultProps = { selectedClassName: `${DEFAULT_CLASS}--selected`, }; +/* +Left for TS migration const propTypes = { children: PropTypes.oneOfType([ PropTypes.array, @@ -31,7 +32,7 @@ const propTypes = { selectedClassName: PropTypes.string, tabIndex: PropTypes.string, tabRef: PropTypes.func, // private -}; +};*/ const Tab = (props) => { let nodeRef = useRef(); @@ -82,7 +83,6 @@ const Tab = (props) => { ); }; -Tab.propTypes = propTypes; Tab.tabsRole = 'Tab'; export default Tab; diff --git a/src/components/TabList.js b/src/components/TabList.js index f4686434c2..c3de9888fb 100644 --- a/src/components/TabList.js +++ b/src/components/TabList.js @@ -1,10 +1,12 @@ -import PropTypes from 'prop-types'; import React from 'react'; import cx from 'clsx'; const defaultProps = { className: 'react-tabs__tab-list', }; + +/* +Left for TS migration const propTypes = { children: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), className: PropTypes.oneOfType([ @@ -12,7 +14,7 @@ const propTypes = { PropTypes.array, PropTypes.object, ]), -}; +};*/ const TabList = (props) => { const { children, className, ...attributes } = { ...defaultProps, @@ -27,6 +29,5 @@ const TabList = (props) => { }; TabList.tabsRole = 'TabList'; -TabList.propTypes = propTypes; export default TabList; diff --git a/src/components/TabPanel.js b/src/components/TabPanel.js index fadaa4f2d9..30fdcbbc72 100644 --- a/src/components/TabPanel.js +++ b/src/components/TabPanel.js @@ -1,4 +1,3 @@ -import PropTypes from 'prop-types'; import React from 'react'; import cx from 'clsx'; @@ -8,6 +7,9 @@ const defaultProps = { forceRender: false, selectedClassName: `${DEFAULT_CLASS}--selected`, }; + +/* +Left for TS migration const propTypes = { children: PropTypes.node, className: PropTypes.oneOfType([ @@ -20,6 +22,7 @@ const propTypes = { selected: PropTypes.bool, // private selectedClassName: PropTypes.string, }; +*/ const TabPanel = (props) => { const { children, @@ -50,6 +53,5 @@ const TabPanel = (props) => { }; TabPanel.tabsRole = 'TabPanel'; -TabPanel.propTypes = propTypes; export default TabPanel; diff --git a/src/components/Tabs.js b/src/components/Tabs.js index 44bc44c0e0..72f1f51248 100644 --- a/src/components/Tabs.js +++ b/src/components/Tabs.js @@ -1,4 +1,4 @@ -import PropTypes from 'prop-types'; +import { checkPropTypes } from 'prop-types'; import React, { useEffect, useState } from 'react'; import { childrenPropType, @@ -12,6 +12,10 @@ const MODE_CONTROLLED = 0; const MODE_UNCONTROLLED = 1; const propTypes = { children: childrenPropType, + onSelect: onSelectPropType, + selectedIndex: selectedIndexPropType, + /* +Left for TS migration className: PropTypes.oneOfType([ PropTypes.string, PropTypes.array, @@ -27,10 +31,8 @@ const propTypes = { environment: PropTypes.object, focusTabOnClick: PropTypes.bool, forceRenderTabPanel: PropTypes.bool, - onSelect: onSelectPropType, - selectedIndex: selectedIndexPropType, selectedTabClassName: PropTypes.string, - selectedTabPanelClassName: PropTypes.string, + selectedTabPanelClassName: PropTypes.string,*/ }; const defaultProps = { defaultFocus: false, @@ -68,6 +70,7 @@ For more information about controlled and uncontrolled mode of react-tabs see ht * It is initialized from the prop defaultFocus, and after the first render it is reset back to false. Later it can become true again when using keys to navigate the tabs. */ const Tabs = (props) => { + checkPropTypes(propTypes, props, 'prop', 'Tabs'); const { children, defaultFocus, @@ -136,7 +139,6 @@ const Tabs = (props) => { return {children}; }; -Tabs.propTypes = propTypes; Tabs.tabsRole = 'Tabs'; export default Tabs; diff --git a/src/components/UncontrolledTabs.js b/src/components/UncontrolledTabs.js index 0044dc33ad..8b28ee2e22 100644 --- a/src/components/UncontrolledTabs.js +++ b/src/components/UncontrolledTabs.js @@ -1,4 +1,4 @@ -import PropTypes from 'prop-types'; +import { checkPropTypes } from 'prop-types'; import React, { cloneElement, useRef, useId } from 'react'; import cx from 'clsx'; import { childrenPropType } from '../helpers/propTypes'; @@ -49,6 +49,8 @@ const defaultProps = { const propTypes = { children: childrenPropType, + /* + Left for TS migration direction: PropTypes.oneOf(['rtl', 'ltr']), className: PropTypes.oneOfType([ PropTypes.string, @@ -65,10 +67,11 @@ const propTypes = { selectedIndex: PropTypes.number.isRequired, selectedTabClassName: PropTypes.string, selectedTabPanelClassName: PropTypes.string, - environment: PropTypes.object, + environment: PropTypes.object,*/ }; const UncontrolledTabs = (props) => { + checkPropTypes(propTypes, props, 'prop', 'UncontrolledTabs'); let tabNodes = useRef([]); let tabIds = useRef([]); const ref = useRef(); @@ -404,6 +407,4 @@ const UncontrolledTabs = (props) => { ); }; -UncontrolledTabs.propTypes = propTypes; - export default UncontrolledTabs; diff --git a/src/components/__tests__/Tabs-errors-test.js b/src/components/__tests__/Tabs-errors-test.js index 2f6a75acfe..824ad9851d 100644 --- a/src/components/__tests__/Tabs-errors-test.js +++ b/src/components/__tests__/Tabs-errors-test.js @@ -21,10 +21,7 @@ describe('', () => { function assertPropTypeWarning(message, nth = 1) { expect(consoleErrorMock).toHaveBeenNthCalledWith( nth, - expect.anything(), - expect.anything(), expect.stringMatching(message), - expect.anything(), ); }