Zubra UI
Code for
GitHub

flip-card

A card with two faces that flips in 3D. Click, Space or Enter flips it. Shadow DOM: the faces are slotted, and the page's CSS styles them, not the card's.

Bonjour
Hello

Try it: events appear here (flippedchange).

Source: flip-card.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/flip-card.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/flip-card.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/flip-card.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/flip-card.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/flip-card.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/flip-card.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/flip-card.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/flip-card.json

The compiled install writes src/components/zubra/flip-card.js and the theme, and adds @zubra/runtime to your dependencies.

Usage

index.html
<flip-card hint="Click or press Space to flip">
  <div slot="front"><strong>Bonjour</strong></div>
  <div slot="back"><strong>Hello</strong></div>
</flip-card>

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

  const element = document.querySelector('flip-card');
  element.addEventListener('flippedchange', (event) => console.log('flippedchange', event.detail));
</script>
Example.jsx
import './components/zubra/flip-card.js';

export function FlipCardExample() {
  return (
    <flip-card
      hint="Click or press Space to flip"
      onflippedchange={(event) => console.log('flippedchange', event.detail)}
    >
      <div slot="front"><strong>Bonjour</strong></div>
      <div slot="back"><strong>Hello</strong></div>
    </flip-card>
  );
}
Example.vue
<script setup>
import './components/zubra/flip-card.js';
const onFlippedchange = (event) => console.log('flippedchange', event.detail);
</script>

<template>
  <flip-card
    hint="Click or press Space to flip"
    @flippedchange="onFlippedchange"
  >
    <div slot="front"><strong>Bonjour</strong></div>
    <div slot="back"><strong>Hello</strong></div>
  </flip-card>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/flip-card.js';
</script>

<flip-card
  hint="Click or press Space to flip"
  onflippedchange={(event) => console.log('flippedchange', event.detail)}
>
  <div slot="front"><strong>Bonjour</strong></div>
  <div slot="back"><strong>Hello</strong></div>
</flip-card>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/flip-card.js';

@Component({
  selector: 'app-flip-card-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <flip-card
      hint="Click or press Space to flip"
      (flippedchange)="onFlippedchange($event)"
    >
      <div slot="front"><strong>Bonjour</strong></div>
      <div slot="back"><strong>Hello</strong></div>
    </flip-card>
  `,
})
export class FlipCardExample {
  onFlippedchange(event: Event) {
    console.log('flippedchange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
flippedbooleanfalse
hintstring"Click or press Space to flip"
Events
EventWhen
flippedchangeIt was flipped; detail is whether the back is showing.
Slots
SlotFor
backThe answer side.
frontThe question side.

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 17.3 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