diff --git a/packages/react/.storybook/story-config.ts b/packages/react/.storybook/story-config.ts index 794da63c..f5722d3c 100644 --- a/packages/react/.storybook/story-config.ts +++ b/packages/react/.storybook/story-config.ts @@ -79,6 +79,7 @@ export type Stories = | 'SignIn' | 'Stepper' | 'Tab' + | 'TabPanel' | 'Tabs' | 'TextField' | 'Toolbar' @@ -253,6 +254,9 @@ const StoryConfig: StorybookConfig = { Tab: { hierarchy: `${StorybookCategories.Navigation}/Tab`, }, + TabPanel: { + hierarchy: `${StorybookCategories.Navigation}/Tab Panel`, + }, Tabs: { hierarchy: `${StorybookCategories.Navigation}/Tabs`, }, diff --git a/packages/react/src/components/TabPanel/TabPanel.stories.mdx b/packages/react/src/components/TabPanel/TabPanel.stories.mdx new file mode 100644 index 00000000..da519357 --- /dev/null +++ b/packages/react/src/components/TabPanel/TabPanel.stories.mdx @@ -0,0 +1,52 @@ +import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs'; +import dedent from 'ts-dedent'; +import StoryConfig from '../../../.storybook/story-config.ts'; +import TabPanel from './TabPanel.tsx'; + +export const meta = { + component: TabPanel, + title: StoryConfig.TabPanel.hierarchy, +}; + + + +export const Template = args => ; + +# TabPanel + +- [Overview](#overview) +- [Props](#props) +- [Usage](#usage) + +## Overview + +TabPanel component can be used with Tabs component to implement the content of the tab views. + + + + {Template.bind({})} + + + +## Props + + + +## Usage + +Import and use the `TabPanel` component in your components as follows. + + + Sample Tab Panel + + ); +}`} +/> diff --git a/packages/react/src/components/TabPanel/TabPanel.tsx b/packages/react/src/components/TabPanel/TabPanel.tsx new file mode 100644 index 00000000..0849567a --- /dev/null +++ b/packages/react/src/components/TabPanel/TabPanel.tsx @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {BoxProps as MuiBoxProps} from '@mui/material'; +import clsx from 'clsx'; +import {forwardRef, ForwardRefExoticComponent, MutableRefObject, ReactElement} from 'react'; +import {WithWrapperProps} from '../../models'; +import {composeComponentDisplayName} from '../../utils'; +import Box from '../Box'; +import './tab-panel.scss'; + +export interface TabPanelProps extends MuiBoxProps { + /* + * The index of the corresponding `TabPanel`. + */ + index: number; + /* + * The value of the selected `TabPanel`. + */ + value: number; +} + +const COMPONENT_NAME: string = 'TabPanel'; + +const TabPanel: ForwardRefExoticComponent & WithWrapperProps = forwardRef( + (props: TabPanelProps, ref: MutableRefObject): ReactElement => { + const {className, children, value, index, ...rest} = props; + + const classes: string = clsx('oxygen-tab-panel', className); + + return ( + + ); + }, +) as ForwardRefExoticComponent & WithWrapperProps; + +TabPanel.displayName = composeComponentDisplayName(COMPONENT_NAME); +TabPanel.muiName = COMPONENT_NAME; + +export default TabPanel; diff --git a/packages/react/src/components/TabPanel/__tests__/TabPanel.test.tsx b/packages/react/src/components/TabPanel/__tests__/TabPanel.test.tsx new file mode 100644 index 00000000..a6db4e30 --- /dev/null +++ b/packages/react/src/components/TabPanel/__tests__/TabPanel.test.tsx @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {render} from '@unit-testing'; +import TabPanel from '../TabPanel'; + +describe('TabPanel', () => { + it('should render successfully', () => { + const {baseElement} = render(); + expect(baseElement).toBeTruthy(); + }); + + it('should match the snapshot', () => { + const {baseElement} = render(); + expect(baseElement).toMatchSnapshot(); + }); +}); diff --git a/packages/react/src/components/TabPanel/__tests__/__snapshots__/TabPanel.test.tsx.snap b/packages/react/src/components/TabPanel/__tests__/__snapshots__/TabPanel.test.tsx.snap new file mode 100644 index 00000000..d42eef6b --- /dev/null +++ b/packages/react/src/components/TabPanel/__tests__/__snapshots__/TabPanel.test.tsx.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TabPanel should match the snapshot 1`] = ` + +
+
+
+
+
+ +`; diff --git a/packages/react/src/components/TabPanel/index.ts b/packages/react/src/components/TabPanel/index.ts new file mode 100644 index 00000000..60dfa08e --- /dev/null +++ b/packages/react/src/components/TabPanel/index.ts @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export {default} from './TabPanel'; +export type {TabPanelProps} from './TabPanel'; diff --git a/packages/react/src/components/TabPanel/tab-panel.scss b/packages/react/src/components/TabPanel/tab-panel.scss new file mode 100644 index 00000000..c918ff03 --- /dev/null +++ b/packages/react/src/components/TabPanel/tab-panel.scss @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +.oxygen-tab-panel { + padding: 1rem; +}