next-helios-fe 1.3.4 → 1.3.5
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.
package/package.json
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
"use client";
|
2
|
-
import React from "react";
|
2
|
+
import React, { useState, useEffect } from "react";
|
3
3
|
|
4
4
|
export interface CheckboxProps
|
5
5
|
extends React.InputHTMLAttributes<HTMLInputElement> {
|
6
6
|
options?: {
|
7
|
+
variant?: "basic" | "switch";
|
7
8
|
disableHover?: boolean;
|
8
9
|
};
|
9
10
|
label?: string;
|
@@ -16,11 +17,32 @@ export const Checkbox: React.FC<CheckboxProps> = ({
|
|
16
17
|
theme,
|
17
18
|
...rest
|
18
19
|
}) => {
|
20
|
+
const [tempChecked, setTempChecked] = useState(false);
|
21
|
+
|
22
|
+
useEffect(() => {
|
23
|
+
if (rest.checked) {
|
24
|
+
setTempChecked(rest.checked as boolean);
|
25
|
+
return;
|
26
|
+
} else if (rest.defaultChecked) {
|
27
|
+
setTempChecked(rest.defaultChecked as boolean);
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
}, [rest.value, rest.defaultValue]);
|
31
|
+
|
32
|
+
useEffect(() => {
|
33
|
+
if (tempChecked) {
|
34
|
+
rest.onChange &&
|
35
|
+
rest.onChange({
|
36
|
+
target: { checked: tempChecked } as HTMLInputElement,
|
37
|
+
} as any);
|
38
|
+
}
|
39
|
+
}, [tempChecked]);
|
40
|
+
|
19
41
|
return (
|
20
42
|
<label
|
21
|
-
className={`flex items-center
|
43
|
+
className={`group/checkbox flex items-center ${
|
22
44
|
!options?.disableHover ? "gap-2" : "gap-4"
|
23
|
-
}`}
|
45
|
+
} ${options?.variant === "switch" ? "justify-between w-full" : "w-fit"}`}
|
24
46
|
>
|
25
47
|
<div
|
26
48
|
className={`flex justify-center items-center ${
|
@@ -28,7 +50,7 @@ export const Checkbox: React.FC<CheckboxProps> = ({
|
|
28
50
|
} ${
|
29
51
|
!options?.disableHover &&
|
30
52
|
"w-8 h-8 rounded-full hover:bg-secondary-light"
|
31
|
-
}`}
|
53
|
+
} ${options?.variant === "switch" && "hidden"}`}
|
32
54
|
>
|
33
55
|
<input
|
34
56
|
type="checkbox"
|
@@ -36,6 +58,10 @@ export const Checkbox: React.FC<CheckboxProps> = ({
|
|
36
58
|
theme && "border-0"
|
37
59
|
}`}
|
38
60
|
style={{ backgroundColor: theme }}
|
61
|
+
checked={tempChecked}
|
62
|
+
onChange={(e) => {
|
63
|
+
setTempChecked(e.target.checked);
|
64
|
+
}}
|
39
65
|
{...rest}
|
40
66
|
/>
|
41
67
|
</div>
|
@@ -48,6 +74,13 @@ export const Checkbox: React.FC<CheckboxProps> = ({
|
|
48
74
|
{label}
|
49
75
|
</span>
|
50
76
|
)}
|
77
|
+
<div
|
78
|
+
className={`flex items-center justify-start w-8 h-5 border rounded-full bg-secondary-bg overflow-hidden cursor-pointer duration-300 group-has-[:checked]/checkbox:justify-end group-has-[:checked]/checkbox:bg-primary ${
|
79
|
+
options?.variant !== "switch" && "hidden"
|
80
|
+
}`}
|
81
|
+
>
|
82
|
+
<div className="w-4 h-4 rounded-full bg-primary duration-300 group-has-[:checked]/checkbox:bg-secondary-bg"></div>
|
83
|
+
</div>
|
51
84
|
</label>
|
52
85
|
);
|
53
86
|
};
|
@@ -4,7 +4,7 @@ import { Icon } from "@iconify/react";
|
|
4
4
|
|
5
5
|
export interface FileProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
6
6
|
options?: {
|
7
|
-
variant?: "
|
7
|
+
variant?: "basic" | "drag&drop";
|
8
8
|
maxSizeInMb?: number;
|
9
9
|
buttonOnly?: boolean;
|
10
10
|
width?: "full" | "fit";
|