DocSpace-client/packages/common/components/AlertComponent/index.js

123 lines
2.8 KiB
JavaScript
Raw Normal View History

2023-04-03 10:52:06 +00:00
import React from "react";
import { inject, observer } from "mobx-react";
2023-04-13 08:33:08 +00:00
import styled, { css } from "styled-components";
2023-04-03 10:52:06 +00:00
import Text from "@docspace/components/text";
import commonIconsStyles from "@docspace/components/utils/common-icons-style";
import ArrowRightIcon from "PUBLIC_DIR/images/arrow.right.react.svg";
import CrossReactSvg from "PUBLIC_DIR/images/cross.react.svg";
import Loaders from "../Loaders";
import { StyledAlertComponent } from "./StyledComponent";
2023-04-03 12:42:51 +00:00
import Link from "@docspace/components/link";
2023-04-03 10:52:06 +00:00
const StyledArrowRightIcon = styled(ArrowRightIcon)`
margin: auto 0;
${({ theme }) =>
theme.interfaceDirection === "rtl" && "transform: scaleX(-1);"}
2023-04-03 10:52:06 +00:00
path {
2023-04-03 12:42:51 +00:00
fill: ${(props) => props.theme.alertComponent.iconColor};
2023-04-03 10:52:06 +00:00
}
`;
const StyledCrossIcon = styled(CrossReactSvg)`
position: absolute;
${({ theme }) =>
theme.interfaceDirection === "rtl"
? css`
left: 0px;
margin-left: 8px;
`
: css`
right: 0px;
margin-right: 8px;
`}
2023-04-03 10:52:06 +00:00
margin-top: 8px;
2023-04-03 12:42:51 +00:00
cursor: pointer;
2023-04-03 10:52:06 +00:00
${commonIconsStyles}
path {
fill: ${(props) => props.color};
}
`;
2023-04-03 12:42:51 +00:00
const AlertComponent = (props) => {
const {
id,
description,
title,
titleFontSize,
additionalDescription,
needArrowIcon = false,
needCloseIcon = false,
link,
2023-06-06 00:54:33 +00:00
onLinkClick,
2023-04-03 12:42:51 +00:00
linkColor,
linkTitle,
onAlertClick,
onCloseClick,
titleColor,
borderColor,
theme,
} = props;
2023-04-03 10:52:06 +00:00
return (
<StyledAlertComponent
2023-04-03 12:42:51 +00:00
theme={theme}
titleColor={titleColor}
borderColor={borderColor}
2023-04-03 10:52:06 +00:00
onClick={onAlertClick}
needArrowIcon={needArrowIcon}
id={id}
>
2023-06-06 00:54:33 +00:00
<div className="main-content">
2023-04-03 10:52:06 +00:00
<Text
className="alert-component_title"
fontSize={titleFontSize ?? "12px"}
fontWeight={600}
>
{title}
</Text>
{additionalDescription && (
<Text fontWeight={600}>{additionalDescription}</Text>
)}
2023-04-03 12:42:51 +00:00
<Text
noSelect
fontSize="12px"
color={theme.alertComponent.descriptionColor}
>
2023-04-03 10:52:06 +00:00
{description}
</Text>
2023-06-06 00:54:33 +00:00
{(link || onLinkClick) && (
<Link
type="page"
href={link}
onClick={onLinkClick}
noHover
color={linkColor}
>
2023-04-03 10:52:06 +00:00
{linkTitle}
</Link>
)}
</div>
{needCloseIcon && (
2023-04-03 12:42:51 +00:00
<StyledCrossIcon size="extraSmall" onClick={onCloseClick} />
2023-04-03 10:52:06 +00:00
)}
{needArrowIcon && (
<StyledArrowRightIcon className="alert-component_arrow" />
)}
</StyledAlertComponent>
);
};
2023-04-13 08:33:08 +00:00
export default inject(({ auth }) => {
const { settingsStore } = auth;
2023-04-03 10:52:06 +00:00
2023-04-13 08:33:08 +00:00
const { theme } = settingsStore;
2023-04-03 10:52:06 +00:00
2023-04-13 08:33:08 +00:00
return {
theme,
};
})(observer(AlertComponent));