Skip to content

Commit

Permalink
simple show more news working
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheaton committed Jun 21, 2024
1 parent 267d6cc commit ca6e4b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/components/HeroSection/HeroElements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,21 @@ export const HeroFollowBlock = styled.div`
font-size: 14px;
}
`;

export const HeroNewsMoreButton = styled.button`
background: #fff;
color: #000;
font-size: 16px;
padding: 10px 24px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 20px;
margin-bottom: 20px;
align-self: center;
&:hover {
background: #000;
color: #fff;
}
`;
13 changes: 12 additions & 1 deletion src/components/HeroSection/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {
HeroNewsItem,
HeroNewsItemContent,
HeroNewsItemDate,
HeroNewsMoreButton,
HeroNewsTitle,
HeroRow,
Img,
UDLLink,
} from "@/components/HeroSection/HeroElements";
import img from "@/images/book_cover.jpg";
import { useState } from "react";

const citation = `
@book{prince2023understanding,
Expand Down Expand Up @@ -140,19 +142,28 @@ const news = [
];

export default function HeroSection() {
const [showMoreNews, setShowMoreNews] = useState(false);

const toggleShowMore = () => {
setShowMoreNews((p) => !p);
};

return (
<HeroContainer id="home">
<HeroContent>
<HeroRow>
<HeroColumn1>
<HeroNewsBlock>
<HeroNewsTitle>RECENT NEWS:</HeroNewsTitle>
{news.map((item, index) => (
{(showMoreNews ? news : news.slice(0, 7)).map((item, index) => (
<HeroNewsItem key={index}>
<HeroNewsItemDate>{item.date}</HeroNewsItemDate>
{item.content}
</HeroNewsItem>
))}
<HeroNewsMoreButton onClick={toggleShowMore}>
{showMoreNews ? "Show less" : "Show more"}
</HeroNewsMoreButton>
</HeroNewsBlock>
<HeroCitationTitle>CITATION:</HeroCitationTitle>
<HeroCitationBlock>
Expand Down

0 comments on commit ca6e4b2

Please sign in to comment.