@mbao01/common 0.0.51 → 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,7 +1,9 @@
1
+ import { CheckboxProps } from './types';
1
2
  import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
2
- declare const Checkbox: import('react').ForwardRefExoticComponent<Omit<Omit<CheckboxPrimitive.CheckboxProps & import('react').RefAttributes<HTMLButtonElement>, "ref">, "checked" | "onCheckedChange"> & {
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
7
  rounded?: "xs" | "sm" | "md" | "lg" | undefined;
6
8
  } & import('react').RefAttributes<HTMLButtonElement>>;
7
- export { Checkbox };
9
+ export { Checkbox, CheckboxControlled };
@@ -1 +1 @@
1
- export { Checkbox } from './Checkbox';
1
+ export { Checkbox, CheckboxControlled } from './Checkbox';
@@ -2,4 +2,4 @@ import { ComponentPropsWithoutRef } from 'react';
2
2
  import { VariantProps } from '../../../libs';
3
3
  import { getCheckboxClasses } from './constants';
4
4
  import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
5
- export type CheckboxProps = Omit<ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>, "checked" | "onCheckedChange"> & VariantProps<typeof getCheckboxClasses>;
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.51",
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": "4719b1effc0e198fed741e9001b853016f2563f6"
174
+ "gitHead": "66624310b556bb7c79fb90088b8594188ba134f3"
175
175
  }
@@ -10,17 +10,17 @@ import {
10
10
  } from "./constants";
11
11
  import { type CheckboxProps } from "./types";
12
12
 
13
- const Checkbox = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
14
- ({ className, size, rounded, variant, defaultChecked, ...props }, ref) => {
15
- const [checked, setChecked] = useState<CheckboxPrimitive.CheckedState | undefined>(
16
- defaultChecked
17
- );
18
-
13
+ const CheckboxRoot = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
14
+ (
15
+ { className, size, rounded, variant, checked, onCheckedChange, defaultChecked, ...props },
16
+ ref
17
+ ) => {
19
18
  return (
20
19
  <CheckboxPrimitive.Root
21
20
  ref={ref}
22
21
  checked={checked}
23
- onCheckedChange={setChecked}
22
+ defaultChecked={defaultChecked}
23
+ onCheckedChange={onCheckedChange}
24
24
  className={cn(getCheckboxClasses({ size, rounded, variant }), className)}
25
25
  {...props}
26
26
  >
@@ -34,6 +34,25 @@ const Checkbox = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxP
34
34
  );
35
35
  }
36
36
  );
37
- Checkbox.displayName = CheckboxPrimitive.Root.displayName;
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
+ });
49
+ Checkbox.displayName = "Checkbox";
50
+
51
+ const CheckboxControlled = forwardRef<ElementRef<typeof CheckboxPrimitive.Root>, CheckboxProps>(
52
+ (props, ref) => {
53
+ return <CheckboxRoot ref={ref} {...props} />;
54
+ }
55
+ );
56
+ CheckboxControlled.displayName = "CheckboxControlled";
38
57
 
39
- export { Checkbox };
58
+ export { Checkbox, CheckboxControlled };
@@ -1,7 +1,7 @@
1
1
  import { cva } from "../../../libs";
2
2
 
3
3
  export const getCheckboxClasses = cva(
4
- "peer flex items-center justify-center h-6 w-6 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",
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
5
  {
6
6
  variants: {
7
7
  variant: {
@@ -19,10 +19,10 @@ export const getCheckboxClasses = cva(
19
19
  error: "border-error data-[state=checked]:bg-error data-[state=checked]:text-error-content",
20
20
  },
21
21
  size: {
22
- xs: "h-4 w-4",
23
- sm: "h-5 w-5",
24
- md: "h-6 w-6",
25
- lg: "h-8 w-8",
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
26
  },
27
27
  rounded: {
28
28
  xs: "rounded-xs",
@@ -36,12 +36,12 @@ export const getCheckboxClasses = cva(
36
36
 
37
37
  export const getCheckboxIndicatorClasses = cva("flex items-center justify-center text-current");
38
38
 
39
- export const getCheckboxIconClasses = cva("h-4 w-4", {
39
+ export const getCheckboxIconClasses = cva("h-3.5 w-3.5", {
40
40
  variants: {
41
41
  size: {
42
42
  xs: "h-2.5 w-2.5",
43
- sm: "h-3.5 w-3.5",
44
- md: "h-5 w-5",
43
+ sm: "h-3 w-3",
44
+ md: "h-4 w-4",
45
45
  lg: "h-6 w-6",
46
46
  },
47
47
  },
@@ -1 +1 @@
1
- export { Checkbox } from "./Checkbox";
1
+ export { Checkbox, CheckboxControlled } from "./Checkbox";
@@ -3,8 +3,5 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
3
3
  import { type VariantProps } from "../../../libs";
4
4
  import { getCheckboxClasses } from "./constants";
5
5
 
6
- export type CheckboxProps = Omit<
7
- ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>,
8
- "checked" | "onCheckedChange"
9
- > &
6
+ export type CheckboxProps = ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> &
10
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";