Новые компоенты

This commit is contained in:
Web-serfer 2026-04-07 18:53:23 +05:00
parent 410a1c3235
commit ffd99c404a
9 changed files with 756 additions and 733 deletions

View file

@ -0,0 +1,258 @@
---
const title = 'Поиск статей';
---
<div id="search-modal" class="modal-overlay" aria-hidden="true">
<div class="modal-container" role="dialog" aria-modal="true" aria-labelledby="search-modal-title">
<button class="modal-close" aria-label="Закрыть" id="search-modal-close-btn">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
<div class="modal-content">
<h2 id="search-modal-title" class="modal-title">{title}</h2>
<p class="modal-description">
Введите ключевые слова для поиска статей
</p>
<form class="search-form" id="search-form">
<div class="search-input-wrapper">
<svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
<input
type="text"
id="search-input"
name="search"
class="search-input"
placeholder="Например: ДТП, ОСАГО, лишение прав..."
required
autocomplete="off"
/>
</div>
<button type="submit" class="search-submit">
Найти статьи
</button>
</form>
</div>
</div>
</div>
<script>
(function() {
const modal = document.getElementById('search-modal');
const closeBtn = document.getElementById('search-modal-close-btn');
const form = document.getElementById('search-form');
const searchInput = document.getElementById('search-input');
function openModal() {
if (!modal) return;
modal.classList.add('active');
modal.setAttribute('aria-hidden', 'false');
document.body.style.overflow = 'hidden';
// Фокус на поле ввода после открытия
setTimeout(() => (searchInput as HTMLInputElement)?.focus(), 100);
}
function closeModal() {
if (!modal) return;
modal.classList.remove('active');
modal.setAttribute('aria-hidden', 'true');
document.body.style.overflow = '';
(searchInput as HTMLInputElement).value = '';
}
// Открытие по кастомному событию
window.addEventListener('open-modal', (e: Event) => {
const customEvent = e as CustomEvent<string>;
if (customEvent.detail === 'search-modal') {
openModal();
}
});
// Закрытие по крестику
closeBtn?.addEventListener('click', closeModal);
// Закрытие по клику вне модального окна
modal?.addEventListener('click', (e) => {
if (e.target === modal) {
closeModal();
}
});
// Закрытие по Escape
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && modal?.classList.contains('active')) {
closeModal();
}
});
// Обработка отправки формы
form?.addEventListener('submit', (e) => {
e.preventDefault();
const query = (searchInput as HTMLInputElement).value.trim();
if (query) {
// Перенаправление на страницу поиска с параметром
window.location.href = `/blog/search?q=${encodeURIComponent(query)}`;
closeModal();
}
});
})();
</script>
<style>
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal-container {
background: #ffffff;
border-radius: 16px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
max-width: 600px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
position: relative;
transform: translateY(-20px) scale(0.95);
transition: transform 0.3s ease;
}
.modal-overlay.active .modal-container {
transform: translateY(0) scale(1);
}
.modal-close {
position: absolute;
top: 16px;
right: 16px;
background: transparent;
border: none;
cursor: pointer;
padding: 8px;
border-radius: 8px;
color: #535e6c;
transition: background 0.2s ease, color 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
}
.modal-close:hover {
background: #f0f2f5;
color: #1e3050;
}
.modal-content {
padding: 40px 32px 32px;
}
.modal-title {
font-size: 1.5rem;
font-weight: 700;
color: #1e3050;
margin: 0 0 12px;
text-align: center;
}
.modal-description {
color: #535e6c;
font-size: 0.95rem;
text-align: center;
margin: 0 0 28px;
line-height: 1.5;
}
.search-form {
display: flex;
flex-direction: column;
gap: 20px;
}
.search-input-wrapper {
position: relative;
display: flex;
align-items: center;
}
.search-icon {
position: absolute;
left: 16px;
color: #9ca3af;
pointer-events: none;
}
.search-input {
width: 100%;
padding: 14px 16px 14px 48px;
border: 2px solid #e0e4e8;
border-radius: 8px;
font-size: 1rem;
font-family: inherit;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
outline: none;
}
.search-input:focus {
border-color: #1e3050;
box-shadow: 0 0 0 3px rgba(30, 48, 80, 0.1);
}
.search-input::placeholder {
color: #9ca3af;
}
.search-submit {
background: linear-gradient(180deg, #eac26e 0%, #ce9f40 100%);
color: #ffffff;
border: none;
padding: 14px 24px;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(234, 194, 110, 0.3);
}
.search-submit:hover {
box-shadow: 0 6px 20px rgba(234, 194, 110, 0.5);
transform: translateY(-2px);
}
.search-submit:active {
transform: translateY(0);
}
@media (max-width: 480px) {
.modal-content {
padding: 32px 24px 24px;
}
.modal-title {
font-size: 1.25rem;
}
}
</style>

View file

@ -0,0 +1,55 @@
---
// Компонент иконки поиска (лупа)
---
<button class="search-icon-btn" id="search-icon-btn" data-modal-target="search-modal" aria-label="Поиск статей">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
<script>
(function() {
const btn = document.getElementById('search-icon-btn');
btn?.addEventListener('click', () => {
window.dispatchEvent(new CustomEvent('open-modal', {
detail: 'search-modal'
}));
});
})();
</script>
<style>
.search-icon-btn {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: #ffffff;
padding: 0.75rem;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
}
.search-icon-btn:hover {
background: rgba(255, 255, 255, 0.15);
border-color: rgba(234, 194, 110, 0.5);
color: #eac26e;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(234, 194, 110, 0.2);
}
.search-icon-btn:active {
transform: translateY(0);
}
@media (max-width: 768px) {
.search-icon-btn {
padding: 0.6rem;
}
}
</style>

View file

@ -1,9 +1,9 @@
---
const sectionsLinks = [
{ label: 'Главная', href: '/' },
{ label: 'Услуги', href: '/services' },
{ label: 'Блог', href: '#' },
{ label: 'Кейсы', href: '/cases' },
{ label: 'Блог', href: '/blog' },
{ label: 'Контакты', href: '/contacts' },
];
@ -18,6 +18,9 @@ const infoLinks = [
{ label: 'Условия использования', href: '/terms' },
{ label: 'Возврат средств', href: '#' },
];
const currentYear = new Date().getFullYear().toString();
---
<footer class="footer">
@ -78,7 +81,7 @@ const infoLinks = [
<!-- Нижняя часть футера (Копирайт) -->
<div class="footer-bottom">
<p class="copyright">© 2026 Автоюрист086. Все права защищены.</p>
<p class="copyright">© {currentYear} Автоюрист086.ru Все права защищены.</p>
<ul class="footer-bottom-links">
{legalLinks.map(link => (
<li><a href={link.href}>{link.label}</a></li>

View file

@ -5,6 +5,8 @@ import BlogHero from '@components/blog/BlogHero.astro';
import BlogCategories from '@components/blog/BlogCategories.astro';
import BlogCard from '@components/blog/BlogCard.astro';
import BlogPagination from '@components/blog/BlogPagination.astro';
import SearchIcon from '@components/blog/SearchIcon.astro';
import SearchModal from '@components/base/SearchModal.astro';
import { blogPosts, categories } from '@data/blogData';
---
@ -14,6 +16,17 @@ import { blogPosts, categories } from '@data/blogData';
canonicalLink={`${SITE_URL}/blog`}
>
<BlogHero />
<!-- Иконка поиска -->
<section class="search-section">
<div class="site-container">
<div class="search-container">
<SearchIcon />
<p class="search-hint">Нажмите для поиска статей</p>
</div>
</div>
</section>
<BlogCategories categories={categories} />
<!-- Сетка статей -->
@ -55,7 +68,26 @@ import { blogPosts, categories } from '@data/blogData';
</section>
</Layout>
<SearchModal />
<style>
.search-section {
padding: 2rem 0;
background: linear-gradient(135deg, #0a2540 0%, #1e3a5f 100%);
}
.search-container {
display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
}
.search-hint {
color: rgba(255, 255, 255, 0.7);
font-size: 0.9rem;
margin: 0;
}
.blog-grid-section {
padding: 3rem 0 0;
background: #f8fafc;

View file

@ -0,0 +1,323 @@
---
import Layout from '@layouts/Layout.astro';
import { SITE_URL } from '@constants';
import BlogCard from '@components/blog/BlogCard.astro';
import SearchModal from '@components/base/SearchModal.astro';
import { blogPosts } from '@data/blogData';
// Получаем параметр поиска из URL
const url = new URL(Astro.request.url);
const searchQuery = url.searchParams.get('q') || '';
// Функция поиска по статьям
function searchArticles(query: string) {
if (!query.trim()) return [];
const lowerQuery = query.toLowerCase();
return blogPosts.filter(post => {
const titleMatch = post.title.toLowerCase().includes(lowerQuery);
const descriptionMatch = post.description.toLowerCase().includes(lowerQuery);
const categoryMatch = post.category.toLowerCase().includes(lowerQuery);
return titleMatch || descriptionMatch || categoryMatch;
});
}
const searchResults = searchArticles(searchQuery);
---
<Layout
title={`${searchQuery ? 'Результаты поиска: ' + searchQuery : 'Поиск статей'} — автоюрист в Сургуте`}
description={`Результаты поиска статей по запросу "${searchQuery}"`}
canonicalLink={`${SITE_URL}/blog/search?q=${encodeURIComponent(searchQuery)}`}
>
<!-- Hero-секция поиска -->
<section class="search-hero">
<div class="site-container">
<div class="search-hero-content">
<h1 class="search-title">
{searchQuery ? `Результаты поиска` : 'Поиск статей'}
</h1>
{searchQuery && (
<div class="search-info">
<p class="search-query-text">
По запросу: <span class="query-highlight">"{searchQuery}"</span>
</p>
<p class="search-count">
{searchResults.length === 0
? 'Ничего не найдено'
: `Найдено статей: ${searchResults.length}`}
</p>
</div>
)}
<button class="open-search-btn" id="open-search-btn" data-modal-target="search-modal">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
Изменить запрос
</button>
</div>
</div>
</section>
<!-- Результаты поиска -->
{searchQuery && searchResults.length > 0 ? (
<section class="results-section">
<div class="site-container">
<div class="results-grid">
{searchResults.map((post) => (
<BlogCard
title={post.title}
description={post.description}
category={post.category}
categoryColor={post.categoryColor}
date={post.date}
readTime={post.readTime}
imageUrl={post.imageUrl}
slug={post.slug}
/>
))}
</div>
</div>
</section>
) : searchQuery ? (
<section class="no-results">
<div class="site-container">
<div class="no-results-content">
<svg class="no-results-icon" width="80" height="80" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
<line x1="8" y1="8" x2="14" y2="14"></line>
<line x1="14" y1="8" x2="8" y2="14"></line>
</svg>
<h2 class="no-results-title">По вашему запросу ничего не найдено</h2>
<p class="no-results-text">
Попробуйте изменить запрос или посмотрите все статьи в блоге
</p>
<a href="/blog" class="back-to-blog-btn">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="19" y1="12" x2="5" y2="12"></line>
<polyline points="12 19 5 12 12 5"></polyline>
</svg>
Вернуться в блог
</a>
</div>
</div>
</section>
) : (
<section class="no-results">
<div class="site-container">
<div class="no-results-content">
<p class="no-results-text">Введите запрос для поиска статей</p>
</div>
</div>
</section>
)}
</Layout>
<SearchModal />
<script>
(function() {
const btn = document.getElementById('open-search-btn');
btn?.addEventListener('click', () => {
window.dispatchEvent(new CustomEvent('open-modal', {
detail: 'search-modal'
}));
});
// Автоматически открываем поиск при загрузке страницы без параметров
document.addEventListener('DOMContentLoaded', () => {
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('q');
if (!query && btn) {
setTimeout(() => {
window.dispatchEvent(new CustomEvent('open-modal', {
detail: 'search-modal'
}));
}, 300);
}
});
})();
</script>
<style>
.search-hero {
padding: 6rem 0 3rem;
background: linear-gradient(135deg, #0a2540 0%, #1e3a5f 100%);
position: relative;
overflow: hidden;
}
.search-hero::before {
content: '';
position: absolute;
top: -30%;
right: -5%;
width: 500px;
height: 500px;
background: radial-gradient(circle, rgba(212, 175, 55, 0.08) 0%, transparent 70%);
border-radius: 50%;
}
.search-hero-content {
position: relative;
z-index: 1;
text-align: center;
max-width: 700px;
margin: 0 auto;
}
.search-title {
font-size: clamp(2rem, 4vw, 3rem);
font-weight: 800;
color: #ffffff;
margin: 0 0 1.5rem;
letter-spacing: -0.02em;
}
.search-info {
margin-bottom: 2rem;
}
.search-query-text {
color: rgba(255, 255, 255, 0.8);
font-size: 1.1rem;
margin: 0 0 0.5rem;
}
.query-highlight {
color: #eac26e;
font-weight: 700;
}
.search-count {
color: rgba(255, 255, 255, 0.6);
font-size: 0.95rem;
margin: 0;
}
.open-search-btn {
background: linear-gradient(135deg, #d4af37 0%, #eac26e 100%);
color: #1e293b;
border: none;
padding: 0.875rem 2rem;
border-radius: 0.75rem;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
display: inline-flex;
align-items: center;
gap: 0.5rem;
}
.open-search-btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(212, 175, 55, 0.4);
}
.open-search-btn:active {
transform: translateY(0);
}
.results-section {
padding: 3rem 0;
background: #f8fafc;
}
.results-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
}
.no-results {
padding: 5rem 0;
background: #f8fafc;
}
.no-results-content {
text-align: center;
max-width: 600px;
margin: 0 auto;
}
.no-results-icon {
color: #d1d5db;
margin-bottom: 1.5rem;
}
.no-results-title {
font-size: 1.75rem;
font-weight: 700;
color: #1e3050;
margin: 0 0 1rem;
}
.no-results-text {
color: #535e6c;
font-size: 1.1rem;
line-height: 1.6;
margin: 0 0 2rem;
}
.back-to-blog-btn {
background: linear-gradient(135deg, #0a2540 0%, #1e3a5f 100%);
color: #ffffff;
border: none;
padding: 0.875rem 2rem;
border-radius: 0.75rem;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 0.5rem;
box-shadow: 0 4px 15px rgba(10, 37, 64, 0.3);
}
.back-to-blog-btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(10, 37, 64, 0.4);
}
/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
.results-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 768px) {
.search-hero {
padding: 5rem 0 2.5rem;
}
.results-grid {
grid-template-columns: 1fr;
gap: 1.5rem;
}
.search-title {
font-size: 2rem;
}
.no-results {
padding: 3rem 0;
}
.no-results-title {
font-size: 1.5rem;
}
}
</style>