# GlassButton

> Camdan bir buton. Berrak cam arkasındaki sayfayı büker; renkli cam senin arka plan rengini alır.

```tsx
import { Play } from 'lucide-react'

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

const COLS = 13
const ROWS = 7

/** 1 around the middle of the grid, falling to 0 at its edge. */
const fade = (col: number, row: number) => {
  const distance = Math.hypot((col - (COLS - 1) / 2) / (COLS / 2), (row - (ROWS - 1) / 2) / (ROWS / 2))
  return Math.min(1, Math.max(0, (1 - distance) / 0.45))
}

// Clear glass bends whatever sits behind it: here, only a fine grid centred on the glass,
// on the page's own colour. Watch its lines bend at the rim. The grid is plain DOM: every
// cell draws its own top and left line, fainter the further it is from the glass.
export default function Demo() {
  return (
    <div className="relative isolate flex h-72 w-full max-w-xl items-center justify-center">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 grid -translate-x-1/2 -translate-y-1/2 grid-cols-[repeat(13,40px)]">
        {Array.from({ length: COLS * ROWS }, (_, i) => (
          <span key={i} className="relative size-10" style={{ opacity: fade(i % COLS, Math.floor(i / COLS)) }}>
            <span className="absolute inset-x-0 top-0 h-px bg-black/10 dark:bg-white/10" />
            <span className="absolute inset-y-0 left-0 w-px bg-black/10 dark:bg-white/10" />
          </span>
        ))}
      </div>
      <GlassButton size="xl" tint={0} icon={<Play />} iconPosition="start">
        Play
      </GlassButton>
    </div>
  )
}
```

**Şunun için**

- Tek bir eylem: harekete geçirici buton, araç çubuğu butonu, buton gibi görünen bir bağlantı.
- Bükülmenin göründüğü görsel ya da renk üstünde berrak cam.

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

- Sonucu butonda görünmesi gereken asenkron bir eylem: GlassActionButton kullan.
- Seçenekler arasında seçim: GlassTabs kullan.
- Yoğun bir formun her butonu: camı önemli olan eyleme sakla.

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

> Alttaki buton UI SDK'nın butonudur; bu yüzden Button `@ui-sdk/core` ve `@ui-sdk/react` paketlerine ihtiyaç duyar. `onClick`'ten bir Promise döndürürsen buton, o sonuçlanana kadar beklemede kalır: yeni basışları yok sayar ve bunu ekran okuyuculara bildirir. Kurulum komutu iki paketi, bileşenin yazıldığı tam sürümle ekler: UI SDK beta aşamasında ve API'si hâlâ değişebilir.

## Kullanım

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

<GlassButton>Get started</GlassButton>
<GlassButton material="tinted" className="bg-sky-500 text-white">Save</GlassButton>
<GlassButton asChild>
  <Link href="/docs">Read the docs</Link>
</GlassButton>
```

## Örnekler

### Renkli cam ve boyutlar

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

// Tinted glass takes the button's own background class, then adds light and shadow.
// Top row: your colours. Bottom row: the four sizes.
export default function Demo() {
  return (
    <div className="flex flex-col items-center gap-10">
      <div className="flex flex-wrap items-center justify-center gap-3">
        <GlassButton material="tinted" size="lg" className="bg-blue-600 text-white">
          Continue
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="bg-neutral-900 text-white dark:bg-white dark:text-neutral-900">
          Publish
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="bg-rose-600 text-white">
          Delete
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="border border-black/15 bg-white text-neutral-900">
          Cancel
        </GlassButton>
      </div>
      <div className="flex flex-wrap items-center justify-center gap-3">
        <GlassButton material="tinted" size="sm" className="bg-emerald-600 text-white">
          Small
        </GlassButton>
        <GlassButton material="tinted" size="md" className="bg-emerald-600 text-white">
          Medium
        </GlassButton>
        <GlassButton material="tinted" size="lg" className="bg-emerald-600 text-white">
          Large
        </GlassButton>
        <GlassButton material="tinted" size="xl" className="bg-emerald-600 text-white">
          Extra large
        </GlassButton>
      </div>
    </div>
  )
}
```

Renkli camı `bg-sky-500` gibi sıradan bir sınıfla boya; cam kendini o renge boyar, ışık ve gölge ekler. Bir `border-*` sınıfı camın kenarı olur.

