# 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 "@vitrumui/react/button";

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
npm install @vitrumui/react # yakında
```

## Kullanım

```tsx
import { GlassButton } from '@vitrumui/react/button'

<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 "@vitrumui/react/button";

// 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 "@vitrumui/react/button";

// `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="/docs">Read the docs</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 "@vitrumui/react/button";

// 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 "@vitrumui/react/button";

// 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.

## 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. |
| `…rest` | `button attributes` | — | Öğeye aktarılır (`onClick`, `disabled`, `type`…). |

## 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: /tr/docs/button
