@mbao01/common 0.0.5 → 0.0.7

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.
Files changed (94) hide show
  1. package/README.md +1 -2
  2. package/dist/types/components/Avatar/Avatar.d.ts +14 -0
  3. package/dist/types/components/Avatar/constants.d.ts +15 -0
  4. package/dist/types/components/Avatar/index.d.ts +1 -0
  5. package/dist/types/components/Avatar/types.d.ts +6 -0
  6. package/dist/types/components/Badge/Badge.d.ts +1 -1
  7. package/dist/types/components/Badge/constants.d.ts +5 -5
  8. package/dist/types/components/Badge/types.d.ts +3 -7
  9. package/dist/types/components/Breadcrumbs/Breadcrumbs.d.ts +3 -0
  10. package/dist/types/components/Breadcrumbs/index.d.ts +1 -0
  11. package/dist/types/components/Breadcrumbs/types.d.ts +2 -0
  12. package/dist/types/components/Button/Button.d.ts +11 -2
  13. package/dist/types/components/Button/constants.d.ts +7 -8
  14. package/dist/types/components/Button/types.d.ts +6 -12
  15. package/dist/types/components/Card/Card.d.ts +1 -1
  16. package/dist/types/components/Card/constants.d.ts +6 -0
  17. package/dist/types/components/Card/types.d.ts +3 -18
  18. package/dist/types/components/Description/Description.d.ts +2 -2
  19. package/dist/types/components/Loading/Loading.d.ts +2 -0
  20. package/dist/types/components/Loading/constants.d.ts +5 -0
  21. package/dist/types/components/Loading/index.d.ts +1 -0
  22. package/dist/types/components/Loading/types.d.ts +3 -0
  23. package/dist/types/components/Progress/Progress.d.ts +5 -0
  24. package/dist/types/components/Progress/constants.d.ts +6 -0
  25. package/dist/types/components/Progress/index.d.ts +1 -0
  26. package/dist/types/components/Progress/types.d.ts +4 -0
  27. package/dist/types/components/Separator/Separator.d.ts +2 -0
  28. package/dist/types/components/Separator/constants.d.ts +3 -0
  29. package/dist/types/components/Separator/index.d.ts +1 -0
  30. package/dist/types/components/Separator/types.d.ts +2 -0
  31. package/dist/types/components/Skeleton/Skeleton.d.ts +1 -1
  32. package/dist/types/components/Skeleton/constants.d.ts +6 -5
  33. package/dist/types/components/Skeleton/types.d.ts +3 -7
  34. package/dist/types/components/Text/Text.d.ts +2 -4
  35. package/dist/types/components/Text/constants.d.ts +4 -5
  36. package/dist/types/components/Text/types.d.ts +4 -9
  37. package/dist/types/components/Tooltip/Tooltip.d.ts +14 -2
  38. package/dist/types/components/Tooltip/constants.d.ts +6 -5
  39. package/dist/types/components/Tooltip/types.d.ts +5 -10
  40. package/dist/types/index.d.ts +5 -0
  41. package/dist/types/libs/cva.d.ts +1 -0
  42. package/dist/types/libs/index.d.ts +1 -0
  43. package/dist/types/utilities/cn.d.ts +2 -0
  44. package/dist/types/utilities/getSubpaths/getSubpaths.d.ts +6 -0
  45. package/dist/types/utilities/getSubpaths/index.d.ts +1 -0
  46. package/dist/types/utilities/index.d.ts +2 -0
  47. package/package.json +14 -4
  48. package/plugin.js +1 -3
  49. package/src/components/Avatar/Avatar.tsx +59 -0
  50. package/src/components/Avatar/constants.ts +69 -0
  51. package/src/components/Avatar/index.ts +1 -0
  52. package/src/components/Avatar/types.ts +25 -0
  53. package/src/components/Badge/Badge.tsx +4 -14
  54. package/src/components/Badge/constants.ts +28 -30
  55. package/src/components/Badge/types.ts +4 -17
  56. package/src/components/Breadcrumbs/Breadcrumbs.tsx +13 -0
  57. package/src/components/Breadcrumbs/index.ts +1 -0
  58. package/src/components/Breadcrumbs/types.ts +3 -0
  59. package/src/components/Button/Button.tsx +51 -37
  60. package/src/components/Button/constants.ts +39 -43
  61. package/src/components/Button/types.ts +7 -25
  62. package/src/components/Card/Card.tsx +9 -15
  63. package/src/components/Card/constants.ts +22 -0
  64. package/src/components/Card/types.ts +4 -18
  65. package/src/components/Description/Description.tsx +11 -6
  66. package/src/components/Loading/Loading.tsx +18 -0
  67. package/src/components/Loading/constants.ts +30 -0
  68. package/src/components/Loading/index.ts +1 -0
  69. package/src/components/Loading/types.ts +5 -0
  70. package/src/components/Progress/Progress.tsx +31 -0
  71. package/src/components/Progress/constants.ts +49 -0
  72. package/src/components/Progress/index.ts +1 -0
  73. package/src/components/Progress/types.ts +9 -0
  74. package/src/components/Separator/Separator.tsx +20 -0
  75. package/src/components/Separator/constants.ts +10 -0
  76. package/src/components/Separator/index.ts +1 -0
  77. package/src/components/Separator/types.ts +5 -0
  78. package/src/components/Skeleton/Skeleton.tsx +7 -11
  79. package/src/components/Skeleton/constants.ts +39 -37
  80. package/src/components/Skeleton/types.ts +4 -7
  81. package/src/components/Text/Text.tsx +24 -9
  82. package/src/components/Text/constants.ts +26 -28
  83. package/src/components/Text/types.ts +9 -20
  84. package/src/components/Tooltip/Tooltip.tsx +35 -21
  85. package/src/components/Tooltip/constants.ts +32 -31
  86. package/src/components/Tooltip/types.ts +13 -22
  87. package/src/index.ts +5 -0
  88. package/src/libs/cva.ts +1 -0
  89. package/src/libs/index.ts +1 -0
  90. package/src/utilities/cn.ts +6 -0
  91. package/src/utilities/getSubpaths/getSubpaths.ts +34 -0
  92. package/src/utilities/getSubpaths/index.ts +1 -0
  93. package/src/utilities/index.ts +2 -0
  94. package/vitest-setup.ts +11 -1
@@ -0,0 +1 @@
1
+ export { Avatar } from "./Avatar";
@@ -0,0 +1,25 @@
1
+ import * as AvatarPrimitive from "@radix-ui/react-avatar";
2
+ import { type VariantProps } from "../../libs";
3
+ import {
4
+ getAvatarClasses,
5
+ getAvatarFallbackClasses,
6
+ getAvatarImageClasses,
7
+ } from "./constants";
8
+
9
+ export type AvatarProps = Omit<
10
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>,
11
+ "asChild" | "size"
12
+ > &
13
+ VariantProps<typeof getAvatarClasses>;
14
+
15
+ export type AvatarImageProps = Omit<
16
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>,
17
+ "asChild"
18
+ > &
19
+ VariantProps<typeof getAvatarImageClasses>;
20
+
21
+ export type AvatarFallbackProps = Omit<
22
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>,
23
+ "asChild"
24
+ > &
25
+ VariantProps<typeof getAvatarFallbackClasses>;
@@ -1,28 +1,18 @@
1
- import c from "clsx";
1
+ import { cn } from "../../utilities";
2
2
  import { getBadgeClasses } from "./constants";
3
3
  import { type BadgeProps } from "./types";
4
4
 
5
5
  export const Badge = ({
6
6
  size,
7
7
  outline,
8
- variant = "ghost",
9
- children,
8
+ variant,
10
9
  className,
11
10
  ...props
12
11
  }: BadgeProps) => {
13
12
  return (
14
13
  <span
14
+ className={cn(getBadgeClasses({ size, variant, outline }), className)}
15
15
  {...props}
16
- className={c(
17
- getBadgeClasses({ size, variant }),
18
- {
19
- "badge-outline": outline,
20
- "text-base-200": !["ghost", "neutral"].includes(variant),
21
- },
22
- className
23
- )}
24
- >
25
- {children}
26
- </span>
16
+ />
27
17
  );
28
18
  };
