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";
import { css } from "@emotion/core";
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;
color: ${Constants.system.grayBlack};
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;