Files
landing-builder/components/wysiwyg/LayersPanel.tsx
jaybe 5bf78b3e01
Auto PR / open-pr (push) Successful in 21s
Auto Label PR / add-automerge-label (pull_request) Successful in 6s
CI / test (pull_request) Successful in 1m49s
테스트/린트 안정화: 버튼 쿼리 모호성 제거, 훅 deps 보강, vi.spyOn 모킹, 멀티선택 Moveable 간섭 방지 재확인, 스냅 우선순위 회귀 그린
2025-11-17 17:33:39 +09:00

70 lines
2.3 KiB
TypeScript

import React, { useCallback, useEffect, useState } from 'react'
import type { Frame } from '@/lib/wysiwyg/schema'
export type LayersPanelProps = {
frame: Frame
onChange?: (next: Frame) => void
}
export function LayersPanel({ frame, onChange }: LayersPanelProps) {
const [model, setModel] = useState<Frame>(frame)
useEffect(() => {
setModel(frame)
}, [frame])
const move = useCallback((id: string, dir: 1 | -1) => {
const idx = model.layers.findIndex((l) => l.id === id)
if (idx < 0) return
const j = idx + dir
if (j < 0 || j >= model.layers.length) return
const nextLayers = model.layers.slice()
const [it] = nextLayers.splice(idx, 1)
nextLayers.splice(j, 0, it)
const next = { ...model, layers: nextLayers }
setModel(next)
onChange?.(next)
}, [model, onChange])
const toggle = useCallback((id: string, key: 'locked' | 'visible') => {
const nextLayers = model.layers.map((l) => l.id === id ? { ...l, [key]: key === 'visible' ? !l.visible : !l.locked } : l)
const next = { ...model, layers: nextLayers }
setModel(next)
onChange?.(next)
}, [model, onChange])
return (
<div aria-label="Layers Panel">
{model.layers.map((l) => (
<div key={l.id} data-testid="layer-item" style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
<span>{l.name}</span>
<button type="button" data-testid={`layer-up-${l.id}`} onClick={() => move(l.id, -1)} aria-label={`move up ${l.name}`}>
</button>
<button type="button" data-testid={`layer-down-${l.id}`} onClick={() => move(l.id, 1)} aria-label={`move down ${l.name}`}>
</button>
<button
type="button"
data-testid={`layer-lock-${l.id}`}
aria-pressed={l.locked ? 'true' : 'false'}
onClick={() => toggle(l.id, 'locked')}
aria-label={`lock ${l.name}`}
>
🔒
</button>
<button
type="button"
data-testid={`layer-hide-${l.id}`}
aria-pressed={l.visible ? 'false' : 'true'}
onClick={() => toggle(l.id, 'visible')}
aria-label={`toggle ${l.name} visibility`}
>
👁
</button>
</div>
))}
</div>
)
}