@availity/mui-breadcrumbs 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 +15 -0
- package/README.md +61 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +74 -0
- package/dist/index.mjs +47 -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/Breadcrumbs.stories.tsx +32 -0
- package/src/lib/Breadcrumbs.test.tsx +117 -0
- package/src/lib/Breadcrumbs.tsx +53 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (2023-07-13)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-breadcrumbs:** initial commit ([39aa735](https://github.com/Availity/element/commit/39aa735c3e9c4b2d8492703924cef25b5337882b))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **mui-breadcrumbs:** import deps ([e131b21](https://github.com/Availity/element/commit/e131b2193a4b3cc7d51a093e71cef932c17cda6e))
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @availity/mui-breadcrumbs
|
|
2
|
+
|
|
3
|
+
> Availity MUI Breadcrumbs component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-breadcrumbs)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-breadcrumbs)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-breadcrumbs/package.json)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
This package extends the MUI Breadcrumbs component: [MUI Breadcrumbs Docs](https://mui.com/components/breadcrumbs/)
|
|
12
|
+
|
|
13
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-breadcrumbs-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-breadcrumbs
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Yarn
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @availity/mui-breadcrumbs
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
#### Import through @availity/element
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Breadcrumbs } from '@availity/element';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Direct import
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Breadcrumbs } from '@availity/mui-breadcrumbs';
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BreadcrumbsProps as BreadcrumbsProps$1 } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
interface Crumb {
|
|
4
|
+
/** The name of the ancestor page. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** The url for navigating to the ancestor page. */
|
|
7
|
+
url: string;
|
|
8
|
+
}
|
|
9
|
+
interface BreadcrumbsProps extends Omit<BreadcrumbsProps$1, 'separator'> {
|
|
10
|
+
/** The name of the active page (the page the user is currently on). */
|
|
11
|
+
active?: string;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
/** The ancestor pages. */
|
|
14
|
+
crumbs?: Crumb[];
|
|
15
|
+
/** The value to display when the active page or an ancestor does not have a value.
|
|
16
|
+
* @default ... */
|
|
17
|
+
emptyState?: string;
|
|
18
|
+
/** Url for the Home route.
|
|
19
|
+
* @default /public/apps/dashboard */
|
|
20
|
+
homeUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
declare const Breadcrumbs: ({ active, children, crumbs, emptyState, homeUrl, ...rest }: BreadcrumbsProps) => JSX.Element;
|
|
23
|
+
|
|
24
|
+
export { Breadcrumbs, BreadcrumbsProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
Breadcrumbs: () => Breadcrumbs
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/Breadcrumbs.tsx
|
|
28
|
+
var import_material = require("@mui/material");
|
|
29
|
+
var import_mui_icon = require("@availity/mui-icon");
|
|
30
|
+
var import_mui_link = require("@availity/mui-link");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var Breadcrumbs = ({
|
|
33
|
+
active,
|
|
34
|
+
children,
|
|
35
|
+
crumbs,
|
|
36
|
+
emptyState = "...",
|
|
37
|
+
homeUrl = "/public/apps/dashboard",
|
|
38
|
+
...rest
|
|
39
|
+
}) => {
|
|
40
|
+
const renderBreadCrumb = ({ name = emptyState, url }) => {
|
|
41
|
+
const props = {
|
|
42
|
+
"aria-label": name,
|
|
43
|
+
children: name
|
|
44
|
+
};
|
|
45
|
+
return url ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_link.Link, {
|
|
46
|
+
...props,
|
|
47
|
+
href: url
|
|
48
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, {
|
|
49
|
+
...props
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Breadcrumbs, {
|
|
53
|
+
...rest,
|
|
54
|
+
separator: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_icon.NavigateNextIcon, {
|
|
55
|
+
fontSize: "small"
|
|
56
|
+
}),
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_link.Link, {
|
|
59
|
+
"aria-label": "Home",
|
|
60
|
+
href: homeUrl,
|
|
61
|
+
children: "Home"
|
|
62
|
+
}),
|
|
63
|
+
crumbs && crumbs.length > 0 && crumbs.map((crumb) => renderBreadCrumb(crumb)),
|
|
64
|
+
children,
|
|
65
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Typography, {
|
|
66
|
+
children: active || emptyState
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
Breadcrumbs
|
|
74
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/lib/Breadcrumbs.tsx
|
|
2
|
+
import { Breadcrumbs as MuiBreadcrumbs, Typography } from "@mui/material";
|
|
3
|
+
import { NavigateNextIcon } from "@availity/mui-icon";
|
|
4
|
+
import { Link } from "@availity/mui-link";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
var Breadcrumbs = ({
|
|
7
|
+
active,
|
|
8
|
+
children,
|
|
9
|
+
crumbs,
|
|
10
|
+
emptyState = "...",
|
|
11
|
+
homeUrl = "/public/apps/dashboard",
|
|
12
|
+
...rest
|
|
13
|
+
}) => {
|
|
14
|
+
const renderBreadCrumb = ({ name = emptyState, url }) => {
|
|
15
|
+
const props = {
|
|
16
|
+
"aria-label": name,
|
|
17
|
+
children: name
|
|
18
|
+
};
|
|
19
|
+
return url ? /* @__PURE__ */ jsx(Link, {
|
|
20
|
+
...props,
|
|
21
|
+
href: url
|
|
22
|
+
}) : /* @__PURE__ */ jsx(Typography, {
|
|
23
|
+
...props
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return /* @__PURE__ */ jsxs(MuiBreadcrumbs, {
|
|
27
|
+
...rest,
|
|
28
|
+
separator: /* @__PURE__ */ jsx(NavigateNextIcon, {
|
|
29
|
+
fontSize: "small"
|
|
30
|
+
}),
|
|
31
|
+
children: [
|
|
32
|
+
/* @__PURE__ */ jsx(Link, {
|
|
33
|
+
"aria-label": "Home",
|
|
34
|
+
href: homeUrl,
|
|
35
|
+
children: "Home"
|
|
36
|
+
}),
|
|
37
|
+
crumbs && crumbs.length > 0 && crumbs.map((crumb) => renderBreadCrumb(crumb)),
|
|
38
|
+
children,
|
|
39
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
40
|
+
children: active || emptyState
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
Breadcrumbs
|
|
47
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-breadcrumbs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Breadcrumbs 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-breadcrumbs-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/breadcrumbs"
|
|
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
|
+
"devDependencies": {
|
|
36
|
+
"@mui/material": "^5.11.9",
|
|
37
|
+
"react": "18.2.0",
|
|
38
|
+
"react-dom": "18.2.0",
|
|
39
|
+
"tsup": "^5.12.7",
|
|
40
|
+
"typescript": "^4.6.4"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@mui/material": "^5.11.9",
|
|
44
|
+
"react": ">=16.3.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@availity/mui-icon": "^0.4.0",
|
|
51
|
+
"@availity/mui-link": "^0.1.0"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-breadcrumbs",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/breadcrumbs/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/breadcrumbs/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/breadcrumbs/.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/breadcrumbs"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/breadcrumbs/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/Breadcrumbs';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { Breadcrumbs, BreadcrumbsProps } from './Breadcrumbs';
|
|
5
|
+
import { Link } from '@availity/mui-link';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Breadcrumbs> = {
|
|
8
|
+
title: 'Components/Breadcrumbs/Breadcrumbs',
|
|
9
|
+
component: Breadcrumbs,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
|
|
15
|
+
export const _Breadcrumbs: StoryObj<typeof Breadcrumbs> = {
|
|
16
|
+
render: (args: BreadcrumbsProps) => <Breadcrumbs {...args} />,
|
|
17
|
+
args: {
|
|
18
|
+
active: 'Current Page',
|
|
19
|
+
crumbs: [{ name: 'Previous Page', url: '#' }],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const _BreadcrumbsChildren: StoryObj<typeof Breadcrumbs> = {
|
|
24
|
+
render: (args: BreadcrumbsProps) => (
|
|
25
|
+
<Breadcrumbs {...args}>
|
|
26
|
+
<Link href="">Previous Page</Link>
|
|
27
|
+
</Breadcrumbs>
|
|
28
|
+
),
|
|
29
|
+
args: {
|
|
30
|
+
active: 'Current Page',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { Breadcrumbs } from './Breadcrumbs';
|
|
3
|
+
import { Link } from '@availity/mui-link';
|
|
4
|
+
|
|
5
|
+
describe('Breadcrumbs', () => {
|
|
6
|
+
describe('rending with crumbs', () => {
|
|
7
|
+
test('should render successfully with crumbs', () => {
|
|
8
|
+
const { getByTestId } = render(
|
|
9
|
+
<Breadcrumbs
|
|
10
|
+
data-testid="testBreadcrumbs"
|
|
11
|
+
crumbs={[
|
|
12
|
+
{ name: 'Grand Parent', url: '/grandparent' },
|
|
13
|
+
{ name: 'Parent', url: '/grandparent/parent' },
|
|
14
|
+
]}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const breadcrumbs = getByTestId('testBreadcrumbs').getElementsByClassName('MuiBreadcrumbs-li');
|
|
19
|
+
|
|
20
|
+
expect(breadcrumbs.length).toBe(4);
|
|
21
|
+
|
|
22
|
+
const homeBreadcrumb = breadcrumbs[0].getElementsByTagName('a')[0];
|
|
23
|
+
expect(homeBreadcrumb).toHaveAttribute('aria-label', 'Home');
|
|
24
|
+
expect(homeBreadcrumb).toHaveAttribute(
|
|
25
|
+
'href',
|
|
26
|
+
'/public/apps/home/#!/loadApp?appUrl=%2Fpublic%2Fapps%2Fdashboard'
|
|
27
|
+
);
|
|
28
|
+
expect(homeBreadcrumb).toHaveTextContent('Home');
|
|
29
|
+
|
|
30
|
+
const grandparentBreadcrumb = breadcrumbs[1].getElementsByTagName('a')[0];
|
|
31
|
+
expect(grandparentBreadcrumb).toHaveAttribute('aria-label', 'Grand Parent');
|
|
32
|
+
expect(grandparentBreadcrumb).toHaveAttribute('href', '/public/apps/home/#!/loadApp?appUrl=%2Fgrandparent');
|
|
33
|
+
expect(grandparentBreadcrumb).toHaveTextContent('Grand Parent');
|
|
34
|
+
|
|
35
|
+
const parentBreadcrumb = breadcrumbs[2].getElementsByTagName('a')[0];
|
|
36
|
+
expect(parentBreadcrumb).toHaveAttribute('aria-label', 'Parent');
|
|
37
|
+
expect(parentBreadcrumb).toHaveAttribute('href', '/public/apps/home/#!/loadApp?appUrl=%2Fgrandparent%2Fparent');
|
|
38
|
+
expect(parentBreadcrumb).toHaveTextContent('Parent');
|
|
39
|
+
|
|
40
|
+
const currentPageBreadcrumb = breadcrumbs[3].getElementsByTagName('p')[0];
|
|
41
|
+
expect(currentPageBreadcrumb).not.toHaveAttribute('aria-label');
|
|
42
|
+
expect(currentPageBreadcrumb).not.toHaveAttribute('href');
|
|
43
|
+
expect(currentPageBreadcrumb).toHaveTextContent('...');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('should render successfully with children', () => {
|
|
47
|
+
const { getByTestId } = render(
|
|
48
|
+
<Breadcrumbs data-testid="testBreadcrumbs" children={<Link href="/custom/url">Custom Breadcrumb</Link>} />
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const breadcrumbs = getByTestId('testBreadcrumbs').getElementsByClassName('MuiBreadcrumbs-li');
|
|
52
|
+
|
|
53
|
+
expect(breadcrumbs.length).toBe(3);
|
|
54
|
+
|
|
55
|
+
const homeBreadcrumb = breadcrumbs[0].getElementsByTagName('a')[0];
|
|
56
|
+
expect(homeBreadcrumb).toHaveAttribute('aria-label', 'Home');
|
|
57
|
+
expect(homeBreadcrumb).toHaveAttribute(
|
|
58
|
+
'href',
|
|
59
|
+
'/public/apps/home/#!/loadApp?appUrl=%2Fpublic%2Fapps%2Fdashboard'
|
|
60
|
+
);
|
|
61
|
+
expect(homeBreadcrumb).toHaveTextContent('Home');
|
|
62
|
+
|
|
63
|
+
const customBreadcrumb = breadcrumbs[1].getElementsByTagName('a')[0];
|
|
64
|
+
expect(customBreadcrumb).toHaveAttribute('href', '/public/apps/home/#!/loadApp?appUrl=%2Fcustom%2Furl');
|
|
65
|
+
expect(customBreadcrumb).toHaveTextContent('Custom Breadcrumb');
|
|
66
|
+
|
|
67
|
+
const currentPageBreadcrumb = breadcrumbs[2].getElementsByTagName('p')[0];
|
|
68
|
+
expect(currentPageBreadcrumb).not.toHaveAttribute('aria-label');
|
|
69
|
+
expect(currentPageBreadcrumb).not.toHaveAttribute('href');
|
|
70
|
+
expect(currentPageBreadcrumb).toHaveTextContent('...');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('should render successfully with a combination of children and crumbs', () => {
|
|
74
|
+
const { getByTestId } = render(
|
|
75
|
+
<Breadcrumbs
|
|
76
|
+
data-testid="testBreadcrumbs"
|
|
77
|
+
children={<Link href="/custom/url">Custom Breadcrumb</Link>}
|
|
78
|
+
crumbs={[
|
|
79
|
+
{ name: 'Grand Parent', url: '/grandparent' },
|
|
80
|
+
{ name: 'Parent', url: '/grandparent/parent' },
|
|
81
|
+
]}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const breadcrumbs = getByTestId('testBreadcrumbs').getElementsByClassName('MuiBreadcrumbs-li');
|
|
86
|
+
|
|
87
|
+
expect(breadcrumbs.length).toBe(5);
|
|
88
|
+
|
|
89
|
+
const homeBreadcrumb = breadcrumbs[0].getElementsByTagName('a')[0];
|
|
90
|
+
expect(homeBreadcrumb).toHaveAttribute('aria-label', 'Home');
|
|
91
|
+
expect(homeBreadcrumb).toHaveAttribute(
|
|
92
|
+
'href',
|
|
93
|
+
'/public/apps/home/#!/loadApp?appUrl=%2Fpublic%2Fapps%2Fdashboard'
|
|
94
|
+
);
|
|
95
|
+
expect(homeBreadcrumb).toHaveTextContent('Home');
|
|
96
|
+
|
|
97
|
+
const grandparentBreadcrumb = breadcrumbs[1].getElementsByTagName('a')[0];
|
|
98
|
+
expect(grandparentBreadcrumb).toHaveAttribute('aria-label', 'Grand Parent');
|
|
99
|
+
expect(grandparentBreadcrumb).toHaveAttribute('href', '/public/apps/home/#!/loadApp?appUrl=%2Fgrandparent');
|
|
100
|
+
expect(grandparentBreadcrumb).toHaveTextContent('Grand Parent');
|
|
101
|
+
|
|
102
|
+
const parentBreadcrumb = breadcrumbs[2].getElementsByTagName('a')[0];
|
|
103
|
+
expect(parentBreadcrumb).toHaveAttribute('aria-label', 'Parent');
|
|
104
|
+
expect(parentBreadcrumb).toHaveAttribute('href', '/public/apps/home/#!/loadApp?appUrl=%2Fgrandparent%2Fparent');
|
|
105
|
+
expect(parentBreadcrumb).toHaveTextContent('Parent');
|
|
106
|
+
|
|
107
|
+
const customBreadcrumb = breadcrumbs[3].getElementsByTagName('a')[0];
|
|
108
|
+
expect(customBreadcrumb).toHaveAttribute('href', '/public/apps/home/#!/loadApp?appUrl=%2Fcustom%2Furl');
|
|
109
|
+
expect(customBreadcrumb).toHaveTextContent('Custom Breadcrumb');
|
|
110
|
+
|
|
111
|
+
const currentPageBreadcrumb = breadcrumbs[4].getElementsByTagName('p')[0];
|
|
112
|
+
expect(currentPageBreadcrumb).not.toHaveAttribute('aria-label');
|
|
113
|
+
expect(currentPageBreadcrumb).not.toHaveAttribute('href');
|
|
114
|
+
expect(currentPageBreadcrumb).toHaveTextContent('...');
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Breadcrumbs as MuiBreadcrumbs, BreadcrumbsProps as MuiBreadcrumbsProps, Typography } from '@mui/material';
|
|
2
|
+
import { NavigateNextIcon } from '@availity/mui-icon';
|
|
3
|
+
import { Link } from '@availity/mui-link';
|
|
4
|
+
|
|
5
|
+
interface Crumb {
|
|
6
|
+
/** The name of the ancestor page. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The url for navigating to the ancestor page. */
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface BreadcrumbsProps extends Omit<MuiBreadcrumbsProps, 'separator'> {
|
|
13
|
+
/** The name of the active page (the page the user is currently on). */
|
|
14
|
+
active?: string;
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
/** The ancestor pages. */
|
|
17
|
+
crumbs?: Crumb[];
|
|
18
|
+
/** The value to display when the active page or an ancestor does not have a value.
|
|
19
|
+
* @default ... */
|
|
20
|
+
emptyState?: string;
|
|
21
|
+
/** Url for the Home route.
|
|
22
|
+
* @default /public/apps/dashboard */
|
|
23
|
+
homeUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Breadcrumbs = ({
|
|
27
|
+
active,
|
|
28
|
+
children,
|
|
29
|
+
crumbs,
|
|
30
|
+
emptyState = '...',
|
|
31
|
+
homeUrl = '/public/apps/dashboard',
|
|
32
|
+
...rest
|
|
33
|
+
}: BreadcrumbsProps): JSX.Element => {
|
|
34
|
+
const renderBreadCrumb = ({ name = emptyState, url }: Crumb) => {
|
|
35
|
+
const props = {
|
|
36
|
+
'aria-label': name,
|
|
37
|
+
children: name,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return url ? <Link {...props} href={url} /> : <Typography {...props} />;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<MuiBreadcrumbs {...rest} separator={<NavigateNextIcon fontSize="small" />}>
|
|
45
|
+
<Link aria-label="Home" href={homeUrl}>
|
|
46
|
+
Home
|
|
47
|
+
</Link>
|
|
48
|
+
{crumbs && crumbs.length > 0 && crumbs.map((crumb) => renderBreadCrumb(crumb))}
|
|
49
|
+
{children}
|
|
50
|
+
{<Typography>{active || emptyState}</Typography>}
|
|
51
|
+
</MuiBreadcrumbs>
|
|
52
|
+
);
|
|
53
|
+
};
|
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
|
+
}
|