### Bağlantı olarak (asChild)

```tsx
import { ArrowUpRight } from 'lucide-react'

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

// `asChild` puts the glass on your own element. The same works with a Next.js or
// TanStack Router <Link>: it stays a real link with its own navigation.
export default function Demo() {
  return (
    <div className="flex flex-col items-center gap-6 text-center">
      <div>
        <p className="text-3xl font-semibold tracking-tight text-neutral-900 dark:text-white">Free and open source</p>
        <p className="mt-2 text-base text-neutral-500 dark:text-neutral-400">MIT licensed. Copy the files, they are yours.</p>
      </div>
      <GlassButton asChild material="tinted" size="lg" icon={<ArrowUpRight />} className="bg-violet-600 text-white">
        <a href="https://github.com/bilalgursen/liquid-glass" target="_blank" rel="noreferrer">
          Star on GitHub
        </a>
      </GlassButton>
    </div>
  )
}
```

`asChild` ile cam, `<button>` yerine tek çocuk öğene gelir: bir `<a>`, Next.js `<Link>`, TanStack Router `<Link>`. Öğen kendi prop'larını ve gezinmesini korur.

### Örtülü renkler üstünde

```tsx
import { ArrowRight, Play } from 'lucide-react'

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

// Clear glass over colour. The backdrop is plain DOM: flat discs of colour on a dark scene
// and a dark scrim over them. The glass sees both, and the text, so the buttons sit in the scene.
export default function Demo() {
  return (
    <div className="relative isolate flex h-96 w-full max-w-2xl flex-col items-start justify-end overflow-hidden rounded-3xl bg-[#0b1030] p-8">
      <div aria-hidden className="absolute inset-0 -z-20">
        <span className="absolute -top-24 -left-16 size-80 rounded-full bg-[#22d3ee]" />
        <span className="absolute -top-32 right-4 size-72 rounded-full bg-[#a855f7]" />
        <span className="absolute -right-20 -bottom-28 size-96 rounded-full bg-[#ec4899]" />
        <span className="absolute -bottom-40 left-24 size-80 rounded-full bg-[#1d4ed8]" />
      </div>
      <div aria-hidden className="absolute inset-0 -z-10 bg-black/35" />
      <p className="text-xs font-semibold tracking-[0.18em] text-white/70">TROMSØ · WINTER SEASON</p>
      <h3 className="mt-2 max-w-sm text-4xl leading-[1.05] font-semibold tracking-tight text-white">Chase the northern lights</h3>
      <div className="mt-6 flex flex-wrap gap-3">
        <GlassButton size="lg" tint={0.35} icon={<ArrowRight />}>
          Plan the trip
        </GlassButton>
        <GlassButton size="lg" tint={0.15} icon={<Play />} iconPosition="start">
          Watch the film
        </GlassButton>
      </div>
    </div>
  )
}
```

Berrak cam arkasında kalanı yeniden boyar: arka plan renkleri, gradyanlar ve görseller, sayfanın kırptığı haliyle `<img>` ve `<video>` (`object-fit`), yazı, satır içi SVG ikonlar ve arka plan bulanıklığı; hepsi kendi yığın sırasıyla. Gölgeler, `::before`/`::after` ve konik gradyanlar boyanmaz.

