Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Text

  • Text
  • Heading
  • SectionHeader
  • Prose
  • Markdown
  • Formula
  • AuroraText
  • LineShadowText
  • AnimatedShinyText
  • AnimatedGradientText
  • WordRotate
  • TypingAnimation
  • SparklesText
  • SplitText
  • BlurText
  • FlipText
  • TextReveal
  • DecryptedText
  • GlitchText
  • CircularText
  • ScrollReveal
  • TrueFocus
  • ASCIIText
  • CurvedLoop
  • FallingText
  • FuzzyText
  • ScrambledText
  • ScrollFloat
  • ScrollVelocity
  • Shuffle
  • TextCursor
  • TextPressure
  • VariableProximity

Code

  • Code
  • CodeBlock
  • Snippet
  • CodeDiff
  • Kbd

FlipText

flip-text

Flips a heading character by character in 3D when the pointer enters it.

Usage

Page heading

The most common usage: the heading is the h1 itself (no wrapper) and its characters flip when the pointer enters. The copy goes straight into children, expressions included.

AI status

tsx
<FlipText as="h1" className="text-2xl font-semibold tracking-tight">
  AI status
</FlipText>

Four flip directions

direction names the side the new face **enters** from: top presses down from above, left turns in from the left, and so on.

From the topFrom the bottomFrom the leftFrom the right
tsx
<FlipText direction="top">From the top</FlipText>
<FlipText direction="bottom">From the bottom</FlipText>
<FlipText direction="left">From the left</FlipText>
<FlipText direction="right">From the right</FlipText>

Timing: duration and stagger

duration is how many seconds one character takes to flip; stagger is the delay between neighbours in milliseconds. A larger stagger makes the wave travel more slowly and more visibly.

A slower wave
tsx
<FlipText duration={0.8} stagger={90} className="text-xl">
  A slower wave
</FlipText>

Split Latin headings on words

splitType="word" splits on whitespace so a long word is not broken apart in a narrow box. Chinese is fine on the default char.

Deploy in seconds

tsx
<FlipText splitType="word" as="h2" className="text-xl font-semibold">
  Deploy in seconds
</FlipText>

When to use

Use FlipText for a page or card heading that should react to the pointer: on mouse enter, the characters flip over one by one.

The line between this and the other text effects in the library is sharp: those are entrance animations (they play once as the text scrolls into view and then rest), while this is a hover interaction that replays on every enter. Use SplitText for a staggered entrance, BlurText for a blur-to-sharp reveal, TextReveal for "this is in progress", and Heading for a plain static title.

It pairs with PageHeader's titleAs, which is designed for exactly this: a heading component that animates itself and renders the heading tag.

Import

ts
import { FlipText } from "@hulianui/ui"

Props

NameTypeDefaultDescription
direction"top" | "bottom" | "left" | "right""top"Which side the new face flips in from (the direction the new face enters, not the one the old face leaves towards).
splitType"char" | "word""char"Split granularity: char per character (CJK-friendly) or word on whitespace, which keeps long Latin words from breaking.
durationnumber0.5Duration of a single character flip, in seconds.
staggernumber30Delay between neighbouring characters, in milliseconds. Equivalent to SplitText's delay.
asElementType"span"Rendered tag. Event and attribute types follow it.

All other native attributes of the rendered tag (className, id, data-*, ref, …) are passed through.

Events

EventTypeDescription
onMouseEnter(e: MouseEvent<HTMLElement>) => voidThe flip is triggered by this event, but your handler is called first and is never replaced.

Slots

SlotTypeDescription
childrenReactNodeHeading content. Plain text is extracted recursively before splitting, so nested markup is flattened; when no text can be extracted, children render as-is.

Example

tsx
// The heading is the h1, with no wrapper
<FlipText as="h1" className="text-lg font-semibold tracking-tight">System status</FlipText>

// Variables and expressions go straight in (this is why it takes children, not text: string)
<FlipText as="h2">{name || "Untitled customer"}</FlipText>

// As PageHeader's titleAs
<PageHeader title={templateName} titleAs={FlipText} />

// Change direction and slow the wave down
<FlipText direction="left" duration={0.8} stagger={90}>A slower wave</FlipText>

// Split Latin headings on words so long words do not break
<FlipText splitType="word" as="h2">Deploy in seconds</FlipText>

Usage guidelines

  • Do not wrap it in an <h1>; use as. <h1><FlipText/></h1> is a redundant nesting and makes a screen reader announce two headings: one from the h1, one from this component's aria-label. Because as participates in type inference, as="h1" also makes the event and attribute types follow h1.
  • Nested markup in children is flattened. Plain text is extracted recursively and then split per character, so <em> and friends do not survive. A heading that genuinely needs rich text should not be flipping character by character.
  • One full round; it does not follow hover state. Moving the pointer away mid-flight would leave characters frozen on an angle, which is visible. Entering plays a complete round, and re-entering while it plays does not restart it.
  • The flip is orthographic, without perspective. It reads as a flip board rather than a cube. Add [perspective:800px] through className if you want depth; the back face is already offset by translateZ(0.5lh), half a line box.
  • The back-face character never enters the DOM text. It is rendered by [data-hulian-flip-back]::after { content: attr(…) }, a rule shipped in preset-core.css, so the heading's textContent is exactly the heading. A real node would make it read "SSyysstteemm", polluting copy-paste and anything a crawler reads. It also means the library preset CSS must be loaded, otherwise the second half of the flip is blank.
  • Screen readers get the whole sentence rather than loose characters: the root carries an aria-label taken from the children text, and every character span is aria-hidden. Passing your own aria-label overrides it.
  • Under prefers-reduced-motion: reduce nothing flips and the front face stays put. Both faces render the same character, so the resting state is already the complete heading.

Related

SplitText · BlurText · TextReveal · ScrollReveal · WordRotate · PageHeader · Heading

Playground

AI status

<FlipText as="h1" direction="top" splitType="char" duration={0.5} stagger={30}>AI status</FlipText>
PreviousBlurTextTypographyNextTextReveal

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Example
    • Usage guidelines
    • Related
  • Playground