mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 04:19:45 +00:00
Пересобрал компоненты карточек и CardList, обновил импорты
This commit is contained in:
1 parent
26018016e1
commit
05f7a7a1d7
12 files changed
+194
-193
No files matched your search
@@ -1,173 +0,0 @@
|
||||
.card {
|
||||
position: relative;
|
||||
display: block;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&__lab {
|
||||
height: 300px;
|
||||
border: 1px solid transparent;
|
||||
color: $text-secondary;
|
||||
|
||||
.content {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
z-index: 2;
|
||||
transition: bottom 0.3s ease;
|
||||
}
|
||||
|
||||
.description {
|
||||
max-height: 0;
|
||||
opacity: 0;
|
||||
transition: max-height 0.3s ease, opacity 0.3s ease;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.link {
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.image {
|
||||
filter: brightness(0.7);
|
||||
}
|
||||
|
||||
.content {
|
||||
bottom: 20px;
|
||||
}
|
||||
|
||||
.description {
|
||||
max-height: 200px;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.link {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__news {
|
||||
height: 250px;
|
||||
|
||||
.content {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 12px 16px;
|
||||
color: white;
|
||||
|
||||
&::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 40%;
|
||||
background: linear-gradient(
|
||||
to top,
|
||||
rgba(0, 0, 0, 0.6),
|
||||
rgba(0, 0, 0, 0)
|
||||
);
|
||||
z-index: -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__project {
|
||||
height: 250px;
|
||||
|
||||
.content {
|
||||
position: absolute;
|
||||
left: 11px;
|
||||
bottom: 0;
|
||||
padding: clamp(12px, 3vw, 22px) clamp(6px, 1.5vw, 16px);
|
||||
color: $text-card-project;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.image {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: filter 0.3s ease;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0 0 12px;
|
||||
font-size: clamp(1.25rem, 1.0011rem + 0.5199vw, 1.625rem);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.description {
|
||||
p {
|
||||
font-size: clamp(1rem, 0.8755rem + 0.26vw, 1.1875rem);
|
||||
line-height: 140%;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 5;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.link {
|
||||
font-size: clamp(12px, 1.5vw, 20px);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.card {
|
||||
height: 215px !important;
|
||||
|
||||
&--lab {
|
||||
.content {
|
||||
left: 10px;
|
||||
right: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.card__lab {
|
||||
&:hover {
|
||||
.title {
|
||||
font-size: 20px;
|
||||
@include mediaMax($mobile-max-widthGosBlock) {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 22px;
|
||||
@include mediaMax($mobile-max-widthGosBlock) {
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
p {
|
||||
font-size: 16px;
|
||||
line-height: 26px;
|
||||
@include mediaMax($mobile-max-widthGosBlock) {
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.link {
|
||||
font-size: 18px;
|
||||
@include mediaMax($mobile-max-widthGosBlock) {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// widgets/Card/Card.tsx
|
||||
import { Link } from "react-router-dom";
|
||||
import styles from "./Card.module.scss";
|
||||
import { classNames } from "@/shared/lib/classNames/classNames";
|
||||
import type { CardData } from "@/widgets/CardList/types";
|
||||
|
||||
interface CardProps {
|
||||
data: CardData & { variant?: "lab" | "news" | "project" };
|
||||
}
|
||||
|
||||
export const Card = ({ data }: CardProps) => {
|
||||
const { id, name, previewText, preview, link, variant = "lab" } = data;
|
||||
|
||||
return (
|
||||
<Link
|
||||
className={classNames(styles.card, {}, [styles[`card__${variant}`]])}
|
||||
to={link || `/${id || name}`}
|
||||
>
|
||||
<img src={preview} alt={name} className={styles.image} />
|
||||
|
||||
<div className={styles.content}>
|
||||
<h3 className={styles.title}>{name}</h3>
|
||||
|
||||
{previewText && variant === "lab" && (
|
||||
<div className={styles.description}>
|
||||
<p>{previewText}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{variant === "lab" && (
|
||||
<div className={styles.link}>
|
||||
<span>Перейти ⟶</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
// Тип для вариантов карточки
|
||||
|
||||
export interface CardData {
|
||||
id?: string; // Опционально, если используется name как уникальный идентификатор
|
||||
name: string; // Название лаборатории
|
||||
previewText: string; // Описание
|
||||
link: string; // Ссылка
|
||||
preview: string; // URL изображения
|
||||
variant?: "lab" | "news" | "project"; // Вариант карточки
|
||||
}
|
||||
// Пропсы компонента Card
|
||||
export interface CardProps {
|
||||
data: CardData;
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
.mainContainer {
|
||||
margin: 0 10%;
|
||||
@include mediaMax($mobile-xs-width) {
|
||||
margin: 0 5%;
|
||||
}
|
||||
}
|
||||
.title {
|
||||
font-size: 36px;
|
||||
font-weight: 600;
|
||||
@@ -9,40 +15,3 @@
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
.list {
|
||||
display: grid;
|
||||
gap: 2rem;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 32px;
|
||||
&__lab {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
}
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__news {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
}
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__project {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
}
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,104 @@
|
||||
// widgets/CardList/CardList.tsx
|
||||
import { CardListProps } from "@/widgets/CardList/types";
|
||||
// pages/MainPage/ui/MainPage/Lists.tsx
|
||||
import { CardListTemplate } from "@/widgets/CardList/CardListTemplate";
|
||||
import { GridConfig } from "@/widgets/CardList/types";
|
||||
import { usePosts } from "@/modules/posts/hooks/usePosts";
|
||||
import styles from "./CardList.module.scss";
|
||||
import { Card } from "@/widgets/Card/Card";
|
||||
import { classNames } from "@/shared/lib/classNames/classNames";
|
||||
import { useNews } from "@/modules";
|
||||
import {
|
||||
transformNewsToCardData,
|
||||
transformPostsToCardData,
|
||||
} from "@/widgets/CardList/CardListFunctions";
|
||||
import { usePostProjects } from "@/modules/posts/hooks/usePostProjects";
|
||||
|
||||
export const CardList = ({
|
||||
items,
|
||||
variant = "lab", // Значение по умолчанию
|
||||
interface ListProps {
|
||||
gridConfig?: GridConfig;
|
||||
tag?: number;
|
||||
}
|
||||
|
||||
const NewsList = ({
|
||||
gridConfig = { desktop: 3, tablet: 2, mobile: 1 },
|
||||
title = "Лаборатории",
|
||||
}: CardListProps) => {
|
||||
const itemsArray = Object.values(items);
|
||||
}: ListProps) => {
|
||||
const { data: newsData, isLoading, isError } = useNews();
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="mainContainer">
|
||||
<h2 className={styles.title}>Новости</h2>
|
||||
<span className="loader"></span>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError) return <div>Ошибка при загрузке данных</div>;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className={styles.title}>{title}</h1>
|
||||
<div
|
||||
className={classNames(styles.list, {}, [styles[`list__${variant}`]])}
|
||||
style={
|
||||
{
|
||||
"--desktop-columns": gridConfig.desktop,
|
||||
"--tablet-columns": gridConfig.tablet,
|
||||
"--mobile-columns": gridConfig.mobile,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
>
|
||||
{itemsArray.map((item) => (
|
||||
<Card key={item.id || item.name} data={{ ...item, variant }} />
|
||||
))}
|
||||
</div>
|
||||
<div className={styles.mainContainer}>
|
||||
{newsData && (
|
||||
<CardListTemplate
|
||||
items={transformNewsToCardData(newsData)}
|
||||
variant="news"
|
||||
gridConfig={gridConfig}
|
||||
title="Новости"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const LabsList = ({
|
||||
gridConfig = { desktop: 3, tablet: 2, mobile: 1 },
|
||||
}: ListProps) => {
|
||||
const { data: postsData, isLoading, isError } = usePosts();
|
||||
const labs = postsData?.labs ? Object.values(postsData.labs) : [];
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="mainContainer">
|
||||
<h2 className={styles.title}>Лаборатории</h2>
|
||||
<span className="loader"></span>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError) return <div>Ошибка при загрузке данных</div>;
|
||||
|
||||
return (
|
||||
<div className={styles.mainContainer}>
|
||||
<CardListTemplate
|
||||
items={transformPostsToCardData(labs)}
|
||||
variant="lab"
|
||||
gridConfig={gridConfig}
|
||||
title="Лаборатории"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ProjectsList = ({
|
||||
gridConfig = { desktop: 3, tablet: 2, mobile: 1 },
|
||||
tag = -1,
|
||||
}: ListProps) => {
|
||||
const { data, isError, isLoading } = usePostProjects(tag);
|
||||
const projects = data ?? [];
|
||||
|
||||
if (isLoading)
|
||||
return (
|
||||
<div className="mainContainer">
|
||||
<h2 className={styles.title}>Проекты</h2>
|
||||
<span className="loader"></span>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (isError) return <div>Ошибка при загрузке данных</div>;
|
||||
|
||||
return (
|
||||
<div className={styles.mainContainer}>
|
||||
<CardListTemplate
|
||||
items={transformPostsToCardData(projects)}
|
||||
variant="project"
|
||||
gridConfig={gridConfig}
|
||||
title="Проекты"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { NewsList, LabsList, ProjectsList };
|
||||
@@ -0,0 +1,30 @@
|
||||
import { CardData } from "@/shared/Components/Card/types";
|
||||
import { App, SKBKit } from "@/shared/types/app";
|
||||
export const transformPostsToCardData = (
|
||||
posts: App.WpPost[]
|
||||
): Record<string, CardData> => {
|
||||
return posts.reduce((acc, post) => {
|
||||
acc[post.id] = {
|
||||
id: post.id.toString(),
|
||||
name: post.title,
|
||||
previewText: post.previewText || "",
|
||||
link: `/post/${post.id}`,
|
||||
preview: post.preview || "",
|
||||
};
|
||||
return acc;
|
||||
}, {} as Record<string, CardData>);
|
||||
};
|
||||
export const transformNewsToCardData = (
|
||||
news: SKBKit.News[]
|
||||
): Record<string, CardData> => {
|
||||
return news.reduce((acc, item) => {
|
||||
acc[item.id] = {
|
||||
id: item.id,
|
||||
name: item.heading,
|
||||
previewText: "", // Если нужно можно вырезать часть текста из preview
|
||||
link: `/news/${item.id}`,
|
||||
preview: item.preview || "",
|
||||
};
|
||||
return acc;
|
||||
}, {} as Record<string, CardData>);
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
.title {
|
||||
font-size: 36px;
|
||||
font-weight: 600;
|
||||
line-height: 44px;
|
||||
margin-top: 0;
|
||||
margin-bottom: 8px;
|
||||
@include mediaMax($tablet-max-width) {
|
||||
font-size: 24px;
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
.list {
|
||||
display: grid;
|
||||
gap: 2rem;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 32px;
|
||||
&__lab {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
}
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__news {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
}
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
&__project {
|
||||
grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
|
||||
@include mediaMax($desktop-small-width) {
|
||||
grid-template-columns: repeat(var(--tablet-columns, 3), 1fr);
|
||||
}
|
||||
@include mediaMax($tablet-max-width) {
|
||||
grid-template-columns: repeat(var(--mobile-columns, 3), 1fr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// widgets/CardList/CardList.tsx
|
||||
import { CardListProps } from "@/widgets/CardList/types";
|
||||
import styles from "./CardListTemplate.module.scss";
|
||||
import { Card } from "@/shared/Components/Card/Card";
|
||||
import { classNames } from "@/shared/lib/classNames/classNames";
|
||||
|
||||
export const CardListTemplate = ({
|
||||
items,
|
||||
variant = "lab", // Значение по умолчанию
|
||||
gridConfig = { desktop: 3, tablet: 2, mobile: 1 },
|
||||
title = "Лаборатории",
|
||||
}: CardListProps) => {
|
||||
const itemsArray = Object.values(items);
|
||||
|
||||
return (
|
||||
<>
|
||||
{itemsArray?.length !== 0 &&
|
||||
<div>
|
||||
<h1 className={styles.title}>{title}</h1>
|
||||
<div
|
||||
className={classNames(styles.list, {}, [styles[`list__${variant}`]])}
|
||||
style={
|
||||
{
|
||||
"--desktop-columns": gridConfig.desktop,
|
||||
"--tablet-columns": gridConfig.tablet,
|
||||
"--mobile-columns": gridConfig.mobile,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
>
|
||||
{itemsArray.map((item) => (
|
||||
<Card key={item.id || item.name} data={{ ...item, variant }} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user