@mbao01/ui 0.0.8 → 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/README.md CHANGED
@@ -1,6 +1,4 @@
1
1
 
2
- ---
3
-
4
2
  So here it is, I have gotten really bored creating UI component from scratch for the many projects I work on.
5
3
  It is high time I have a unified component library - so here it is.
6
4
  I have built this to be highly opinionated on certain libraries I love to use like typescript, tailwind, date-fns, and react.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/ui",
3
3
  "private": false,
4
- "version": "0.0.8",
4
+ "version": "0.1.0",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -20,6 +20,12 @@
20
20
  "plugin.d.ts",
21
21
  "dist/types"
22
22
  ],
23
+ "bugs": "https://github.com/mbao01/mbao01/issues",
24
+ "homepage": "https://ui.ayomidebakare.site",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/mbao01/mbao01.git"
28
+ },
23
29
  "sideEffects": false,
24
30
  "scripts": {
25
31
  "dev": "storybook dev -p 6006",
@@ -38,6 +44,7 @@
38
44
  "daisyui": "^4.4.24"
39
45
  },
40
46
  "devDependencies": {
47
+ "@heroicons/react": "^2.1.1",
41
48
  "@storybook/addon-essentials": "^7.6.6",
42
49
  "@storybook/addon-interactions": "^7.6.6",
43
50
  "@storybook/addon-links": "^7.6.6",
@@ -68,7 +75,9 @@
68
75
  "postcss": "^8.4.32",
69
76
  "react": "^18.2.0",
70
77
  "react-dom": "^18.2.0",
71
- "storybook": "^7.6.6",
78
+ "react-router-dom": "^6.21.3",
79
+ "storybook": "^7.6.10",
80
+ "storybook-addon-react-router-v6": "^2.0.10",
72
81
  "tailwindcss": "^3.4.0",
73
82
  "typescript": "^5.2.2",
74
83
  "vite": "^5.0.8",
@@ -76,11 +85,13 @@
76
85
  "vitest": "^1.1.1"
77
86
  },
78
87
  "peerDependencies": {
88
+ "@heroicons/react": "^2.1.1",
79
89
  "postcss": "^8.4.32",
80
90
  "react": "^18.2.0",
81
91
  "react-dom": "^18.2.0",
92
+ "react-router-dom": "^6.21.3",
82
93
  "tailwindcss": "^3.4.0",
83
94
  "typescript": "^5.2.2"
84
95
  },
85
- "gitHead": "6c20368a9d6ab3655e9d1161a053ffac6945b722"
96
+ "gitHead": "f59eb6ddcd7936eb43ccff7f829d6393ed3a2690"
86
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,4 @@
1
+ export type BreadcrumbsProps = {
2
+ root?: string;
3
+ labels?: Record<string, string>;
4
+ };
@@ -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
+ };