/
dimamir
/
rill
Обзор
Документация
Войти
/
dimamir
/
rill
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/src/components/DocsRating.js
67 строк
2 KB
royendo
New Tutorials! (#5538)
24 сен 2024, 20:20
Не верифицирован
24 сен 2024, 20:20
9d58678
Код
Авторство
О чём код?
import React, { useState } from 'react'; import { useLocation } from '@docusaurus/router'; const DocsRating = () => { const [voted, setVoted] = useState(false); const location = useLocation(); const handleVote = (vote) => { if (!voted) { // Push the vote event to the GTM dataLayer if (window.dataLayer) { window.dataLayer.push({ event: 'custom_vote', category: 'DocsRating', label: location.pathname, value: vote, }); } setVoted(true); } }; return ( <div style={{ display: 'flex', alignItems: 'center', gap: '10px', marginTop: '20px' }}> <p style={{ margin: 0 }}>Was this content helpful?</p> <button onClick={() => handleVote('up')} disabled={voted} aria-label="Thumbs up" style={{ background: 'none', border: 'none', cursor: voted ? 'not-allowed' : 'pointer', fontSize: '1.5rem', opacity: voted ? 0.5 : 1, display: 'flex', alignItems: 'center', }} > 👍 </button> <button onClick={() => handleVote('down')} disabled={voted} aria-label="Thumbs down" style={{ background: 'none', border: 'none', cursor: voted ? 'not-allowed' : 'pointer', fontSize: '1.5rem', opacity: voted ? 0.5 : 1, display: 'flex', alignItems: 'center', }} > 👎 </button> </div> ); }; export default DocsRating;