DocumentationSpaceType

SpaceType

Wraps a phrase around rotating rings with a soft radial wave.

Svelte

Shared live previews stay running while you switch code examples and API documentation.

Words in orbit · Make it yours
KIDA-UI / SMALL-DETAILS-BIG-DELIGHT /
1.00×
#211C24
#FFFAFB
Auto

Smaller rings pack the letters closer. Letter size stays fixed.

0%

Pulse the rings and tilt the letters with the wave.

Make it yours. Set speed to zero to pause.

Quick start

Add to your project

Copy the component and everything it needs into your React project.

RecommendedUse the shadcn CLI
npx shadcn@latest add https://kida-ui.onrender.com/r/space-type.json

Run this from a project with components.json. The CLI creates all required files and installs the declared runtime dependencies. New to shadcn? Follow theinstallation guide first.

View registry JSON
Copy manually7 files

1. Create the source files

Keep this directory structure so the component's relative imports continue to work.

src/components/ui/kida/space-type.tsx
'use client'

import './space-type.css'
import {
  getSpaceTypeGeometry,
  type SpaceTypeControls,
  type SpaceTypeGeometry,
  type SpaceTypeOptions,
  spaceType,
} from './motion/space-type.js'
import {
  type CSSProperties,
  forwardRef,
  type HTMLAttributes,
  useEffect,
  useMemo,
  useRef,
  useState,
} from 'react'
import { composeRefs } from './compose-refs.js'
import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.js'

export interface SpaceTypeProps
  extends SpaceTypeOptions,
    Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'color'> {
  text: string
  /** Number of stacked rings, from 1 to 6. @default 1 */
  rows?: number
  /** Text color; alternatively set --kida-space-type-color. */
  color?: string
  /** Surface color; alternatively set --kida-space-type-background. */
  background?: string
  /** Strength of the pulsing cylinder and tilting letter surface, from 0 to 100. @default 0 */
  longitude?: number
  /** Base radius in pixels, clamped to the available frame. Defaults to auto. */
  radius?: number
  /** Reports fitted geometry and the available radius range after measurement. */
  onGeometryChange?: (geometry: SpaceTypeGeometry | null) => void
}

