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

VariableProximity

variable-proximity

Adjusts variable-font axes as the pointer approaches each character.

Usage

Basic usage

Use containerRef to base the distance on the container coordinate system; moving the mouse closer to the glyph interpolates the weight/visual size verbatim.

Move the mouse here Hover meMove the mouse here Hover me
tsx
const ref = useRef<HTMLDivElement>(null);

<div ref={ref} className="relative">
  <VariableProximity
    label="Move the mouse here Hover me"
    fromFontVariationSettings="'wght' 400, 'opsz' 9"
    toFontVariationSettings="'wght' 900, 'opsz' 40"
    containerRef={ref}
    radius={90}
    falloff="linear"
  />
</div>

Gaussian attenuation

falloff="gaussian" makes the center closer together, the transition softer, and more natural with a larger radius.

Move the mouse here Hover meMove the mouse here Hover me
tsx
<VariableProximity
  label="Move the mouse here Hover me"
  fromFontVariationSettings="'wght' 400, 'opsz' 9"
  toFontVariationSettings="'wght' 900, 'opsz' 40"
  containerRef={ref}
  radius={120}
  falloff="gaussian"
/>

Exponential decay · Small radius

falloff="exponential" The growth is steeper, and the change is obvious only when it is close to the glyph with a small radius.

Move the mouse here Hover meMove the mouse here Hover me
tsx
<VariableProximity
  label="Move the mouse here Hover me"
  fromFontVariationSettings="'wght' 400, 'opsz' 9"
  toFontVariationSettings="'wght' 900, 'opsz' 40"
  containerRef={ref}
  radius={55}
  falloff="exponential"
/>

Light base

It is also available on light backgrounds, and the text color token automatically adapts to light and dark.

Move the mouse here Hover meMove the mouse here Hover me
tsx
<div ref={ref} className="relative">
  <VariableProximity
    label="Move the mouse here Hover me"
    fromFontVariationSettings="'wght' 400, 'opsz' 9"
    toFontVariationSettings="'wght' 900, 'opsz' 40"
    containerRef={ref}
    radius={90}
    falloff="linear"
    className="text-3xl font-medium"
  />
</div>

When to use

Use VariableProximity when each glyph should interpolate variable-font axes such as wght or opsz from pointer distance, with a selectable container coordinate system and falloff curve. Use TextPressure for a lighter effect that falls back to system-font scaleX, or Shuffle for scrambled text.

Import

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

Props

NameTypeDefaultDescription
label*string-Render text (split word by word, spaces retained as unbreakable word gaps); sr-only copy read in full
fromFontVariationSettings*string-Variable axis settings when the mouse is far away, such as "'wght' 400, 'opsz' 9" (variable fonts are required for visual changes)
toFontVariationSettings*string-The target axis setting when the mouse is close to it, interpolating towards this axis by axis; the default axis falls back to the from value
containerRefRefObject<HTMLElement | null>-Reference container for calculating mouse relative coordinates; default falls back to viewport coordinates
radiusnumber50Influence radius (px); if exceeded, the from setting will be restored
falloff"linear" | "exponential" | "gaussian""linear"Decay curve; exponential is steeper, gaussian center is more concentrated and soft
classNamestring-Extra class name merged into root span
styleCSSProperties-Inline styles merged into the root span
Note: The default demonstration controls of showcase controls are radius={90}, but the default value of the interface is 50.

Events

EventTypeDescription
onClickReact.MouseEventHandler<HTMLSpanElement>Callback when root span is clicked

Example

tsx
function Demo() {
  const ref = useRef<HTMLDivElement>(null);
  return (
    <div ref={ref} className="relative flex items-center justify-center">
      <VariableProximity
        label="Move your pointer here"
        fromFontVariationSettings="'wght' 400, 'opsz' 9"
        toFontVariationSettings="'wght' 900, 'opsz' 40"
        containerRef={ref}
        radius={90}
        falloff="linear"
        className="text-3xl font-medium"
      />
    </div>
  );
}

Usage guidelines

  • Visual changes require a real variable font whose axes match from and to, such as wght or opsz. Unsupported axes do not change; this is a font capability boundary.
  • containerRef defines the distance coordinate system. Without it, viewport coordinates are used and an embedded effect may feel offset; normally point it to the wrapping box.
  • toFontVariationSettings interpolates only axes also present in from; additional target axes are ignored.
  • Reduced-motion mode freezes the baseline from settings and disables pointer interpolation.

Related

Text · Heading · Prose · Markdown · AuroraText · AnimatedShinyText

Playground

Move the mouse here Hover meMove the mouse here Hover me
const ref = useRef<HTMLDivElement>(null);
<div ref={ref} className="relative">
  <VariableProximity
    label="Move the mouse here Hover me"
    fromFontVariationSettings="'wght' 400, 'opsz' 9"
    toFontVariationSettings="'wght' 900, 'opsz' 40"
    containerRef={ref}
    radius={90}
    falloff="linear"
  />
</div>
PreviousTextPressureTypographyNextMathTextarea

On this page

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