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

react-slot-counter

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-slot-counter

A versatile and engaging component to display numbers in a captivating slot machine UI, perfect for enhancing user experience and grabbing attention in your web projects

  • 1.7.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.5K
decreased by-57.05%
Maintainers
1
Weekly downloads
 
Created
Source

react-slot-counter

react-slot-counter is a feature-rich React component that displays numbers and strings with an engaging slot machine animation effect.

NPM License Size

Features

  • Customize animation duration and other settings
  • Animate only changed characters
  • Control animation start with a ref
  • Easily add custom styles to the characters and separators

Installation

To install the package, run the following command:

npm install react-slot-counter

Usage

Import SlotCounter and use it in your component. Here's a simple example:

import React from 'react';
import SlotCounter from 'react-slot-counter';

function App() {
  return (
    <>
      <SlotCounter value={123456} />
      <SlotCounter value="1,234,567" />
      <SlotCounter value={['1', '2', '3', '4', '5', '6']} />
      <SlotCounter value="??????" />
      <SlotCounter value={36.5} duration={2} />
      <SlotCounter
        value={123456}
        charClassName="char"
        separatorClassName="sep"
      />
    </>
  );
}

export default App;

Demo

For more examples of usage and available options, check out the demo page.

Props

PropTypeDefaultDescriptionVersion
value (required)number | string | string[]The value to be displayed. It can be a number or a string with numbers and commas.
startValuenumber | string | string[]The initial value to be displayed before the animation starts. It sets the beginning of the slot machine animation.1.7.0
durationnumber0.7The duration of the animation in seconds.
dummyCharactersArray<string>Defaults to random numbers from 0 to 9An array of dummy characters to be used in the animation.
dummyCharacterCountnumber6The number of dummy characters to be displayed in the animation before reaching the target character.
autoAnimationStartbooleantrueDetermines whether the animation should start automatically when the component is first mounted.
animateUnchangedbooleanfalseDetermines whether to animate only the characters that have changed.
hasInfiniteListbooleanfalseDetermines whether the list should appear as continuous, with the end of the target character seamlessly connected to the beginning.1.4.2
containerClassNamestringThe class name of container.
charClassNamestringThe class name of each character.
separatorClassNamestringThe class name of the separator character (. or ,).
valueClassNamestringThe class name for the value of the slot, making it possible to customize the styling and visibility of the value.1.4.3

Ref

You can access the SlotCounter component using a ref. This ref can be used to start the animation of the component.

MethodDescription
startAnimationStart the animation of the component

The startAnimation method accepts an optional object with the following properties:

  • duration: The duration of the animation in seconds. Overrides the duration prop.
  • dummyCharacterCount: The number of dummy characters to be displayed in the animation before reaching the target character. Overrides the dummyCharacterCount prop.
  • direction: This option determines the direction of the slot machine animation. The accepted values are bottom-top and top-bottom. The default value is bottom-top. If bottom-top is chosen, the animation will start from the bottom and move towards the top. If top-bottom is chosen, the animation will start from the top and move downwards.

Example:

import React, { useRef } from 'react';
import SlotCounter, { SlotCounterRef } from 'react-slot-counter';

function App() {
  const counterRef = useRef < SlotCounterRef > null;

  const handleStartClick = () => {
    counterRef.current?.startAnimation();
  };

  return (
    <div>
      <SlotCounter value={123456} ref={counterRef} />
      <button onClick={handleStartClick}>Start</button>
    </div>
  );
}

export default App;

Contributing

Contributions, issues, and feature requests are welcome! If you'd like to contribute, please follow these steps:

  1. Fork the project
  2. Create a new branch for your feature or bugfix
  3. Commit your changes
  4. Push your changes to the branch
  5. Open a pull request

Please also make sure to update tests as appropriate and follow the coding style of the project.

License

This project is licensed under the MIT License

Keywords

FAQs

Package last updated on 10 Jun 2023

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