export const SpaceType = forwardRef<HTMLDivElement, SpaceTypeProps>(function SpaceType(
  {
    text,
    speed = 1,
    paused = false,
    rows = 1,
    color,
    background,
    longitude = 0,
    radius,
    onGeometryChange,
    style,
    ...props
  },
  forwardedRef,
) {
  const rootRef = useRef<HTMLDivElement>(null)
  const controlsRef = useRef<SpaceTypeControls | null>(null)
  const [size, setSize] = useState({ width: 0, height: 0 })
  const rowCount = Number.isFinite(rows) ? Math.max(1, Math.min(6, Math.round(rows))) : 1
  const wave = Number.isFinite(longitude) ? Math.max(0, Math.min(100, longitude)) : 0
  const characters = Array.from(text)
  const geometry = useMemo(
    () => getSpaceTypeGeometry(size.width, size.height, characters.length, rowCount, wave, radius),
    [size.width, size.height, characters.length, rowCount, wave, radius],
  )

  useIsomorphicLayoutEffect(() => {
    const root = rootRef.current
    if (!root) return
    const observer = new ResizeObserver(([entry]) => {
      if (!entry) return
      const { width, height } = entry.contentRect
      setSize((current) =>
        current.width === width && current.height === height ? current : { width, height },
      )
    })
    observer.observe(root)
    const controls = spaceType(root)
    controlsRef.current = controls
    return () => {
      observer.disconnect()
      controls.destroy()
      controlsRef.current = null
    }
  }, [])

  useIsomorphicLayoutEffect(() => {
    controlsRef.current?.setPlayback({ speed, paused: paused || characters.length === 0 })
  }, [speed, paused, characters.length])

  useEffect(() => {
    onGeometryChange?.(geometry)
  }, [geometry, onGeometryChange])

  return (
    <div
      {...props}
      ref={composeRefs(rootRef, forwardedRef)}
      data-kida-space-type=""
      style={
        {
          '--kida-space-type-count': Math.max(characters.length, 1),
          '--kida-space-type-rows': rowCount,
          '--kida-space-type-longitude': wave,
          ...(color === undefined ? {} : { '--kida-space-type-color': color }),
          ...(background === undefined ? {} : { '--kida-space-type-background': background }),
          ...(geometry
            ? {
                '--kida-space-type-size': `${geometry.fontSize}px`,
                '--kida-space-type-radius': `${geometry.radius}px`,
                '--kida-space-type-perspective': `${geometry.perspective}px`,
              }
            : {}),
          ...style,
        } as CSSProperties
      }
    >
      <span data-kida-space-type-text="">{text}</span>
      <div data-kida-space-type-space="" aria-hidden="true">
        <div data-kida-space-type-camera="">
          <div data-kida-space-type-ring="">
            {Array.from({ length: rowCount }, (_, row) => (
              <div
                // biome-ignore lint/suspicious/noArrayIndexKey: row slots are stable positions without local state
                key={row}
                data-kida-space-type-row=""
                style={{ '--kida-space-type-row': row } as CSSProperties}
              >
                {characters.map((character, index) => (
                  <span
                    // biome-ignore lint/suspicious/noArrayIndexKey: glyph slots preserve rotation while editing text
                    key={index}
                    data-kida-space-type-letter=""
                    style={{ '--kida-space-type-index': index } as CSSProperties}
                  >
                    <span data-kida-space-type-face="front">{character}</span>
                    <span data-kida-space-type-face="back">{character}</span>
                  </span>
                ))}
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  )
})
src/components/ui/kida/compose-refs.ts
import type { Ref } from 'react'

/** Feed one node to several refs — ours for measuring, Zag's for animation detection. */
export function composeRefs<T>(...refs: (Ref<T> | undefined)[]) {
  return (node: T | null) => {
    for (const ref of refs) {
      if (typeof ref === 'function') ref(node)
      else if (ref) (ref as { current: T | null }).current = node
    }
  }
}
src/components/ui/kida/use-isomorphic-layout-effect.ts
'use client'

import { useEffect, useLayoutEffect } from 'react'

/**
 * `useLayoutEffect` in the browser, `useEffect` on the server.
 *
 * Motion has to be applied before paint or the user sees an unstyled frame, but React
 * warns when `useLayoutEffect` runs during SSR — where it does nothing anyway.
 */
export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
src/components/ui/kida/space-type.css
[data-kida-space-type] {
  --kida-space-type-color: #211c24;
  --kida-space-type-background: #fffafb;
  width: 100%;
  --kida-space-type-size: calc(
    min(9cqw, 350cqw / var(--kida-space-type-count), 20cqw / var(--kida-space-type-rows))
  );
  /* Reserve the strongest wave before measurement as well. */
  --kida-space-type-radius: calc(34cqw / 1.32);
  position: relative;
  container-type: inline-size;
  height: var(--kida-space-type-height, clamp(15rem, 40vw, 28rem));
  padding: 0;
  border: 0;
  overflow: clip;
  background: var(--kida-space-type-background);
}

[data-kida-space-type] [data-kida-space-type-space] {
  position: relative;
  width: 100%;
  height: 100%;
  user-select: none;
  pointer-events: none;
  perspective: var(--kida-space-type-perspective, 1200cqw);
}

[data-kida-space-type] [data-kida-space-type-camera],
[data-kida-space-type] [data-kida-space-type-ring],
[data-kida-space-type] [data-kida-space-type-row],
[data-kida-space-type] [data-kida-space-type-letter] {
  position: absolute;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

[data-kida-space-type] [data-kida-space-type-camera] {
  top: 50%;
  left: 50%;
  transform: rotateX(18deg) rotateZ(-3deg);
}

[data-kida-space-type] [data-kida-space-type-ring] {
  transform: rotateY(-90deg);
}

[data-kida-space-type] [data-kida-space-type-row] {
  /* A wave travels along the cylinder's rows. Each letter follows its local slope. */
  --kida-space-type-wave-angle: calc(
    var(--kida-space-type-phase) *
    2880deg +
    var(--kida-space-type-row) *
    2160deg /
    var(--kida-space-type-count)
  );
  --kida-space-type-wave-amplitude: calc(
    var(--kida-space-type-radius) *
    var(--kida-space-type-longitude) *
    0.0032
  );
  --kida-space-type-row-radius: calc(
    var(--kida-space-type-radius) +
    sin(var(--kida-space-type-wave-angle)) *
    var(--kida-space-type-wave-amplitude)
  );
  --kida-space-type-surface-tilt: atan2(
    calc(
      var(--kida-space-type-wave-amplitude) *
      cos(var(--kida-space-type-wave-angle)) *
      sin(2160deg / var(--kida-space-type-count))
    ),
    calc(var(--kida-space-type-size) * 1.2)
  );
  transform: translateY(
    calc(
      (var(--kida-space-type-row) - (var(--kida-space-type-rows) - 1) / 2) *
      var(--kida-space-type-size) *
      1.2
    )
  );
}

[data-kida-space-type] [data-kida-space-type-letter] {
  transform: rotateY(calc(var(--kida-space-type-index) * 360deg / var(--kida-space-type-count)))
    translateZ(var(--kida-space-type-row-radius)) rotateX(var(--kida-space-type-surface-tilt));
}

[data-kida-space-type] [data-kida-space-type-face] {
  position: absolute;
  top: calc(var(--kida-space-type-size) * -0.5);
  left: calc(var(--kida-space-type-size) * -0.4);
  width: calc(var(--kida-space-type-size) * 0.8);
  height: var(--kida-space-type-size);
  backface-visibility: hidden;
  font-family: var(--kida-space-type-font, "Helvetica Neue", "Segoe UI", sans-serif);
  font-size: var(--kida-space-type-size);
  font-weight: 200;
  line-height: 1;
  text-align: center;
  white-space: pre;
}

[data-kida-space-type] [data-kida-space-type-face="front"] {
  color: var(--kida-space-type-color);
  transform: translateZ(0.1px) scaleX(0.7);
}

[data-kida-space-type] [data-kida-space-type-face="back"] {
  color: color-mix(in srgb, var(--kida-space-type-color) 30%, var(--kida-space-type-background));
  transform: rotateY(180deg) translateZ(0.1px) scaleX(-0.7);
}

[data-kida-space-type] [data-kida-space-type-text] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@property --kida-space-type-phase {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
src/components/ui/kida/motion/space-type.ts
import { prefersReducedMotion, watchReducedMotion } from './reduced-motion.js'

export { getSpaceTypeGeometry, type SpaceTypeGeometry } from './space-type-geometry.js'

export interface SpaceTypeOptions {
  /** Rotation rate; zero freezes the current angle. @default 1 */
  speed?: number
  /** Pause without resetting the current angle. @default false */
  paused?: boolean
}

export interface SpaceTypeControls {
  setPlayback(options: SpaceTypeOptions): void
  destroy(): void
}

/** Shared loop lifecycle; adapters only render the geometry and update playback options. */
export function spaceType(root: HTMLElement, options: SpaceTypeOptions = {}): SpaceTypeControls {
  const ring = root.querySelector<HTMLElement>('[data-kida-space-type-ring]')
  let animation: Animation | undefined
  let visible = false
  let destroyed = false
  let speed = 1
  let paused = false

  const sync = () => {
    if (destroyed || !ring) return
    if (prefersReducedMotion()) {
      animation?.cancel()
      animation = undefined
      root.dataset.state = 'reduced'
      return
    }
    if (!animation) {
      animation = ring.animate(
        [
          { transform: 'rotateY(-90deg)', '--kida-space-type-phase': '0' },
          { transform: 'rotateY(270deg)', '--kida-space-type-phase': '1' },
        ],
        { duration: 24000, iterations: Number.POSITIVE_INFINITY, easing: 'linear' },
      )
      animation.pause()
    }
    if (animation.playbackRate !== speed) animation.updatePlaybackRate(speed)
    if (paused || speed === 0 || !visible || document.hidden) {
      animation.pause()
      root.dataset.state = 'paused'
    } else {
      animation.play()
      root.dataset.state = 'active'
    }
  }

  const setPlayback = (next: SpaceTypeOptions) => {
    speed = Number.isFinite(next.speed) ? Math.max(0, Math.min(3, next.speed ?? 1)) : 1
    paused = next.paused ?? false
    sync()
  }
  const observer = new IntersectionObserver(([entry]) => {
    visible = entry?.isIntersecting ?? false
    sync()
  })
  observer.observe(root)
  document.addEventListener('visibilitychange', sync)
  const unwatch = watchReducedMotion(sync)
  setPlayback(options)

  return {
    setPlayback,
    destroy() {
      destroyed = true
      observer.disconnect()
      document.removeEventListener('visibilitychange', sync)
      unwatch()
      animation?.cancel()
      animation = undefined
      root.dataset.state = 'idle'
    },
  }
}
src/components/ui/kida/motion/space-type-geometry.ts
const TILT = (18 * Math.PI) / 180
const ROLL = (3 * Math.PI) / 180
const PROJECTION_ALLOWANCE = 1.1
const RADIUS_RESERVE = 0.88
const MAX_WAVE = 0.32

/** Bounds reserve the full longitude wave, so its strength never changes the base radius. */
export function getSpaceTypeGeometry(
  width: number,
  height: number,
  characterCount: number,
  rows: number,
  _longitude: number,
  requestedRadius?: number,
) {
  if (width <= 0 || height <= 0) return null

  rows = Number.isFinite(rows) ? Math.max(1, Math.min(6, Math.round(rows))) : 1
  const count = Math.max(1, characterCount)
  const inset = Math.max(8, width * 0.018)
  const halfWidth = Math.max(0, width / 2 - inset) / PROJECTION_ALLOWANCE
  const halfHeight = Math.max(0, height / 2 - inset) / PROJECTION_ALLOWANCE
  const radialX = Math.cos(ROLL)
  const stackX = Math.sin(ROLL)
  const radialY = Math.hypot(Math.cos(TILT) * Math.sin(ROLL), Math.sin(TILT))
  const stackY = Math.cos(TILT) * Math.cos(ROLL)

  const radiusLimit = (fontSize: number, tilted = false) => {
    // Tilting the glyph surface can project half its height into the radial plane.
    const glyphRadialExtent = fontSize * (tilted ? 0.9 : 0.4)
    const stackHalfHeight = fontSize * ((rows - 1) * 0.6 + 0.5)
    return Math.max(
      0,
      Math.min(
        (halfWidth - stackHalfHeight * stackX) / radialX - glyphRadialExtent,
        (halfHeight - stackHalfHeight * stackY) / radialY - glyphRadialExtent,
      ),
    )
  }

  // Size type against the resting ring, independently of radius and wave strength.
  let fontSize = Math.min(width * 0.09, (width * 3.5) / count, (width * 0.2) / rows)
  const nominalRadius = width * 0.34
  const initialRadius = Math.min(nominalRadius, radiusLimit(fontSize) * RADIUS_RESERVE)
  if (count > 1) {
    fontSize = Math.min(fontSize, (2 * initialRadius * Math.sin(Math.PI / count)) / 0.7)
  }

  const maxRadius = radiusLimit(fontSize, true) / (1 + MAX_WAVE)
  const defaultRadius = Math.min(nominalRadius, maxRadius * RADIUS_RESERVE)
  // Compact rings intentionally pack the same-sized letters more densely.
  const minRadius = Math.min(maxRadius, (width * 0.1) / (1 + MAX_WAVE))
  const radius = Math.max(
    minRadius,
    Math.min(
      maxRadius,
      typeof requestedRadius === 'number' && Number.isFinite(requestedRadius)
        ? requestedRadius
        : defaultRadius,
    ),
  )

  return {
    fontSize,
    radius,
    minRadius,
    maxRadius,
    perspective: Math.max(width, height) * 12,
  }
}

export type SpaceTypeGeometry = NonNullable<ReturnType<typeof getSpaceTypeGeometry>>
src/components/ui/kida/motion/reduced-motion.ts
const QUERY = '(prefers-reduced-motion: reduce)'

/**
 * Whether the user has asked for reduced motion.
 *
 * SSR-safe: returns `false` when there is no `window`, matching the CSS default
 * (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;
 * this is for the JS-driven paths that CSS cannot express).
 */
export function prefersReducedMotion(): boolean {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false
  return window.matchMedia(QUERY).matches
}

/**
 * Subscribe to changes of the reduced-motion preference.
 * Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.
 */
export function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}

  const list = window.matchMedia(QUERY)
  const handler = (event: MediaQueryListEvent) => onChange(event.matches)
  list.addEventListener('change', handler)
  return () => list.removeEventListener('change', handler)
}
import { SpaceType } from '@/components/ui/kida/space-type'

export default function SpaceTypeExample() {
  return <SpaceType text="KIDA-UI / MADE-TO-MOVE / " rows={2} speed={0.75} />
}

Customization

Edit the phrase, change its colors, add rows with the number control, and adjust speed, radius, and longitude. Set speed to zero to pause. Smaller rings pack the same-sized letters closer; larger rings spread them out. Radius changes preserve the current rotation and font size.

Longitude makes the rings pulse inward and outward while the letters tilt to follow the cylinder’s changing surface. The wave travels along the rows and completes eight pulses per rotation. Its strength changes without changing the base radius, resizing the letters, or resetting playback. The radius range reserves room for maximum Longitude strength upfront, so its value and limits stay fixed as you adjust the wave. The range still adapts to the container, text, and rows to keep the animation inside its frame. Compact rings intentionally produce dense, overlapping typography, like a typographic sculpture.

API

Props

Prop Type Default Description
text string required Phrase rendered around each ring.
rows number 1 Number of rings, rounded and clamped to 1–6.
speed number 1 Rotation rate from 0–3×. One turn takes 24 seconds at 1×. Zero freezes the current angle.
paused boolean false Pause and resume without resetting rotation.
radius number auto Base radius in CSS pixels, clamped to the measured frame.
longitude number 0 Strength of the pulsing rings and tilting letter surface, clamped to 0–100.
color string CSS value Front text color. Back letters blend this with the background.
background string CSS value Ring surface color.
onGeometryChange (geometry: SpaceTypeGeometry | null) => void — Reports fitted fontSize, radius, minRadius, maxRadius, and perspective; null before measurement.

Native div attributes, className, style, event handlers, and a forwarded ref are passed to the root. Text, colors, radius, rows, and longitude update without restarting rotation.

CSS custom properties

Property Default Description
--kida-space-type-color #211c24 Front text color.
--kida-space-type-background #fffafb Surface color used to blend the back letters.
--kida-space-type-font Helvetica Neue, Segoe UI, sans-serif Thin display font.
--kida-space-type-height clamp(15rem, 40vw, 28rem) Preview frame height; changes trigger measurement.

Accessibility and input behavior

The authored phrase is exposed once to assistive technology. Repeated rows and front/back glyphs are decorative copies hidden from the accessibility tree. Use SpaceType as display typography alongside readable essential copy. The customization controls use native labeled inputs and buttons; the text input keeps the complete phrase editable and copyable.

Reduced motion keeps the ring static and preserves the authored phrase. Playback pauses off-screen and in hidden tabs. Observers, preference listeners, and animations are released on unmount, including React Strict Mode’s repeated setup and cleanup.

Server markup is deterministic and contains the phrase before hydration. Geometry fits the container after hydration using ResizeObserver. Modern browsers with CSS 3D transforms, registered custom properties, trigonometric functions, and Web Animations are required for the complete effect.

Troubleshooting

Use short display phrases. Long phrases automatically use smaller letters. Radius changes never change their size. If a requested radius exceeds the frame, it is clamped; increase the container size or --kida-space-type-height to give the ring more room. Letter spacing is controlled by the circle’s radius and has no separate prop or control.