@availity/mui-tabs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +61 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -0
- package/dist/index.mjs +16 -0
- package/introduction.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +53 -0
- package/project.json +41 -0
- package/src/index.ts +1 -0
- package/src/lib/Tab.stories.tsx +39 -0
- package/src/lib/Tab.test.tsx +9 -0
- package/src/lib/Tab.tsx +17 -0
- package/src/lib/TabContext.stories.tsx +41 -0
- package/src/lib/TabContext.test.tsx +25 -0
- package/src/lib/TabContext.tsx +9 -0
- package/src/lib/TabList.stories.tsx +35 -0
- package/src/lib/TabList.test.tsx +19 -0
- package/src/lib/TabList.tsx +24 -0
- package/src/lib/TabPanel.stories.tsx +33 -0
- package/src/lib/TabPanel.test.tsx +25 -0
- package/src/lib/TabPanel.tsx +9 -0
- package/src/lib/Tabs.stories.tsx +38 -0
- package/src/lib/Tabs.test.tsx +9 -0
- package/src/lib/Tabs.tsx +25 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (2023-07-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-tabs:** tab component initial commit ([8b20c7e](https://github.com/Availity/element/commit/8b20c7e6be1759a256f110be91f2113c011a8727))
|
|
11
|
+
* **mui-tabs:** tabcontext component initial commit ([9b52724](https://github.com/Availity/element/commit/9b52724abcc70aff355377fff3b81177df271441))
|
|
12
|
+
* **mui-tabs:** tablist component initial commit ([9c445a3](https://github.com/Availity/element/commit/9c445a3d963b5d52852e0a216d058c4e6d6e76b4))
|
|
13
|
+
* **mui-tabs:** tabpanel component initial commit ([d3af6d7](https://github.com/Availity/element/commit/d3af6d7ab1487b39f958e8f4ecbfe73d19cf86d9))
|
|
14
|
+
* **mui-tabs:** tabs component initial commit ([d4e7818](https://github.com/Availity/element/commit/d4e7818f4123d215e4cd0f5df475b5fb0eadc69a))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **mui-tabs:** disableRipple is not allowed on DOM elements ([ad0ada9](https://github.com/Availity/element/commit/ad0ada98922f339ec79cf64f081b54c34107c0b1))
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @availity/mui-tabs
|
|
2
|
+
|
|
3
|
+
> Availity MUI Tabs component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-tabs)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-tabs)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-tabs/package.json)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
This package extends the MUI Tabs component: [MUI Tabs Docs](https://mui.com/components/tabs/)
|
|
12
|
+
|
|
13
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-tabs-introduction--docs)
|
|
14
|
+
|
|
15
|
+
Availity standards for design and usage can be found in the [Availity Design Guide](https://zeroheight.com/2e36e50c7)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Import Through @availity/element (Recommended)
|
|
20
|
+
|
|
21
|
+
#### NPM
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @availity/element
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Yarn
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add @availity/element
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Direct Import
|
|
34
|
+
|
|
35
|
+
#### NPM
|
|
36
|
+
|
|
37
|
+
_This package has a few peer dependencies. Add `@mui/material` & `@emotion/react` to your project if not already installed._
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @availity/mui-tabs
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Yarn
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @availity/mui-tabs
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
#### Import through @availity/element
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Tabs } from '@availity/element';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Direct import
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Tabs } from '@availity/mui-tabs';
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TabsProps as TabsProps$1 } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
interface TabsProps extends Omit<TabsProps$1, 'centered' | 'centerRipple' | 'disableFocusRipple' | 'disableRipple' | 'disableTouchRipple' | 'focusRipple' | 'orientation' | 'TouchRippleProps' | 'touchRippleRef'> {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
declare const Tabs: ({ children, ...rest }: TabsProps) => JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { Tabs, TabsProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Tabs: () => Tabs
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/Tabs.tsx
|
|
28
|
+
var import_material = require("@mui/material");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var Tabs = ({ children, ...rest }) => {
|
|
31
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Tabs, {
|
|
32
|
+
...rest,
|
|
33
|
+
disableRipple: true,
|
|
34
|
+
disableTouchRipple: true,
|
|
35
|
+
orientation: "horizontal",
|
|
36
|
+
centered: false,
|
|
37
|
+
children
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
Tabs
|
|
43
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/lib/Tabs.tsx
|
|
2
|
+
import { Tabs as MuiTabs } from "@mui/material";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var Tabs = ({ children, ...rest }) => {
|
|
5
|
+
return /* @__PURE__ */ jsx(MuiTabs, {
|
|
6
|
+
...rest,
|
|
7
|
+
disableRipple: true,
|
|
8
|
+
disableTouchRipple: true,
|
|
9
|
+
orientation: "horizontal",
|
|
10
|
+
centered: false,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
Tabs
|
|
16
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-tabs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Tabs Component - part of the @availity/element design system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"typescript",
|
|
8
|
+
"availity",
|
|
9
|
+
"mui"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://availity.github.io/element/?path=/docs/components-tabs-introduction--docs",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Availity/element/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Availity/element.git",
|
|
18
|
+
"directory": "packages/tabs"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Availity Developers <AVOSS@availity.com>",
|
|
22
|
+
"browser": "./dist/index.js",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
28
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"clean:nm": "rm -rf node_modules",
|
|
31
|
+
"bundlesize": "bundlesize",
|
|
32
|
+
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
33
|
+
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@mui/lab": "^5.0.0-alpha.121"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@availity/mui-divider": "^0.3.0",
|
|
40
|
+
"@mui/material": "^5.11.9",
|
|
41
|
+
"react": "18.2.0",
|
|
42
|
+
"react-dom": "18.2.0",
|
|
43
|
+
"tsup": "^5.12.7",
|
|
44
|
+
"typescript": "^4.6.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@mui/material": "^5.11.9",
|
|
48
|
+
"react": ">=16.3.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-tabs",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/tabs/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/tabs/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/tabs/.eslintcache",
|
|
17
|
+
"maxWarnings": -1,
|
|
18
|
+
"quiet": false,
|
|
19
|
+
"noEslintrc": false,
|
|
20
|
+
"hasTypeAwareRules": true,
|
|
21
|
+
"cacheStrategy": "metadata"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"test": {
|
|
25
|
+
"executor": "@nrwl/jest:jest",
|
|
26
|
+
"outputs": ["coverage/tabs"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/tabs/jest.config.js",
|
|
29
|
+
"passWithNoTests": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"version": {
|
|
33
|
+
"executor": "@jscutlery/semver:version",
|
|
34
|
+
"options": {
|
|
35
|
+
"preset": "conventional",
|
|
36
|
+
"commitMessageFormat": "chore(${projectName}): release version ${version} [skip ci]",
|
|
37
|
+
"tagPrefix": "@availity/${projectName}@"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/Tabs';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
5
|
+
import { Tabs } from './Tabs';
|
|
6
|
+
import { Tab, TabProps } from './Tab';
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof Tabs> = {
|
|
9
|
+
title: 'Components/Tabs/Tab',
|
|
10
|
+
component: Tabs,
|
|
11
|
+
tags: ['autodocs'],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
function a11yProps(index: number) {
|
|
17
|
+
return {
|
|
18
|
+
id: `simple-tab-${index}`,
|
|
19
|
+
'aria-controls': `simple-tabpanel-${index}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const _Tab: StoryObj<typeof Tab> = {
|
|
24
|
+
render: (args: TabProps) => {
|
|
25
|
+
const [value, setValue] = useState(0);
|
|
26
|
+
|
|
27
|
+
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
|
28
|
+
setValue(newValue);
|
|
29
|
+
};
|
|
30
|
+
return (
|
|
31
|
+
<Tabs value={value} onChange={handleChange}>
|
|
32
|
+
<Tab label="Item One" {...args} {...a11yProps(0)} />
|
|
33
|
+
<Tab label="Item Two" {...args} {...a11yProps(1)} />
|
|
34
|
+
<Tab label="Item Three" {...args} {...a11yProps(2)} disabled />
|
|
35
|
+
</Tabs>
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
args: {},
|
|
39
|
+
};
|
package/src/lib/Tab.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tab as MuiTab, TabProps as MuiTabProps } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export type TabProps = Omit<
|
|
4
|
+
MuiTabProps,
|
|
5
|
+
| 'centerRipple'
|
|
6
|
+
| 'disableFocusRipple'
|
|
7
|
+
| 'disableRipple'
|
|
8
|
+
| 'disableTouchRipple'
|
|
9
|
+
| 'focusRipple'
|
|
10
|
+
| 'icon'
|
|
11
|
+
| 'iconPosition'
|
|
12
|
+
| 'TouchRippleProps'
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
export const Tab = (props: TabProps): JSX.Element => {
|
|
16
|
+
return <MuiTab {...props} disableRipple disableFocusRipple disableTouchRipple />;
|
|
17
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
5
|
+
import { TabContext, TabContextProps } from './TabContext';
|
|
6
|
+
import { Divider } from '@availity/mui-divider';
|
|
7
|
+
import { TabList } from './TabList';
|
|
8
|
+
import { Tab } from './Tab';
|
|
9
|
+
import { TabPanel } from './TabPanel';
|
|
10
|
+
|
|
11
|
+
const meta: Meta<typeof TabContext> = {
|
|
12
|
+
title: 'Components/Tabs/TabContext',
|
|
13
|
+
component: TabContext,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
|
|
19
|
+
export const _TabContext: StoryObj<typeof TabContext> = {
|
|
20
|
+
render: (args: TabContextProps) => {
|
|
21
|
+
const [value, setValue] = useState('1');
|
|
22
|
+
|
|
23
|
+
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
|
|
24
|
+
setValue(newValue);
|
|
25
|
+
};
|
|
26
|
+
return (
|
|
27
|
+
<TabContext {...args} value={value}>
|
|
28
|
+
<TabList onChange={handleChange} aria-label="lab API tabs example">
|
|
29
|
+
<Tab label="Item One" value="1" />
|
|
30
|
+
<Tab label="Item Two" value="2" />
|
|
31
|
+
<Tab label="Item Three" value="3" />
|
|
32
|
+
</TabList>
|
|
33
|
+
<Divider />
|
|
34
|
+
<TabPanel value="1">Item One</TabPanel>
|
|
35
|
+
<TabPanel value="2">Item Two</TabPanel>
|
|
36
|
+
<TabPanel value="3">Item Three</TabPanel>
|
|
37
|
+
</TabContext>
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
args: {},
|
|
41
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { TabContext } from './TabContext';
|
|
3
|
+
import { Divider } from '@availity/mui-divider';
|
|
4
|
+
import { TabList } from './TabList';
|
|
5
|
+
import { Tab } from './Tab';
|
|
6
|
+
import { TabPanel } from './TabPanel';
|
|
7
|
+
|
|
8
|
+
describe('TabContext', () => {
|
|
9
|
+
test('should render successfully', () => {
|
|
10
|
+
const { getByText } = render(
|
|
11
|
+
<TabContext value="1">
|
|
12
|
+
<TabList aria-label="lab API tabs example">
|
|
13
|
+
<Tab label="Item One" value="1" />
|
|
14
|
+
<Tab label="Item Two" value="2" />
|
|
15
|
+
<Tab label="Item Three" value="3" />
|
|
16
|
+
</TabList>
|
|
17
|
+
<Divider />
|
|
18
|
+
<TabPanel value="1">This is item One</TabPanel>
|
|
19
|
+
<TabPanel value="2">This is item Two</TabPanel>
|
|
20
|
+
<TabPanel value="3">This is item Three</TabPanel>
|
|
21
|
+
</TabContext>
|
|
22
|
+
);
|
|
23
|
+
expect(getByText('This is item One')).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TabContext as MuiTabContext, TabContextProps as MuiTabContextProps } from '@mui/lab';
|
|
2
|
+
|
|
3
|
+
export interface TabContextProps extends MuiTabContextProps {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const TabContext = ({ children, ...rest }: TabContextProps): JSX.Element => {
|
|
8
|
+
return <MuiTabContext {...rest}>{children}</MuiTabContext>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
5
|
+
import { TabList, TabListProps } from './TabList';
|
|
6
|
+
import { Tab } from './Tab';
|
|
7
|
+
import { TabContext } from './TabContext';
|
|
8
|
+
|
|
9
|
+
const meta: Meta<typeof TabList> = {
|
|
10
|
+
title: 'Components/Tabs/TabList',
|
|
11
|
+
component: TabList,
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
export const _TabList: StoryObj<typeof TabList> = {
|
|
18
|
+
render: (args: TabListProps) => {
|
|
19
|
+
const [value, setValue] = useState('1');
|
|
20
|
+
|
|
21
|
+
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
|
|
22
|
+
setValue(newValue);
|
|
23
|
+
};
|
|
24
|
+
return (
|
|
25
|
+
<TabContext value={value}>
|
|
26
|
+
<TabList {...args} onChange={handleChange} aria-label="lab API tabs example">
|
|
27
|
+
<Tab label="Item One" value="1" />
|
|
28
|
+
<Tab label="Item Two" value="2" />
|
|
29
|
+
<Tab label="Item Three" value="3" />
|
|
30
|
+
</TabList>
|
|
31
|
+
</TabContext>
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
args: {},
|
|
35
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { TabList } from './TabList';
|
|
3
|
+
import { Tab } from './Tab';
|
|
4
|
+
import { TabContext } from './TabContext';
|
|
5
|
+
|
|
6
|
+
describe('TabList', () => {
|
|
7
|
+
test('should render successfully', () => {
|
|
8
|
+
const { getByRole } = render(
|
|
9
|
+
<TabContext value={'1'}>
|
|
10
|
+
<TabList aria-label="lab API tabs example">
|
|
11
|
+
<Tab label="Item One" value="1" />
|
|
12
|
+
<Tab label="Item Two" value="2" />
|
|
13
|
+
<Tab label="Item Three" value="3" />
|
|
14
|
+
</TabList>
|
|
15
|
+
</TabContext>
|
|
16
|
+
);
|
|
17
|
+
expect(getByRole('tablist')).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TabList as MuiTabList, TabListProps as MuiTabListProps } from '@mui/lab';
|
|
2
|
+
|
|
3
|
+
export interface TabListProps
|
|
4
|
+
extends Omit<
|
|
5
|
+
MuiTabListProps,
|
|
6
|
+
| 'centered'
|
|
7
|
+
| 'centerRipple'
|
|
8
|
+
| 'disableRipple'
|
|
9
|
+
| 'disableTouchRipple'
|
|
10
|
+
| 'focusRipple'
|
|
11
|
+
| 'orientation'
|
|
12
|
+
| 'TouchRippleProps'
|
|
13
|
+
| 'touchRippleRef'
|
|
14
|
+
> {
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const TabList = ({ children, ...rest }: TabListProps): JSX.Element => {
|
|
19
|
+
return (
|
|
20
|
+
<MuiTabList {...rest} disableRipple disableTouchRipple orientation="horizontal" centered={false}>
|
|
21
|
+
{children}
|
|
22
|
+
</MuiTabList>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { TabContext } from './TabContext';
|
|
5
|
+
import { Divider } from '@availity/mui-divider';
|
|
6
|
+
import { TabList } from './TabList';
|
|
7
|
+
import { Tab } from './Tab';
|
|
8
|
+
import { TabPanel, TabPanelProps } from './TabPanel';
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof TabPanel> = {
|
|
11
|
+
title: 'Components/Tabs/TabPanel',
|
|
12
|
+
component: TabContext,
|
|
13
|
+
tags: ['autodocs'],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default meta;
|
|
17
|
+
|
|
18
|
+
export const _TabPanel: StoryObj<typeof TabPanel> = {
|
|
19
|
+
render: (args: TabPanelProps) => {
|
|
20
|
+
return (
|
|
21
|
+
<TabContext value="1">
|
|
22
|
+
<TabList aria-label="lab API tabs example">
|
|
23
|
+
<Tab label="Item One" value="1" />
|
|
24
|
+
</TabList>
|
|
25
|
+
<Divider />
|
|
26
|
+
<TabPanel {...args} value="1" />
|
|
27
|
+
</TabContext>
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
args: {
|
|
31
|
+
children: 'Item One',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { TabContext } from './TabContext';
|
|
3
|
+
import { Divider } from '@availity/mui-divider';
|
|
4
|
+
import { TabList } from './TabList';
|
|
5
|
+
import { Tab } from './Tab';
|
|
6
|
+
import { TabPanel } from './TabPanel';
|
|
7
|
+
|
|
8
|
+
describe('TabContext', () => {
|
|
9
|
+
test('should render successfully', () => {
|
|
10
|
+
const { getByText } = render(
|
|
11
|
+
<TabContext value="1">
|
|
12
|
+
<TabList aria-label="lab API tabs example">
|
|
13
|
+
<Tab label="Item One" value="1" />
|
|
14
|
+
<Tab label="Item Two" value="2" />
|
|
15
|
+
<Tab label="Item Three" value="3" />
|
|
16
|
+
</TabList>
|
|
17
|
+
<Divider />
|
|
18
|
+
<TabPanel value="1">This is item One</TabPanel>
|
|
19
|
+
<TabPanel value="2">This is item Two</TabPanel>
|
|
20
|
+
<TabPanel value="3">This is item Three</TabPanel>
|
|
21
|
+
</TabContext>
|
|
22
|
+
);
|
|
23
|
+
expect(getByText('This is item One')).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TabPanel as MuiTabPanel, TabPanelProps as MuiTabPanelProps } from '@mui/lab';
|
|
2
|
+
|
|
3
|
+
export interface TabPanelProps extends MuiTabPanelProps {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const TabPanel = ({ children, ...rest }: TabPanelProps): JSX.Element => {
|
|
8
|
+
return <MuiTabPanel {...rest}>{children}</MuiTabPanel>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
5
|
+
import { Tabs, TabsProps } from './Tabs';
|
|
6
|
+
import { Tab } from './Tab';
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof Tabs> = {
|
|
9
|
+
title: 'Components/Tabs/Tabs',
|
|
10
|
+
component: Tabs,
|
|
11
|
+
tags: ['autodocs'],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
function a11yProps(index: number) {
|
|
17
|
+
return {
|
|
18
|
+
id: `simple-tab-${index}`,
|
|
19
|
+
'aria-controls': `simple-tabpanel-${index}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const _Tabs: StoryObj<typeof Tabs> = {
|
|
24
|
+
render: (args: TabsProps) => {
|
|
25
|
+
const [value, setValue] = useState(0);
|
|
26
|
+
|
|
27
|
+
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
|
28
|
+
setValue(newValue);
|
|
29
|
+
};
|
|
30
|
+
return (
|
|
31
|
+
<Tabs {...args} value={value} onChange={handleChange}>
|
|
32
|
+
<Tab label="Item One" {...a11yProps(0)} />
|
|
33
|
+
<Tab label="Item Two" {...a11yProps(1)} />
|
|
34
|
+
<Tab label="Item Three" {...a11yProps(2)} />
|
|
35
|
+
</Tabs>
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
};
|
package/src/lib/Tabs.tsx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Tabs as MuiTabs, TabsProps as MuiTabsProps } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export interface TabsProps
|
|
4
|
+
extends Omit<
|
|
5
|
+
MuiTabsProps,
|
|
6
|
+
| 'centered'
|
|
7
|
+
| 'centerRipple'
|
|
8
|
+
| 'disableFocusRipple'
|
|
9
|
+
| 'disableRipple'
|
|
10
|
+
| 'disableTouchRipple'
|
|
11
|
+
| 'focusRipple'
|
|
12
|
+
| 'orientation'
|
|
13
|
+
| 'TouchRippleProps'
|
|
14
|
+
| 'touchRippleRef'
|
|
15
|
+
> {
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const Tabs = ({ children, ...rest }: TabsProps): JSX.Element => {
|
|
20
|
+
return (
|
|
21
|
+
<MuiTabs {...rest} disableRipple disableTouchRipple orientation="horizontal" centered={false}>
|
|
22
|
+
{children}
|
|
23
|
+
</MuiTabs>
|
|
24
|
+
);
|
|
25
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
+
"allowJs": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
|
|
10
|
+
}
|