2024-03-21 14:09:55 +00:00
|
|
|
// (c) Copyright Ascensio System SIA 2009-2024
|
2024-03-18 09:54:09 +00:00
|
|
|
//
|
2024-03-17 23:13:02 +00:00
|
|
|
// This program is a free software product.
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
|
|
|
|
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
|
|
|
|
// any third-party rights.
|
2024-03-18 09:54:09 +00:00
|
|
|
//
|
2024-03-17 23:13:02 +00:00
|
|
|
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
2024-03-18 09:54:09 +00:00
|
|
|
//
|
2024-03-17 23:13:02 +00:00
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
2024-03-18 09:54:09 +00:00
|
|
|
//
|
2024-03-17 23:13:02 +00:00
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
2024-03-18 09:54:09 +00:00
|
|
|
//
|
2024-03-17 23:13:02 +00:00
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
// trademark law for use of our trademarks.
|
2024-03-18 09:54:09 +00:00
|
|
|
//
|
2024-03-17 23:13:02 +00:00
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
|
2021-02-26 13:29:50 +00:00
|
|
|
import React from "react";
|
2021-02-08 14:56:36 +00:00
|
|
|
import styled, { css } from "styled-components";
|
2023-01-27 14:08:30 +00:00
|
|
|
import ExpanderDownReactSvg from "PUBLIC_DIR/images/expander-down.react.svg";
|
2023-12-26 10:46:17 +00:00
|
|
|
|
|
|
|
import { Base } from "../../themes";
|
|
|
|
import { Text } from "../text";
|
|
|
|
import { TextProps } from "../text/Text.types";
|
|
|
|
|
|
|
|
// import { transform } from "lodash";
|
|
|
|
import {
|
|
|
|
SimpleLinkWithDropdownProps,
|
|
|
|
TDropdownType,
|
|
|
|
} from "./LinkWithDropdown.types";
|
|
|
|
|
2021-02-08 14:56:36 +00:00
|
|
|
const SimpleLinkWithDropdown = ({
|
|
|
|
isBold,
|
|
|
|
fontSize,
|
|
|
|
fontWeight,
|
|
|
|
isTextOverflow,
|
|
|
|
isHovered,
|
|
|
|
isSemitransparent,
|
|
|
|
color,
|
|
|
|
title,
|
|
|
|
dropdownType,
|
|
|
|
data,
|
|
|
|
isDisabled,
|
2023-12-26 10:46:17 +00:00
|
|
|
children,
|
2021-02-08 14:56:36 +00:00
|
|
|
...props
|
2023-12-26 10:46:17 +00:00
|
|
|
}: SimpleLinkWithDropdownProps) => <a {...props}>{children}</a>;
|
2021-02-08 14:56:36 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line react/prop-types, no-unused-vars
|
2021-02-20 08:46:32 +00:00
|
|
|
const ExpanderDownIconWrapper = ({
|
2021-02-08 14:56:36 +00:00
|
|
|
isSemitransparent,
|
|
|
|
dropdownType,
|
|
|
|
isOpen,
|
2021-03-03 09:05:23 +00:00
|
|
|
isDisabled,
|
2021-02-08 14:56:36 +00:00
|
|
|
...props
|
2023-12-26 10:46:17 +00:00
|
|
|
}: {
|
|
|
|
isSemitransparent: boolean;
|
|
|
|
dropdownType: TDropdownType;
|
|
|
|
isOpen: boolean;
|
|
|
|
isDisabled: boolean;
|
2023-01-16 11:01:35 +00:00
|
|
|
}) => <ExpanderDownReactSvg {...props} />;
|
2021-02-08 14:56:36 +00:00
|
|
|
|
2023-12-26 10:46:17 +00:00
|
|
|
const Caret = styled(ExpanderDownIconWrapper)<{ color?: string }>`
|
2021-02-08 14:56:36 +00:00
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
width: ${(props) => props.theme.linkWithDropdown.caret.width};
|
|
|
|
min-width: ${(props) => props.theme.linkWithDropdown.caret.minWidth};
|
|
|
|
height: ${(props) => props.theme.linkWithDropdown.caret.height};
|
|
|
|
min-height: ${(props) => props.theme.linkWithDropdown.caret.minHeight};
|
|
|
|
margin-left: ${(props) => props.theme.linkWithDropdown.caret.marginLeft};
|
|
|
|
margin-top: ${(props) => props.theme.linkWithDropdown.caret.marginTop};
|
|
|
|
|
|
|
|
right: ${(props) => props.theme.linkWithDropdown.caret.right};
|
|
|
|
top: ${(props) => props.theme.linkWithDropdown.caret.top};
|
|
|
|
bottom: ${(props) => props.theme.linkWithDropdown.caret.bottom};
|
2023-05-31 13:07:59 +00:00
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.theme.interfaceDirection === "rtl" &&
|
|
|
|
css`
|
2023-12-26 10:46:17 +00:00
|
|
|
margin-right: ${props.theme.linkWithDropdown.caret.marginLeft};
|
2023-05-31 13:07:59 +00:00
|
|
|
margin-left: 0;
|
2023-12-26 10:46:17 +00:00
|
|
|
left: ${props.theme.linkWithDropdown.caret.right};
|
2023-05-31 13:07:59 +00:00
|
|
|
right: 0;
|
|
|
|
`}
|
|
|
|
|
2021-02-08 14:56:36 +00:00
|
|
|
margin: ${(props) => props.theme.linkWithDropdown.caret.margin};
|
|
|
|
|
|
|
|
path {
|
2023-12-26 10:46:17 +00:00
|
|
|
fill: ${(props) =>
|
|
|
|
props.isDisabled
|
|
|
|
? props.theme.linkWithDropdown.disableColor
|
|
|
|
: props.color};
|
2021-02-08 14:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.dropdownType === "appearDashedAfterHover" &&
|
|
|
|
`opacity: ${props.theme.linkWithDropdown.caret.opacity};`}
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.isOpen &&
|
|
|
|
`
|
|
|
|
bottom: ${props.theme.linkWithDropdown.caret.isOpenBottom};
|
|
|
|
transform: ${props.theme.linkWithDropdown.caret.transform};
|
|
|
|
`}
|
|
|
|
`;
|
|
|
|
Caret.defaultProps = { theme: Base };
|
|
|
|
|
|
|
|
const StyledLinkWithDropdown = styled(SimpleLinkWithDropdown)`
|
|
|
|
${(props) => !props.isDisabled && "cursor: pointer;"}
|
|
|
|
text-decoration: none;
|
|
|
|
user-select: none;
|
|
|
|
position: relative;
|
2022-04-27 12:22:14 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2021-02-08 14:56:36 +00:00
|
|
|
|
|
|
|
padding-right: ${(props) => props.theme.linkWithDropdown.paddingRight};
|
|
|
|
|
2023-05-31 13:07:59 +00:00
|
|
|
${(props) =>
|
|
|
|
props.theme.interfaceDirection === "rtl" &&
|
|
|
|
css`
|
2023-12-26 10:46:17 +00:00
|
|
|
padding-left: ${props.theme.linkWithDropdown.paddingRight};
|
2023-05-31 13:07:59 +00:00
|
|
|
padding-right: 0;
|
|
|
|
`}
|
|
|
|
|
2023-12-26 10:46:17 +00:00
|
|
|
color: ${(props) =>
|
|
|
|
props.isDisabled ? props.theme.linkWithDropdown.disableColor : props.color};
|
2021-02-08 14:56:36 +00:00
|
|
|
|
|
|
|
${(props) => props.isSemitransparent && `opacity: 0.5`};
|
|
|
|
${(props) =>
|
|
|
|
props.dropdownType === "alwaysDashed" &&
|
|
|
|
`text-decoration: ${props.theme.linkWithDropdown.textDecoration};`};
|
|
|
|
|
|
|
|
&:not([href]):not([tabindex]) {
|
|
|
|
${(props) =>
|
|
|
|
props.dropdownType === "alwaysDashed" &&
|
|
|
|
`text-decoration: ${props.theme.linkWithDropdown.textDecoration};`};
|
2023-12-26 10:46:17 +00:00
|
|
|
color: ${(props) =>
|
|
|
|
props.isDisabled
|
|
|
|
? props.theme.linkWithDropdown.disableColor
|
|
|
|
: props.color};
|
2021-02-08 14:56:36 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: ${(props) =>
|
|
|
|
props.theme.linkWithDropdown.textDecoration};
|
2023-12-26 10:46:17 +00:00
|
|
|
color: ${(props) =>
|
|
|
|
props.isDisabled
|
|
|
|
? props.theme.linkWithDropdown.disableColor
|
|
|
|
: props.color};
|
2021-02-08 14:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
:hover {
|
2023-12-26 10:46:17 +00:00
|
|
|
color: ${(props) =>
|
|
|
|
props.isDisabled
|
|
|
|
? props.theme.linkWithDropdown.disableColor
|
|
|
|
: props.color};
|
2021-02-08 14:56:36 +00:00
|
|
|
|
|
|
|
svg {
|
|
|
|
${(props) =>
|
|
|
|
props.dropdownType === "appearDashedAfterHover" &&
|
|
|
|
`position: absolute; opacity: ${props.theme.linkWithDropdown.svg.opacity};`};
|
|
|
|
${(props) =>
|
|
|
|
props.isSemitransparent &&
|
|
|
|
`opacity: ${props.theme.linkWithDropdown.svg.semiTransparentOpacity};`};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
StyledLinkWithDropdown.defaultProps = { theme: Base };
|
2022-07-14 14:26:21 +00:00
|
|
|
|
2023-12-26 10:46:17 +00:00
|
|
|
const StyledTextWithExpander = styled.div<{ isOpen?: boolean }>`
|
2022-07-14 14:26:21 +00:00
|
|
|
display: flex;
|
|
|
|
gap: 4px;
|
|
|
|
|
|
|
|
.expander {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
width: 6.35px;
|
|
|
|
svg {
|
|
|
|
transform: ${(props) => (props.isOpen ? "rotate(180deg)" : "rotate(0)")};
|
|
|
|
width: 6.35px;
|
|
|
|
height: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2023-12-26 10:46:17 +00:00
|
|
|
const SimpleText = ({ c, ...props }: TextProps & { c?: string }) => (
|
|
|
|
<Text as="span" {...props} />
|
|
|
|
);
|
|
|
|
|
|
|
|
const StyledText = styled(SimpleText)<{ isTextOverflow?: boolean }>`
|
2022-12-09 13:49:53 +00:00
|
|
|
color: inherit;
|
2021-02-08 14:56:36 +00:00
|
|
|
${(props) =>
|
|
|
|
props.isTextOverflow &&
|
|
|
|
css`
|
|
|
|
display: inline-block;
|
2023-12-26 10:46:17 +00:00
|
|
|
max-width: ${props.theme.linkWithDropdown.text.maxWidth};
|
2022-12-09 13:49:53 +00:00
|
|
|
`};
|
2021-02-08 14:56:36 +00:00
|
|
|
`;
|
|
|
|
StyledText.defaultProps = { theme: Base };
|
|
|
|
|
2024-01-26 12:45:04 +00:00
|
|
|
// const focusColor = css`
|
|
|
|
// color: ${(props) => props.theme.linkWithDropdown.color.focus};
|
|
|
|
// background: ${(props) => props.theme.linkWithDropdown.background.focus};
|
|
|
|
// .expander {
|
|
|
|
// path {
|
|
|
|
// fill: ${(props) => props.theme.linkWithDropdown.color.focus};
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// `;
|
|
|
|
|
2024-02-09 21:40:59 +00:00
|
|
|
const StyledSpan = styled.span<{ $isOpen?: boolean }>`
|
2022-12-09 13:49:53 +00:00
|
|
|
display: inline-block;
|
|
|
|
padding: 4px 8px;
|
|
|
|
border-radius: 3px;
|
2021-02-08 14:56:36 +00:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.drop-down-item {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fixed-max-width {
|
|
|
|
max-width: ${(props) => props.theme.linkWithDropdown.text.maxWidth};
|
|
|
|
}
|
2022-12-09 13:49:53 +00:00
|
|
|
|
|
|
|
color: ${(props) => props.theme.linkWithDropdown.color.default};
|
|
|
|
background: ${(props) => props.theme.linkWithDropdown.background.default};
|
|
|
|
.expander {
|
|
|
|
path {
|
|
|
|
fill: ${(props) => props.theme.linkWithDropdown.color.default};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 21:40:59 +00:00
|
|
|
:hover {
|
|
|
|
color: ${(props) => props.theme.linkWithDropdown.color.hover};
|
|
|
|
|
|
|
|
background: ${(props) => props.theme.linkWithDropdown.background.hover};
|
|
|
|
.expander {
|
|
|
|
path {
|
|
|
|
fill: ${(props) => props.theme.linkWithDropdown.color.hover};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 13:49:53 +00:00
|
|
|
${(props) =>
|
2024-02-09 21:40:59 +00:00
|
|
|
props.$isOpen &&
|
2022-12-09 13:49:53 +00:00
|
|
|
css`
|
2024-02-09 21:40:59 +00:00
|
|
|
color: ${props.theme.linkWithDropdown.color.hover};
|
|
|
|
background: ${props.theme.linkWithDropdown.background.hover};
|
2022-12-09 13:49:53 +00:00
|
|
|
`}
|
2021-02-08 14:56:36 +00:00
|
|
|
`;
|
|
|
|
StyledSpan.defaultProps = { theme: Base };
|
|
|
|
|
2022-07-14 14:26:21 +00:00
|
|
|
export {
|
|
|
|
StyledSpan,
|
|
|
|
StyledTextWithExpander,
|
|
|
|
StyledText,
|
|
|
|
StyledLinkWithDropdown,
|
|
|
|
Caret,
|
|
|
|
};
|