Slot Counter

Content Type: Widget
Categories: Utility,User Interface,Data

Overview

Slot Counter shows a number with a slot-machine animation. Each digit rolls like a reel and stops on the right value. It's based on the open-source react-slot-counter library (version 3.0.1).

Place the widget in a data view and select a String or Integer attribute:

- Use Integer for plain numbers, such as 1284905.

- Use String when you want separators, such as 1,284,905 or 12.5.

When the attribute changes, the counter animates to the new value.

All settings are attributes, so you can change them at runtime or leave them empty to use the default. You can set:

- a start value

- the duration and speed

- the direction (bottom-up or top-down)

- your own dummy characters (for example A,B,C)

- a count-up mode

- equal digit width

- a debounce delay

- starting the animation only when the counter scrolls into view

Six class-name settings let you style the container, characters, separators and reels from your theme.

Use it for KPI tiles on a dashboard, live totals such as votes or orders, eye-catching numbers on a landing page, or scores that roll in.

Documentation

Typical usage scenario

Use Slot Counter to make numbers stand out. The value rolls into place like slot-machine reels, and it animates again every time the attribute changes.

Where it helps:

- KPI tiles on a dashboard, such as visitors, orders or revenue

- Live totals that change while the user watches, such as votes or stock levels

- Eye-catching numbers on a landing or result page, started when the user scrolls to them

- Scores or codes that roll in, also with letters as dummy characters

Place the widget in a data view and select a String or Integer attribute. No Java or JavaScript is needed.

Features and limitations

Features:

- Shows a String or Integer attribute with a slot-machine animation, and animates again each time the value changes

- Supports the separators , . and space in String values (for example 1,284,905 or 12.5)

- A start value, with an option to use it only for the first animation

- Duration, speed, delay per column and debounce delay

- Direction: bottom-up (default) or top-down

- Your own dummy characters and the number of dummy characters per reel

- Count-up or count-down mode instead of random characters

- Equal width for all digits and an endless reel option

- Can start the animation when the counter scrolls into view

- Class names for the container, characters, separators, value, reels and numbers, plus a built-in default style

- Large Integer values are shown in full, and the last value stays visible while loading

Limitations:

- Every setting is an attribute; you can't type static values in the widget properties. Use attribute default values or set them in a microflow or nanoflow.

- duration, speed and delay are Integer attributes, so only whole numbers are possible. The defaults (0.7 and 1.4) apply only when the attribute is empty.

- With startValueOnce = false (the default), every change animates from the start value, so all digits spin.

- direction accepts only the exact text top-down; anything else means bottom-up.

- animateOnVisible starts only when the whole counter is visible in the browser window.

- The widget only displays the value; it doesn't change the attribute.

- Web only; native mobile is not supported.

Dependencies

- Mendix Studio Pro 10.24.17 or a later 10.24 version

Installation

1. Download mendix.SlotCounter.mpk from the Marketplace or from the GitHub release Version1.1.0.

2. Copy it into the widgets folder of your app (App > Show App Directory in Explorer).

3. In Studio Pro, press F4 (App > Synchronize App Directory). The widget appears in the Toolbox as Slot Counter.

Configuration

1. Add a String or Integer attribute for the number to an entity.

2. Optionally, add attributes for the settings you need: Boolean for on/off settings, Integer for numbers, String for texts and class names.

3. Place a data view with the entity on a page and drag Slot Counter into it.

4. Select the attribute for Counter Number on the General tab, and attributes for the other settings.

5. To style the counter, add your own CSS classes to the app theme (for example theme/web/main.scss) and put the class names in the class-name attributes. A class name you set replaces the built-in one.

Tip: to make only the changed digits spin on updates, set startValueOnce to true.

Known bugs

No known bugs.

Report issues at https://github.com/bharathidas/Slot-Counter/issues

Frequently Asked Questions

Can I use a Decimal attribute?

No. Counter Number accepts String and Integer attributes. For a decimal number, format it as text in a String attribute, for example 12.50.

Why do all digits spin when only one changed?

With startValueOnce = false (the default), every animation starts from the start value. Set startValueOnce to true so later changes spin only the changed digits.

How do I set a duration of 1.5 seconds?

The duration attribute is an Integer, so only whole seconds are possible. Leave it empty for the default of 0.7 seconds.

The counter doesn't animate on load after upgrading from 1.0. Why?

Your autoAnimationStart attribute is false, and version 1.0 ignored this setting. Leave it empty or set it to true.

Can I use letters while the reels roll?

Yes. Set dummyCharacters to a comma-separated list, for example A,B,C.

The animation never starts with animateOnVisible. Why?

The counter must be fully visible in the browser window. Make sure it isn't cut off or taller than the window.

Releases

Version: 1.1.0
Framework Version: 10.24.17
Release Notes:

## Slot Counter 1.1.0


Slot-machine style animated counter for Mendix, based on react-slot-counter 3.0.1.


### Compatibility

- Mendix Studio Pro **10.24.17** (built with `@mendix/pluggable-widgets-tools` 10.16.0).

