Todos os componentes

Motion Number Upvotes

Motion Number Upvotes é um componente para React e Tailwind CSS, da biblioteca UI Layouts, com licença MIT. Copia e cola no teu projeto.

UI Layouts MIT other

O que é

Motion Number Upvotes é um componente para React e Tailwind CSS, da biblioteca UI Layouts, com licença MIT. Copia e cola no teu projeto.

Como usar

Abre o componente no catálogo, carrega em copiar, e cola no teu projeto. O prompt copiado leva o código e as regras para o teu agente o reproduzir sem alterar nada.

Abrir no catálogo

Cinco cópias grátis por mês. Sem cartão.

Não precisa de pacotes além do que o projeto já tem

Licença

Este componente vem de UI Layouts e é redistribuído sob a licença MIT, que permite uso comercial. O aviso de copyright viaja com o código.

Motion Number Upvotes

./registry/components/motion-number/motion-number-upvotes.tsx
'use client';
import NumberFlow from '@number-flow/react';
import { ArrowDown, ArrowUp } from 'lucide-react';
import { motion } from 'motion/react';
import type React from 'react';
import { useState } from 'react';

const UpvoteDownvote: React.FC = () => {
  const [votes, setVotes] = useState(14); // Initial votes
  const [activeVote, setActiveVote] = useState<'up' | 'down' | null>(null); // Track active arrow

  const handleVote = (state: 'up' | 'down') => {
    if (state === 'up') {
      setVotes(votes + 1);
      setActiveVote(state);
    } else {
      setVotes(votes - 1);
      setActiveVote(state);
    }
  };

  return (
    <div
      className={`flex flex-col items-center gap-2 p-4  border rounded-xl shadow-lg w-fit mx-auto ${
        activeVote === 'up'
          ? 'dark:bg-green-950 bg-green-300 border-green-600 text-white'
          : activeVote === 'down'
            ? 'dark:bg-red-950 bg-red-300 border-red-600 text-white'
            : 'dark:bg-neutral-950 bg-neutral-50 text-primary'
      }`}
    >
      <div className='  text-lg font-medium'>
        <NumberFlow value={votes} format={{ notation: 'compact' }} /> Upvotes
      </div>

      <div className='flex items-center gap-4'>
        <motion.button
          whileTap={{ scale: 0.9 }}
          onClick={() => handleVote('up')}
          className={`p-2 rounded-full text-white ${
            activeVote === 'up' ? 'bg-green-500 ' : ' bg-black '
          } transition-colors`}
        >
          <ArrowUp size={24} />
        </motion.button>

        <motion.button
          whileTap={{ scale: 0.9 }}
          onClick={() => handleVote('down')}
          className={`p-2 rounded-full text-white ${
            activeVote === 'down' ? 'bg-red-500 ' : ' bg-black '
          } transition-colors`}
        >
          <ArrowDown size={24} />
        </motion.button>
      </div>
    </div>
  );
};

export default UpvoteDownvote;

Componentes parecidos