@mbao01/common 0.0.50 → 0.0.52

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,6 +1,9 @@
1
- import * as React from "react";
2
- declare const Checkbox: React.ForwardRefExoticComponent<Omit<React.HTMLProps<HTMLInputElement>, "type" | "ref" | "size"> & {
1
+ import { CheckboxProps } from './types';
2
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
3
+ declare const Checkbox: import('react').ForwardRefExoticComponent<Omit<CheckboxProps, "checked" | "onCheckedChange"> & import('react').RefAttributes<HTMLButtonElement>>;
4
+ declare const CheckboxControlled: import('react').ForwardRefExoticComponent<Omit<CheckboxPrimitive.CheckboxProps & import('react').RefAttributes<HTMLButtonElement>, "ref"> & {
3
5
  variant?: "accent" | "error" | "info" | "primary" | "secondary" | "success" | "warning" | undefined;
4
6
  size?: "xs" | "sm" | "md" | "lg" | undefined;
5
- } & React.RefAttributes<HTMLInputElement>>;
6
- export { Checkbox };
7
+ rounded?: "xs" | "sm" | "md" | "lg" | undefined;
8
+ } & import('react').RefAttributes<HTMLButtonElement>>;
9
+ export { Checkbox, CheckboxControlled };
@@ -1,4 +1,9 @@
1
1
  export declare const getCheckboxClasses: (props?: ({
2
2
  variant?: "accent" | "error" | "info" | "primary" | "secondary" | "success" | "warning" | null | undefined;
3
3
  size?: "xs" | "sm" | "md" | "lg" | null | undefined;
4
+ rounded?: "xs" | "sm" | "md" | "lg" | null | undefined;
5
+ } & import('class-variance-authority/types').ClassProp) | undefined) => string;
6
+ export declare const getCheckboxIndicatorClasses: (props?: import('class-variance-authority/types').ClassProp | undefined) => string;
7
+ export declare const getCheckboxIconClasses: (props?: ({
8
+ size?: "xs" | "sm" | "md" | "lg" | null | undefined;
4
9
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
@@ -1 +1 @@
1
- export { Checkbox } from './Checkbox';
1
+ export { Checkbox, CheckboxControlled } from './Checkbox';
@@ -1,3 +1,5 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
1
2
  import { VariantProps } from '../../../libs';
2
3
  import { getCheckboxClasses } from './constants';
3
- export type CheckboxProps = Omit<React.HTMLProps<HTMLInputElement>, "size" | "ref" | "type"> & VariantProps<typeof getCheckboxClasses>;
4
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
5
+ export type CheckboxProps = ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> & VariantProps<typeof getCheckboxClasses>;
@@ -7,7 +7,7 @@ export { Range } from './Range';
7
7
  export { Select } from './Select';
8
8
  export { Slider } from './Slider';
9
9
  export { Switch } from './Switch';
10
- export { Checkbox } from './Checkbox';
10
+ export { Checkbox, CheckboxControlled } from './Checkbox';
11
11
  export { TagsInput } from './TagsInput';
12
12
  export { Textarea } from './Textarea';
13
13
  export { TextField } from './TextField';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.0.50",
4
+ "version": "0.0.52",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -171,5 +171,5 @@
171
171
  "react-dom": "^18.2.0",
172
172
  "typescript": "^5.2.2"
173
173
  },
174
- "gitHead": "1a3e0a5b712ff6dbb8fc8265056caedc28b2c00c"
174
+ "gitHead": "66624310b556bb7c79fb90088b8594188ba134f3"
175
175
  }
@@ -1,18 +1,58 @@
1
- import * as React from "react";
1
+ import type { ElementRef } from "react";
2
+ import { forwardRef, useState } from "react";
3
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
4
+ import { CheckIcon, MinusIcon } from "lucide-react";
2
5
  import { cn } from "../../../utilities";
3
- import { getCheckboxClasses } from "./constants";
6
+ import {
7
+ getCheckboxClasses,
8
+ getCheckboxIconClasses,
9
+ getCheckboxIndicatorClasses,
10
+ } from "./constants";
4
11
  import { type CheckboxProps } from "./types";
5
12
 
6
- const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
7
- ({ className, size, variant, ...props }, ref) => (
8
- <input
9
- ref={ref}
10
- type="checkbox"
11
- className={cn(getCheckboxClasses({ size, variant }), className)}
12
- {...props}
13
- />
14
- )
13
+ const CheckboxRoot = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
14
+ (
15
+ { className, size, rounded, variant, checked, onCheckedChange, defaultChecked, ...props },
16
+ ref
17
+ ) => {
18
+ return (
19
+ <CheckboxPrimitive.Root
20
+ ref={ref}
21
+ checked={checked}
22
+ defaultChecked={defaultChecked}
23
+ onCheckedChange={onCheckedChange}
24
+ className={cn(getCheckboxClasses({ size, rounded, variant }), className)}
25
+ {...props}
26
+ >
27
+ <CheckboxPrimitive.Indicator className={cn(getCheckboxIndicatorClasses())}>
28
+ {checked === "indeterminate" && (
29
+ <MinusIcon className={cn(getCheckboxIconClasses({ size }))} />
30
+ )}
31
+ {checked === true && <CheckIcon className={cn(getCheckboxIconClasses({ size }))} />}
32
+ </CheckboxPrimitive.Indicator>
33
+ </CheckboxPrimitive.Root>
34
+ );
35
+ }
15
36
  );
