limit news articles shown and add button to show more
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
"use client"
|
||||||
|
import { useState } from "react";
|
||||||
import { SectionHeader } from "../general/SectionHeader";
|
import { SectionHeader } from "../general/SectionHeader";
|
||||||
import { NewsItem } from "./NewsItem";
|
import { NewsItem } from "./NewsItem";
|
||||||
import styles from "./newsList.module.scss";
|
import styles from "./newsList.module.scss";
|
||||||
@ -6,15 +8,16 @@ import { NewsFragment } from "@/lib/news";
|
|||||||
export const NewsList = ({
|
export const NewsList = ({
|
||||||
news,
|
news,
|
||||||
heading,
|
heading,
|
||||||
featured,
|
featured
|
||||||
limit,
|
|
||||||
}: {
|
}: {
|
||||||
news: NewsFragment[];
|
news: NewsFragment[];
|
||||||
heading?: string;
|
heading?: string;
|
||||||
featured?: boolean;
|
featured?: boolean;
|
||||||
limit?: number;
|
|
||||||
}) => {
|
}) => {
|
||||||
const filteredNews = limit ? news.slice(0, limit) : news;
|
const [limit, setLimit] = useState(17);
|
||||||
|
function increaseLimit() {
|
||||||
|
setLimit(limit + 16);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.newsWrapper}>
|
<section className={styles.newsWrapper}>
|
||||||
@ -22,10 +25,17 @@ export const NewsList = ({
|
|||||||
<SectionHeader heading={heading} link="/aktuelt" linkText="Se flere artikler" />
|
<SectionHeader heading={heading} link="/aktuelt" linkText="Se flere artikler" />
|
||||||
)}
|
)}
|
||||||
<ul className={`${styles.newsList} ${featured && styles.featured}`}>
|
<ul className={`${styles.newsList} ${featured && styles.featured}`}>
|
||||||
{filteredNews.map((singleNews) => (
|
{news.slice(0, limit).map((singleNews) => (
|
||||||
<NewsItem key={singleNews.id} news={singleNews} />
|
<NewsItem key={singleNews.id} news={singleNews} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
{limit && news.length > limit && (
|
||||||
|
<div className={styles.showMore}>
|
||||||
|
<button onClick={increaseLimit}>
|
||||||
|
<span>Last inn flere artikler</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -54,6 +54,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.showMore {
|
||||||
|
margin-top: var(--spacing-s);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.newsList, .newsList.featured {
|
.newsList, .newsList.featured {
|
||||||
li {
|
li {
|
||||||
|
Reference in New Issue
Block a user