| 156 | } |
| 157 | |
| 158 | const ScrollButton = ({ icon, onClick, disabled }: ScrollButtonProps) => { |
| 159 | const Icon = icon; |
| 160 | const [isPressed, setIsPressed] = React.useState(false); |
| 161 | const intervalRef = React.useRef<NodeJS.Timeout | null>(null); |
| 162 | |
| 163 | React.useEffect(() => { |
| 164 | if (isPressed) { |
| 165 | intervalRef.current = setInterval(() => { |
| 166 | onClick?.(); |
| 167 | }, 300); |
| 168 | } else { |
| 169 | clearInterval(intervalRef.current as NodeJS.Timeout); |
| 170 | } |
| 171 | return () => clearInterval(intervalRef.current as NodeJS.Timeout); |
| 172 | }, [isPressed, onClick]); |
| 173 | |
| 174 | React.useEffect(() => { |
| 175 | if (disabled) { |
| 176 | clearInterval(intervalRef.current as NodeJS.Timeout); |
| 177 | setIsPressed(false); |
| 178 | } |
| 179 | }, [disabled]); |
| 180 | |
| 181 | return ( |
| 182 | <button |
| 183 | type="button" |
| 184 | className={cn( |
| 185 | // base |
| 186 | "group inline-flex size-5 items-center truncate rounded-sm transition", |
| 187 | disabled |
| 188 | ? "cursor-not-allowed text-gray-400 dark:text-gray-600" |
| 189 | : "cursor-pointer text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-300 dark:hover:bg-gray-800 dark:hover:text-gray-50" |
| 190 | )} |
| 191 | disabled={disabled} |
| 192 | onClick={(e) => { |
| 193 | e.stopPropagation(); |
| 194 | onClick?.(); |
| 195 | }} |
| 196 | onMouseDown={(e) => { |
| 197 | e.stopPropagation(); |
| 198 | setIsPressed(true); |
| 199 | }} |
| 200 | onMouseUp={(e) => { |
| 201 | e.stopPropagation(); |
| 202 | setIsPressed(false); |
| 203 | }} |
| 204 | > |
| 205 | <Icon className="size-full" aria-hidden="true" /> |
| 206 | </button> |
| 207 | ); |
| 208 | }; |
| 209 | |
| 210 | interface LegendProps extends React.OlHTMLAttributes<HTMLOListElement> { |
| 211 | categories: { name: string; chartType: "bar" | "line" }[]; |