Skip to content

Digital Flip

v0.0.5+

TuiDigitalFlip is a numerical display component featuring a mechanical flip effect. By simulating the dynamic movement of physical flip cards, it makes numerical changes more visually engaging. It is commonly used for data dashboards, statistical boards, or countdown scenarios.

Usage Scenario

The flip effect is more prominent on larger cards. Although size: small is supported, it is recommended to use sizes of size: default or larger.

Basic Usage

Basic Display

The simplest usage is to bind the value. The component automatically handles numerical changes and triggers the flip animation. It supports integers, floating-point numbers, and time strings (e.g., "12:30:59").

html
<script setup>
import { ref } from 'vue';

const num = ref(12345);
</script>

<template>
  <TuiDigitalFlip :value="num" />
</template>

Formatting

Thousands and Decimals

  • useGrouping: Enables the thousands separator (e.g., 1,234,567).
  • Decimal Support: The component automatically recognizes and retains decimal points without extra configuration.
html
<template>
  <TuiDigitalFlip :value="123456" useGrouping />
  
  <TuiDigitalFlip :value="123.45" />
</template>

Prefix & Suffix

Use the prefix and suffix attributes to add units or symbols to the value, such as currency symbols or percentages.

html
<template>
  <TuiDigitalFlip :value="1234" prefix="$ " />
  
  <TuiDigitalFlip :value="85" suffix=" %" />
  
  <TuiDigitalFlip :value="122" prefix="Output " suffix=" tons" />
</template>

Animation Control

Flip Speed and Delay

  • duration: Duration of the flip animation in milliseconds (ms), default is 600.
  • delay: Delay time before the first load or numerical change animation triggers (ms).
html
<template>
  <TuiDigitalFlip :value="88888" :duration="300" />
  
  <TuiDigitalFlip :value="12345" :delay="3000" />
</template>

Flip Mode

The flipMode attribute controls the logic of numerical scrolling:

  • shortest (Default): Selects the shortest path for scrolling (e.g., flipping 9 -> 0 directly downwards).
  • downOnly: Always scrolls downwards (simulating a traditional mechanical watch).
  • smart: Intelligent mode that selects the direction automatically based on the numerical change.
html
<TuiDigitalFlip :value="count" flipMode="downOnly" />

Appearance

Sizes and Styles

  • size: Built-in sizes include huge, large, default, small, and custom.

  • appearance:

  • default: Standard style (typically dark background with light text).

  • reverse: Inverted style (light background with dark text).

  • bordered: Whether to display borders for individual digits.

  • dropShadow: Whether to display drop shadows.

html
<template>
  <TuiDigitalFlip :value="12345" size="large" appearance="reverse" bordered />
</template>

Custom Styles

Set size="custom" and pass a customClass to deeply customize the width, height, font size, and color scheme of the flip component via CSS variables.

html
<template>
  <TuiDigitalFlip 
    :value="12345" 
    size="custom" 
    appearance="custom"
    customClass="my-flip-style" 
  />
</template>

<style lang="less">
.my-flip-style {
  /* Define Dimensions */
  --tui-dflip-fz: 20px;   /* Font size */
  --tui-dflip-lh: 24px;   /* Line height */
  --tui-dflip-w: 24px;    /* Single card width */
  --tui-dflip-h: 30px;    /* Single card height */
  
  /* Define Colors */
  --tui-dflip-fc: #e6a23c;       /* Font color */
  --tui-dflip-bg: #409eff;       /* Card background */
  --tui-dflip-bg_alt: #66b1ff;   /* Flip side background */
}
</style>

API Reference

Props

PropertyTypeDefaultDescription
valueString/Number0Required. Numerical value or time string to display.
durationNumber600Flip animation duration (ms).
delayNumber1000Animation delay start time (ms).
flipModeString'shortest'Flip mode. Options: smart, downOnly, shortest.
useGroupingBooleanfalseWhether to enable the thousands separator.
prefixString-Prefix text.
suffixString-Suffix text.
gapNumber-Spacing between digits (px).
sizeString'default'Size. Options: huge, large, default, small, custom.
appearanceString'default'Appearance style. Options: default, reverse, custom.
borderedBooleanfalseWhether to display borders.
dropShadowBooleanfalseWhether to display shadows.
customClassString-Custom class name used with size="custom".

Released under the MIT License.