Giter Site home page Giter Site logo

paoloiulita / react-numeric-stepper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anatoliygatt/numeric-stepper

0.0 0.0 1.0 7.11 MB

๐ŸŽ› A numeric stepper component for React.

Home Page: https://numeric-stepper.netlify.app

License: MIT License

Shell 0.29% TypeScript 99.71%

react-numeric-stepper's Introduction


numeric-stepper Demo

numeric-stepper

A numeric stepper component for React. Inspired by Ehsan Rahimi's Tally Counter Micro-Interaction Dribbble shot.


GitHub CI Workflow Status NPM Version License


๐Ÿ“– Table of Contents

๐Ÿš€ Getting Started

๐Ÿ‡ Jump Start

npm install @anatoliygatt/numeric-stepper @emotion/react @emotion/styled framer-motion
import { useState } from 'react';
import { NumericStepper } from '@anatoliygatt/numeric-stepper';

function Example() {
  const INITIAL_VALUE = 20;
  const [value, setValue] = useState(INITIAL_VALUE);
  return (
    <NumericStepper
      minimumValue={10}
      maximumValue={100}
      stepValue={10}
      value={INITIAL_VALUE}
      size="lg"
      inactiveTrackColor="#fed7aa"
      activeTrackColor="#fddec0"
      activeButtonColor="#ffedd5"
      inactiveIconColor="#fb923c"
      hoverIconColor="#ea580c"
      activeIconColor="#9a3412"
      disabledIconColor="#fdba74"
      thumbColor="#f97316"
      thumbShadowAnimationOnTrackHoverEnabled={false}
      focusRingColor="#fff7ed"
      onChange={(value) => {
        setValue(value);
      }}
    />
  );
}

๐Ÿ’ป Live Demo

Open in CodeSandbox

โš™๏ธ Configuration

NumericStepper supports the following props:

Prop Type Default value Description
minimumValue number 0 The minimum value.
maximumValue number Number.MAX_SAFE_INTEGER The maximum value.
stepValue number 1 The step increment value.
value number The initial value.
onChange Function The callback invoked when the value changes.
size string sm The size of the numeric stepper. There are 3 available sizes:
  • sm โ€” 185x74px
  • md โ€” 277.5x111px
  • lg โ€” 370x148px
inactiveTrackColor string #2b2b2b The color of the track while the thumb is not being horizontally dragged.
activeTrackColor string #1f1f1f The color of the track while the thumb is being horizontally dragged and is at the maximum trackable distance from the track's center.
hoverButtonColor string transparent The color of the decrement/increment button in a hover state.
activeButtonColor string #ececec The color of the decrement/increment button in an active state.
inactiveIconColor string #858585 The color of the decrement/increment button icon in an inactive state.
hoverIconColor string #ffffff The color of the decrement/increment button icon in a hover state.
activeIconColor string #000000 The color of the decrement/increment button icon in an active state.
disabledIconColor string #383838 The color of the decrement/increment button icon in a disabled state.
thumbColor string #444444 The color of the thumb.
thumbLabelColor string #ffffff The color of the thumb's label.
thumbShadowAnimation
OnTrackHoverEnabled
boolean true If true, the thumb's shadow will animate when hovering over the track.
focusRingColor string #ececec The color of the focus ring of the interactive elements.

In order to customise the thumb's font settings, we can use CSS, like so:

[data-testid='numeric-stepper-thumb'] {
  font-family: 'Times New Roman', Times, serif;
  font-style: italic;
  font-weight: 800;
}

โ™ฟ๏ธ Accessibility

In order to comply with the web accessibility standards, we must make use of the decrementButtonAriaLabel and incrementButtonAriaLabel props, like so:

function AccessibleExample() {
  return (
    <NumericStepper
      decrementButtonAriaLabel="Decrement"
      incrementButtonAriaLabel="Increment"
    />
  );
}

Also, we can use a thumbAriaLabel prop to provide a description for the value rendered inside a thumb, like so:

function EnhancedThumbAccessibilityExample() {
  const [value, setValue] = useState(0);
  return (
    <NumericStepper
      value={value}
      thumbAriaLabel={`${value} items`}
      onChange={(value) => {
        setValue(value);
      }}
    />
  );
}

๐Ÿ‘จ๐Ÿผโ€โš–๏ธ License

MIT

react-numeric-stepper's People

Contributors

anatoliygatt avatar dependabot[bot] avatar semantic-release-bot avatar paoloiulita avatar

Forkers

nathanbosse

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.