@mbao01/ui 0.0.9 → 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/package.json +8 -3
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +30 -0
- package/src/components/Breadcrumbs/constant.ts +17 -0
- package/src/components/Breadcrumbs/index.ts +1 -0
- package/src/components/Breadcrumbs/types.ts +4 -0
- package/src/components/Link/Link.tsx +31 -0
- package/src/components/Link/constant.ts +21 -0
- package/src/components/Link/index.ts +1 -0
- package/src/components/Link/types.ts +19 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/ui",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"daisyui": "^4.4.24"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
+
"@heroicons/react": "^2.1.1",
|
|
47
48
|
"@storybook/addon-essentials": "^7.6.6",
|
|
48
49
|
"@storybook/addon-interactions": "^7.6.6",
|
|
49
50
|
"@storybook/addon-links": "^7.6.6",
|
|
@@ -74,7 +75,9 @@
|
|
|
74
75
|
"postcss": "^8.4.32",
|
|
75
76
|
"react": "^18.2.0",
|
|
76
77
|
"react-dom": "^18.2.0",
|
|
77
|
-
"
|
|
78
|
+
"react-router-dom": "^6.21.3",
|
|
79
|
+
"storybook": "^7.6.10",
|
|
80
|
+
"storybook-addon-react-router-v6": "^2.0.10",
|
|
78
81
|
"tailwindcss": "^3.4.0",
|
|
79
82
|
"typescript": "^5.2.2",
|
|
80
83
|
"vite": "^5.0.8",
|
|
@@ -82,11 +85,13 @@
|
|
|
82
85
|
"vitest": "^1.1.1"
|
|
83
86
|
},
|
|
84
87
|
"peerDependencies": {
|
|
88
|
+
"@heroicons/react": "^2.1.1",
|
|
85
89
|
"postcss": "^8.4.32",
|
|
86
90
|
"react": "^18.2.0",
|
|
87
91
|
"react-dom": "^18.2.0",
|
|
92
|
+
"react-router-dom": "^6.21.3",
|
|
88
93
|
"tailwindcss": "^3.4.0",
|
|
89
94
|
"typescript": "^5.2.2"
|
|
90
95
|
},
|
|
91
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "f59eb6ddcd7936eb43ccff7f829d6393ed3a2690"
|
|
92
97
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useLocation } from "react-router-dom";
|
|
2
|
+
import { getBreadcrumbs } from "./constant";
|
|
3
|
+
import type { BreadcrumbsProps } from "./types";
|
|
4
|
+
import { Link } from "../Link";
|
|
5
|
+
|
|
6
|
+
export const Breadcrumbs = ({ root, labels }: BreadcrumbsProps) => {
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
const breadcrumbs = getBreadcrumbs(location.pathname, labels);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div className="breadcrumbs -ml-1 w-fit px-1 text-sm">
|
|
12
|
+
<ul>
|
|
13
|
+
{root && (
|
|
14
|
+
<li>
|
|
15
|
+
<Link hover href="/">
|
|
16
|
+
{root}
|
|
17
|
+
</Link>
|
|
18
|
+
</li>
|
|
19
|
+
)}
|
|
20
|
+
{breadcrumbs.map((crumb) => (
|
|
21
|
+
<li key={crumb.href.pathname}>
|
|
22
|
+
<Link hover href={crumb.href} className="capitalize">
|
|
23
|
+
{crumb.segment}
|
|
24
|
+
</Link>
|
|
25
|
+
</li>
|
|
26
|
+
))}
|
|
27
|
+
</ul>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const getBreadcrumbs = (
|
|
2
|
+
pathname: string,
|
|
3
|
+
labels?: Record<string, string>
|
|
4
|
+
) => {
|
|
5
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
6
|
+
|
|
7
|
+
const breadcrumbs = segments.map((segment, index) => {
|
|
8
|
+
const path = `/${segments.slice(0, index + 1).join("/")}`;
|
|
9
|
+
return {
|
|
10
|
+
href: { pathname: path },
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
12
|
+
segment: labels?.[segment] || segment, // always fallback to segment if label is falsy
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return breadcrumbs;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Breadcrumbs } from './Breadcrumbs';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import c from "clsx";
|
|
2
|
+
import { Link as RouterLink } from "react-router-dom";
|
|
3
|
+
import { getLinkClasses } from "./constant";
|
|
4
|
+
import { type LinkProps } from "./types";
|
|
5
|
+
import { ArrowUpRightIcon } from "@heroicons/react/20/solid";
|
|
6
|
+
|
|
7
|
+
export const Link = ({
|
|
8
|
+
href,
|
|
9
|
+
hover,
|
|
10
|
+
target,
|
|
11
|
+
variant,
|
|
12
|
+
children,
|
|
13
|
+
className,
|
|
14
|
+
...props
|
|
15
|
+
}: LinkProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<RouterLink
|
|
18
|
+
{...props}
|
|
19
|
+
to={href}
|
|
20
|
+
className={c(getLinkClasses({ hover, variant }), className)}
|
|
21
|
+
>
|
|
22
|
+
{children}
|
|
23
|
+
{target === "_blank" && (
|
|
24
|
+
<ArrowUpRightIcon
|
|
25
|
+
name="external"
|
|
26
|
+
className="ml-[2px] inline h-4 w-4 align-middle"
|
|
27
|
+
/>
|
|
28
|
+
)}
|
|
29
|
+
</RouterLink>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import c from 'clsx';
|
|
2
|
+
import { LinkVariant } from './types';
|
|
3
|
+
|
|
4
|
+
const LINK_VARIANTS = {
|
|
5
|
+
accent: c('link-accent'),
|
|
6
|
+
default: c('link-default'),
|
|
7
|
+
error: c('link-error'),
|
|
8
|
+
info: c('link-info'),
|
|
9
|
+
link: c('link-link'),
|
|
10
|
+
neutral: c('link-neutral'),
|
|
11
|
+
primary: c('link-primary'),
|
|
12
|
+
secondary: c('link-secondary'),
|
|
13
|
+
success: c('link-success'),
|
|
14
|
+
warning: c('link-warning'),
|
|
15
|
+
} satisfies Record<LinkVariant, string>;
|
|
16
|
+
|
|
17
|
+
export const getLinkClasses = ({ hover, variant }: { hover?: boolean; variant?: LinkVariant }) => {
|
|
18
|
+
return c('link transition-all', LINK_VARIANTS[variant!], {
|
|
19
|
+
'link-hover': hover,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Link } from './Link';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { To, LinkProps as RouterLinkProps } from "react-router-dom";
|
|
2
|
+
|
|
3
|
+
export type LinkVariant =
|
|
4
|
+
| "default"
|
|
5
|
+
| "neutral"
|
|
6
|
+
| "primary"
|
|
7
|
+
| "secondary"
|
|
8
|
+
| "accent"
|
|
9
|
+
| "link"
|
|
10
|
+
| "info"
|
|
11
|
+
| "success"
|
|
12
|
+
| "warning"
|
|
13
|
+
| "error";
|
|
14
|
+
|
|
15
|
+
export type LinkProps = Omit<RouterLinkProps, "to"> & {
|
|
16
|
+
href: To;
|
|
17
|
+
hover?: boolean;
|
|
18
|
+
variant?: LinkVariant;
|
|
19
|
+
};
|