@dust-tt/sparkle 0.2.190-rc → 0.2.190

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": "@dust-tt/sparkle",
3
- "version": "0.2.190-rc",
3
+ "version": "0.2.190",
4
4
  "scripts": {
5
5
  "build": "rm -rf dist && rollup -c",
6
6
  "build:with-tw-base": "rollup -c --environment INCLUDE_TW_BASE:true",
package/src/_index.ts CHANGED
@@ -103,8 +103,8 @@ export { Avatar };
103
103
  import Spinner from "./components/Spinner";
104
104
  export { Spinner };
105
105
 
106
- import DragArea from "./components/DragArea";
107
- export { DragArea };
106
+ import DropzoneOverlay from "./components/DropzoneOverlay";
107
+ export { DropzoneOverlay };
108
108
 
109
109
  import CollapseButton from "./components/CollapseButton";
110
110
  export { CollapseButton };
@@ -1,29 +1,50 @@
1
1
  import Lottie, { LottieRefCurrentProps } from "lottie-react";
2
- import React, { useRef } from "react";
2
+ import React, { useEffect, useRef, useState } from "react";
3
3
 
4
4
  import { ArrowUpOnSquareIcon, Icon } from "@sparkle/_index";
5
5
  import anim from "@sparkle/lottie/dragArea";
6
6
 
7
- export interface DragZoneProps {
8
- title?: string;
9
- description?: string;
7
+ export interface DropzoneOverlayProps {
8
+ description: string;
9
+ isDragActive: boolean;
10
+ title: string;
10
11
  visual?: React.ReactNode;
11
12
  }
12
13
 
13
- const DragArea: React.FC<DragZoneProps> = ({
14
- title = "Drag and drop",
15
- description = "Drag and drop your files here",
14
+ export default function DropzoneOverlay({
15
+ description,
16
+ isDragActive,
17
+ title,
16
18
  visual = (
17
19
  <Icon visual={ArrowUpOnSquareIcon} size="lg" className="s-text-white" />
18
20
  ),
19
- }) => {
21
+ }: DropzoneOverlayProps) {
20
22
  const lottieRef = useRef<LottieRefCurrentProps | null>(null);
21
23
 
24
+ const [isActiveDelayed, setIsActiveDelayed] = useState(false);
25
+
26
+ // This is used to delay the removal of the overlay when the user stops dragging.
27
+ useEffect(() => {
28
+ if (isDragActive) {
29
+ setIsActiveDelayed(true);
30
+ } else {
31
+ const timeoutId = setTimeout(() => {
32
+ setIsActiveDelayed(false);
33
+ }, 400);
34
+ return () => clearTimeout(timeoutId);
35
+ }
36
+ }, [isDragActive]);
37
+
38
+ if (!isActiveDelayed) {
39
+ return null;
40
+ }
41
+
22
42
  return (
23
43
  <div
24
- className="s-flex s-h-full s-w-full s-flex-col s-items-center s-justify-center s-gap-0 s-bg-white/80 s-text-element-800"
44
+ className="s-absolute s-inset-0 s-z-50 s-flex s-h-full s-w-full s-flex-col s-items-center s-justify-center s-gap-0 s-bg-white/80 s-text-element-800"
25
45
  onMouseLeave={() => {
26
46
  lottieRef.current?.setDirection(-1);
47
+ lottieRef.current?.setSpeed(2);
27
48
  lottieRef.current?.play();
28
49
  }}
29
50
  onDrop={() => {
@@ -47,6 +68,4 @@ const DragArea: React.FC<DragZoneProps> = ({
47
68
  <div className="s-font-base s-text-base">{description}</div>
48
69
  </div>
49
70
  );
50
- };
51
-
52
- export default DragArea;
71
+ }