# GlassCard

> Buzlu camdan bir kart. İçeriğin üstünde durur; yüzü arkasında kalanı bulanıklaştırıp tonlar, yazı okunur kalır; kenarı da onu merkeze doğru çeker.

```tsx
import { Cloud, Navigation } from 'lucide-react'
import { useEffect, useState, type CSSProperties } from 'react'

import { GlassCard } from '@/components/liquid-glass'

// Two rows of colour slide behind two cards, and the rims bend them as they pass. The rows
// move, so the cards are `live`: they repaint what is behind them every frame.
const colours = ['#0a84ff', '#ff6b3d', '#30d158', '#ff375f', '#ffd60a', '#bf5af2']

function Row({ shift, seconds, reverse = false }: { shift: number; seconds: number; reverse?: boolean }) {
  const pills = [...colours, ...colours].map((_, i) => colours[(i + shift) % colours.length])
  return (
    // Two identical halves slide by exactly one half, on the kit's own marquee (it stops under reduced motion).
    <div
      data-glass-marquee
      className="flex w-max"
      style={{ '--glass-marquee-duration': `${seconds}s`, animationDirection: reverse ? 'reverse' : undefined } as CSSProperties}
    >
      {[0, 1].map((half) => (
        <div key={half} className="flex gap-3 pr-3">
          {pills.map((colour, i) => (
            <span key={i} className="h-12 w-24 shrink-0 rounded-full" style={{ background: colour }} />
          ))}
        </div>
      ))}
    </div>
  )
}

type ProgressiveBlurProps = {
  className?: string
  backgroundColor?: string
  position?: 'left' | 'right'
  width?: string
  blurAmount?: string
}

/** A progressive blur at one end of the rows: the stage colour over a backdrop blur, fading towards the middle. */
function ProgressiveBlur({
  className = '',
  backgroundColor = 'var(--stage, #ececee)',
  position = 'left',
  width = '150px',
  blurAmount = '4px',
}: ProgressiveBlurProps) {
  const isLeft = position === 'left'
  return (
    <div
      aria-hidden
      className={`pointer-events-none absolute top-0 h-full select-none ${className}`}
      style={{
        [isLeft ? 'left' : 'right']: 0,
        width,
        background: `linear-gradient(to ${isLeft ? 'left' : 'right'}, transparent, ${backgroundColor})`,
        maskImage: `linear-gradient(to ${isLeft ? 'right' : 'left'}, #000 50%, transparent)`,
        WebkitMaskImage: `linear-gradient(to ${isLeft ? 'right' : 'left'}, #000 50%, transparent)`,
        WebkitBackdropFilter: `blur(${blurAmount})`,
        backdropFilter: `blur(${blurAmount})`,
        WebkitUserSelect: 'none',
        userSelect: 'none',
      }}
    />
  )
}

/** Today, read after mount so a prerendered page doesn't freeze the day it was built. */
function useToday() {
  const [today, setToday] = useState<Date | null>(null)
  useEffect(() => setToday(new Date()), [])
  return today
}

export default function Demo() {
  const today = useToday()
  const events = [
    { title: 'Visit my GitHub', note: 'github.com/bilalgursen', href: 'https://github.com/bilalgursen', colour: '#0a84ff' },
    { title: 'Star liquid-glass', note: 'Leave a star on the repo', href: 'https://github.com/bilalgursen/liquid-glass', colour: '#ff6b3d' },
  ]
  return (
    // Where the two cards do not fit side by side (a phone), only the first one shows, centred on the two rows.
    <div className="@container relative flex w-full items-center justify-center gap-5 py-14">
      <div
        aria-hidden
        className="absolute inset-0 flex flex-col justify-center gap-3 overflow-hidden"
      >
        <Row shift={0} seconds={40} />
        <Row shift={3} seconds={48} reverse />
        <ProgressiveBlur position="left" />
        <ProgressiveBlur position="right" />
      </div>

      <GlassCard live className="flex size-44 flex-col justify-between p-4">
        <div>
          <p className="flex items-center gap-1 text-[13px] font-semibold">
            Istanbul
            <Navigation className="size-2.5 fill-current" />
          </p>
          <p className="mt-0.5 text-[44px] leading-none font-light tracking-[-0.04em]">16°</p>
        </div>
        <div className="text-[12px] leading-snug font-semibold">
          <Cloud className="mb-1 size-4 fill-current" />
          <p>Cloudy</p>
          <p className="opacity-60">H:19° L:15°</p>
        </div>
      </GlassCard>

      <GlassCard live className="hidden h-44 w-64 flex-col justify-between p-5 @min-[452px]:flex">
        <div className="flex items-baseline justify-between">
          <p className="text-[14px] font-semibold">{today ? today.toLocaleDateString(undefined, { weekday: 'long' }) : 'Today'}</p>
          <p className="text-[34px] leading-none font-semibold tracking-[-0.05em] tabular-nums">{today?.getDate()}</p>
        </div>
        <ul className="flex flex-col gap-2">
          {events.map((e) => (
            <li key={e.title}>
              <a href={e.href} target="_blank" rel="noreferrer" className="flex items-stretch gap-2.5 rounded-sm">
                <span className="w-1 shrink-0 rounded-full" style={{ background: e.colour }} />
                <span>
                  <span className="block text-[13px] leading-tight font-semibold">{e.title}</span>
                  <span className="block text-[11px] font-medium opacity-60">{e.note}</span>
                </span>
              </a>
            </li>
          ))}
        </ul>
      </GlassCard>
    </div>
  )
}
```

**Şunun için**

- Renk, görsel ya da hareket üstünde küçük bir içerik yüzeyi: bir widget, çalan parça kartı, bir özet.
- Arkalarında kalanın tasarımın parçası olduğu bir ya da iki kart.

**Şunun için değil**

- Uzun metin ve formlar: arka plan görünür. Sade bir kart kullan.
- Düz bir zemindeki kart: bükülecek bir şey yok.
- Tıklanan tek bir eylem: GlassButton kullan.

```bash
npx shadcn@latest add https://onemorethink.dev/r/card.json
```

## Kullanım

```tsx
import { GlassCard } from '@/components/liquid-glass'

