next-helios-fe 1.3.3 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "next-helios-fe",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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 w-fit ${
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
  };
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import React, { useState, useEffect } from "react";
2
+ import React, { useState, useEffect, useRef } from "react";
3
3
  import { Icon } from "@iconify/react";
4
4
 
5
5
  export interface FileProps extends React.InputHTMLAttributes<HTMLInputElement> {
6
6
  options?: {
7
- variant?: "default" | "drag&drop";
7
+ variant?: "basic" | "drag&drop";
8
8
  maxSizeInMb?: number;
9
9
  buttonOnly?: boolean;
10
10
  width?: "full" | "fit";
@@ -22,6 +22,7 @@ export const File: React.FC<FileProps> = ({
22
22
  value,
23
23
  ...rest
24
24
  }) => {
25
+ const inputRef = useRef<HTMLInputElement>(null);
25
26
  const [tempFile, setTempFile] = useState<any>([]);
26
27
  const width = options?.width === "fit" ? "w-fit" : "w-full";
27
28
  const height =
@@ -78,6 +79,7 @@ export const File: React.FC<FileProps> = ({
78
79
  }`}
79
80
  >
80
81
  <input
82
+ ref={inputRef}
81
83
  type="file"
82
84
  className={`peer/file w-full px-4 border-default border rounded-md bg-secondary-bg text-transparent file:hidden focus:outline-none focus:ring-1 focus:ring-primary focus:shadow focus:shadow-primary focus:border-primary-dark disabled:bg-secondary-light disabled:text-slate-400 ${height}`}
83
85
  onChange={(e) => {
@@ -184,6 +186,9 @@ export const File: React.FC<FileProps> = ({
184
186
  type="button"
185
187
  className="p-2 rounded-full hover:bg-secondary-light"
186
188
  disabled={rest.disabled}
189
+ onClick={() => {
190
+ inputRef.current?.click();
191
+ }}
187
192
  >
188
193
  <Icon icon="mi:attachment" className="text-xl" />
189
194
  </button>