Giter Site home page Giter Site logo

josephsb / react-twitter-poll Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 904 KB

React-Twitter-Poll is a React library for creating polls like Twitter or Facebook. It is easy to use and flexible, and allows developers to create polls of different types, with different visualization options and analysis data.

License: MIT License

JavaScript 8.02% TypeScript 72.11% CSS 19.87%

react-twitter-poll's Introduction

React Twitter Poll

React-Twitter-Poll is a React library for creating polls like Twitter or Facebook. It is easy to use and flexible, and allows developers to create polls of different types, with different visualization options and analysis data.

JavaScript Style Guide ts License: MIT

Install

NPM

npm i react-twitter-poll

Yarn

yarn add react-twitter-poll

Usage

import React, { useState } from 'react';
import ReactTwitterPoll from 'react-twitter-poll';
import 'react-twitter-poll/dist/index.css';

const dataOptions = [
  {
    id: 0,
    text: "Universitario",
    votes: 18
  },
  {
    id: 1,
    text: "Alianza Lima",
    votes: 14
  },
  {
    id: 2,
    text: "Melgar",
    votes: 3
  },
  {
    id: 3,
    text: "Sporting Cristal",
    votes: 15
  }
]

function App() {
  const [options, setOptions] = useState([...dataOptions]);

  const handleVote = (item: option) => {
    const tempOptions = [...options];
    const index = tempOptions.findIndex(x => x.id === item.id);
    tempOptions[index].votes = tempOptions[index].votes + 1
    setOptions([...tempOptions])
  }

  return (
    <div className="App">
      <br />
      <ReactTwitterPoll
        title='¿Cual es tu equipo favorito de la Liga 1?'
        options={options}
        onVote={handleVote}
        //optionSelected={options[2]}
      />
    </div>
  );
}

export default App;

Component Props

Prop Type Required Default Description
options option undefined An array of objecst to vote on with keys "id", "text" and "votes"
title string undefined The title of the poll
footerVisible boolean true Whether or not to show a footer with the total number of votes
onVote (option: option) => void undefined A callback function that is called when an option is selected
optionSelected option undefined The selected option
className string undefined A CSS class to apply to the poll container
CustomTitle ({ title }: { title?: string }) => JSX.Element undefined A custom component to render the title of the poll
CustomFooter ({ totalVotes }: { totalVotes: number }) => JSX.Element undefined A custom component to render the footer of the poll
CustomOption ({ item, onClick }: { item: option, onClick: () => void }) => JSX.Element undefined A custom component to render an option
CustomOptionSelected ({ item, percentVotes, isSelected }: { item: option, percentVotes: number, isSelected: boolean }) => JSX.Element undefined A custom component to render a selected option

License

MIT © JosephSB

react-twitter-poll's People

Contributors

josephsb avatar

Watchers

 avatar

Forkers

marlonfolken

react-twitter-poll's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.