DocSpace-buildtools/web/ASC.Web.Components/src/components/link/index.js

81 lines
1.8 KiB
JavaScript
Raw Normal View History

import React, { memo } from "react";
2019-08-12 09:41:53 +00:00
import styled, { css } from "styled-components";
import PropTypes from "prop-types";
import Text from "../text";
2019-08-12 09:41:53 +00:00
2019-06-21 16:02:16 +00:00
const colorCss = css`
2019-08-12 09:41:53 +00:00
color: ${props => props.color};
2019-06-21 16:02:16 +00:00
`;
const hoveredCss = css`
2019-08-12 09:41:53 +00:00
${colorCss};
text-decoration: ${props => (props.type === 'page' ? 'underline' : 'underline dashed')};
2019-06-21 16:02:16 +00:00
`;
const StyledLink = styled(Text)`
text-decoration: none;
2019-08-12 09:41:53 +00:00
user-select: none;
cursor: pointer;
opacity: ${props => props.isSemitransparent && "0.5"};
2019-06-21 16:02:16 +00:00
line-height: calc(100% + 6px);
2019-08-12 09:41:53 +00:00
${colorCss};
2019-08-12 09:41:53 +00:00
&:hover {
${hoveredCss};
}
2019-06-21 16:02:16 +00:00
2019-08-12 09:41:53 +00:00
${props => props.isHovered && hoveredCss}
2019-06-21 16:02:16 +00:00
`;
// eslint-disable-next-line react/display-name
const Link = memo(({ isTextOverflow, children, ...rest }) => {
// console.log("Link render", rest);
2019-08-12 09:41:53 +00:00
return (
<StyledLink
tag="a"
truncate={isTextOverflow}
{...rest}
>
{children}
</StyledLink>
2019-08-12 09:41:53 +00:00
);
});
2019-06-21 16:02:16 +00:00
Link.propTypes = {
2019-08-12 09:41:53 +00:00
color: PropTypes.string,
fontSize: PropTypes.string,
2019-08-12 09:41:53 +00:00
href: PropTypes.string,
isBold: PropTypes.bool,
isHovered: PropTypes.bool,
isSemitransparent: PropTypes.bool,
isTextOverflow: PropTypes.bool,
onClick: PropTypes.func,
rel: PropTypes.string,
tabIndex: PropTypes.number,
2019-08-12 09:41:53 +00:00
target: PropTypes.oneOf(["_blank", "_self", "_parent", "_top"]),
title: PropTypes.string,
type: PropTypes.oneOf(["action", "page"]),
children: PropTypes.any,
className: PropTypes.string,
id: PropTypes.string,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
2019-06-21 16:02:16 +00:00
};
Link.defaultProps = {
2019-08-12 09:41:53 +00:00
color: "#333333",
fontSize: '13px',
2019-08-12 09:41:53 +00:00
href: undefined,
isBold: false,
isHovered: false,
isSemitransparent: false,
isTextOverflow: true,
rel: "noopener noreferrer",
tabIndex: -1,
type: "page",
className: "",
2019-08-12 09:41:53 +00:00
};
2019-06-21 16:02:16 +00:00
export default Link;