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

quark-ui-rate

v0.8.0

Published

Give rate to something.

Downloads

16

Readme

Introduction

Give rate to something.

It's a cross-framework component enpowered by quarkc.

Installation

npm i quark-ui-rate

Use whatever package manager you like.

Usage

Since it's cross-framework, you can use it in popular javascript frameworks like Vue, React, Angular and jQuery. Rate component is fully controlled, it only reacts to passed-down attribute changes.

First import it in your main JS entry:

import "quark-ui-rate";

Vue

First create an attribute(vue2)in your .vue SFC script:

export default {
  data() {
    return {
      // create attribute to bind
      rateValue: 4.7,
    };
  },
  methods: {
    handleInput(event) {
      this.rateValue = event.detail;
    },
    handleChange(event) {
      console.log("value changed", event.detail);
    },
  },
};

or writable ref(vue3):

import { ref } from "vue";
const rateValue = ref(4.7);
const handleInput = (event) => {
  // set ref's value
  rateValue.value = event.detail;
};
const handleChange = (event) => {
  console.log("value changed", event.detail);
};

Then in your .vue SFC template, bind it to value attribute:

<quark-ui-rate
  size="1.5rem"
  :value="rateValue"
  space="0.5rem"
  color="#ddd"
  active-color="linear-gradient(to right, #a8f, #8af)"
  @input="handleInput"
  @change="handleChange"
></quark-ui-rate>

fix console warning

By default, Vue will try to resolve any non-native HTML tag as a registered Vue component before falling back to rendering it as custom element. This will cause Vue to emit a "failed to resolve component" warning during development. Your should tell Vue to ignore element with name "quark-ui-rate" or just ignore any element prefixed with "quark-". Please refer to Vue's official document for resolution and detailed explanation.

React

in your function component:

import { useState } from "react";

export default function App() {
  const [value, setValue] = useState(4.7);
  const handleInput = (event) => {
    setValue(event.detail);
  };
  const handleChange = (event) => {
    console.log("value changed", event.detail);
  };
  return (
    <div>
      <quark-ui-rate
        size="1.5rem"
        value={value}
        space="0.5rem"
        color="#ddd"
        activeColor="linear-gradient(to right, #a8f, #8af)"
        onInput={handleInput}
        onChange={handleChange}
      ></quark-ui-rate>
    </div>
  );
}

Vanilla JS

document.addEventListener("DOMContentLoaded", () => {
  const rate = document.getElementById("rate");
  rate.addEventListener("input", (event) => {
    rate.setAttribute("value", event.detail);
  });
  rate.addEventListener("change", (event) => {
    console.log("value changed", event.detail);
  });
});

Then use it as a normal web component in your .html files:

<quark-ui-rate
  id="rate"
  size="1.5rem"
  value="4.7"
  space="0.5rem"
  color="#ddd"
  activeColor="linear-gradient(to right, #a8f, #8af)"
></quark-ui-rate>

Examples above show a 4.7 stars rating out of 5 (top rating stars' count can be customized by the component property count, which is default to 5).

demo

API

Attributes

| Attribute | Description | Type | Default | | ----------- | ------------------------------- | ---------------- | ------- | | value | current rating | number | 0 | | count | icon count | number | 5 | | size | icon size, unit default to 'px' | number | string | 20px | | space | space between icons | number | string | 4px | | icon | icon's url | string | | | color | default color of icon | string | #F0F3F5 | | activeColor | active color of icon | string | | | allowHalf | is half select allowed | boolean | false | | readonly | is readonly | boolean | false | | disabled | is disabled | boolean | false |

Events

| Event | Description | Parameters | | ------ | ---------------------------------- | ------------------ | | input | called when new rating value given | { detail: number } | | change | called when rating value changed | { detail: number } |