Zubra UI
Code for
GitHub

word-rotate

One word at a time from words, each sliding out as the next slides in every interval ms. Screen readers hear the whole list once, it pauses on hover, and reduced motion shows the first word only.

This one has no events: it shows what it's given.

Source: word-rotate.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/word-rotate.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/word-rotate.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/word-rotate.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/word-rotate.json
One file, no dependencies (3.5 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/word-rotate.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/word-rotate.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/word-rotate.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/word-rotate.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/word-rotate.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/word-rotate.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/word-rotate.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/word-rotate.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/word-rotate.js"></script>

The compiled install writes src/components/zubra/word-rotate.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<word-rotate></word-rotate>

<script type="module">
  import './components/zubra/word-rotate.js';

  const element = document.querySelector('word-rotate');
  element.words = ['sourdough', 'focaccia', 'brioche', 'rye'];
  element.interval = 2000;
</script>
Example.jsx
import './components/zubra/word-rotate.js';

const words = ['sourdough', 'focaccia', 'brioche', 'rye'];
const interval = 2000;

export function WordRotateExample() {
  return (
    <word-rotate words={words} interval={interval}></word-rotate>
  );
}
Example.vue
<script setup>
import './components/zubra/word-rotate.js';
const words = ['sourdough', 'focaccia', 'brioche', 'rye'];
const interval = 2000;
</script>

<template>
  <word-rotate :words.prop="words" :interval.prop="interval"></word-rotate>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/word-rotate.js';
  const words = ['sourdough', 'focaccia', 'brioche', 'rye'];
  const interval = 2000;
</script>

<word-rotate {words} {interval}></word-rotate>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/word-rotate.js';

@Component({
  selector: 'app-word-rotate-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <word-rotate [words]="words" [interval]="interval"></word-rotate>
  `,
})
export class WordRotateExample {
  words = ['sourdough', 'focaccia', 'brioche', 'rye'];

  interval = 2000;
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
words
property only
unknown[][]
intervalnumber2500

Size

1.1 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.4 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour