add anchor / delete linter error / small revision

This commit is contained in:
aurinex
2025-07-08 23:46:22 +05:00
parent a9c056f8bf
commit 824a79a117
6 changed files with 254 additions and 64 deletions

View File

@ -7,7 +7,14 @@ function App() {
<> <>
<Header /> <Header />
<Routes> <Routes>
<Route path="/" element={<MainPage />} /> <Route
path="/"
element={
<>
<MainPage />
</>
}
/>
</Routes> </Routes>
</> </>
) )

View File

@ -1,6 +1,5 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { import {
Dialog,
TextField, TextField,
Button, Button,
IconButton, IconButton,
@ -10,7 +9,6 @@ import {
RadioGroup, RadioGroup,
FormControlLabel, FormControlLabel,
FormControl, FormControl,
InputAdornment,
InputLabel, InputLabel,
OutlinedInput, OutlinedInput,
Checkbox, Checkbox,
@ -37,7 +35,7 @@ const TextMaskCustom = React.forwardRef<HTMLInputElement, CustomProps>(
_: /[0-9]/, _: /[0-9]/,
}} }}
inputRef={ref} inputRef={ref}
onAccept={(value: any) => onAccept={(value: string) =>
onChange({ target: { name: props.name, value } }) onChange({ target: { name: props.name, value } })
} }
overwrite overwrite
@ -52,9 +50,10 @@ const TextMaskCustom = React.forwardRef<HTMLInputElement, CustomProps>(
interface FeedbackProps { interface FeedbackProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
handleScrollToAnchor?: (anchor: string) => void;
} }
const Feedback: React.FC<FeedbackProps> = ({ open, onClose }) => { const Feedback: React.FC<FeedbackProps> = ({ open, onClose, handleScrollToAnchor }) => {
const [name, setName] = useState(""); const [name, setName] = useState("");
const [phone, setPhone] = useState("+7"); const [phone, setPhone] = useState("+7");
const [country, setCountry] = useState("Европа"); const [country, setCountry] = useState("Европа");
@ -63,6 +62,14 @@ const Feedback: React.FC<FeedbackProps> = ({ open, onClose }) => {
const [agreeToPolicy, setAgreeToPolicy] = useState(false); const [agreeToPolicy, setAgreeToPolicy] = useState(false);
const { isMobile } = useResponsive(); const { isMobile } = useResponsive();
React.useEffect(() => {
if (open) {
window.history.pushState(null, '', '#feedback');
} else if (!open && !isMobile && handleScrollToAnchor) {
handleScrollToAnchor('#main');
}
}, [open, handleScrollToAnchor]);
const handleSubmit = (e: React.FormEvent) => { const handleSubmit = (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
if (!agreeToPolicy) { if (!agreeToPolicy) {
@ -71,9 +78,12 @@ const Feedback: React.FC<FeedbackProps> = ({ open, onClose }) => {
); );
return; return;
} }
// логика отправки формы
console.log({ name, phone, country, budget, description, agreeToPolicy }); console.log({ name, phone, country, budget, description, agreeToPolicy });
onClose(); onClose();
if (handleScrollToAnchor) {
handleScrollToAnchor('#main');
}
}; };
const textFieldSx = { const textFieldSx = {
@ -129,8 +139,13 @@ const Feedback: React.FC<FeedbackProps> = ({ open, onClose }) => {
justifyContent: "center", justifyContent: "center",
zIndex: 1300, // высокий z-index как у диалога zIndex: 1300, // высокий z-index как у диалога
bgcolor: "rgba(0, 0, 0, 0.5)", // затемнение фона bgcolor: "rgba(0, 0, 0, 0.5)", // затемнение фона
color: "black",
}} }}
onClick={onClose} // закрытие при клике на фон onClick={() => {
onClose();
if (handleScrollToAnchor) handleScrollToAnchor('#main');
}}
id="feedback"
> >
<Box <Box
sx={{ sx={{
@ -147,8 +162,11 @@ const Feedback: React.FC<FeedbackProps> = ({ open, onClose }) => {
onClick={(e) => e.stopPropagation()} // предотвращаем закрытие при клике на контент onClick={(e) => e.stopPropagation()} // предотвращаем закрытие при клике на контент
> >
<Box> <Box>
<IconButton <IconButton
onClick={onClose} onClick={() => {
onClose();
if (handleScrollToAnchor) handleScrollToAnchor('#main');
}}
sx={{ sx={{
position: "absolute", position: "absolute",
right: "1vw", right: "1vw",
@ -226,7 +244,7 @@ const Feedback: React.FC<FeedbackProps> = ({ open, onClose }) => {
id="phone-input" id="phone-input"
value={phone} value={phone}
onChange={handlePhoneChange} onChange={handlePhoneChange}
inputComponent={TextMaskCustom as any} inputComponent={TextMaskCustom as unknown as React.ComponentType<import('@mui/material').InputBaseComponentProps>}
label="Ваш телефон*" label="Ваш телефон*"
notched notched
sx={{ sx={{

View File

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import { import {
Box, Box,
Typography, Typography,
@ -7,38 +7,62 @@ import {
List, List,
ListItem, ListItem,
Button, Button,
Link,
} from "@mui/material"; } from "@mui/material";
import MenuIcon from "@mui/icons-material/Menu"; import MenuIcon from "@mui/icons-material/Menu";
import logo from "../assets/icon/autobro.png"; import logo from "../assets/icon/autobro.png";
import { useResponsive } from "../theme/useResponsive"; import { useResponsive } from "../theme/useResponsive";
import Feedback from "./Feedback"; import Feedback from "./Feedback";
import { scrollToAnchor } from "../utils/scrollUtils";
const Header = () => { const Header = () => {
const { isMobile } = useResponsive(); const { isMobile } = useResponsive();
const [drawerOpen, setDrawerOpen] = useState(false); const [drawerOpen, setDrawerOpen] = useState(false);
const [feedbackOpen, setFeedbackOpen] = useState(false); const [feedbackOpen, setFeedbackOpen] = useState(false);
const [scrolled, setScrolled] = useState(false);
const menuItems = [ const menuItems = [
"О нас", { title: "О нас", anchor: "#about" },
"Калькулятор", { title: "Калькулятор", anchor: "#calculator" },
"Отзывы", { title: "Отзывы", anchor: "#reviews" },
"Контакты", { title: "Контакты", anchor: "#contacts" },
"В наличии", { title: "В наличии", anchor: "#available" },
"Команда", { title: "Команда", anchor: "#team" },
"Доставленные авто", { title: "Доставленные авто", anchor: "#delivered" },
"Этапы работы", { title: "Этапы работы", anchor: "#stages" },
{ title: " ", anchor: "#main"},
]; ];
const toggleDrawer = (open) => (event) => { // Отслеживание скролла
useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 10) {
setScrolled(true);
} else {
setScrolled(false);
}
};
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
const toggleDrawer = (open: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => {
if ( if (
event.type === "keydown" && event.type === "keydown" &&
(event.key === "Tab" || event.key === "Shift") ((event as React.KeyboardEvent).key === "Tab" || (event as React.KeyboardEvent).key === "Shift")
) { ) {
return; return;
} }
setDrawerOpen(open); setDrawerOpen(open);
}; };
// Используем глобальную функцию из utils
const handleScrollToAnchor = (anchor: string) => {
scrollToAnchor(anchor, setDrawerOpen, isMobile);
};
return ( return (
<> <>
<Box <Box
@ -53,16 +77,29 @@ const Header = () => {
userSelect: "none", userSelect: "none",
color: "white", color: "white",
padding: isMobile ? "0 4vw" : 0, padding: isMobile ? "0 4vw" : 0,
position: "fixed",
top: 0,
left: 0,
right: 0,
zIndex: 1000,
transition: "all 0.3s ease",
boxShadow: scrolled ? "0 2px 10px rgba(0,0,0,0.2)" : "none",
}} }}
> >
<img <Box
component="img"
src={logo} src={logo}
alt="logo" alt="logo"
style={{ onClick={() => handleScrollToAnchor("#main")}
width: isMobile ? "10vw" : "7vw", sx={{
height: isMobile ? "10vw" : "7vw", width: isMobile ? "17vw" : "9vw",
height: isMobile ? "17vw" : "9vw",
cursor: "pointer",
"&:hover": { scale: 1.1 },
transition: "all 0.4s ease",
}} }}
/> >
</Box>
{isMobile ? ( {isMobile ? (
<Box <Box
@ -93,45 +130,57 @@ const Header = () => {
) : ( ) : (
// Desktop menu // Desktop menu
menuItems.map((item, index) => ( menuItems.map((item, index) => (
<Typography <Link
key={index} key={index}
component="button"
onClick={() => handleScrollToAnchor(item.anchor)}
underline="none"
sx={{ sx={{
fontFamily: "Unbounded", fontFamily: "Unbounded",
fontSize: "1vw", fontSize: "1.2vw",
cursor: "pointer", cursor: "pointer",
color: "white",
"&:hover": { color: "#C27664" },
transition: "all 0.3s ease",
}} }}
> >
{item} {item.title}
</Typography> </Link>
)) ))
)} )}
</Box> </Box>
{/* Пустой блок для компенсации фиксированного хедера */}
<Box sx={{ height: isMobile ? "15vw" : "10vw" }} />
{/* Мобильное меню */} {/* Мобильное меню */}
<Drawer <Drawer
anchor="right" anchor="right"
open={isMobile && drawerOpen} open={drawerOpen}
onClose={toggleDrawer(false)} onClose={toggleDrawer(false)}
> >
<Box <Box
sx={{ width: "70vw", bgcolor: "#2D2D2D", height: "100%" }} sx={{ width: "58vw", bgcolor: "#2D2D2D", height: "100%" }}
role="presentation" role="presentation"
onClick={toggleDrawer(false)}
onKeyDown={toggleDrawer(false)}
> >
<List> <List>
{menuItems.map((item, index) => ( {menuItems.map((item, index) => (
<ListItem key={index}> <ListItem
key={index}
onClick={() => handleScrollToAnchor(item.anchor)}
sx={{ cursor: "pointer" }}
>
<Typography <Typography
sx={{ sx={{
fontFamily: "Unbounded", fontFamily: "Unbounded",
fontSize: "4vw", fontSize: "4vw",
color: "white", color: "white",
padding: "2vw 0", padding: "2vw 0",
cursor: "pointer", "&:hover": { color: "#C27664" },
transition: "color 0.3s ease",
}} }}
> >
{item} {item.title}
</Typography> </Typography>
</ListItem> </ListItem>
))} ))}
@ -139,8 +188,7 @@ const Header = () => {
</Box> </Box>
</Drawer> </Drawer>
{/* Форма обратной связи */} <Feedback open={feedbackOpen} onClose={() => setFeedbackOpen(false)} handleScrollToAnchor={handleScrollToAnchor} />
<Feedback open={feedbackOpen} onClose={() => setFeedbackOpen(false)} />
</> </>
); );
}; };

View File

@ -1,11 +1,17 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Button, Container, Box, Typography } from "@mui/material"; import { Button, Box, Typography, IconButton } from "@mui/material";
import Feedback from "../components/Feedback"; import Feedback from "../components/Feedback";
import car from "../../src/assets/icon/car.png"; import car from "../../src/assets/icon/car.png";
import { Gradient } from "@mui/icons-material"; import { useResponsive } from "../theme/useResponsive";
import TelegramIcon from '@mui/icons-material/Telegram';
import VkIcon from '@mui/icons-material/Facebook';
import WhatsAppIcon from '@mui/icons-material/WhatsApp';
import { scrollToAnchor } from "../utils/scrollUtils";
function MainPage() { function MainPage() {
const [feedbackOpen, setFeedbackOpen] = useState(false); const [feedbackOpen, setFeedbackOpen] = useState(false);
const setDrawerOpen = () => {};
const { isMobile } = useResponsive();
const handleOpenFeedback = () => { const handleOpenFeedback = () => {
setFeedbackOpen(true); setFeedbackOpen(true);
@ -15,8 +21,12 @@ function MainPage() {
setFeedbackOpen(false); setFeedbackOpen(false);
}; };
const handleScrollToAnchor = (anchor: string) => {
scrollToAnchor(anchor, setDrawerOpen, isMobile);
};
return ( return (
<Box sx={{ bgcolor: "#2D2D2D", color: "white", userSelect: "none" }}> <Box sx={{ bgcolor: "#2D2D2D", color: "white", userSelect: "none" }} id="main">
<Box <Box
id="title" id="title"
sx={{ sx={{
@ -67,34 +77,121 @@ function MainPage() {
src={car} src={car}
alt="logo" alt="logo"
style={{ style={{
width: "70vw", width: "60vw",
height: "36vw", height: "32vw",
position: "relative", position: "relative",
top: "-20vw", top: "-19vw",
left: "10vw", left: "12vw",
zIndex: 2, zIndex: 2,
pointerEvents: "none",
}} }}
/> />
</Box>
<Box
{/* <Box id="button" sx={{ textAlign: "center" }}>
<Button
variant="contained"
onClick={handleOpenFeedback}
sx={{ sx={{
bgcolor: "#c22d1a", position: "absolute",
color: "white", right: "4.5vw",
py: 1.5, top: isMobile ? "18.3vw" : "13.3vw",
px: 3, display: "flex",
"&:hover": { bgcolor: "#a42517" }, flexDirection: "column",
mb: "2vw", gap: "1vw",
zIndex: 1,
}} }}
> >
Оставить заявку <Button
</Button> onClick={() => handleScrollToAnchor("#calculator")}
variant="contained"
sx={{
bgcolor: "#C27664",
color: "white",
fontSize: "1.5vw",
padding: "2.2vw 2vw",
textTransform: "none",
borderRadius: "3vw",
fontWeight: "bold",
fontFamily: "Unbounded",
"&:hover": { bgcolor: "#945B4D" },
transition: "all 0.3s ease",
}}
>
Рассчитать стоимость
</Button>
<Button
variant="outlined"
onClick={handleOpenFeedback}
sx={{
color: "#C27664",
fontSize: "1.5vw",
padding: "2.2vw 2vw",
textTransform: "none",
borderRadius: "3vw",
fontWeight: "bold",
fontFamily: "Unbounded",
borderColor: "#C27664",
"&:hover": { borderColor: "#945B4D", bgcolor: "transparent", color: "#945B4D" },
transition: "all 0.3s ease",
}}
>
Подобрать авто
</Button>
</Box>
<Box id="contacts" sx={{
// position: "absolute",
// top: isMobile ? "18.3vw" : "13.3vw",
// right: "4.5vw",
// width: "100%",
// display: "flex",
// flexDirection: "column",
// gap: isMobile ? "1vw" : "2vw",
<Feedback open={feedbackOpen} onClose={handleCloseFeedback} /> position: "absolute",
</Box> */} right: "1vw",
top: isMobile ? "20.3vw" : "15.3vw",
display: "flex",
flexDirection: "column",
gap: "1vw",
zIndex: 1,
}}>
<IconButton
sx={{
color: "#C27664",
borderRadius: "50%",
width: "3vw",
height: "3vw",
"&:hover": { color: "#945B4D", borderColor: "#945B4D" }
}}
>
<VkIcon sx={{ fontSize: "3vw" }} />
</IconButton>
<IconButton
sx={{
color: "#C27664",
borderRadius: "50%",
width: "3vw",
height: "3vw",
"&:hover": { color: "#945B4D", borderColor: "#945B4D" }
}}
>
<TelegramIcon sx={{ fontSize: "3vw" }} />
</IconButton>
<IconButton
sx={{
color: "#C27664",
borderRadius: "50%",
width: "3vw",
height: "3vw",
"&:hover": { color: "#945B4D", borderColor: "#945B4D" }
}}
>
<WhatsAppIcon sx={{ fontSize: "3vw" }} />
</IconButton>
</Box>
</Box>
<Feedback open={feedbackOpen} onClose={handleCloseFeedback} handleScrollToAnchor={handleScrollToAnchor} />
</Box> </Box>
); );
} }

21
src/utils/scrollUtils.ts Normal file
View File

@ -0,0 +1,21 @@
/**
* Плавная прокрутка к указанному якорю
* @param anchor - идентификатор якоря, например "#about"
* @param setDrawerOpen - опциональная функция для закрытия мобильного меню
* @param isMobile - флаг мобильного устройства
*/
export const scrollToAnchor = (
anchor: string,
setDrawerOpen?: (isOpen: boolean) => void,
isMobile?: boolean
): void => {
const element = document.querySelector(anchor);
if (element) {
element.scrollIntoView({ behavior: "smooth" });
// Обновляем URL с хешем без перезагрузки страницы
window.history.pushState(null, '', anchor);
}
if (isMobile && setDrawerOpen) {
setDrawerOpen(false);
}
};

View File

@ -19,7 +19,6 @@
"strict": true, "strict": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true "noUncheckedSideEffectImports": true
}, },