Вот улучшенная, более красивая и современная кнопка "Запустить тесты" с анимацией нажатия и плавным изменением стиля, встроенным в ваш компонент.
Я добавил визуальный эффект загрузки, тень, смену цвета и анимацию загрузки (спиннер) рядом с текстом.
import React, { useState } from 'react';
import { runApiTests } from './data/apiTestService';
function App() {
const [isTesting, setIsTesting] = useState(false);
const [progress, setProgress] = useState(0);
const [results, setResults] = useState([]);
const [currentScreenshot, setCurrentScreenshot] = useState(null);
const getScreenshotPath = (id) => {
return import(`./screenshots/request_${id}.png`)
.then((module) => module.default)
.catch(() => null);
};
async function handleRunTests() {
setIsTesting(true);
setResults([]);
setProgress(0);
setCurrentScreenshot(null);
await runApiTests(
(progressValue) => setProgress(progressValue),
async (result) => {
setResults((prev) => [...prev, result]);
const screenshotPath = await getScreenshotPath(result.id - 1);
setCurrentScreenshot(screenshotPath || 'https://via.placeholder.com/400?text=No+Screenshot');
}
);
setIsTesting(false);
}
return (
<div style={{ maxWidth: 800, margin: '20px auto', fontFamily: 'Arial, sans-serif' }}>
<h1>API Тесты (симулятор)</h1>
<button
onClick={handleRunTests}
disabled={isTesting}
style={{
position: 'relative',
padding: '12px 28px',
fontSize: 18,
fontWeight: '600',
color: isTesting ? '#ccc' : '#fff',
background: isTesting ? 'linear-gradient(90deg, #6c757d, #5a6268)' : 'linear-gradient(90deg, #007bff, #0056b3)',
border: 'none',
borderRadius: 8,
cursor: isTesting ? 'not-allowed' : 'pointer',
boxShadow: isTesting
? 'inset 0 0 5px rgba(0,0,0,0.2)'
: '0 4px 14px rgba(0, 123, 255, 0.5)',
transition: 'all 0.3s ease',
userSelect: 'none',
overflow: 'hidden',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: 10,
}}
onMouseDown={(e) => {
if (!isTesting) e.currentTarget.style.transform = 'scale(0.95)';
}}
onMouseUp={(e) => {
e.currentTarget.style.transform = 'scale(1)';
}}
onMouseLeave={(e) => {
e.currentTarget.style.transform = 'scale(1)';
}}
>
{isTesting && (
<svg
style={{
width: 20,
height: 20,
animation: 'spin 1s linear infinite'
}}
viewBox="0 0 50 50"
>
<circle
cx="25"
cy="25"
r="20"
fill="none"
stroke="#fff"
strokeWidth="5"
strokeLinecap="round"
strokeDasharray="31.415, 31.415"
strokeDashoffset="0"
/>
</svg>
)}
{isTesting ? 'Тестирование...' : 'Запустить тесты'}
</button>
{isTesting && (
<div style={{
marginTop: 20,
height: 20,
backgroundColor: '#eee',
borderRadius: 10,
overflow: 'hidden',
boxShadow: 'inset 0 1px 3px rgba(0,0,0,0.2)'
}}>
<div style={{
height: '100%',
width: `${progress}%`,
backgroundColor: '#4caf50',
transition: 'width 0.3s ease',
}} />
</div>
)}
{!isTesting && results.length > 0 && (
<div style={{ marginTop: 20 }}>
<h2>Результаты:</h2>
<ul style={{ listStyle: 'none', paddingLeft: 0 }}>
{results.map((r) => (
<li key={r.id} style={{
marginBottom: 10,
padding: 10,
borderRadius: 5,
backgroundColor: r.passed ? 'green' : 'red',
color: 'white',
}}>
<strong>{r.passed ? '✔' : '✖'} {r.description}</strong><br />
Статус: {r.status || 'Ошибка'} {r.statusText || ''}<br />
{r.error && <span>Ошибка: {r.error}</span>}
</li>
))}
</ul>
</div>
)}
{currentScreenshot && (
<div style={{ marginTop: 20 }}>
<h3>Текущий скриншот:</h3>
<img
src={currentScreenshot}
alt="Скриншот"
style={{
maxWidth: '100%',
maxHeight: 400,
border: '1px solid #ccc',
borderRadius: 5,
}}
/>
</div>
)}
{/* Ключевая анимация для спиннера */}
<style>
{`
@keyframes spin {
0% { transform: rotate(0deg);}
100% { transform: rotate(360deg);}
}
`}
</style>
</div>
);
}
export default App;
Что добавлено и улучшено:
- Градиентная сине-серая кнопка, которая становится «засерая» и недоступной при тестировании.
- При нажатии кнопка слегка уменьшается в размере — ощущение нажатия.
- Справа от текста появляется круглый спиннер, вращающийся во время тестирования.
- Плавный переход цвета, тени и состояния disabled.
- Использован flexbox в кнопке для центрирования текста и иконки.
- Под ключевой анимацией в конце кода описан CSS @keyframes для спиннера.
Вы можете поправить цвета и размеры под свои предпочтения — сейчас это современный, яркий и минималистичный дизайн кнопки запуска.
Если хочешь — могу показать, как сделать эту кнопку через CSS-модули или styled-components.