@arkyn/components 1.4.8 → 1.4.10
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/dist/bundle.js +35452 -11761
- package/dist/bundle.umd.cjs +592 -72
- package/dist/components/AudioUpload/AudioUploadError/index.d.ts +5 -0
- package/dist/components/AudioUpload/AudioUploadError/index.d.ts.map +1 -0
- package/dist/components/AudioUpload/AudioUploadError/index.js +10 -0
- package/dist/components/AudioUpload/AudioUploadLabel/index.d.ts +5 -0
- package/dist/components/AudioUpload/AudioUploadLabel/index.d.ts.map +1 -0
- package/dist/components/AudioUpload/AudioUploadLabel/index.js +9 -0
- package/dist/components/AudioUpload/HasFileContent/index.d.ts +5 -0
- package/dist/components/AudioUpload/HasFileContent/index.d.ts.map +1 -0
- package/dist/components/AudioUpload/HasFileContent/index.js +82 -0
- package/dist/components/AudioUpload/NoFileContent/index.d.ts +5 -0
- package/dist/components/AudioUpload/NoFileContent/index.d.ts.map +1 -0
- package/dist/components/AudioUpload/NoFileContent/index.js +29 -0
- package/dist/components/AudioUpload/index.d.ts +5 -0
- package/dist/components/AudioUpload/index.d.ts.map +1 -0
- package/dist/components/AudioUpload/index.js +58 -0
- package/dist/components/ImageUpload/HasFileContent/index.d.ts +2 -2
- package/dist/components/ImageUpload/HasFileContent/index.d.ts.map +1 -1
- package/dist/components/ImageUpload/NoFileContent/index.d.ts +2 -2
- package/dist/components/ImageUpload/NoFileContent/index.d.ts.map +1 -1
- package/dist/components/Input/CpfCpnjInput/getConfig.d.ts +1 -1
- package/dist/components/Input/CurrencyInput/getConfig.d.ts +1 -1
- package/dist/components/Input/MaskInput/getConfig.d.ts +1 -1
- package/dist/components/Input/SimpleInput/getConfig.d.ts +2 -2
- package/dist/components/Select/getConfig.d.ts +1 -1
- package/dist/components/Slider/index.d.ts +5 -0
- package/dist/components/Slider/index.d.ts.map +1 -0
- package/dist/components/Slider/index.js +52 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/AudioUpload/AudioUploadError/index.tsx +12 -0
- package/src/components/AudioUpload/AudioUploadError/styles.css +6 -0
- package/src/components/AudioUpload/AudioUploadLabel/index.tsx +13 -0
- package/src/components/AudioUpload/AudioUploadLabel/styles.css +15 -0
- package/src/components/AudioUpload/HasFileContent/index.tsx +163 -0
- package/src/components/AudioUpload/HasFileContent/styles.css +59 -0
- package/src/components/AudioUpload/NoFileContent/index.tsx +59 -0
- package/src/components/AudioUpload/NoFileContent/styles.css +19 -0
- package/src/components/AudioUpload/index.tsx +121 -0
- package/src/components/AudioUpload/styles.css +33 -0
- package/src/components/ImageUpload/HasFileContent/index.tsx +2 -2
- package/src/components/ImageUpload/NoFileContent/index.tsx +2 -2
- package/src/components/ImageUpload/styles.css +1 -1
- package/src/components/Slider/index.tsx +73 -0
- package/src/components/Slider/styles.css +37 -0
- package/src/index.ts +2 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
import { useFieldErrors } from "@arkyn/components";
|
2
|
+
import { AudioUploadProps } from "@arkyn/types";
|
3
|
+
import { useState } from "react";
|
4
|
+
|
5
|
+
import { AudioUploadError } from "./AudioUploadError";
|
6
|
+
import { AudioUploadLabel } from "./AudioUploadLabel";
|
7
|
+
import { HasFileContent } from "./HasFileContent";
|
8
|
+
import { NoFileContent } from "./NoFileContent";
|
9
|
+
|
10
|
+
import "./styles.css";
|
11
|
+
|
12
|
+
function AudioUpload(props: AudioUploadProps) {
|
13
|
+
const {
|
14
|
+
name,
|
15
|
+
label,
|
16
|
+
fileName = "file",
|
17
|
+
method = "POST",
|
18
|
+
onUpload,
|
19
|
+
fileResponseName = "url",
|
20
|
+
selectAudioButtonText = "Selecionar arquivo de áudio",
|
21
|
+
dropAudioText = "Ou arraste e solte um arquivo de áudio aqui",
|
22
|
+
changeAudioButtonText = "Trocar arquivo de áudio",
|
23
|
+
acceptAudio = "audio/*",
|
24
|
+
action,
|
25
|
+
defaultValue = "",
|
26
|
+
showAsterisk = false,
|
27
|
+
disabled = false,
|
28
|
+
} = props;
|
29
|
+
|
30
|
+
const fieldErrors = useFieldErrors();
|
31
|
+
const fieldError = fieldErrors[name];
|
32
|
+
|
33
|
+
const [value, setValue] = useState(defaultValue);
|
34
|
+
const [error, setError] = useState("");
|
35
|
+
const [file, setFile] = useState<File | null>(null);
|
36
|
+
const [filePath, setFilePath] = useState(defaultValue);
|
37
|
+
const [isLoading, setIsLoading] = useState(false);
|
38
|
+
|
39
|
+
async function handleUploadAudio(file: File) {
|
40
|
+
if (disabled) return;
|
41
|
+
|
42
|
+
setIsLoading(true);
|
43
|
+
setFile(file);
|
44
|
+
setError("");
|
45
|
+
|
46
|
+
const formData = new FormData();
|
47
|
+
formData.append(fileName, file);
|
48
|
+
|
49
|
+
await fetch(action, { method: method, body: formData })
|
50
|
+
.then(async (response) => await response.json())
|
51
|
+
.then((response) => {
|
52
|
+
if (!!response?.error) setError(response.error);
|
53
|
+
else setValue(response?.[fileResponseName]);
|
54
|
+
onUpload && onUpload(response?.[fileResponseName]);
|
55
|
+
})
|
56
|
+
.catch((error) => {
|
57
|
+
console.error(error);
|
58
|
+
setError("Erro ao enviar audio");
|
59
|
+
})
|
60
|
+
.finally(() => setIsLoading(false));
|
61
|
+
}
|
62
|
+
|
63
|
+
function handleSelectFile(file: File) {
|
64
|
+
if (disabled) return;
|
65
|
+
|
66
|
+
console.log(file.type);
|
67
|
+
|
68
|
+
if (file.type.indexOf("audio") === -1) {
|
69
|
+
setError("O arquivo selecionado não é um arquivo de áudio");
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
|
73
|
+
setFilePath(URL.createObjectURL(file));
|
74
|
+
handleUploadAudio(file);
|
75
|
+
}
|
76
|
+
|
77
|
+
const errorMessage = fieldError || error;
|
78
|
+
|
79
|
+
const hasErrorClassName = errorMessage ? "hasError" : "noHasError";
|
80
|
+
const hasImageClassName = filePath ? "hasAudio" : "noHasAudio";
|
81
|
+
const className = `arkynAudioUpload ${hasErrorClassName} ${hasImageClassName}`;
|
82
|
+
|
83
|
+
return (
|
84
|
+
<div className="arkynAudioUploadContainer">
|
85
|
+
{label && <AudioUploadLabel label={label} showAsterisk={showAsterisk} />}
|
86
|
+
|
87
|
+
<div className={className}>
|
88
|
+
<input type="hidden" name={name} value={value || ""} />
|
89
|
+
|
90
|
+
{!filePath && (
|
91
|
+
<NoFileContent
|
92
|
+
disabled={disabled}
|
93
|
+
isLoading={isLoading}
|
94
|
+
acceptAudio={acceptAudio}
|
95
|
+
dropAudioText={dropAudioText}
|
96
|
+
handleSelectFile={handleSelectFile}
|
97
|
+
selectAudioButtonText={selectAudioButtonText}
|
98
|
+
/>
|
99
|
+
)}
|
100
|
+
|
101
|
+
{filePath && (
|
102
|
+
<HasFileContent
|
103
|
+
filePath={filePath}
|
104
|
+
acceptAudio={acceptAudio}
|
105
|
+
changeAudioButtonText={changeAudioButtonText}
|
106
|
+
disabled={disabled}
|
107
|
+
handleSelectFile={handleSelectFile}
|
108
|
+
isLoading={isLoading}
|
109
|
+
reSendAudio={
|
110
|
+
!!errorMessage && file ? () => handleUploadAudio(file) : undefined
|
111
|
+
}
|
112
|
+
/>
|
113
|
+
)}
|
114
|
+
</div>
|
115
|
+
|
116
|
+
{errorMessage && <AudioUploadError error={errorMessage} />}
|
117
|
+
</div>
|
118
|
+
);
|
119
|
+
}
|
120
|
+
|
121
|
+
export { AudioUpload };
|
@@ -0,0 +1,33 @@
|
|
1
|
+
.arkynAudioUploadContainer {
|
2
|
+
display: flex;
|
3
|
+
flex-direction: column;
|
4
|
+
gap: 6px;
|
5
|
+
}
|
6
|
+
|
7
|
+
.arkynAudioUpload {
|
8
|
+
border-width: 1px;
|
9
|
+
|
10
|
+
outline: 1px solid transparent;
|
11
|
+
|
12
|
+
border-color: var(--border);
|
13
|
+
border-radius: var(--rounded-inputs);
|
14
|
+
|
15
|
+
width: 100%;
|
16
|
+
height: 137px;
|
17
|
+
max-width: 475px;
|
18
|
+
|
19
|
+
background: rgba(var(--input-background), 1);
|
20
|
+
}
|
21
|
+
|
22
|
+
.arkynAudioUpload.hasAudio {
|
23
|
+
border-style: solid;
|
24
|
+
}
|
25
|
+
|
26
|
+
.arkynAudioUpload.noHasAudio {
|
27
|
+
border-style: dashed;
|
28
|
+
}
|
29
|
+
|
30
|
+
.arkynAudioUpload.hasError {
|
31
|
+
border-color: rgb(var(--spotlight-danger));
|
32
|
+
outline-color: rgb(var(--spotlight-danger));
|
33
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ImageUploadHasFileContentProps } from "@arkyn/types";
|
2
2
|
import { RefreshCw } from "lucide-react";
|
3
3
|
|
4
4
|
import { Button } from "../../Button";
|
@@ -7,7 +7,7 @@ import { Tooltip } from "../../Tooltip";
|
|
7
7
|
|
8
8
|
import "./styles.css";
|
9
9
|
|
10
|
-
function HasFileContent(props:
|
10
|
+
function HasFileContent(props: ImageUploadHasFileContentProps) {
|
11
11
|
const {
|
12
12
|
disabled,
|
13
13
|
filePath,
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { ImageUploadNoFileContentProps } from "@arkyn/types";
|
2
2
|
import { DragEvent } from "react";
|
3
3
|
|
4
4
|
import { Button } from "../../Button";
|
5
5
|
|
6
6
|
import "./styles.css";
|
7
7
|
|
8
|
-
function NoFileContent(props:
|
8
|
+
function NoFileContent(props: ImageUploadNoFileContentProps) {
|
9
9
|
const {
|
10
10
|
dropImageText,
|
11
11
|
isLoading,
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { SliderProps } from "@arkyn/types";
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
3
|
+
|
4
|
+
import "./styles.css";
|
5
|
+
|
6
|
+
function Slider(props: SliderProps) {
|
7
|
+
const { onChange, value, disableDrag = false, onDragging } = props;
|
8
|
+
const [isDragging, setIsDragging] = useState(false);
|
9
|
+
const sliderRef = useRef<HTMLDivElement>(null);
|
10
|
+
|
11
|
+
const handleMouseDown = () => {
|
12
|
+
setIsDragging(true);
|
13
|
+
};
|
14
|
+
|
15
|
+
const handleMouseUp = () => {
|
16
|
+
setIsDragging(false);
|
17
|
+
};
|
18
|
+
|
19
|
+
const handleMouseMove = (event: MouseEvent) => {
|
20
|
+
if (disableDrag) return;
|
21
|
+
if (!isDragging || !sliderRef.current) return;
|
22
|
+
|
23
|
+
const rect = sliderRef.current.getBoundingClientRect();
|
24
|
+
const offsetX = event.clientX - rect.left;
|
25
|
+
const newValue = Math.min(Math.max((offsetX / rect.width) * 100, 0), 100);
|
26
|
+
|
27
|
+
onChange(newValue);
|
28
|
+
};
|
29
|
+
|
30
|
+
const handleSliderClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
31
|
+
if (!sliderRef.current) return;
|
32
|
+
|
33
|
+
const rect = sliderRef.current.getBoundingClientRect();
|
34
|
+
const offsetX = event.clientX - rect.left;
|
35
|
+
const newValue = Math.min(Math.max((offsetX / rect.width) * 100, 0), 100);
|
36
|
+
|
37
|
+
onChange(newValue);
|
38
|
+
};
|
39
|
+
|
40
|
+
useEffect(() => {
|
41
|
+
if (isDragging) {
|
42
|
+
onDragging && onDragging(true);
|
43
|
+
document.addEventListener("mousemove", handleMouseMove);
|
44
|
+
document.addEventListener("mouseup", handleMouseUp);
|
45
|
+
} else {
|
46
|
+
onDragging && onDragging(false);
|
47
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
48
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
49
|
+
}
|
50
|
+
|
51
|
+
return () => {
|
52
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
53
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
54
|
+
};
|
55
|
+
}, [isDragging]);
|
56
|
+
|
57
|
+
const isDraggingClass = isDragging ? "isDragging" : "isNotDragging";
|
58
|
+
const sliderClassname = `arkynSliderTrack ${isDraggingClass}`;
|
59
|
+
|
60
|
+
return (
|
61
|
+
<div
|
62
|
+
className={sliderClassname}
|
63
|
+
ref={sliderRef}
|
64
|
+
onMouseDown={handleMouseDown}
|
65
|
+
onClick={handleSliderClick}
|
66
|
+
>
|
67
|
+
<div className="arkynSliderFill" style={{ width: `${value}%` }} />
|
68
|
+
<div className="arkynSliderThumb" style={{ left: `${value}%` }} />
|
69
|
+
</div>
|
70
|
+
);
|
71
|
+
}
|
72
|
+
|
73
|
+
export { Slider };
|
@@ -0,0 +1,37 @@
|
|
1
|
+
.arkynSliderTrack {
|
2
|
+
width: 100%;
|
3
|
+
max-width: 400px;
|
4
|
+
|
5
|
+
height: 6px;
|
6
|
+
border: 1px solid var(--border);
|
7
|
+
background: rgba(var(--input-background), 1);
|
8
|
+
border-radius: 5px;
|
9
|
+
position: relative;
|
10
|
+
cursor: pointer;
|
11
|
+
}
|
12
|
+
|
13
|
+
.arkynSliderTrack.isDragging {
|
14
|
+
cursor: grabbing;
|
15
|
+
}
|
16
|
+
|
17
|
+
.arkynSliderFill {
|
18
|
+
height: 100%;
|
19
|
+
background: rgb(var(--spotlight-primary));
|
20
|
+
border-radius: 5px;
|
21
|
+
}
|
22
|
+
|
23
|
+
.arkynSliderThumb {
|
24
|
+
width: 12px;
|
25
|
+
cursor: grab;
|
26
|
+
height: 12px;
|
27
|
+
background: rgb(var(--spotlight-primary));
|
28
|
+
border-radius: 50%;
|
29
|
+
position: absolute;
|
30
|
+
top: 50%;
|
31
|
+
transform: translate(-50%, -50%);
|
32
|
+
}
|
33
|
+
|
34
|
+
.arkynSliderValue {
|
35
|
+
margin-top: 10px;
|
36
|
+
font-size: 18px;
|
37
|
+
}
|
package/src/index.ts
CHANGED
@@ -19,6 +19,7 @@ export {
|
|
19
19
|
} from "./components/Table";
|
20
20
|
|
21
21
|
// Form
|
22
|
+
export { AudioUpload } from "./components/AudioUpload";
|
22
23
|
export { Button } from "./components/Button";
|
23
24
|
export { Checkbox } from "./components/Checkbox";
|
24
25
|
export { FormController, FormError, FormLabel } from "./components/Form";
|
@@ -29,6 +30,7 @@ export { MultiSelect } from "./components/MultiSelect";
|
|
29
30
|
export { RadioBox, RadioGroup } from "./components/Radio";
|
30
31
|
export { RichText } from "./components/RichText";
|
31
32
|
export { Select } from "./components/Select";
|
33
|
+
export { Slider } from "./components/Slider";
|
32
34
|
export { Switch } from "./components/Switch";
|
33
35
|
export { Textarea } from "./components/Textarea";
|
34
36
|
|