npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-voting

v1.2.3

Published

A reusable and customizable voting component for Angular projects

Downloads

15

Readme

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

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

| API | Type | Description | Default | Required | | ----------------------- | ------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | [data] | Voting | Voting topic and option and their details | undefined | true | | [isLoading] | boolean | Show loading state | false | false | | [showUsers] | boolean | Show the users count on option | true | false | | [showScale] | boolean | Show the percentage scale of voting | true | false | | [disable] | boolean | Disable voting | false | false | | [selectedOptionValue] | boolean | Shows a checkmark of which option was selected by user | "" | false | | [styleParams] | StyleParams | Customize the Voting component. | borderColor: '#d3d3d3', margin: '1rem', hoverColor: '#ebebeb', scaleColor: '#9797dc', fontSize: '1.5rem', topicBackgroundColor:'#ffffff', optionsBackgroundColor:'#ffffff', topicFontColor: 'black', optionsFontColor: 'black' | false | | (selected) | string | Emits 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