@@ -1,31 +1,29 @@
1
- import c from "clsx";
2
- import type { BadgeSize, BadgeVariant } from "./types";
1
+ import { cva } from "../../libs";
3
2
 
4
- const BADGE_SIZE = {
5
- xs: c("badge-xs"),
6
- sm: c("badge-sm"),
7
- md: c("badge-md"),
8
- lg: c("badge-lg"),
9
- } satisfies Record<BadgeSize, string>;
10
-
11
- const BADGE_VARIANTS = {
12
- accent: c("badge-accent"),
13
- error: c("badge-error"),
14
- ghost: c("badge-ghost"),
15
- info: c("badge-info"),
16
- neutral: c("badge-neutral"),
17
- primary: c("badge-primary"),
18
- secondary: c("badge-secondary"),
19
- success: c("badge-success"),
20
- warning: c("badge-warning"),
21
- } satisfies Record<BadgeVariant, string>;
22
-
23
- export const getBadgeClasses = ({
24
- size,
25
- variant,
26
- }: {
27
- size?: BadgeSize;
28
- variant?: BadgeVariant;
29
- }) => {
30
- return c("badge", BADGE_VARIANTS[variant!], BADGE_SIZE[size!]);
31
- };
3
+ export const getBadgeClasses = cva("badge", {
4
+ variants: {
5
+ variant: {
6
+ accent: "badge-accent",
7
+ error: "badge-error",
8
+ ghost: "badge-ghost",
9
+ info: "badge-info",
10
+ neutral: "badge-neutral",
11
+ primary: "badge-primary",
12
+ secondary: "badge-secondary",
13
+ success: "badge-success",
14
+ warning: "badge-warning",
15
+ },
16
+ outline: {
17
+ true: "badge-outline",
18
+ },
19
+ size: {
20
+ xs: "badge-xs",
21
+ sm: "badge-sm",
22
+ md: "badge-md",
23
+ lg: "badge-lg",
24
+ },
25
+ },
26
+ defaultVariants: {
27
+ variant: "ghost",
28
+ },
29
+ });
@@ -1,18 +1,5 @@
1
- export type BadgeSize = "xs" | "sm" | "md" | "lg";
1
+ import { type VariantProps } from "../../libs";
2
+ import { getBadgeClasses } from "./constants";
2
3
 
3
- export type BadgeVariant =
4
- | "neutral"
5
- | "primary"
6
- | "secondary"
7
- | "accent"
8
- | "ghost"
9
- | "info"
10
- | "success"
11
- | "warning"
12
- | "error";
13
-
14
- export type BadgeProps = React.HTMLAttributes<HTMLSpanElement> & {
15
- size?: BadgeSize;
16
- outline?: boolean;
17
- variant?: BadgeVariant;
18
- };
4
+ export type BadgeProps = React.HTMLAttributes<HTMLSpanElement> &
5
+ VariantProps<typeof getBadgeClasses>;
@@ -0,0 +1,13 @@
1
+ import type { BreadcrumbProps, BreadcrumbsProps } from "./types";
2
+
3
+ export const Breadcrumbs = (props: BreadcrumbsProps) => {
4
+ return (
5
+ <div className="breadcrumbs -ml-1 w-fit px-1 text-sm">
6
+ <ul {...props} />
7
+ </div>
8
+ );
9
+ };
10
+
11
+ export const Breadcrumb = (props: BreadcrumbProps) => {
12
+ return <li {...props} />;
13
+ };
@@ -0,0 +1 @@
1
+ export { Breadcrumbs } from "./Breadcrumbs";
@@ -0,0 +1,3 @@
1
+ export type BreadcrumbProps = React.HTMLAttributes<HTMLLIElement>;
2
+
3
+ export type BreadcrumbsProps = React.HTMLAttributes<HTMLUListElement>;
@@ -1,40 +1,54 @@
1
- import c from "clsx";
2
- import { getButtonClasses } from "./constants";
1
+ import React from "react";
2
+ import { Slot } from "@radix-ui/react-slot";
3
3
  import { type ButtonProps } from "./types";
