slate/components/core/ViewAll.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
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;
color: ${Constants.system.grayBlack};
text-decoration: underline;
cursor: pointer;
2020-10-26 03:18:55 +03:00
width: 64px;
`;
2020-10-23 09:25:19 +03:00
export const ViewAllButton = (props) => {
const [isTruncated, setTruncated] = useState(true);
2020-10-23 09:25:19 +03:00
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;
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>
<div css={STYLES_VIEW_BUTTON} onClick={() => setTruncated(!isTruncated)}>
{isTruncated ? "view all" : "view less"}
</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;