import React, { useState, useContext } from 'react' import { ModalContext } from '@freesewing/react/context/Modal' import { ModalWrapper } from '@freesewing/react/components/Modal' import { KioskIcon } from '@freesewing/react/components/Icon' /** * A component to render Tabs, typically used for dev examples. * * Note that children MUST be at least two Tab components. * * @component * @param {object} props - All component props * @param {string} props.tabs - The list of tabs * @param {number} [props.active = 0] - The index of the active tab * @param {JSX.Element} props.children - The component children, will be rendered if props.js is not set * @param {bool} [props.withModal = false] - Set to true to load tab content in a modal window when kiosk icon is clicked * @returns {JSX.Element} */ export const Tabs = ({ tabs = '', active = 0, children, withModal = false }) => { const { setModal } = useContext(ModalContext) // Keep active tab in state const [activeTab, setActiveTab] = useState(active) /* * Parse tab list * Comma-seperated tabs passed as a string are how it works in MDX */ const tablist = Array.isArray(tabs) ? tabs : tabs.split(',').map((tab) => tab.trim()) if (!tablist) return null // Pass down activeTab and tabId for conditional rendering const childrenWithTabSetter = children.map((child, tabId) => React.cloneElement(child, { activeTab, tabId, key: tabId }) ) return (