Стили для проектов, хук для динамического размера

This commit is contained in:
ifraimka1 committed 2025-04-30 16:31:30 +03:00
1 parent f22179654b
commit 3b201e8a8b
5 files changed
+196 -154

No files matched your search

+4
View File
@@ -95,6 +95,10 @@ header h1 {
}
}
h2 {
margin-bottom: 1em;
}
#root {
display: flex;
min-height: 100vh;
@@ -0,0 +1,41 @@
import { useEffect } from 'react';
type ResizeHandler = (parent: HTMLElement, childHeight: number) => void;
interface UseResizeObserverConfig {
parentSelector: string;
childSelector?: string;
onResize?: ResizeHandler;
}
export const useResizeObserver = ({
parentSelector,
childSelector = 'blockquote',
onResize = (parent, height) => {
parent.style.marginBottom = `calc(${height}px + 2em)`;
}
}: UseResizeObserverConfig) => {
useEffect(() => {
const resizeObserver = new ResizeObserver(entries => {
entries.forEach(entry => {
const parent = entry.target as HTMLElement;
const child = parent.querySelector(childSelector) as HTMLElement | null;
if (child) {
const childHeight = child.offsetHeight;
onResize(parent, childHeight);
}
});
});
const elements = document.querySelectorAll(parentSelector);
const elementsArray = Array.from(elements) as HTMLElement[];
elementsArray.forEach(element => resizeObserver.observe(element));
return () => {
elementsArray.forEach(element => resizeObserver.unobserve(element));
resizeObserver.disconnect();
};
}, [parentSelector, childSelector, onResize]);
};
+3 -2
View File
@@ -17,7 +17,7 @@ $background-tape: #F5F5F7;
.project {
.header {
text-align: center;
margin-bottom: 4em;
margin-bottom: 2em;
}
.wp-block-columns {
@@ -82,7 +82,8 @@ $background-tape: #F5F5F7;
width: 100%;
border-collapse: separate;
border-spacing: 0;
font-size: 20px;
font-size: 18px;
word-wrap: normal;
th,
td {
+3
View File
@@ -2,6 +2,7 @@ import { ReactNode } from "react";
import MediaBlock from "@/widgets/MediaBlock/MediaBlock";
import { PageContent, PageHeader } from "@/widgets/WpPost";
import { useResizeObserver } from "@/shared/lib/ResizeObserver/ResizeObserver";
import { App } from "@/shared/types/app";
import "./Projects.scss";
@@ -15,6 +16,8 @@ export default function WpPost({
post,
children,
}: WpPostProps) {
useResizeObserver({parentSelector: '.wp-block-pullquote'});
return (
<div className={post.categories?.includes('projects') ? "project" : ""}>
<PageHeader className="header">