<GlassCard className="w-64 p-5">
  <p className="font-semibold">Wednesday</p>
  <p className="text-sm opacity-60">Design review · 10:00</p>
</GlassCard>

// Something moves behind it: repaint what it bends every frame.
<GlassCard live className="size-44 p-4">…</GlassCard>

// Clearer glass: no frost, less tint.
<GlassCard blur={0} tint={0.3} className="w-64 p-5">…</GlassCard>
```

## Örnekler

### Bir duvar kâğıdının üstünde widget'lar

```tsx
import { Flame, Headphones, Smartphone, Watch } from 'lucide-react'

import { GlassCard } from '@/components/liquid-glass'

// A home screen of widgets over a still wallpaper: bands of colour and three hard-edged discs,
// all plain CSS, and the rims bend them. Nothing moves behind the cards, so they need no
// `live`: like every glass in the kit, they repaint only when something changes, and stop
// drawing at rest.
const wallpaper = 'linear-gradient(155deg, #0a84ff 0 24%, #5e5ce6 24% 46%, #bf5af2 46% 66%, #ff375f 66% 84%, #ff9f0a 84%)'

/** A progress ring in plain CSS: a conic gradient with its middle masked out. */
function Ring({ value, colour }: { value: number; colour: string }) {
  const hole = 'radial-gradient(farthest-side, transparent calc(100% - 9px), #000 calc(100% - 8px))'
  return (
    <span
      role="img"
      aria-label={`${Math.round(value * 100)}%`}
      className="block aspect-square rounded-full"
      style={{
        background: `conic-gradient(${colour} ${value * 100}%, color-mix(in srgb, ${colour} 22%, transparent) 0)`,
        maskImage: hole,
        WebkitMaskImage: hole,
      }}
    />
  )
}

const move = { done: 420, goal: 600 }
const devices = [
  { name: 'Phone', level: 82, icon: Smartphone },
  { name: 'Earbuds', level: 64, icon: Headphones },
  { name: 'Watch', level: 18, icon: Watch },
]
const track = { title: 'Slow Liquid', artist: 'Glasswork', played: 0.38, elapsed: '1:12', left: '-2:04' }