4
+ import { getButtonClasses } from "./constants";
5
+ import { Loading } from "../Loading";
6
+ import { cn } from "../../utilities";
7
+
8
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
9
+ (
10
+ {
11
+ as,
12
+ className,
13
+ outline,
14
+ children,
15
+ isLoading,
16
+ variant,
17
+ size,
18
+ wide,
19
+ ...props
20
+ },
21
+ ref
22
+ ) => {
23
+ const Comp = as ? Slot : "button";
24
+ const SlotChild = as ? as : React.Fragment;
25
+
26
+ return (
27
+ <Comp
28
+ ref={ref}
29
+ className={cn(
30
+ getButtonClasses({ size, wide, outline, variant, isLoading }),
31
+ className
32
+ )}
33
+ {...props}
34
+ >
35
+ {/* slot merges it's prop into it's immediate child */}
36
+ <SlotChild>
37
+ {children}
38
+ {isLoading ? (
39
+ <span
40
+ className="absolute left-0 top-0 flex h-full w-full items-center justify-center bg-[inherit]"
41
+ data-testid="loading"
42
+ >
43
+ <Loading />
44
+ </span>
45
+ ) : null}
46
+ </SlotChild>
47
+ </Comp>
48
+ );
49
+ }
50
+ );
4
51
 
5
- export const Button = (props: ButtonProps) => {
6
- const {
7
- className,
8
- outline,
9
- label,
10
- disabled,
11
- onClick,
12
- loading,
13
- variant,
14
- size,
15
- wide,
16
- ...rest
17
- } = props;
52
+ Button.displayName = "Button";
18
53
 
19
- return (
20
- <button
21
- {...rest}
22
- onClick={onClick}
23
- disabled={disabled}
24
- className={c(
25
- getButtonClasses({ size, wide, outline, variant, loading }),
26
- className
27
- )}
28
- >
29
- {label}
30
- {loading ? (
31
- <span
32
- className="absolute left-0 top-0 flex h-full w-full items-center justify-center bg-[inherit]"
33
- data-testid="loading"
34
- >
35
- <span className="loading loading-spinner" />
36
- </span>
37
- ) : null}
38
- </button>
39
- );
40
- };
54
+ export { Button };
@@ -1,44 +1,40 @@
1
- import c from 'clsx';
2
- import type { ButtonSize, ButtonVariant } from './types';
1
+ import { cva } from "../../libs";
3
2
 
4
- const BUTTON_SIZE = {
5
- xs: c('btn-xs'),
6
- sm: c('btn-sm'),
7
- md: c('btn-md'),
8
- lg: c('btn-lg'),
9
- } satisfies Record<ButtonSize, string>;
10
-
11
- const BUTTON_VARIANTS = {
12
- accent: c('btn-accent'),
13
- default: c('btn-default'),
14
- error: c('btn-error'),
15
- ghost: c('btn-ghost'),
16
- info: c('btn-info'),
17
- link: c('btn-link'),
18
- neutral: c('btn-neutral'),
19
- primary: c('btn-primary'),
20
- secondary: c('btn-secondary'),
21
- success: c('btn-success'),
22
- warning: c('btn-warning'),
23
- } satisfies Record<ButtonVariant, string>;
24
-
25
- export const getButtonClasses = ({
26
- size,
27
- wide,
28
- loading,
29
- outline,
30
- variant,
31
- }: {
32
- size?: ButtonSize;
33
- wide?: boolean;
34
- loading?: boolean;
35
- outline?: boolean;
36
- variant?: ButtonVariant;
37
- }) => {
38
- return c('btn', BUTTON_VARIANTS[variant!], BUTTON_SIZE[size!], {
39
- 'btn-outline': outline,
40
- 'btn-wide': wide,
41
- 'relative overflow-hidden': loading,
42
- 'min-h-fit h-10': !size,
43
- });
44
- };
3
+ export const getButtonClasses = cva("btn", {
4
+ variants: {
5
+ variant: {
6
+ accent: "btn-accent",
7
+ default: "btn-default",
8
+ error: "btn-error",
9
+ ghost: "btn-ghost",
10
+ info: "btn-info",
11
+ link: "btn-link",
12
+ neutral: "btn-neutral",
13
+ primary: "btn-primary",
14
+ secondary: "btn-secondary",
15
+ success: "btn-success",
16
+ warning: "btn-warning",
17
+ },
18
+ outline: {
19
+ true: "btn-outline",
20
+ },
21
+ wide: {
22
+ true: "btn-wide",
23
+ },
24
+ size: {
25
+ xs: "btn-xs",
26
+ sm: "btn-sm",
27
+ md: "btn-md",
28
+ lg: "btn-lg",
29
+ },
30
+ isLoading: {
31
+ true: "relative overflow-hidden",
32
+ },
33
+ },
34
+ compoundVariants: [
35
+ {
36
+ size: undefined,
37
+ className: "min-h-fit h-10",
38
+ },
39
+ ],
40
+ });
@@ -1,26 +1,8 @@
1
- import type { ButtonHTMLAttributes, ReactNode } from 'react';
1
+ import { type VariantProps } from "../../libs";
2
+ import { type ButtonHTMLAttributes } from "react";
3
+ import { getButtonClasses } from "./constants";
2
4
 
