@mbao01/common 0.0.17 → 0.0.18

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.
@@ -1,5 +1,5 @@
1
1
  export declare const getAvatarClasses: (props?: ({
2
- size?: 4 | 8 | 12 | 16 | 24 | 32 | 48 | 64 | null | undefined;
2
+ size?: 16 | 4 | 8 | 12 | 24 | 32 | 48 | 64 | null | undefined;
3
3
  status?: "online" | "offline" | null | undefined;
4
4
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
5
5
  export declare const getAvatarImageClasses: (props?: ({
@@ -8,7 +8,7 @@ export declare const getAvatarImageClasses: (props?: ({
8
8
  ring?: boolean | null | undefined;
9
9
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
10
10
  export declare const getAvatarFallbackClasses: (props?: ({
11
- size?: 4 | 8 | 12 | 16 | 24 | 32 | 48 | 64 | null | undefined;
11
+ size?: 16 | 4 | 8 | 12 | 24 | 32 | 48 | 64 | null | undefined;
12
12
  variant?: "accent" | "default" | "error" | "ghost" | "info" | "neutral" | "primary" | "secondary" | "success" | "warning" | null | undefined;
13
13
  shape?: "circle" | "round" | "hexagon" | "triangle" | "television" | null | undefined;
14
14
  ring?: boolean | null | undefined;
@@ -1,6 +1,6 @@
1
1
  export declare const getSkeletonClasses: (props?: ({
2
2
  variant?: "pulse" | null | undefined;
3
- width?: 4 | 8 | 12 | 16 | 24 | 32 | 48 | 64 | 2 | "full" | null | undefined;
4
- height?: 4 | 8 | 12 | 16 | 24 | 32 | 48 | 64 | 2 | "full" | null | undefined;
3
+ width?: 16 | 2 | 4 | 8 | 12 | 24 | 32 | 48 | 64 | "full" | null | undefined;
4
+ height?: 16 | 2 | 4 | 8 | 12 | 24 | 32 | 48 | 64 | "full" | null | undefined;
5
5
  round?: boolean | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ import * as TogglePrimitive from "@radix-ui/react-toggle";
3
+ declare const Toggle: React.ForwardRefExoticComponent<Omit<TogglePrimitive.ToggleProps & React.RefAttributes<HTMLButtonElement>, "ref"> & Omit<{
4
+ variant?: "accent" | "default" | "error" | "ghost" | "info" | "link" | "neutral" | "primary" | "secondary" | "success" | "warning" | undefined;
5
+ outline?: boolean | undefined;
6
+ wide?: boolean | undefined;
7
+ size?: "xs" | "sm" | "md" | "lg" | undefined;
8
+ isLoading?: boolean | undefined;
9
+ }, "variant" | "isLoading"> & {
10
+ variant?: "accent" | "default" | "error" | "info" | "link" | "neutral" | "primary" | "secondary" | "success" | "warning" | undefined;
11
+ } & React.RefAttributes<HTMLButtonElement>>;
12
+ export { Toggle };
@@ -0,0 +1,3 @@
1
+ export declare const getToggleClasses: (props?: ({
2
+ variant?: "accent" | "default" | "error" | "info" | "link" | "neutral" | "primary" | "secondary" | "success" | "warning" | null | undefined;
3
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
@@ -0,0 +1 @@
1
+ export { Toggle } from "./Toggle";
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import * as TogglePrimitive from "@radix-ui/react-toggle";
3
+ import { type VariantProps } from "../../libs";
4
+ import { getButtonClasses } from "../Button/constants";
5
+ import { getToggleClasses } from "./constants";
6
+ export type BaseToggleProps = Omit<VariantProps<typeof getButtonClasses>, "variant" | "isLoading"> & VariantProps<typeof getToggleClasses>;
7
+ export type ToggleProps = React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> & BaseToggleProps;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
3
+ import type { ToggleGroupProps } from "./types";
4
+ declare const ToggleGroup: {
5
+ ({ className, variant, children, ...props }: ToggleGroupProps): import("react/jsx-runtime").JSX.Element;
6
+ Item: import("react").ForwardRefExoticComponent<Omit<ToggleGroupPrimitive.ToggleGroupItemProps & import("react").RefAttributes<HTMLButtonElement>, "ref"> & Omit<{
7
+ variant?: "accent" | "default" | "error" | "ghost" | "info" | "link" | "neutral" | "primary" | "secondary" | "success" | "warning" | undefined;
8
+ outline?: boolean | undefined;
9
+ wide?: boolean | undefined;
10
+ size?: "xs" | "sm" | "md" | "lg" | undefined;
11
+ isLoading?: boolean | undefined;
12
+ }, "variant" | "isLoading"> & {
13
+ variant?: "accent" | "default" | "error" | "info" | "link" | "neutral" | "primary" | "secondary" | "success" | "warning" | undefined;
14
+ } & import("react").RefAttributes<HTMLButtonElement>>;
15
+ };
16
+ export { ToggleGroup };
@@ -0,0 +1 @@
1
+ export declare const getToggleGroupClasses: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
@@ -0,0 +1 @@
1
+ export { ToggleGroup } from "./ToggleGroup";
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
3
+ import { BaseToggleProps } from "../Toggle/types";
4
+ export type ToggleGroupProps = React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> & Pick<BaseToggleProps, "variant">;
5
+ export type ToggleGroupItemProps = React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> & BaseToggleProps;
6
+ export type ToggleGroupContextType = Pick<BaseToggleProps, "variant">;
@@ -1,6 +1,7 @@
1
1
  /** actions */
2
2
  export * from "./components/Button";
3
3
  export * from "./components/Breadcrumbs";
4
+ export * from "./components/Toggle";
4
5
  /** data display */
5
6
  export * from "./components/Alert";
6
7
  export * from "./components/Avatar";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.0.17",
4
+ "version": "0.0.18",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -73,6 +73,8 @@
73
73
  "@radix-ui/react-slider": "^1.1.2",
74
74
  "@radix-ui/react-slot": "^1.0.2",
75
75
  "@radix-ui/react-tabs": "^1.0.4",
76
+ "@radix-ui/react-toggle": "^1.0.3",
77
+ "@radix-ui/react-toggle-group": "^1.0.4",
76
78
  "@radix-ui/react-tooltip": "^1.0.7",
77
79
  "class-variance-authority": "^0.7.0",
78
80
  "clsx": "^2.1.0",
@@ -130,5 +132,5 @@
130
132
  "react-dom": "^18.2.0",
131
133
  "typescript": "^5.2.2"
132
134
  },
133
- "gitHead": "626046c20b138596dc5bd520b29c885823531fb6"
135
+ "gitHead": "9bc26c6619e27427b22532be6aa94ea63817c0b1"
134
136
  }
@@ -0,0 +1,27 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import * as TogglePrimitive from "@radix-ui/react-toggle";
5
+ import { type ToggleProps } from "./types";
6
+ import { cn } from "../../utilities";
7
+ import { getToggleClasses } from "./constants";
8
+ import { getButtonClasses } from "../Button/constants";
9
+
10
+ const Toggle = React.forwardRef<
11
+ React.ElementRef<typeof TogglePrimitive.Root>,
12
+ ToggleProps
13
+ >(({ className, variant = "default", size, wide, outline, ...props }, ref) => (
14
+ <TogglePrimitive.Root
15
+ ref={ref}
16
+ className={cn(
17
+ getButtonClasses({ size, wide, outline }),
18
+ getToggleClasses({ variant }),
19
+ className
20
+ )}
21
+ {...props}
22
+ />
23
+ ));
24
+
25
+ Toggle.displayName = TogglePrimitive.Root.displayName;
26
+
27
+ export { Toggle };
@@ -0,0 +1,21 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getToggleClasses = cva(
4
+ "transition-colors disabled:pointer-events-none disabled:opacity-50 data-[state=off]:btn-ghost",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ accent: "data-[state=on]:btn-accent",
9
+ default: "data-[state=on]:btn-default",
10
+ error: "data-[state=on]:btn-error",
11
+ info: "data-[state=on]:btn-info",
12
+ link: "data-[state=on]:btn-link",
13
+ neutral: "data-[state=on]:btn-neutral",
14
+ primary: "data-[state=on]:btn-primary",
15
+ secondary: "data-[state=on]:btn-secondary",
16
+ success: "data-[state=on]:btn-success",
17
+ warning: "data-[state=on]:btn-warning",
18
+ },
19
+ },
20
+ }
21
+ );
@@ -0,0 +1 @@
1
+ export { Toggle } from "./Toggle";
@@ -0,0 +1,15 @@
1
+ import * as TogglePrimitive from "@radix-ui/react-toggle";
2
+ import { type VariantProps } from "../../libs";
3
+ import { getButtonClasses } from "../Button/constants";
4
+ import { getToggleClasses } from "./constants";
5
+
6
+ export type BaseToggleProps = Omit<
7
+ VariantProps<typeof getButtonClasses>,
8
+ "variant" | "isLoading"
9
+ > &
10
+ VariantProps<typeof getToggleClasses>;
11
+
12
+ export type ToggleProps = React.ComponentPropsWithoutRef<
13
+ typeof TogglePrimitive.Root
14
+ > &
15
+ BaseToggleProps;
@@ -0,0 +1,62 @@
1
+ "use client";
2
+
3
+ import { createContext, forwardRef, useContext } from "react";
4
+ import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
5
+ import type {
6
+ ToggleGroupContextType,
7
+ ToggleGroupItemProps,
8
+ ToggleGroupProps,
9
+ } from "./types";
10
+ import { cn } from "../../utilities";
11
+ import { getToggleClasses } from "../Toggle/constants";
12
+ import { getToggleGroupClasses } from "./constants";
13
+ import { getButtonClasses } from "../Button/constants";
14
+
15
+ const ToggleGroupContext = createContext<ToggleGroupContextType>({
16
+ variant: "default",
17
+ });
18
+
19
+ const ToggleGroup = ({
20
+ className,
21
+ variant,
22
+ children,
23
+ ...props
24
+ }: ToggleGroupProps) => (
25
+ <ToggleGroupPrimitive.Root
26
+ className={cn(getToggleGroupClasses(), className)}
27
+ {...props}
28
+ >
29
+ <ToggleGroupContext.Provider value={{ variant }}>
30
+ {children}
31
+ </ToggleGroupContext.Provider>
32
+ </ToggleGroupPrimitive.Root>
33
+ );
34
+
35
+ const ToggleGroupItem = forwardRef<
36
+ React.ElementRef<typeof ToggleGroupPrimitive.Item>,
37
+ ToggleGroupItemProps
38
+ >(({ className, children, variant, size, wide, outline, ...props }, ref) => {
39
+ const context = useContext(ToggleGroupContext);
40
+
41
+ return (
42
+ <ToggleGroupPrimitive.Item
43
+ ref={ref}
44
+ className={cn(
45
+ getButtonClasses({ size, wide, outline }),
46
+ getToggleClasses({
47
+ variant: context.variant ?? variant,
48
+ }),
49
+ className
50
+ )}
51
+ {...props}
52
+ >
53
+ {children}
54
+ </ToggleGroupPrimitive.Item>
55
+ );
56
+ });
57
+
58
+ ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
59
+
60
+ ToggleGroup.Item = ToggleGroupItem;
61
+
62
+ export { ToggleGroup };
@@ -0,0 +1,5 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getToggleGroupClasses = cva(
4
+ "flex items-center justify-center gap-1"
5
+ );
@@ -0,0 +1 @@
1
+ export { ToggleGroup } from "./ToggleGroup";
@@ -0,0 +1,14 @@
1
+ import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
2
+ import { BaseToggleProps } from "../Toggle/types";
3
+
4
+ export type ToggleGroupProps = React.ComponentPropsWithoutRef<
5
+ typeof ToggleGroupPrimitive.Root
6
+ > &
7
+ Pick<BaseToggleProps, "variant">;
8
+
9
+ export type ToggleGroupItemProps = React.ComponentPropsWithoutRef<
10
+ typeof ToggleGroupPrimitive.Item
11
+ > &
12
+ BaseToggleProps;
13
+
14
+ export type ToggleGroupContextType = Pick<BaseToggleProps, "variant">;
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /** actions */
2
2
  export * from "./components/Button";
3
3
  export * from "./components/Breadcrumbs";
4
+ export * from "./components/Toggle";
4
5
 
5
6
  /** data display */
6
7
  export * from "./components/Alert";