@jswf/react-star-rating
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@jswf/react-star-rating

Text-based rating that allows decimal numbers
ScreenShot

1.Contents

1.1 Props

interface Props {
  style?: React.CSSProperties;       //Owner CSS
  backStyle?: React.CSSProperties;   //Background Text CSS
  foreStyle?: React.CSSProperties;   //Foreground Text CSS
  star?: string;                     //Star charactor '★'
  max: number;                       //Max Star value
  value: number;                     //Current Star value
  onValue?: (value: number) => void; //Change current value Event
}

1.2 Usage

<StarRating max={5} value={2.5} />
<StarRating max={10} value={3} star="▲" />
<StarRating
  style={{ fontSize: "150%" }}
  max={max}
  value={value}
  star="星"
  backStyle={{color:"black"}}
  foreStyle={{color:"red"}}
  onValue={v => {
    setValue(v);
  }}
/>

2.links

3.Sample source

import { useState } from "react";
import React from "react";
import { StarRating } from "./StarRating";
import styled from "styled-components";

const Root = styled.div`
  > div {
    display: flex;
    > div {
      width: 5em;
      text-align: center;
    }
    > button {
      width: 3em;
    }
  }
`;

export function RatingTest() {
  const [max, setMax] = useState(5);
  const [value, setValue] = useState(2.2);

  return (
    <>
      <StarRating max={max} value={value} />
      <StarRating max={max} value={value} star="▲" />
      <StarRating
        style={{ fontSize: "150%" }}
        max={max}
        value={value}
        star="あ"
        backStyle={{color:"black"}}
        foreStyle={{color:"red"}}
        onValue={v => {
          setValue(v);
        }}
      />
      <Root>
        <div>
          <div>max</div>
          <button onClick={() => {setMax(max - 2);}}>-2</button>
          <button onClick={() => {setMax(max - 1);}}>-1</button>
          <div>{max}</div>
          <button onClick={() => {setMax(max + 1);}}>+1</button>
          <button onClick={() => {setMax(max + 2);}}>+2</button>
        </div>
        <div>
          <div>value</div>
          <button onClick={() => {setValue(value - 1);}}>-1</button>
          <button onClick={() => {setValue(value - 0.1);}}>-0.1</button>
          <div>{value.toFixed(1)}</div>
          <button onClick={() => {setValue(value + 0.1);}}>+0.1</button>
          <button onClick={() => {setValue(value + 1);}}>+1</button>
        </div>
      </Root>
    </>
  );
}


5.license

MIT

Readme

Keywords

Package Sidebar

Install

npm i @jswf/react-star-rating

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

12.1 kB

Total Files

5

Last publish

Collaborators

  • sora_kumo