Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-voting

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-voting

A reusable and customizable voting component for Angular projects

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

NgVoting

ng-voting is a reusable Angular component that can be used to easily implement a voting platform in your app. It is responsive and completely customizable.

Demo

ng-voting

Table of Contents

  • Installation
  • Usage
  • Customize
  • API
  • Whats next
  • Author

Installation

npm i ng-voting

Usage

  • Import the NgVotingComponent in the module of your choice.
...
import { NgVotingComponent } from 'ng-voting'

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...,
    NgVotingComponent
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  • In your.component.ts add some data of type Voting. can be import like import { Voting } from ng-voting
  • In your.component.html add the ng-voting tag and pass you data of type Voting to [data] as shown below.

your.component.ts

import { Voting } from 'ng-voting';

@Component({
  selector: 'your-root',
  templateUrl: './your.component.html'
})
export class YourComponent {
  data: Voting =  {
    question: "Do you like ng-voting?",
    options: [
        {
            label: "Yes",
            value: "yes",
            votesCount: 1,
            imageUrl: "optional-image-url",
            users: [
              ...users,
              {
                name: "John Snow",
                image: "assets/profile1.jpg"
              },
            ]
        },
        {
            label: "No",
            value: "no",
            votesCount: 0,
            imageUrl: "optional-image-url"
        }
    ]
  }

  optionSelected(value: string) {
    // You get back the selected option here.
  }

your.component.html

<ng-voting [data]="data" (selected)="optionSelected($event)"></ng-voting>

Voting

export interface Voting {
  question: string;
  options: Option[];
}

export interface Option {
  label: string;
  value: string;
  votesCount: number;
  imageUrl?: string;
  users?: { name: string; image?: string }[];
  color?: string;
  bgColor?: string;
  selected?: boolean;
}

Customize

  • The component can be completely customized, from adding background colors, font sizes to modifying the margins
  • Import the StyleParams like import { StypeParams } from 'ng-voting', and create and object.
  • Pass the object to [styleParams] in your html. (use rem instead of px)
// In your .ts file, create an object and change these values
// (use `rem` and not `px`)

styleParams: StyleParams = {
  borderColor: "#d3d3d3",
  margin: "1rem",
  hoverColor: "#ebebeb",
  scaleColor: "#9797dc",
  fontSize: "1.5rem",
  topicBackgroundColor: "#ffffff",
  optionsBackgroundColor: "#ffffff",
  topicFontColor: "black",
  optionsFontColor: "black",
};
// In your html file, pass that object. <ng-voting [data]="data" [styleParams]="styleParams" (selected)="increaseVoteCount($event)"></ng-voting>

API

APITypeDescriptionDefaultRequired
[data]VotingVoting topic and option and their detailsundefinedtrue
[isLoading]booleanShow loading statefalsefalse
[showUsers]booleanShow the users count on optiontruefalse
[showScale]booleanShow the percentage scale of votingtruefalse
[disable]booleanDisable votingfalsefalse
[selectedOptionValue]booleanShows a checkmark of which option was selected by user""false
[styleParams]StyleParamsCustomize the Voting component.borderColor: '#d3d3d3', margin: '1rem', hoverColor: '#ebebeb', scaleColor: '#9797dc', fontSize: '1.5rem', topicBackgroundColor:'#ffffff', optionsBackgroundColor:'#ffffff', topicFontColor: 'black', optionsFontColor: 'black'false
(selected)stringEmits the selected option value
  • Example usage
<ng-voting
        [data]="data"
        [styleParams]="styleParams"
        [showScale]="true"
        [showUsers]="true"
        [isLoading]="false"
        [selectedOptionValue]="''"
        [disable]="false"
        (selected)="handleVote($event)"></ng-voting>

Whats next

  • A customization app, where you can try out the component and generate the code for it.
  • More reusable components.

Author

Keywords

FAQs

Package last updated on 07 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc