From 1d2bf1b918c1f3982255610e6737fb96b6ff7829 Mon Sep 17 00:00:00 2001 From: Zack Stickles Date: Tue, 1 Jun 2021 17:32:55 -0700 Subject: [PATCH] chore: JS tab interaction --- src/components/Tabs/Pages.js | 13 +++++++++++++ src/components/Tabs/useTabs.js | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 src/components/Tabs/Pages.js create mode 100644 src/components/Tabs/useTabs.js diff --git a/src/components/Tabs/Pages.js b/src/components/Tabs/Pages.js new file mode 100644 index 000000000..76c9a1404 --- /dev/null +++ b/src/components/Tabs/Pages.js @@ -0,0 +1,13 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +const Pages = ({ children }) => + React.Children.map(children, (child, index) => + React.cloneElement(child, { index }) + ); + +Pages.propTypes = { + children: PropTypes.node.isRequired, +}; + +export default Pages; diff --git a/src/components/Tabs/useTabs.js b/src/components/Tabs/useTabs.js new file mode 100644 index 000000000..f8216e128 --- /dev/null +++ b/src/components/Tabs/useTabs.js @@ -0,0 +1,6 @@ +import { useContext } from 'react'; +import TabsContext from './Context'; + +const useTabs = () => useContext(TabsContext); + +export default useTabs;