slate/components/core/ViewAll.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
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;
2021-07-07 22:58:14 +03:00
color: ${Constants.system.grayDark2};
cursor: pointer;
2020-11-05 00:44:28 +03:00
width: 120px;
`;
2020-10-23 09:25:19 +03:00
export const ViewAllButton = (props) => {
const [isTruncated, setTruncated] = useState(true);
const text = props.fullText || "";
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;
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)}>
{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 09:25:19 +03:00
export default ViewAllButton;