export default function Demo() {
  return (
    <div className="relative flex w-full max-w-2xl justify-center overflow-hidden rounded-3xl px-3 py-10 sm:px-5 sm:py-16" style={{ background: wallpaper }}>
      <div aria-hidden className="absolute inset-0">
        <span className="absolute -top-10 left-[8%] size-40 rounded-full bg-[#ffd60a]" />
        <span className="absolute top-[38%] right-[6%] size-56 rounded-full bg-[#30d158]" />
        <span className="absolute -bottom-16 left-[22%] size-48 rounded-full bg-white" />
      </div>

      <div className="relative grid w-full max-w-[316px] grid-cols-2 gap-3 sm:max-w-[372px] sm:gap-5">
        {/* Activity: one ring, one number. */}
        <GlassCard className="flex aspect-square flex-col justify-between p-3 sm:p-4">
          <span className="relative w-12 sm:w-[72px]">
            <Ring value={move.done / move.goal} colour="#ff375f" />
            <Flame className="absolute inset-0 m-auto size-4 fill-current text-[#ff375f] sm:size-5" />
          </span>
          <div>
            <p className="text-[20px] leading-none font-semibold tracking-[-0.03em] tabular-nums sm:text-[26px]">
              {move.done}
              <span className="opacity-50">/{move.goal}</span>
            </p>
            <p className="mt-1 text-[10px] font-semibold tracking-wide whitespace-nowrap text-[#ff375f] uppercase sm:text-[11px]">Move · kcal</p>
          </div>
        </GlassCard>

        {/* Batteries: a level for each device. */}
        <GlassCard className="flex aspect-square flex-col justify-between p-3 sm:p-4">
          {devices.map(({ name, level, icon: Icon }) => (
            <div key={name}>
              <p className="flex items-center gap-1 text-[11px] leading-none font-semibold sm:gap-1.5 sm:text-[12px]">
                <Icon className="size-3.5 shrink-0" />
                <span className="flex-1">{name}</span>
                <span className="tabular-nums opacity-60">{level}%</span>
              </p>
              <span className="mt-1.5 block h-1 overflow-hidden rounded-full bg-current/15">
                <span className="block h-full rounded-full" style={{ width: `${level}%`, background: level > 20 ? '#30d158' : '#ff375f' }} />
              </span>
            </div>
          ))}
        </GlassCard>

        {/* Now playing: the cover, the track, and how far in. */}
        <GlassCard className="col-span-2 flex items-center gap-3.5 p-3.5 sm:gap-5 sm:p-5">
          <span
            aria-hidden
            className="size-[72px] shrink-0 rounded-2xl sm:size-[104px]"
            style={{ background: 'radial-gradient(circle at 30% 30%, #ffd60a 0 22%, transparent 23%), linear-gradient(135deg, #ff375f, #5e5ce6)' }}
          />
          <div className="min-w-0 flex-1">
            <p className="text-[11px] font-semibold tracking-wide uppercase opacity-60">Now playing</p>
            <p className="mt-1 truncate text-[17px] leading-tight font-semibold tracking-[-0.01em]">{track.title}</p>
            <p className="truncate text-[13px] font-medium opacity-60">{track.artist}</p>
            <span className="mt-3 block h-1 overflow-hidden rounded-full bg-current/15">
              <span className="block h-full rounded-full bg-current" style={{ width: `${track.played * 100}%` }} />
            </span>
            <p className="mt-1.5 flex justify-between text-[11px] font-medium tabular-nums opacity-60">
              <span>{track.elapsed}</span>
              <span>{track.left}</span>
            </p>
          </div>
        </GlassCard>
      </div>
    </div>
  )
}
```

Buradaki duvar kâğıdı gibi durağan bir zeminin üstünde kartın `live`a ihtiyacı yok. Setteki her cam gibi yalnız bir şey değişince yeniden boyanır, dururken hiçbir şey çizmez. `live`ı yalnız kartın arkasında bir şey hareket ediyorsa aç (yukarıdaki renk sıraları gibi): kart o zaman ekranda kaldığı sürece her kare çizer.

Kenar, arkada kalanı kartın merkezine doğru çeker (görüntü alanının %6.5'i kadar) ve bu çekiş kartın yarısı boyunca söner; yazı ve renk kenar boyunca uzar. Ardından yüz, bükülmüş görüntüyü 5 px bulanıklıkla buzlar (`blur`) ve bir tonla örter (`tint`): açık sayfada %70 beyaz, koyu sayfada %70 siyah. Kenarın içinde 1.3 px beyaz bir çizgi uzanır; renk ayrışması ya da ışık yok, yalnız yumuşak bir gölge var. Butondan farklı olarak kart imlecin altında sabit kalır: içerik tutar, şişmez. Boyut ve iç boşluk senin sınıflarından gelir; cam kartın köşelerini alır: varsayılan `rounded-[28px]`, değiştirmek için herhangi bir `rounded-*` sınıfı. Berrak camdaki yazı, camın vardığı tonu izler (`data-glass-tone`); açık ve koyu zeminde okunur. Renkli bir kart için `material="tinted"` ile bir `bg-*` sınıfı kullan.

## API referansı

| Prop | Tür | Varsayılan | Açıklama |
| --- | --- | --- | --- |
| `children` | `ReactNode` | — | Kartın içeriği. |
| `material` | `'clear' \| 'tinted'` | `'clear'` | Clear arkasında kalanı büker; tinted arka plan rengini kullanır. |
| `tint` | `number` | `0.7` | Yalnız clear: renk tonunun arkayı ne kadar örttüğü (0–1): açık sayfada beyaz, koyu sayfada siyah. |
| `blur` | `number` | `5` | Yalnız clear: arkanın ne kadar buzlandığı, CSS `blur()` gibi px. `0` keskin gösterir. |
| `live` | `boolean` | `false` | Kartın arkasında hareket eden içerik için arkayı her karede yeniden boya. |
| `className` | `string` | — | Boyut, iç boşluk, köşeler (`rounded-*`) ve renkli camda renk (`bg-*`). |
| `…rest` | `div attributes` | — | `<div>`'e aktarılır (`role`, `aria-label`, `onClick`…). |

## Erişilebilirlik

- Sade bir `<div>`: kart tek bir şeyi temsil ediyorsa adlandır (`role="group"` ve bir `aria-label`).
- Cam tuvali `aria-hidden`; yalnız senin içeriğin okunur.
- Arkasında hareket eden içerik hareketi azalt tercihine uymalı: yukarıdaki sıralar durur.

Source: https://onemorethink.dev/tr/docs/card
