@mbao01/ui 0.0.9 → 0.1.1

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.
@@ -0,0 +1,2 @@
1
+ import type { BreadcrumbsProps } from "./types";
2
+ export declare const Breadcrumbs: ({ root, labels }: BreadcrumbsProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ export declare const getBreadcrumbs: (pathname: string, labels?: Record<string, string>) => {
2
+ href: {
3
+ pathname: string;
4
+ };
5
+ segment: string;
6
+ }[];
@@ -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,2 @@
1
+ import { type ButtonProps } from "./types";
2
+ export declare const Button: (props: ButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { ButtonSize, ButtonVariant } from './types';
2
+ export declare const getButtonClasses: ({ size, wide, loading, outline, variant, }: {
3
+ size?: ButtonSize | undefined;
4
+ wide?: boolean | undefined;
5
+ loading?: boolean | undefined;
6
+ outline?: boolean | undefined;
7
+ variant?: ButtonVariant | undefined;
8
+ }) => string;
@@ -0,0 +1 @@
1
+ export { Button } from "./Button";
@@ -0,0 +1,12 @@
1
+ import type { ButtonHTMLAttributes, ReactNode } from 'react';
2
+ export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
3
+ export type ButtonVariant = 'default' | 'neutral' | 'primary' | 'secondary' | 'accent' | 'ghost' | 'link' | 'info' | 'success' | 'warning' | 'error';
4
+ export type ButtonProps = {
5
+ size?: ButtonSize;
6
+ wide?: boolean;
7
+ label: ReactNode;
8
+ loading?: boolean;
9
+ outline?: boolean;
10
+ variant?: ButtonVariant;
11
+ disabled?: boolean;
12
+ } & ButtonHTMLAttributes<HTMLButtonElement>;
@@ -0,0 +1,2 @@
1
+ import { type LinkProps } from "./types";
2
+ export declare const Link: ({ href, hover, target, variant, children, className, ...props }: LinkProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { LinkVariant } from './types';
2
+ export declare const getLinkClasses: ({ hover, variant }: {
3
+ hover?: boolean | undefined;
4
+ variant?: LinkVariant | undefined;
5
+ }) => string;
@@ -0,0 +1 @@
1
+ export { Link } from './Link';
@@ -0,0 +1,7 @@
1
+ import type { To, LinkProps as RouterLinkProps } from "react-router-dom";
2
+ export type LinkVariant = "default" | "neutral" | "primary" | "secondary" | "accent" | "link" | "info" | "success" | "warning" | "error";
3
+ export type LinkProps = Omit<RouterLinkProps, "to"> & {
4
+ href: To;
5
+ hover?: boolean;
6
+ variant?: LinkVariant;
7
+ };
@@ -0,0 +1,4 @@
1
+ import { type TextProps } from './types';
2
+ export declare const Text: ({ as, size, variant, children, className }: TextProps) => import("react").DetailedReactHTMLElement<{
3
+ className: string;
4
+ }, HTMLElement>;
@@ -0,0 +1,5 @@
1
+ import type { TextSize, TextVariant } from './types';
2
+ export declare const getTextClasses: ({ size, variant }: {
3
+ size?: TextSize | undefined;
4
+ variant?: TextVariant | undefined;
5
+ }) => string;
@@ -0,0 +1 @@
1
+ export { Text } from './Text';
@@ -0,0 +1,10 @@
1
+ export type TextSize = 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
2
+ export type TextTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'p' | 'span';
3
+ export type TextVariant = 'info' | 'error' | 'success' | 'warning' | 'primary' | 'secondary' | 'accent' | 'neutral';
4
+ export type TextProps = {
5
+ as?: TextTag;
6
+ size?: TextSize;
7
+ variant?: TextVariant;
8
+ children: React.ReactNode;
9
+ className?: string;
10
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./components/Breadcrumbs";
2
+ export * from "./components/Button";
3
+ export * from "./components/Link";
4
+ export * from "./components/Text";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/ui",
3
3
  "private": false,
4
- "version": "0.0.9",
4
+ "version": "0.1.1",
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
- "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",
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": "10e56e5ce5495f4c29d84d7fc1a53622c436f72f"
96
+ "gitHead": "a8f9e309d549d280a3c3b1048ab7946d554744bd"
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,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
+ };
package/src/index.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export * from "./components/Breadcrumbs";
1
2
  export * from "./components/Button";
3
+ export * from "./components/Link";
2
4
  export * from "./components/Text";