37
+ CheckboxRoot.displayName = CheckboxPrimitive.Root.displayName;
38
+
39
+ const Checkbox = forwardRef<
40
+ ElementRef<typeof CheckboxPrimitive.Root>,
41
+ Omit<CheckboxProps, "checked" | "onCheckedChange">
42
+ >(({ defaultChecked, ...props }, ref) => {
43
+ const [checked, setChecked] = useState<CheckboxPrimitive.CheckedState | undefined>(
44
+ defaultChecked
45
+ );
46
+
47
+ return <CheckboxRoot ref={ref} checked={checked} onCheckedChange={setChecked} {...props} />;
48
+ });
16
49
  Checkbox.displayName = "Checkbox";
17
50
 
18
- export { Checkbox };
51
+ const CheckboxControlled = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
52
+ (props, ref) => {
53
+ return <CheckboxRoot ref={ref} {...props} />;
54
+ }
55
+ );
56
+ CheckboxControlled.displayName = "CheckboxControlled";
57
+
58
+ export { Checkbox, CheckboxControlled };
@@ -1,21 +1,48 @@
1
1
  import { cva } from "../../../libs";
2
2
 
3
- export const getCheckboxClasses = cva("checkbox", {
4
- variants: {
5
- variant: {
6
- primary: "checkbox-primary",
7
- secondary: "checkbox-secondary",
8
- accent: "checkbox-accent",
9
- success: "checkbox-success",
10
- warning: "checkbox-warning",
11
- info: "checkbox-info",
12
- error: "checkbox-error",
3
+ export const getCheckboxClasses = cva(
4
+ "peer flex items-center justify-center h-4 w-4 shrink-0 rounded-sm border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-base-content disabled:cursor-not-allowed disabled:opacity-50",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ primary:
9
+ "border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-content",
10
+ secondary:
11
+ "border-secondary data-[state=checked]:bg-secondary data-[state=checked]:text-secondary-content",
12
+ accent:
13
+ "border-accent data-[state=checked]:bg-accent data-[state=checked]:text-accent-content",
14
+ success:
15
+ "border-success data-[state=checked]:bg-success data-[state=checked]:text-success-content",
16
+ warning:
17
+ "border-warning data-[state=checked]:bg-warning data-[state=checked]:text-warning-content",
18
+ info: "border-info data-[state=checked]:bg-info data-[state=checked]:text-info-content",
19
+ error: "border-error data-[state=checked]:bg-error data-[state=checked]:text-error-content",
20
+ },
21
+ size: {
22
+ xs: "h-3 w-3",
23
+ sm: "h-4 w-4",
24
+ md: "h-5 w-5",
25
+ lg: "h-7 w-7",
26
+ },
27
+ rounded: {
28
+ xs: "rounded-xs",
29
+ sm: "rounded-sm",
30
+ md: "rounded-md",
31
+ lg: "rounded-lg",
32
+ },
13
33
  },
34
+ }
35
+ );
36
+
37
+ export const getCheckboxIndicatorClasses = cva("flex items-center justify-center text-current");
38
+
39
+ export const getCheckboxIconClasses = cva("h-3.5 w-3.5", {
40
+ variants: {
14
41
  size: {
15
- xs: "checkbox-xs",
16
- sm: "checkbox-sm",
17
- md: "checkbox-md",
18
- lg: "checkbox-lg",
42
+ xs: "h-2.5 w-2.5",
43
+ sm: "h-3 w-3",
44
+ md: "h-4 w-4",
45
+ lg: "h-6 w-6",
19
46
  },
20
47
  },
21
48
  });
@@ -1 +1 @@
1
- export { Checkbox } from "./Checkbox";
1
+ export { Checkbox, CheckboxControlled } from "./Checkbox";
@@ -1,5 +1,7 @@
1
+ import { ComponentPropsWithoutRef } from "react";
2
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
1
3
  import { type VariantProps } from "../../../libs";
2
4
  import { getCheckboxClasses } from "./constants";
3
5
 
4
- export type CheckboxProps = Omit<React.HTMLProps<HTMLInputElement>, "size" | "ref" | "type"> &
6
+ export type CheckboxProps = ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> &
5
7
  VariantProps<typeof getCheckboxClasses>;
@@ -7,7 +7,7 @@ export { Range } from "./Range";
7
7
  export { Select } from "./Select";
8
8
  export { Slider } from "./Slider";
9
9
  export { Switch } from "./Switch";
10
- export { Checkbox } from "./Checkbox";
10
+ export { Checkbox, CheckboxControlled } from "./Checkbox";
11
11
  export { TagsInput } from "./TagsInput";
12
12
  export { Textarea } from "./Textarea";
13
13
  export { TextField } from "./TextField";