2020-10-23 08:56:20 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
|
2020-11-04 20:55:48 +03:00
|
|
|
import { css } from "@emotion/core";
|
2020-10-23 08:56:20 +03:00
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
const STYLES_VIEW_BUTTON = css`
|
2020-10-26 03:18:55 +03:00
|
|
|
font-family: ${Constants.font.medium};
|
|
|
|
font-weight: 400;
|
|
|
|
font-size: 14px;
|
|
|
|
margin-top: 4px;
|
2020-10-23 08:56:20 +03:00
|
|
|
color: ${Constants.system.grayBlack};
|
|
|
|
cursor: pointer;
|
2020-11-05 00:44:28 +03:00
|
|
|
width: 120px;
|
2020-10-23 08:56:20 +03:00
|
|
|
`;
|
|
|
|
|
2020-10-23 09:25:19 +03:00
|
|
|
export const ViewAllButton = (props) => {
|
2020-10-23 08:56:20 +03:00
|
|
|
const [isTruncated, setTruncated] = useState(true);
|
2020-11-17 06:25:03 +03:00
|
|
|
const text = props.fullText || "";
|
2020-10-23 08:56:20 +03:00
|
|
|
const maxCharacter = props.maxCharacter;
|
|
|
|
const displayText = isTruncated ? text.slice(0, maxCharacter) : text;
|
2020-10-25 22:34:56 +03:00
|
|
|
const textCount = text.length;
|
2020-11-05 00:44:28 +03:00
|
|
|
const noButton = props.noButton;
|
2020-10-23 08:56:20 +03:00
|
|
|
|
|
|
|
return (
|
2020-10-23 09:25:19 +03:00
|
|
|
<div>
|
|
|
|
{displayText}
|
2020-10-26 03:18:55 +03:00
|
|
|
{textCount > maxCharacter ? (
|
|
|
|
<span>
|
|
|
|
<span>{isTruncated ? "..." : ""}</span>
|
2020-11-05 00:44:28 +03:00
|
|
|
{noButton ? null : (
|
|
|
|
<div css={STYLES_VIEW_BUTTON} onClick={() => setTruncated(!isTruncated)}>
|
2020-11-17 06:25:03 +03:00
|
|
|
{isTruncated ? "+ Show more" : "- Show less"}
|
2020-11-05 00:44:28 +03:00
|
|
|
</div>
|
|
|
|
)}
|
2020-10-25 22:34:56 +03:00
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
""
|
|
|
|
)}
|
2020-10-23 09:25:19 +03:00
|
|
|
</div>
|
2020-10-23 08:56:20 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-23 09:25:19 +03:00
|
|
|
export default ViewAllButton;
|