> Başka bir kaynaktan gelen görsel CORS başlıklarıyla sunulmalıdır (görsel CDN'leri çoğunlukla gönderir): cam görseli CORS ile yeniden ister, sunucu izin vermezse onu dışarıda bırakır.

### Köşeli

```tsx
import { Plus } from 'lucide-react'

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

// The glass takes the button's own corners: add a `rounded-*` class and the lens follows.
// Fine ruled lines show the bend running along the straight edges and around each corner.
export default function Demo() {
  return (
    <div className="relative isolate flex h-72 w-full max-w-2xl flex-wrap items-center justify-center gap-4 overflow-hidden rounded-3xl">
      <div aria-hidden className="absolute inset-0 -z-10 flex flex-col justify-between">
        {Array.from({ length: 33 }, (_, i) => (
          <span key={i} className="h-px bg-black/10 dark:bg-white/10" />
        ))}
      </div>
      <GlassButton size="xl" tint={0.3} className="rounded-2xl" icon={<Plus />} iconPosition="start">
        New project
      </GlassButton>
      <GlassButton size="xl" material="tinted" className="rounded-2xl bg-neutral-900 text-white dark:bg-white dark:text-neutral-900">
        Open
      </GlassButton>
    </div>
  )
}
```

Cam, üstünde durduğu öğenin köşelerini alır. Bir `rounded-*` sınıfı ekle; mercek, kenarı ve gölgesi onu izler, bükülme haptaki kadar derin kalır.

### Basılı tutup çek (pull)

```tsx
import { Mic, Plus } from 'lucide-react'

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

const TICKS = 61

// Hold a button and drag away (`pull`, on by default). It comes after the pointer a little way through a rubber
// band, stretches along the pull and thins across it, and swings back like gel when you let go.
// The round ones are small, so they follow from the very point you pressed; the wide one waits
// until the pointer is past its edge. Behind them a ruler to read the stretch against: plain
// DOM, one thin line per tick, fainter towards the ends.
export default function Demo() {
  return (
    <div className="relative isolate flex h-72 w-full max-w-xl items-center justify-center gap-4 overflow-hidden">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 flex -translate-x-1/2 -translate-y-1/2 items-center gap-[7px]">
        {Array.from({ length: TICKS }, (_, i) => (
          <span
            key={i}
            className={`w-px bg-black/15 dark:bg-white/15 ${i % 10 === 0 ? 'h-28' : i % 5 === 0 ? 'h-20' : 'h-10'}`}
            style={{ opacity: Math.min(1, (1 - Math.abs(i - (TICKS - 1) / 2) / ((TICKS - 1) / 2)) / 0.4) }}
          />
        ))}
      </div>
      <GlassButton size="lg" tint={0.2} aria-label="Add" className="w-12 !px-0">
        <Plus />
      </GlassButton>
      <GlassButton size="lg" tint={0.2}>
        Hold and drag
      </GlassButton>
      <GlassButton size="lg" material="tinted" aria-label="Record" className="w-12 bg-neutral-900 !px-0 text-white dark:bg-white dark:text-neutral-900">
        <Mic />
      </GlassButton>
    </div>
  )
}
```

Butonu basılı tutup uzağa sürükleyen imleç onu peşinden çeker. Buton bir lastik bantla biraz gelir (geniş butonda en çok 10 px), çekiş yönünde uzar, karşı yönde incelir; bırakınca jöle gibi yerine yaylanır. 72 px'e kadar olan buton basıldığı noktadan itibaren imleci izler; daha geniş olan, imleç kenarını geçince kıpırdar. Varsayılan olarak açıktır (`pull={false}` butonu yerinde tutar); azaltılmış harekette buton yerinde durur. Butonun dışında bırakırsan, her butonda olduğu gibi tıklama gerçekleşmez.

## API referansı

| Prop | Tür | Varsayılan | Açıklama |
| --- | --- | --- | --- |
| `material` | `'clear' \| 'tinted'` | `'clear'` | Clear sayfayı büker; tinted arka plan rengini kullanır. |
| `size` | `'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Yükseklik 32, 40, 48 ya da 64 px. |
| `icon` | `ReactNode` | — | Bir ikon öğesi (ör. lucide-react ikonu). |
| `iconPosition` | `'start' \| 'end'` | `'end'` | İkonun hangi tarafta durduğu. |
| `tint` | `number` | `0.6` | Yalnız clear: renk tonunun arkayı ne kadar örttüğü (0–1). |
| `asChild` | `boolean` | `false` | Camı `<button>` yerine tek çocuk öğeye koy. |
| `pull` | `boolean` | `true` | Basılı tutup sürükle: buton imlecin peşinden biraz gelir, çekiş yönünde uzar, bırakınca yerine yaylanır. |
| `…rest` | `button attributes` | — | Butona aktarılır: `onClick`, `disabled`, `type` ve UI SDK'nın `pendingAnnouncement` ile `focusableWhenDisabled` prop'ları. |

## Erişilebilirlik

- Gerçek bir `<button>` (ya da `asChild` ile kendi öğen): odak, Enter ve Space her zamanki gibi çalışır.
- Cam tuvali `aria-hidden`; yalnız senin etiketin okunur.
- Yalnız ikonlu butonlar `aria-label` ister.

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