mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-28 16:20:34 +08:00
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import {
|
|
Button,
|
|
Modal,
|
|
ModalBody,
|
|
ModalCloseButton,
|
|
ModalContent,
|
|
ModalHeader,
|
|
ModalOverlay,
|
|
useColorModeValue,
|
|
useDisclosure,
|
|
} from "@chakra-ui/react";
|
|
import React, { ReactNode } from "react";
|
|
|
|
const killEvent = (e) => e.stopPropagation();
|
|
|
|
export const CollapsableText = ({
|
|
text,
|
|
maxLength = 220,
|
|
isDisabled,
|
|
}: {
|
|
text: ReactNode;
|
|
maxLength?: number;
|
|
isDisabled?: boolean;
|
|
}) => {
|
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
|
|
const moreButtonColor = useColorModeValue("gray.600", "gray.400");
|
|
|
|
if (typeof text !== "string" || text.length <= maxLength) {
|
|
return <>{text}</>;
|
|
} else {
|
|
return (
|
|
<>
|
|
<span>
|
|
{text.substring(0, maxLength - 3)}
|
|
<Button
|
|
style={{ display: "inline" }}
|
|
size={"xs"}
|
|
variant={"solid"}
|
|
bg={moreButtonColor}
|
|
color={"white"}
|
|
isDisabled={isDisabled}
|
|
onClick={onOpen}
|
|
>
|
|
...
|
|
</Button>
|
|
</span>
|
|
<Modal isOpen={isOpen} onClose={onClose} size="xl" scrollBehavior={"inside"}>
|
|
{/* we kill the event here to disable drag and drop, since it is in the same container */}
|
|
<ModalOverlay onMouseDown={killEvent}>
|
|
<ModalContent alignItems="center">
|
|
<ModalHeader>Full Text</ModalHeader>
|
|
<ModalCloseButton />
|
|
<ModalBody>{text}</ModalBody>
|
|
</ModalContent>
|
|
</ModalOverlay>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
};
|