# useGlass / GlassSurface

> `useGlass()` ve `<GlassSurface>` ile herhangi bir özel bileşene — kartlar, gezinti çubukları, yüzen dock'lar veya modallar — Vitrum'un gerçek zamanlı WebGL2 kırılmasını kazandır.

```tsx
import { Compass, Layers, Search, Sparkles } from "lucide-react";
import { useState } from "react";

import { GlassSurface, useGlass } from "@vitrumui/react/surface";

function CustomHookCard() {
  const [active, setActive] = useState(false);
  const { ref, style, glassProps, isReady } = useGlass<HTMLButtonElement>({
    radius: 20,
    blur: 6,
    refraction: 1.15,
    interactive: true,
    elevation: "md",
  });

  return (
    <button
      ref={ref}
      type="button"
      onClick={() => setActive((v) => !v)}
      {...glassProps}
      style={style}
      className="flex w-full cursor-pointer items-center justify-between border border-white/50 bg-white/55 px-4 py-3 text-left text-neutral-900 backdrop-blur-md dark:border-white/20 dark:bg-black/45 dark:text-white data-[vt-tone=dark]:text-white data-[vt-tone=light]:text-neutral-900"
    >
      <span className="flex items-center gap-2.5">
        <Sparkles className="size-4 opacity-80" />
        <span className="text-sm font-semibold">
          {active ? "useGlass() active" : "Custom useGlass() button"}
        </span>
      </span>
      <span className="font-mono text-[11px] opacity-60">
        {isReady ? "WebGL2" : "CSS"}
      </span>
    </button>
  );
}

export default function Demo() {
  return (
    <div className="relative isolate flex w-full max-w-md flex-col items-center gap-5 overflow-hidden rounded-[28px] p-8">
      <div
        aria-hidden
        className="absolute inset-0 -z-10 border border-border bg-zinc-900"
      />
      <GlassSurface
        as="nav"
        aria-label="Floating dock"
        radius="9999px"
        blur={6}
        refraction={1.1}
        elevation="lg"
        className="flex items-center gap-1 px-3 py-2"
      >
        {[
          { icon: Compass, label: "Explore" },
          { icon: Layers, label: "Layers" },
          { icon: Search, label: "Search" },
        ].map(({ icon: Icon, label }) => (
          <span
            key={label}
            className="inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium"
          >
            <Icon className="size-3.5" />
            {label}
          </span>
        ))}
      </GlassSurface>
      <CustomHookCard />
    </div>
  );
}
```

## <GlassSurface> kullanımı

`<GlassSurface>`, `useGlass()` ile güçlendirilmiş polimorfik bir kırılmalı cam kapsayıcısıdır (`as="div" | "nav" | "header" | "section" | "aside"…`). Köşe yarıçapı, buzlu bulanıklık, kenar parıltısı ve gölge yüksekliği için dengeli varsayılanlarla gelir ve Vitrum'un çevrimdışı lisans kontrolünü otomatik çalıştırır.

```tsx
import { GlassSurface } from '@vitrumui/react/surface'

<GlassSurface
  as="nav"
  aria-label="Floating dock"
  radius="9999px"
  blur={6}
  refraction={1.1}
  elevation="lg"
  className="flex items-center gap-2 px-4 py-2"
>
  <button>Explore</button>
  <button>Layers</button>
</GlassSurface>
```

## useGlass() kancası

İşaretleme, olay işleyicileri veya ref'ler üzerinde tam kontrol gerektiğinde `useGlass()` kancasını doğrudan herhangi bir HTML öğesine bağla. `{ ref, style, glassProps, isReady, reduceMotion }` döndürür, SSR sırasında deterministik çalışır (sıfır hidrasyon uyuşmazlığı) ve `prefers-reduced-motion` tercihine uyar.

```tsx
import { useGlass } from '@vitrumui/react/surface'

export function CustomGlassCard({ children }: { children: React.ReactNode }) {
  const { ref, style, glassProps, isReady } = useGlass<HTMLDivElement>({
    radius: 24,
    blur: 6,
    refraction: 1.15,
    interactive: true,
    elevation: 'md',
  })

  return (
    <div ref={ref} {...glassProps} style={style} className="p-6">
      {children}
      <span className="sr-only">{isReady ? 'WebGL2 active' : 'CSS fallback'}</span>
    </div>
  )
}
```

## API referansı

| Prop | Tür | Varsayılan | Açıklama |
| --- | --- | --- | --- |
| `as` | `React.ElementType` | `'div'` | `<GlassSurface>` üzerinde: çizilecek HTML etiketi veya bileşen. |
| `radius` | `number \| string` | `24` | Piksel cinsinden köşe yarıçapı (sayı) veya herhangi bir CSS uzunluğu (`'9999px'`, `'1.5rem'`). |
| `tint / tintColor` | `number / string` | `0.65 / —` | Renk tonu opaklığı (0–1) ve isteğe bağlı CSS rengi; belirtilmezse etkin `<VitrumProvider>` temasını devralır. |
| `blur / refraction / specular` | `number` | `5 / 1 / 1` | Piksel cinsinden buzlanma bulanıklığı, kenar kırılma çarpanı ve parıltı çarpanı. |
| `interactive` | `boolean` | `false` | İmleç altında yaylı üzerine gelme ve basma deformasyonunu etkinleştirir. |
| `elevation` | `'none' \| 'sm' \| 'md' \| 'lg'` | `'md'` | Kırılmalı camın altına yerleştirilen gölge derinliği. |
| `live / backdrop / disabled` | `boolean / string / boolean` | `false / — / false` | Hareketli arka planlar için her karede yeniden boyar, kırılmayı bir CSS seçiciyle sınırlar veya CSS yedeğini zorlar. |

Source: /tr/docs/custom-glass
