DocSpace-buildtools/packages/common/components/FloatingButton/FloatingButton.js

153 lines
4.2 KiB
JavaScript
Raw Normal View History

2022-11-09 17:33:07 +00:00
import React, { useEffect, useState, useMemo } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
import {
StyledFloatingButtonWrapper,
StyledFloatingButton,
StyledAlertIcon,
StyledCircleWrap,
StyledCircle,
2021-03-10 17:10:09 +00:00
IconBox,
} from "./StyledFloatingButton";
Merge branch 'develop' into feature/workspaces # Conflicts: # packages/asc-web-common/src/components/FilterInput/FilterInput.js # packages/asc-web-common/src/components/FilterInput/sub-components/SortComboBox.js # packages/asc-web-common/src/components/PageLayout/index.js # packages/asc-web-common/src/components/PageLayout/sub-components/article-body.js # packages/asc-web-common/src/components/PageLayout/sub-components/article-header.js # packages/asc-web-common/src/components/PageLayout/sub-components/article-main-button.js # packages/asc-web-common/src/components/PageLayout/sub-components/section-body.js # packages/asc-web-common/src/components/PageLayout/sub-components/section-header.js # packages/asc-web-common/src/components/PrivateRoute/PrivateRoute.js # products/ASC.Files/Client/package.json # products/ASC.Files/Client/src/components/Article/Body/TreeFolders.js # products/ASC.Files/Client/src/components/pages/DocEditor/index.js # products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js # products/ASC.Files/Client/src/components/panels/OperationsPanel/index.js # products/ASC.Files/Client/src/components/panels/SharingPanel/SharingRow.js # products/ASC.Files/Client/src/components/panels/SharingPanel/index.js # products/ASC.Files/Client/src/index.js # products/ASC.Files/Client/src/store/files/actions.js # products/ASC.Files/Client/yarn.lock # products/ASC.People/Client/package.json # products/ASC.People/Client/src/components/pages/Home/Section/Body/index.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/ContactField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/DateField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/EmailField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/RadioField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/TextChangeField.js # products/ASC.People/Client/src/components/pages/ProfileAction/Section/Body/FormFields/TextField.js # products/ASC.People/Client/src/index.js # products/ASC.People/Client/yarn.lock # web/ASC.Web.Client/package.json # web/ASC.Web.Client/src/App.js # web/ASC.Web.Client/src/components/pages/Confirm/index.js # web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateEmail.js # web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeEmail.js # web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeOwner.js # web/ASC.Web.Client/src/helpers/confirmRoute.js # web/ASC.Web.Client/src/index.js # web/ASC.Web.Common/package.json # web/ASC.Web.Common/yarn.lock # web/ASC.Web.Components/package.json # web/ASC.Web.Components/yarn.lock # web/ASC.Web.Login/src/LoginContent.jsx # web/ASC.Web.Login/src/sub-components/register-container.js # yarn.lock
2020-12-15 15:40:27 +00:00
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";
2022-08-15 07:38:46 +00:00
import { ColorTheme, ThemeType } from "@docspace/common/components/ColorTheme";
const StyledButtonAlertIcon = styled(ButtonAlertIcon)`
${commonIconsStyles}
`;
2022-06-02 08:49:28 +00:00
const Delay = 1000;
2022-08-15 07:38:46 +00:00
const FloatingButton = (props) => {
const {
2022-08-15 07:38:46 +00:00
id,
className,
style,
icon,
alert,
percent,
onClick,
color,
clearUploadedFilesHistory,
2022-08-15 07:38:46 +00:00
...rest
} = props;
const [animationCompleted, setAnimationCompleted] = useState(false);
const onProgressClear = () => {
clearUploadedFilesHistory && clearUploadedFilesHistory();
};
2020-11-16 11:47:30 +00:00
2022-11-09 17:33:07 +00:00
const displayProgress = useMemo(() => {
return !(percent === 100 && animationCompleted) && icon != "minus";
}, [percent, animationCompleted, icon]);
2022-06-02 08:49:28 +00:00
let timerId = null;
useEffect(() => {
2022-06-02 08:49:28 +00:00
timerId = setTimeout(
() => setAnimationCompleted(percent === 100 ? true : false),
Delay
);
return () => {
clearTimeout(timerId);
};
}, [percent, setAnimationCompleted]);
2020-11-16 11:47:30 +00:00
return (
2023-02-21 12:27:52 +00:00
<StyledFloatingButtonWrapper className="layout-progress-bar_wrapper">
2022-08-15 07:38:46 +00:00
<ColorTheme
{...props}
themeId={ThemeType.FloatingButton}
color={color}
id={id}
className={`${className} not-selectable`}
style={style}
icon={icon}
onClick={onClick}
2022-11-09 17:33:07 +00:00
displayProgress={displayProgress}
>
2022-11-09 17:33:07 +00:00
<StyledCircle displayProgress={displayProgress} percent={percent}>
<div className="circle__mask circle__full">
<div className="circle__fill"></div>
</div>
<div className="circle__mask">
<div className="circle__fill"></div>
</div>
<StyledFloatingButton className="circle__background" color={color}>
<IconBox>
{icon == "upload" ? (
<ButtonUploadIcon />
) : icon == "file" ? (
<ButtonFileIcon />
) : icon == "trash" ? (
<ButtonTrashIcon />
) : icon == "move" ? (
<ButtonMoveIcon />
) : icon == "plus" ? (
<ButtonPlusIcon />
) : icon == "minus" ? (
<ButtonMinusIcon />
) : (
<ButtonDuplicateIcon />
)}
</IconBox>
<StyledAlertIcon>
{alert ? <StyledButtonAlertIcon size="medium" /> : <></>}
</StyledAlertIcon>
</StyledFloatingButton>
</StyledCircle>
2022-08-15 07:38:46 +00:00
</ColorTheme>
{clearUploadedFilesHistory && percent === 100 && (
<CloseIcon
className="layout-progress-bar_close-icon"
onClick={onProgressClear}
/>
)}
</StyledFloatingButtonWrapper>
2020-11-16 11:47:30 +00:00
);
};
FloatingButton.propTypes = {
id: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
icon: PropTypes.oneOf([
"upload",
"file",
"trash",
"move",
"duplicate",
"plus",
"minus",
]),
2020-11-16 11:47:30 +00:00
alert: PropTypes.bool,
percent: PropTypes.number,
2021-01-19 11:14:15 +00:00
onClick: PropTypes.func,
color: PropTypes.string,
2020-11-16 11:47:30 +00:00
};
FloatingButton.defaultProps = {
id: undefined,
className: undefined,
style: undefined,
icon: "upload",
2020-11-16 11:47:30 +00:00
alert: false,
percent: 0,
2020-11-16 11:47:30 +00:00
};
export default FloatingButton;