import React, { useEffect, useState, useMemo } from "react"; import PropTypes from "prop-types"; import styled from "styled-components"; import { StyledFloatingButtonWrapper, StyledFloatingButton, StyledAlertIcon, StyledCircleWrap, StyledCircle, IconBox, } from "./StyledFloatingButton"; import ButtonUploadIcon from "PUBLIC_DIR/images/button.upload.react.svg"; import ButtonFileIcon from "PUBLIC_DIR/images/button.file.react.svg"; import ButtonTrashIcon from "PUBLIC_DIR/images/button.trash.react.svg"; import ButtonMoveIcon from "PUBLIC_DIR/images/button.move.react.svg"; import ButtonDuplicateIcon from "PUBLIC_DIR/images/button.duplicate.react.svg"; import ButtonAlertIcon from "PUBLIC_DIR/images/button.alert.react.svg"; import commonIconsStyles from "@docspace/components/utils/common-icons-style"; import ButtonPlusIcon from "PUBLIC_DIR/images/actions.button.plus.react.svg"; import ButtonMinusIcon from "PUBLIC_DIR/images/actions.button.minus.react.svg"; import CloseIcon from "PUBLIC_DIR/images/close-icon.react.svg"; import { ColorTheme, ThemeType } from "@docspace/common/components/ColorTheme"; const StyledButtonAlertIcon = styled(ButtonAlertIcon)` ${commonIconsStyles} `; const Delay = 1000; const FloatingButton = (props) => { const { id, className, style, icon, alert, percent, onClick, color, clearUploadedFilesHistory, ...rest } = props; const [animationCompleted, setAnimationCompleted] = useState(false); const onProgressClear = () => { clearUploadedFilesHistory && clearUploadedFilesHistory(); }; const displayProgress = useMemo(() => { return !(percent === 100 && animationCompleted) && icon != "minus"; }, [percent, animationCompleted, icon]); let timerId = null; useEffect(() => { timerId = setTimeout( () => setAnimationCompleted(percent === 100 ? true : false), Delay ); return () => { clearTimeout(timerId); }; }, [percent, setAnimationCompleted]); return (
{icon == "upload" ? ( ) : icon == "file" ? ( ) : icon == "trash" ? ( ) : icon == "move" ? ( ) : icon == "plus" ? ( ) : icon == "minus" ? ( ) : ( )} {alert ? : <>}
{clearUploadedFilesHistory && percent === 100 && ( )}
); }; FloatingButton.propTypes = { id: PropTypes.string, className: PropTypes.string, style: PropTypes.object, icon: PropTypes.oneOf([ "upload", "file", "trash", "move", "duplicate", "plus", "minus", ]), alert: PropTypes.bool, percent: PropTypes.number, onClick: PropTypes.func, color: PropTypes.string, }; FloatingButton.defaultProps = { id: undefined, className: undefined, style: undefined, icon: "upload", alert: false, percent: 0, }; export default FloatingButton;