Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added gift description with toggle #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion client/src/components/UpdatedGiftItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import React, { useState } from "react";

type GiftItemProps = {
name: string;
price: number;
description: string;
};

function UpdatedGiftItem({ name, price }: GiftItemProps) {
function UpdatedGiftItem({ name, price, description }: GiftItemProps) {
const[expanded, setExpanded] = useState(false);
const toggleDescription = () => {
setExpanded(!expanded);
}

return (
<div className="relative flex flex-col bg-gray-100 flex-start">
<div className="bg-gray-200 w-40 h-40 mx-auto mb-2 relative">
Expand All @@ -25,6 +33,13 @@ function UpdatedGiftItem({ name, price }: GiftItemProps) {
<div className="">
<h2 className="text-sm text-black font-bold">{name}</h2>
<h2 className="text-xs text-black">${price}</h2>
{description.length > 50 && !expanded ? (
<p className='text-xs text-gray-500 cursor-pointer' onClick={toggleDescription}>
{description.slice(0,50)}... Show More
</p>
) : (
<p className='text-xs text-gray-500'>{description}</p>
)}
</div>
</div>
);
Expand Down
13 changes: 6 additions & 7 deletions client/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,15 @@ const HomePage = () => {
<div className=" w-1000">
<GiftSortNavBar />
</div>

<div className="overflow-y-auto" style={{ maxHeight: '290px', maxWidth: '1000px' }}>
<div className="flex flex-wrap justify-between gap-4">
{displayCollection.Gifts.map((gift, index) => (
<div key={index}>
<UpdatedGiftItem name={gift.Name} price={gift.Price} />
</div>
))}
<div className="flex flex-wrap -mx-2">
{displayCollection.Gifts.map((gift, index) => (
<div key={index} className="w-1/4 px-2">
<UpdatedGiftItem name={gift.Name} price={gift.Price} description={gift.Description}/>
</div>
))}
</div>
</div>
</div>
</div>
);
Expand Down
Loading