snort/packages/app/src/Components/Event/ShowMore.tsx

41 lines
979 B
TypeScript
Raw Normal View History

import "./ShowMore.css";
2024-01-04 17:01:18 +00:00
2023-11-07 12:30:01 +00:00
import classNames from "classnames";
2024-01-04 17:01:18 +00:00
import { useEffect } from "react";
import { useInView } from "react-intersection-observer";
import { FormattedMessage } from "react-intl";
2023-02-06 21:42:47 +00:00
interface ShowMoreProps {
text?: string;
className?: string;
onClick: () => void;
2023-02-06 21:42:47 +00:00
}
2023-02-08 21:10:26 +00:00
const ShowMore = ({ text, onClick, className = "" }: ShowMoreProps) => {
2023-02-06 21:42:47 +00:00
return (
<div className="show-more-container">
2023-11-07 12:30:01 +00:00
<button className={classNames("show-more", className)} onClick={onClick}>
{text || <FormattedMessage defaultMessage="Show More" id="O8Z8t9" />}
2023-02-06 21:42:47 +00:00
</button>
</div>
);
};
2023-02-06 21:42:47 +00:00
export default ShowMore;
2023-11-07 12:30:01 +00:00
export function ShowMoreInView({ text, onClick, className }: ShowMoreProps) {
2023-12-13 09:25:15 +00:00
const { ref, inView } = useInView({ rootMargin: "2000px" });
2023-11-07 12:30:01 +00:00
useEffect(() => {
if (inView) {
onClick();
}
}, [inView]);
2023-11-07 12:37:23 +00:00
return (
<div className={classNames("show-more-container", className)} ref={ref}>
{text}
</div>
);
}