- Web, React client. Not available for native mobile.

- For Mendix 9, use [Version1.0](https://github.com/bharathidas/Slot-Counter/releases/tag/Version1.0).


### Changes and fixes

- Rebuilt for Studio Pro 10.24.17 and updated to react-slot-counter 3.0.1.

- **autoAnimationStart** is now honoured (1.0 always animated on load).

- **numberSlotClassName** and **numberClassName** are now applied.

- An empty **dummyCharacters** attribute now uses random digits instead of blank characters.

- Integer values are shown in full, without exponent notation.

- While the attribute is loading, the last value stays visible. Unavailable or empty settings use their defaults.

- The widget's **Class** property is added to the container.

- The Studio Pro design-mode preview shows the selected attribute name.

- Removed console logging; clearer property descriptions. Package size is about 16 KB.

- Widget source code is now in the repository (`slotCounter/`).


**Important when upgrading:** if your app sets the **autoAnimationStart** attribute to `false`, the counter will now show the value on load without animating. Leave it empty or set it to `true` to keep the 1.0 behaviour.


### Install

1. Download `mendix.SlotCounter.mpk` below.

2. Copy it into the `widgets` folder of your app (**App > Show App Directory in Explorer**).

3. In Studio Pro, press **F4** (**App > Synchronize App Directory**).

4. Place **Slot Counter** in a data view and select a String or Integer attribute for **Counter Number**.


### Upgrade from 1.0

Replace the `.mpk` in the `widgets` folder, press **F4**, and choose **Update all widgets** if Studio Pro reports that the widget definition has changed. If the running app still shows the old widget, use **App > Clean Deployment Directory** and run again.


### Previous version

[Version1.0](https://github.com/bharathidas/Slot-Counter/releases/tag/Version1.0) (Mendix 9.24.18).

Version: 1.0.0
Framework Version: 9.24.18
Release Notes: **Slot Counter** Counter is a widget that helps you add animated and interactive number displays to your web applications. It's easy to use, works with different types of data, and lets you customize the animations to make your numbers stand out. **Features** • **Counter Number** - The value to be displayed. • **StartValue** - The initial value to be displayed before the animation starts. It sets the beginning of the slot machine animation. • **startValueOnce**- If set to true, the animation starts from the startValue only for the first render. For subsequent animations, it starts from the last value. • **duration**- The duration of the animation in seconds. • **speed**- The speed of counter when running. • **Delay**-The delay time of each column. • **dummyCharacters**- An array of dummy characters to be used in the animation. • **dummyCharacterCount**-The number of dummy characters to be displayed in the animation before reaching the target character. • **autoAnimationStart**-Determines whether the animation should start automatically when the component is first mounted. • **animateUnchanged**- Determines whether to animate only the characters that have changed. • **hasInfiniteList**-Determines whether the list should appear as continuous, with the end of the target character seamlessly connected to the beginning. • **sequentialAnimationMode**-Determines if the animation should increment or decrement sequentially from the startValue to value instead of random animation. • **useMonospaceWidth**-Ensures that all numeric characters occupy the same horizontal space, just like they would in a monospace font. • **direction**-Sets the direction of the slot machine animation. Accepted values are ‘bottom-up' and 'top-down'. • **debounceDelay**-Specifies the delay in milliseconds for debouncing animations. When the value changes rapidly, it allows the animation to execute smoothly. • **animateOnVisible**-Activates the animation when the component is visible in the viewport. rootMargin sets the margin around the viewport for triggering the animation, while triggerOnce determines if the animation should occur only once (true) or every time the component becomes visible (false). • **containerClassName**-The class name of container. • **charClassName**-The class name of each character. • **separatorClassName**-The class name of the separator character (. or ,). • **valueClassName**-The class name for the value of the slot, making it possible to customize the styling and visibility of the value. • **numberSlotClassName**- The class name for the number slot, allowing you to customize the styling of the number slot. • **numberClassName**- The class name for the number, allowing you to customize the styling of the number. **Dependencies**: • Mendix modeler 9.24.18. **Demo URL:** [https://slotcouter-sandbox.mxapps.io/login.html?profile=Responsive](https://slotcouter-sandbox.mxapps.io/login.html?profile=Responsive) demo_administrator Eb42f1yQ93aL **Issues, suggestions and feature requests** [https://github.com/bharathidas/Slot-Counter/issues](https://github.com/bharathidas/Slot-Counter/issues) **Screenshots:** ![Screenshot_1](https://github.com/user-attachments/assets/f7e42110-fcee-4672-a681-04de2767af03) ![Screenshot_2](https://github.com/user-attachments/assets/35ff1bac-f722-4803-acd7-3f49b8c9571b) ![Screenshot_3](https://github.com/user-attachments/assets/843f0259-b81d-4f2c-9c65-a767c08efe1d) ![Screenshot_4](https://github.com/user-attachments/assets/19915660-535f-4f3e-af15-64487f6cbc94)