3
- export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg';
4
-
5
- export type ButtonVariant =
6
- | 'default'
7
- | 'neutral'
8
- | 'primary'
9
- | 'secondary'
10
- | 'accent'
11
- | 'ghost'
12
- | 'link'
13
- | 'info'
14
- | 'success'
15
- | 'warning'
16
- | 'error';
17
-
18
- export type ButtonProps = {
19
- size?: ButtonSize;
20
- wide?: boolean;
21
- label: ReactNode;
22
- loading?: boolean;
23
- outline?: boolean;
24
- variant?: ButtonVariant;
25
- disabled?: boolean;
26
- } & ButtonHTMLAttributes<HTMLButtonElement>;
5
+ export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> &
6
+ VariantProps<typeof getButtonClasses> & {
7
+ as?: keyof Pick<JSX.IntrinsicElements, "a" | "span" | "p">;
8
+ };
@@ -1,5 +1,4 @@
1
- import c from "clsx";
2
- import {
1
+ import type {
3
2
  CardContentProps,
4
3
  CardDescriptionProps,
5
4
  CardFooterProps,
@@ -7,6 +6,8 @@ import {
7
6
  CardImageProps,
8
7
  CardProps,
9
8
  } from "./types";
9
+ import { cn } from "../../utilities";
10
+ import { getCardClasses } from "./constants";
10
11
 
11
12
  const Card = ({
12
13
  compact,
@@ -17,15 +18,8 @@ const Card = ({
17
18
  ...props
18
19
  }: CardProps) => (
19
20
  <div
20
- className={c(
21
- "card",
22
- {
23
- "card-bordered": bordered,
24
- "card-compact": compact,
25
- "card-normal": !compact,
26
- "image-full": overlay,
27
- "card-side": horizontal,
28
- },
21
+ className={cn(
22
+ getCardClasses({ bordered, compact, horizontal, overlay }),
29
23
  className
30
24
  )}
31
25
  {...props}
@@ -33,15 +27,15 @@ const Card = ({
33
27
  );
34
28
 
35
29
  const CardHeader = ({ className, ...props }: CardHeaderProps) => (
36
- <h3 className={c("card-title", className)} {...props} />
30
+ <h3 className={cn("card-title", className)} {...props} />
37
31
  );
38
32
 
39
33
  const CardDescription = ({ className, ...props }: CardDescriptionProps) => (
40
- <p className={c("text-sm text-muted-foreground", className)} {...props} />
34
+ <p className={cn("text-sm text-muted-foreground", className)} {...props} />
41
35
  );
42
36
 
43
37
  const CardContent = ({ className, ...props }: CardContentProps) => (
44
- <div className={c("card-body p-6 pt-0", className)} {...props} />
38
+ <div className={cn("card-body p-6 pt-0", className)} {...props} />
45
39
  );
46
40
 
47
41
  const CardImage = ({ className, src, alt, ...props }: CardImageProps) => (
@@ -51,7 +45,7 @@ const CardImage = ({ className, src, alt, ...props }: CardImageProps) => (
51
45
  );
52
46
 
53
47
  const CardFooter = ({ className, ...props }: CardFooterProps) => (
54
- <div className={c("card-actions", className)} {...props} />
48
+ <div className={cn("card-actions", className)} {...props} />
55
49
  );
56
50
 
57
51
  Card.Header = CardHeader;
@@ -0,0 +1,22 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getCardClasses = cva("card", {
4
+ variants: {
5
+ bordered: {
6
+ true: "card-bordered",
7
+ },
8
+ compact: {
9
+ true: "card-compact",
10
+ false: "card-normal",
11
+ },
12
+ horizontal: {
13
+ true: "card-side",
14
+ },
15
+ overlay: {
16
+ true: "image-full",
17
+ },
18
+ },
19
+ defaultVariants: {
20
+ compact: false,
21
+ },
22
+ });
@@ -1,23 +1,9 @@
1
1
  import React from "react";
2
+ import { type VariantProps } from "../../libs";
3
+ import { getCardClasses } from "./constants";
2
4
 
3
- export type CardProps = {
4
- /**
5
- * applies smaller padding to the card.
6
- */
7
- compact?: boolean;
8
- /**
9
- * applies border to the card.
10
- */
11
- bordered?: boolean;
12
- /**
13
- * shows the card horizontally with image to the right or left of it.
14
- */
15
- horizontal?: boolean;
16
- /**
17
- * overlay is used to make the image full width with the content on top.
18
- */
19
- overlay?: boolean;
20
- } & React.HTMLAttributes<HTMLDivElement>;
5
+ export type CardProps = React.HTMLAttributes<HTMLDivElement> &
6
+ VariantProps<typeof getCardClasses>;
21
7
 
22
8
  export type CardContentProps = React.HTMLAttributes<HTMLDivElement>;
23
9
  export type CardImageProps = React.ImgHTMLAttributes<HTMLImageElement>;
@@ -1,26 +1,31 @@
1
- import c from "clsx";
2
1
  import type {
3
2
  DescriptionProps,
4
3
  DescriptionTermProps,
5
4
  DescriptionDetailProps,
6
5
  } from "./types";
6
+ import { cn } from "../../utilities";
7
7
 
8
8
  const Description = (props: DescriptionProps) => {
9
9
  return <dl role="list" {...props} />;
10
10
  };
11
11
 
12
- const DescriptionTerm = (props: DescriptionTermProps) => {
12
+ const DescriptionTerm = ({ className, ...props }: DescriptionTermProps) => {
13
13
  return (
14
14
  <dt
15
- {...props}
16
15
  role="listitem"
17
- className={c("mb-1 py-2 text-sm font-medium", props.className)}
16
+ className={cn("py-2 text-sm font-semibold", className)}
17
+ {...props}
18
18
  />
19
19
  );
20
20
  };
21
21
 
22
- const DescriptionDetail = (props: DescriptionDetailProps) => {
23
- return <dd {...props} className={c("text-base", props.className)} />;
22
+ const DescriptionDetail = ({ className, ...props }: DescriptionDetailProps) => {
23
+ return (
24
+ <dd
25
+ className={cn("text-base [&:not(:last-child)]:mb-1", className)}
26
+ {...props}
27
+ />
28
+ );
24
29
  };
25
30
 
26
31
  Description.Term = DescriptionTerm;
@@ -0,0 +1,18 @@
1
+ import { getLoadingClasses } from "./constants";
2
+ import { type LoadingProps } from "./types";
3
+ import { cn } from "../../utilities";
4
+
5
+ export const Loading = ({
6
+ size,
7
+ intent,
8
+ variant,
9
+ className,
10
+ ...props
11
+ }: LoadingProps) => {
12
+ return (
13
+ <span
14
+ className={cn(getLoadingClasses({ intent, size, variant }), className)}
15
+ {...props}
16
+ />
17
+ );
18
+ };
@@ -0,0 +1,30 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getLoadingClasses = cva("loading", {
4
+ variants: {
5
+ variant: {
6
+ spinner: "loading-spinner",
7
+ dots: "loading-dots",
8
+ ring: "loading-ring",
9
+ ball: "loading-ball",
10
+ bars: "loading-bars",
11
+ infinity: "loading-infinity",
12
+ },
13
+ intent: {
14
+ primary: "text-primary",
15
+ secondary: "text-secondary",
16
+ accent: "text-accent",
17
+ neutral: "text-neutral",
18
+ info: "text-info",
19
+ success: "text-success",
20
+ warning: "text-warning",
21
+ error: "text-error",
22
+ },
23
+ size: {
24
+ xs: "loading-xs",
25
+ sm: "loading-sm",
26
+ md: "loading-md",
27
+ lg: "loading-lg",
28
+ },
29
+ },
30
+ });
@@ -0,0 +1 @@
1
+ export { Loading } from "./Loading";
@@ -0,0 +1,5 @@
1
+ import { type VariantProps } from "../../libs";
2
+ import { getLoadingClasses } from "./constants";
3
+
4
+ export type LoadingProps = React.HTMLAttributes<HTMLSpanElement> &
5
+ VariantProps<typeof getLoadingClasses>;
@@ -0,0 +1,31 @@
1
+ "use client";
2
+
3
+ import React from "react";
4
+ import * as ProgressPrimitive from "@radix-ui/react-progress";
5
+ import { type ProgressProps } from "./types";
6
+ import { cn } from "../../utilities";
7
+ import { getProgressClasses, getProgressIndicatorClasses } from "./constants";
8
+
9
+ export const Progress = React.forwardRef<
10
+ React.ElementRef<typeof ProgressPrimitive.Root>,
11
+ ProgressProps
12
+ >(({ className, value, max = 100, variant, ...props }, ref) => (
13
+ <ProgressPrimitive.Root
14
+ ref={ref}
15
+ max={max}
16
+ value={value}
17
+ className={cn(getProgressClasses({ variant }), className)}
18
+ {...props}
19
+ >
20
+ <ProgressPrimitive.Indicator
21
+ className={cn(getProgressIndicatorClasses({ variant }))}
22
+ style={{
23
+ transform: `translateX(-${
24
+ (100 * (max - Math.max(Math.min(value ?? 0, max), 0))) / max
25
+ }%)`,
26
+ }}
27
+ />
28
+ </ProgressPrimitive.Root>
29
+ ));
30
+
31
+ Progress.displayName = ProgressPrimitive.Root.displayName;
@@ -0,0 +1,49 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getProgressClasses = cva(
4
+ "relative h-2 w-full overflow-hidden rounded-full",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ accent: "bg-accent/20",
9
+ base: "bg-base-content/20",
10
+ error: "bg-error/20",
11
+ ghost: "bg-ghost/20",
12
+ info: "bg-info/20",
13
+ link: "bg-link/20",
14
+ neutral: "bg-neutral/20",
15
+ primary: "bg-primary/20",
16
+ secondary: "bg-secondary/20",
17
+ success: "bg-success/20",
18
+ warning: "bg-warning/20",
19
+ },
20
+ },
21
+ defaultVariants: {
22
+ variant: "base",
23
+ },
24
+ }
25
+ );
26
+
27
+ export const getProgressIndicatorClasses = cva(
28
+ "h-full w-full flex-1 transition-all",
29
+ {
30
+ variants: {
31
+ variant: {
32
+ accent: "bg-accent",
33
+ base: "bg-base-content",
34
+ error: "bg-error",
35
+ ghost: "bg-ghost",
36
+ info: "bg-info",
37
+ link: "bg-link",
38
+ neutral: "bg-neutral",
39
+ primary: "bg-primary",
40
+ secondary: "bg-secondary",
41
+ success: "bg-success",
42
+ warning: "bg-warning",
43
+ },
44
+ },
45
+ defaultVariants: {
46
+ variant: "base",
47
+ },
48
+ }
49
+ );