feat(ui): yaylı açılır sorular, ayrı SSS karoları ve ölçekli sıralama alanı (→ 2.5.11)
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
DOM recording oturumlarının (toggle davranışı, sıralama bölümü) tamamladığı iş; çalışma ağacında commit'siz bekliyordu, Bilal'in isteğiyle tek commit'e alındı. - Accordion: açılış-kapanış yaylı (hareket.ts), sürüm listesi ve SSS aynı dili kullanır. - Ana sayfa SSS: tek kutu yerine ayrı karolar; açılan soru komşularından ayrılır. - Sıralama girişi: OlcekliSayiAlani — iri rakamlar, sayı uzadıkça küçülen ölçek (hero-form, cta-sira-form, tercih-profili-kapisi). - DESIGN.md ve sürüm notları 2.5.8 / 2.5.10 / 2.5.11. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -1,34 +1,159 @@
|
||||
"use client"
|
||||
|
||||
// Akordeon (DESIGN.md §4.45). Davranış Skiper UI 103 "Bouncy accordion"dan
|
||||
// (skiper-ui.com/v1/skiper103, Pro bileşen: kaynağı alınmadı, yalnız önizlemedeki
|
||||
// hareket 16 ms DOM kaydıyla ölçüldü, 27 Eki 2026; §11.3'e göre çevrildi):
|
||||
// - Boy `YAY.acilir` ile açılır ve kapanır (sekmeli: %11 aşıp oturur).
|
||||
// - Kapanırken boy dinlenme değerinin altına çöküp geri gelir (eksi kısım alt
|
||||
// boşluk olur; alttaki öğeler bir an yukarı çekilip yerine döner).
|
||||
// - İçerik boyla aynı anda 0,3 s'de bulanıktan netleşir, kapanırken bulanıklaşıp
|
||||
// söner (`ACILIR_ICERIK`); yazı sekmez, yalnız kap seker.
|
||||
// - Ok ikonu değişmez, 180° döner.
|
||||
// - Tekli akordeonda başka öğeye basınca kapanan ve açılan aynı anda hareket eder.
|
||||
// - `varyant="karo"` (Bilal, 27 Eki 2026): her öğe ayrı karo; açılan 10 px
|
||||
// ayrılıp dört köşesi yuvarlanır, komşuların yalnız ona bakan köşesi
|
||||
// yuvarlanır, kapalı grup tek blok gibi durur (ilkinin üstü, sonuncunun altı
|
||||
// yuvarlak). Kenar boşluğu ve köşeler boyla aynı yayla sürülür. Kapalı
|
||||
// komşular 1 px üst üste biner ki kenarlıklar çift çizgi olmasın.
|
||||
// `varyant="duz"` (varsayılan): tek yüzey, ayraç çizgileri; sürüm notları.
|
||||
// Radix erişilebilirliği (klavye, aria) her iki varyantta korunur.
|
||||
|
||||
import * as React from "react"
|
||||
import { Accordion as AccordionPrimitive } from "radix-ui"
|
||||
import {
|
||||
animate,
|
||||
motion,
|
||||
useMotionValue,
|
||||
useReducedMotion,
|
||||
useTransform,
|
||||
type AnimationPlaybackControls,
|
||||
} from "motion/react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
import { ACILIR_BULANIKLIK_PX, ACILIR_ICERIK, YAY } from "@/lib/hareket"
|
||||
import { ChevronDownIcon } from "lucide-react"
|
||||
|
||||
function Accordion({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
||||
// Radix açık/kapalı durumunu bileşen ağacına vermez; boyu `motion` ile
|
||||
// animasyonlayabilmek için kök değerini burada tutup öğeye soruyoruz.
|
||||
const AcikMiBaglami = React.createContext<(deger: string) => boolean>(
|
||||
() => false
|
||||
)
|
||||
const OgeDegeriBaglami = React.createContext<string>("")
|
||||
// Karo varyantı: öğe sırası (komşu açık mı sorusu için) ve varyant.
|
||||
const KaroBaglami = React.createContext<{ karo: boolean; sira: string[] }>({
|
||||
karo: false,
|
||||
sira: [],
|
||||
})
|
||||
|
||||
/** Karo köşesi: satır ölçeği `rounded-2xl` = 32 px (DESIGN.md §2, `--radius-2xl`). */
|
||||
const KARO_KOSE_PX = 32
|
||||
/** Açılan karonun komşularından ayrılma payı (Skiper 103 ölçümü: margin-block 10 px). */
|
||||
const KARO_ARALIK_PX = 10
|
||||
|
||||
type KokProps = React.ComponentProps<typeof AccordionPrimitive.Root> & {
|
||||
varyant?: "duz" | "karo"
|
||||
}
|
||||
|
||||
function Accordion({ className, varyant = "duz", ...props }: KokProps) {
|
||||
const karo = varyant === "karo"
|
||||
const sira = karo
|
||||
? React.Children.toArray(props.children).flatMap((c) =>
|
||||
React.isValidElement<{ value?: unknown }>(c) &&
|
||||
typeof c.props.value === "string"
|
||||
? [c.props.value]
|
||||
: []
|
||||
)
|
||||
: []
|
||||
const coklu = props.type === "multiple"
|
||||
const [icDeger, setIcDeger] = React.useState<string | string[]>(() =>
|
||||
coklu
|
||||
? ((props as Extract<KokProps, { type: "multiple" }>).defaultValue ?? [])
|
||||
: ((props as Extract<KokProps, { type: "single" }>).defaultValue ?? "")
|
||||
)
|
||||
const disDeger = props.value as string | string[] | undefined
|
||||
const deger = disDeger ?? icDeger
|
||||
const acikMi = React.useCallback(
|
||||
(v: string) => (Array.isArray(deger) ? deger.includes(v) : deger === v),
|
||||
[deger]
|
||||
)
|
||||
const onValueChange = props.onValueChange as
|
||||
| ((v: string | string[]) => void)
|
||||
| undefined
|
||||
const { defaultValue: _varsayilan, ...kalan } = props as KokProps & {
|
||||
defaultValue?: string | string[]
|
||||
}
|
||||
void _varsayilan
|
||||
const kokProps = {
|
||||
...kalan,
|
||||
value: deger,
|
||||
onValueChange: (v: string | string[]) => {
|
||||
setIcDeger(v)
|
||||
onValueChange?.(v)
|
||||
},
|
||||
} as KokProps
|
||||
return (
|
||||
<AccordionPrimitive.Root
|
||||
data-slot="accordion"
|
||||
className={cn("flex w-full flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
<AcikMiBaglami.Provider value={acikMi}>
|
||||
<KaroBaglami.Provider value={{ karo, sira }}>
|
||||
<AccordionPrimitive.Root
|
||||
data-slot="accordion"
|
||||
className={cn("flex w-full flex-col", className)}
|
||||
{...kokProps}
|
||||
/>
|
||||
</KaroBaglami.Provider>
|
||||
</AcikMiBaglami.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
||||
const { karo, sira } = React.useContext(KaroBaglami)
|
||||
const acikMi = React.useContext(AcikMiBaglami)
|
||||
const azalt = useReducedMotion()
|
||||
if (!karo) {
|
||||
return (
|
||||
<OgeDegeriBaglami.Provider value={props.value}>
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("not-last:border-b", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</AccordionPrimitive.Item>
|
||||
</OgeDegeriBaglami.Provider>
|
||||
)
|
||||
}
|
||||
const i = sira.indexOf(props.value)
|
||||
const son = sira.length - 1
|
||||
const acik = acikMi(props.value)
|
||||
const ustAcik = i > 0 && acikMi(sira[i - 1])
|
||||
const altAcik = i < son && acikMi(sira[i + 1])
|
||||
const ust = acik || i === 0 || ustAcik ? KARO_KOSE_PX : 0
|
||||
const alt = acik || i === son || altAcik ? KARO_KOSE_PX : 0
|
||||
// Köşe ve boşluk satır içi stil olduğu için squircle sınıfı elle verilir
|
||||
// (globals.css: `.kt-squircle`); kapalı komşular 1 px biner.
|
||||
return (
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("not-last:border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
<OgeDegeriBaglami.Provider value={props.value}>
|
||||
<AccordionPrimitive.Item asChild data-slot="accordion-item" {...props}>
|
||||
<motion.div
|
||||
className={cn("kt-squircle", className)}
|
||||
initial={false}
|
||||
animate={{
|
||||
marginTop: acik ? KARO_ARALIK_PX : i === 0 || ustAcik ? 0 : -1,
|
||||
marginBottom: acik ? KARO_ARALIK_PX : 0,
|
||||
borderTopLeftRadius: ust,
|
||||
borderTopRightRadius: ust,
|
||||
borderBottomLeftRadius: alt,
|
||||
borderBottomRightRadius: alt,
|
||||
}}
|
||||
transition={azalt ? { duration: 0 } : YAY.acilir}
|
||||
>
|
||||
{children}
|
||||
</motion.div>
|
||||
</AccordionPrimitive.Item>
|
||||
</OgeDegeriBaglami.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -48,8 +173,10 @@ function AccordionTrigger({
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDownIcon data-slot="accordion-trigger-icon" className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden" />
|
||||
<ChevronUpIcon data-slot="accordion-trigger-icon" className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline" />
|
||||
<ChevronDownIcon
|
||||
data-slot="accordion-trigger-icon"
|
||||
className="pointer-events-none shrink-0 transition-transform duration-200 group-aria-expanded/accordion-trigger:rotate-180 motion-reduce:transition-none"
|
||||
/>
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
)
|
||||
@@ -60,13 +187,63 @@ function AccordionContent({
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
||||
const acikMi = React.useContext(AcikMiBaglami)
|
||||
const acik = acikMi(React.useContext(OgeDegeriBaglami))
|
||||
const azalt = useReducedMotion()
|
||||
const icRef = React.useRef<HTMLDivElement>(null)
|
||||
const kontrol = React.useRef<AnimationPlaybackControls | null>(null)
|
||||
// Boy tek bir sayıdan sürülür; eksiye inince yükseklik 0'da kalır, fazlası
|
||||
// eksi alt boşluk olur: kapanan öğe referanstaki gibi dinlenme boyunun
|
||||
// altına çöküp geri gelir (tarayıcı eksi yüksekliği reddeder ve yay son
|
||||
// geçerli değerde takılırdı; 27 Eki 2026 ölçümü).
|
||||
// Sonsuz = açık ve oturmuş: boy "auto"ya bırakılır ki iç içe akordeon ya da
|
||||
// pencere genişliği değişince içerik kendi boyunu bulsun. React durumu yok;
|
||||
// her şey MotionValue'da, yeniden render gerekmez.
|
||||
const boy = useMotionValue(acik ? Number.POSITIVE_INFINITY : 0)
|
||||
const yukseklik = useTransform(boy, (v) =>
|
||||
v === Number.POSITIVE_INFINITY ? "auto" : Math.max(0, v)
|
||||
)
|
||||
const altBosluk = useTransform(boy, (v) => Math.min(0, v))
|
||||
const ilk = React.useRef(true)
|
||||
|
||||
React.useEffect(() => {
|
||||
if (ilk.current) {
|
||||
ilk.current = false
|
||||
return
|
||||
}
|
||||
kontrol.current?.stop()
|
||||
const hedef = icRef.current?.offsetHeight ?? 0
|
||||
if (acik) {
|
||||
if (azalt) {
|
||||
boy.jump(Number.POSITIVE_INFINITY)
|
||||
return
|
||||
}
|
||||
kontrol.current = animate(boy, hedef, {
|
||||
...YAY.acilir,
|
||||
onComplete: () => boy.jump(Number.POSITIVE_INFINITY),
|
||||
})
|
||||
} else {
|
||||
// Oturmuş açık öğe ölçülen boydan iner; yarıda yakalanan öğe olduğu
|
||||
// yerden döner.
|
||||
if (boy.get() === Number.POSITIVE_INFINITY) boy.jump(hedef)
|
||||
if (azalt) {
|
||||
boy.jump(0)
|
||||
return
|
||||
}
|
||||
kontrol.current = animate(boy, 0, YAY.acilir)
|
||||
}
|
||||
// boy sabit bir MotionValue; yalnız açık/kapalı ve hareketi azalt tetikler.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [acik, azalt])
|
||||
|
||||
// forceMount: kapalı içerik de ilk HTML'de kalır — JS çalıştırmayan
|
||||
// tarayıcılar (arama/AI botları) cevapları okuyabilsin. Radix kapalıyken
|
||||
// içeriği hiç render etmez; forceMount ile de yükseklik ölçümü kapalıyken 0
|
||||
// çıktığı için accordion-up/down keyframe'leri çalışmaz. Aç/kapa bu yüzden
|
||||
// grid-rows geçişiyle yapılır; geçiş Content'in KENDİSİNDE değil çocuğunda
|
||||
// durur, çünkü Radix ölçüm sırasında Content'in transition-duration'ını
|
||||
// sıfırlar. visibility geçişi kapalı içeriği odak/ekran okuyucudan çıkarır.
|
||||
// çıktığı için accordion-up/down keyframe'leri çalışmaz. Boy bu yüzden
|
||||
// yukarıdaki yayla sürülür; `initial={false}` sunucu HTML'inde kapalı
|
||||
// içeriği 0 boy ve 0 opaklıkla basar. visibility geçişi kapalı içeriği yay
|
||||
// oturduktan sonra odak/ekran okuyucudan çıkarır (açılırken anında geri
|
||||
// gelir).
|
||||
return (
|
||||
<AccordionPrimitive.Content
|
||||
forceMount
|
||||
@@ -74,18 +251,30 @@ function AccordionContent({
|
||||
className="group/accordion-content text-sm"
|
||||
{...props}
|
||||
>
|
||||
<div className="grid grid-rows-[1fr] transition-[grid-template-rows,visibility] duration-200 ease-out group-data-[state=closed]/accordion-content:invisible group-data-[state=closed]/accordion-content:grid-rows-[0fr] motion-reduce:transition-none">
|
||||
<div className="min-h-0 overflow-hidden">
|
||||
<div
|
||||
className={cn(
|
||||
"pt-0 pb-2.5 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
<motion.div
|
||||
className="overflow-hidden transition-[visibility] duration-700 group-data-[state=closed]/accordion-content:invisible motion-reduce:transition-none"
|
||||
style={{ height: yukseklik, marginBottom: altBosluk }}
|
||||
initial={false}
|
||||
animate={
|
||||
acik
|
||||
? { opacity: 1, filter: "blur(0px)" }
|
||||
: {
|
||||
opacity: 0,
|
||||
filter: azalt ? "blur(0px)" : `blur(${ACILIR_BULANIKLIK_PX}px)`,
|
||||
}
|
||||
}
|
||||
transition={azalt ? { duration: 0 } : ACILIR_ICERIK}
|
||||
>
|
||||
<div
|
||||
ref={icRef}
|
||||
className={cn(
|
||||
"pt-0 pb-2.5 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
</AccordionPrimitive.Content>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user