Skip to content

Commit

Permalink
Merge pull request #41 from DopamineDriven/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DopamineDriven authored Dec 3, 2024
2 parents 6a684e2 + 60e5721 commit f418172
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 24 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/ui/reviews-paginated/ui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const variants = {
}
};

const buttonVariants = cva(rootClassName, {
const buttonVariants = cva(rootClassName.root, {
variants,
defaultVariants: {
variant: "default",
Expand Down
84 changes: 61 additions & 23 deletions apps/web/src/ui/reviews-paginated/ui/ReviewContent.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
"use client";

import { useState } from "react";
import { useRef, useState } from "react";
import { ChevronDown, ChevronUp } from "lucide-react";
import { Button } from "@/ui/reviews-paginated/ui/Button";

export function ReviewContent({ content }: { content: string }) {
const [isExpanded, setIsExpanded] = useState(false);
const ref = useRef<HTMLDivElement | null>(null);

function refCb(props: HTMLDivElement | null) {
props = ref.current;
if (!props) {
return;
} else {
console.log(
"innerHeight: ".concat(
props.getBoundingClientRect().height.toString(10)
)
);
}
}
return (
<div>
<p className={`text-zinc-100 ${isExpanded ? "" : "line-clamp-3"}`}>
{content}
</p>
{content.length > 150 && (
<Button
variant="ghost"
size="sm"
className="mt-2 text-[#C5A572] hover:bg-zinc-800 hover:text-[#C5A572]"
onClick={() => setIsExpanded(!isExpanded)}>
{isExpanded ? (
<>
Show less <ChevronUp className="ml-2 h-4 w-4" />
</>
) : (
<>
Read more <ChevronDown className="ml-2 h-4 w-4" />
</>
)}
</Button>
)}
</div>
<>
<div className="hidden md:visible" ref={refCb}>
<p
className={`md:text-zinc-100 ${isExpanded ? "" : "md:line-clamp-3"}`}>
{content}
</p>
{content.length > 150 && (
<Button
variant="ghost"
size="sm"
className="md:mt-2 md:text-[#C5A572] md:hover:bg-zinc-800 md:hover:text-[#C5A572]"
onClick={() => setIsExpanded(!isExpanded)}>
{isExpanded ? (
<>
Show less <ChevronUp className="md:ml-2 md:h-4 md:w-4" />
</>
) : (
<>
Read more <ChevronDown className="md:ml-2 md:h-4 md:w-4" />
</>
)}
</Button>
)}
</div>{" "}
<div className="visible md:hidden" ref={refCb}>
<p className={`text-zinc-100 ${isExpanded ? "" : "line-clamp-3"}`}>
{content}
</p>
{content.length > 120 && (
<Button
variant="ghost"
size="sm"
className="mt-2 text-[#C5A572] hover:bg-zinc-800 hover:text-[#C5A572]"
onClick={() => setIsExpanded(!isExpanded)}>
{isExpanded ? (
<>
Show less <ChevronUp className="ml-2 h-4 w-4" />
</>
) : (
<>
Read more <ChevronDown className="ml-2 h-4 w-4" />
</>
)}
</Button>
)}
</div>
</>
);
}

0 comments on commit f418172

Please sign in to comment.