사용자가 옮기고, 크기를 바꾸고, 헤더만 남도록 접고, 닫을 수 있는 떠 있는 표면입니다.
이 페이지의 내용
플로팅 패널은 작업 화면 옆에 열린 채로 머무르면서도 그 아래의 페이지를 계속 사용할 수 있게 하는 떠 있는 표면입니다. 캔버스의 레이어, 색상 선택기, 속성 검사기, 채팅 등에 사용합니다. 사용자는 헤더를 잡아 패널을 드래그하고, 모서리에서 크기를 바꾸고, 헤더만 남도록 접고, 닫을 수 있습니다. 플로팅 패널은 role="dialog"가 있는 popover="manual"이므로, 브라우저가 버튼에서 패널을 열고 최상위 레이어(top layer)로 올려 페이지의 모든 요소 위에 표시합니다. 순서를 관리할 z-index가 필요 없습니다. 나머지인 이동, 크기 조절, 접기, Escape 키, 포커스, 어느 패널이 앞에 오는지는 panel동작이 처리합니다.
플로팅 패널
<buttontype="button"class="btn btn-sm"commandfor="layers"command="toggle-popover"> Layers</button><buttontype="button"class="btn btn-sm"commandfor="comments"command="toggle-popover"> Comments</button><divid="layers"popover="manual"role="dialog"class="panel"aria-labelledby="layers-title"style="--panel-x: 24px; --panel-y: 24px; --panel-width: 232px"><divclass="panel-header"><buttontype="button"class="panel-handle"aria-label="Move the Layers panel with the arrow keys"></button><h2class="panel-title"id="layers-title">Layers</h2><divclass="panel-actions"><buttontype="button"class="btn btn-quiet btn-sm btn-square panel-minimize"aria-pressed="false"aria-label="Minimize"><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M3 8L13 8"/></svg></button><buttontype="button"class="btn btn-quiet btn-sm btn-square"commandfor="layers"command="hide-popover"aria-label="Close"><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M4 4L12 12"/><pathd="M4 12L12 4"/></svg></button></div></div><divclass="panel-body"><olclass="list"><liclass="list-row"><spanclass="list-body"><spanclass="list-title">Header</span></span></li><liclass="list-row"><spanclass="list-body"><spanclass="list-title">Hero image</span></span></li><liclass="list-row"><spanclass="list-body"><spanclass="list-title">Pricing table</span></span></li><liclass="list-row"><spanclass="list-body"><spanclass="list-title">Footer</span></span></li></ol></div><spanclass="panel-resize"aria-hidden="true"></span></div><divid="comments"popover="manual"role="dialog"class="panel"aria-labelledby="comments-title"style="--panel-x: 296px; --panel-y: 64px; --panel-width: 272px"><divclass="panel-header"><buttontype="button"class="panel-handle"aria-label="Move the Comments panel with the arrow keys"></button><h2class="panel-title"id="comments-title">Comments</h2><divclass="panel-actions"><buttontype="button"class="btn btn-quiet btn-sm btn-square panel-minimize"aria-pressed="false"aria-label="Minimize"><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M3 8L13 8"/></svg></button><buttontype="button"class="btn btn-quiet btn-sm btn-square"commandfor="comments"command="hide-popover"aria-label="Close"><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M4 4L12 12"/><pathd="M4 12L12 4"/></svg></button></div></div><divclass="panel-body"><divclass="flexflex-colgap-sm"><pclass="m(0)"><spanclass="fg-text-strong">Mira</span> The hero image crops the product on narrow screens.</p><pclass="m(0)"><spanclass="fg-text-strong">Jun</span> Fixed in the next build: it keeps the middle third.</p><inputclass="input input-sm"type="text"placeholder="Reply"aria-label="Reply"></div></div><spanclass="panel-resize"aria-hidden="true"></span></div><script>document.getElementById('layers').showPopover()document.getElementById('comments').showPopover()</script><scripttype="module">import{ attach }from'@master/ui/behaviors'attach()</script>
헤더나 패널의 아래쪽 끝 모서리를 드래그해 보세요. 뒤에 있는 패널 안을 누르면 그 패널이 앞으로 옵니다. Tab 키로 헤더로 이동해 방향키를 사용하세요. Shift 키와 방향키를 함께 누르면 더 멀리 이동하고, Alt 키와 방향키를 함께 누르면 크기가 바뀝니다. Escape 키를 누르면 패널이 닫힙니다.
시트. 팝오버와 같은 떠 있는 면에 플로팅 그림자가 적용됩니다. 헤더나 모서리를 잡고 있는 동안에는 오버레이 그림자로 솟아오르며, 드래그해도 텍스트가 선택되지 않습니다. 모서리 반경은 작은 버튼의 모서리 반경에 헤더가 버튼 주위에 두는 6px 여백을 더한 14px입니다.
헤더는 가는 구분선 위에 놓인 같은 시트의 막대로, 시작 쪽에 제목이, 끝쪽에 동작 버튼이 있습니다. 둘 아래에는 막대 크기의 버튼인 핸들이 깔려 있으므로, 헤더에서 컨트롤이 아닌 곳 어디를 눌러도 패널을 집어 들 수 있으며, 커서는 편 손에서 쥔 손으로 바뀝니다. 제목은 포인터 입력을 받지 않으므로 제목을 눌러도 핸들이 입력을 받습니다.
핸들에 포커스가 있으면 패널 전체에 포커스 링이 표시됩니다. 키로 움직이는 대상이 패널 전체이기 때문입니다.
접힌 상태. 최소화 버튼을 누르면 패널에는 헤더만 남습니다. 본문과 모서리는 숨겨지고, 버튼은 오목한 영역 안에 놓입니다.
본문은 주어진 공간보다 길면 아래 페이지를 움직이지 않고 패널 안에서 스크롤됩니다.
모서리는 끝쪽 아래에 있는 두 개의 짧은 대각선으로, 조작 영역은 16px이고 터치 화면에서는 44px입니다. 터치 화면에서도 헤더의 버튼은 크기를 유지하며, 버튼의 조작 영역이 헤더 가장자리까지 넓어집니다.
위치와 크기는 사용자 지정 속성입니다. 뷰포트의 왼쪽 위 모서리를 기준으로 패널의 왼쪽 위 모서리까지의 거리를 픽셀 단위로 나타내는 --panel-x와 --panel-y, 그리고 --panel-width와 --panel-height입니다. 이 값은 이벤트만 알 수 있으므로 동작이 포인터와 키 입력에 따라 작성합니다. 미리보기에서 각 패널의 시작 위치를 정하듯이 페이지에서 직접 작성할 수도 있습니다.
배치와 제한은 스타일시트가 clamp()로 처리하며, 기준은 고정 위치 요소의 백분율이 참조하는 뷰포트로, 스크롤바는 제외됩니다.
패널은 뷰포트보다 넓어지지 않고 --panel-min-width(12rem)보다 좁아지지 않으며, 너비 전체가 뷰포트 안에 머무릅니다.
헤더는 뷰포트를 벗어나지 않으므로 패널을 언제든 찾아 다시 드래그해 올 수 있습니다. 패널은 뷰포트보다 높아지지 않으며, 들어가지 않는 본문은 스크롤됩니다.
창이 좁아지면 패널이 안쪽으로 밀려 들어옵니다. 창이 넓어지면 패널은 지정받았던 위치로 돌아갈 수 있습니다. 패널이 보관하는 위치는 clamp()로 바뀌지 않기 때문입니다.
위치를 지정하지 않으면 패널은 끝쪽 위 모서리에서 8px(--panel-gutter) 안쪽에 열립니다.
이동과 크기 조절이 끝날 때마다 동작은 스타일시트가 패널을 그린 위치를 읽어 그 값을 보관합니다. 따라서 애플리케이션이 저장하는 값은 사용자가 실제로 본 위치입니다.
패널은 표시된 순서대로 최상위 레이어에 놓이며, 마지막에 표시된 패널이 맨 앞에 옵니다. 다른 패널 뒤에 있는 패널 안을 누르거나 그 안에 포커스가 가면 그 패널이 앞으로 옵니다. 동작이 패널을 다시 표시해 최상위 레이어의 마지막에 두기 때문입니다. 브라우저가 그리기 전에 한 작업 안에서 숨겼다가 다시 표시하므로, 패널이 사라지는 모습은 보이지 않고 등장 애니메이션도 재생되지 않으며, 브라우저는 열림에서 열림으로 가는 toggle 이벤트를 한 번 보고합니다. 포커스는 사용자가 둔 곳에 그대로 있습니다.
panel은 panel 클래스가 있는 루트 요소를 받아, 연결한 동작을 해제하는 함수를 반환합니다. 이 함수의 value는 패널의 위치, 크기, 접힘 여부를 나타내는 { x, y, width, height, minimized }입니다. 네 숫자는 픽셀 단위이며, 스타일시트의 기본값이 적용되는 경우에는 null입니다. 이 값을 보관했다가 페이지를 불러올 때 다시 설정하세요.
이동. 핸들을 드래그하면 --panel-x와 --panel-y를 작성하며, 패널을 집어 든 지점이 포인터 아래에 머무릅니다. 핸들에서 방향키를 누르면 16px씩, Shift 키와 함께 누르면 네 배만큼 이동합니다.
크기 조절. 모서리를 드래그하면 --panel-width와 --panel-height를 작성합니다. 핸들에서 Alt 키와 방향키를 누르면 한 단계씩 같은 일을 합니다. 오른쪽에서 왼쪽으로 쓰는 언어에서는 모서리가 왼쪽 아래에 있으므로 패널이 왼쪽으로 넓어지며, Alt+ArrowLeft를 누르면 넓어집니다.
접기. 최소화 버튼을 클릭하면 버튼의 aria-pressed가 전환됩니다.
닫기. 패널 안에 포커스가 있을 때 Escape 키를 누르면 패널이 닫힙니다. 단, 먼저 닫히는 메뉴처럼 패널 안의 컨트롤이 그 키를 처리한 경우는 예외입니다. 닫기 버튼은 command="hide-popover"이므로 스크립트가 필요 없습니다.
포커스. 컨트롤에서 연 패널은 포커스를 핸들로 옮기며, 포커스가 패널 안에 있는 상태로 닫히면 포커스를 그 컨트롤로 돌려줍니다. 페이지를 불러올 때 열린 패널은 포커스를 현재 위치에 그대로 둡니다.
이벤트. 루트는 패널이 이동하거나 크기가 바뀌는 동안 input을 발생시키고, 드래그가 끝나거나 키로 이동했거나 접혔을 때 change를 발생시킵니다. 두 이벤트 모두 버블링되므로 본문의 필드에서 발생한 이벤트도 루트에 전달됩니다. event.target을 루트와 비교하세요.
옵션
설정하는 내용
step
방향키 한 번으로 패널을 이동하거나 크기를 바꾸는 거리로, 픽셀 단위입니다. 기본값은 16입니다
동작을 연결하지 않아도 패널은 버튼에서 페이지 위 최상위 레이어로 열리고 닫기 버튼으로 닫힙니다. 패널은 사용자 지정 속성이 정한 위치에 머무릅니다.
commandfor와 command="toggle-popover"가 있는 버튼으로 패널을 열고 닫습니다. popovertarget도 같은 일을 합니다. 탭 순서에서 패널은 버튼 바로 다음에 오며, 패널이 열리면 포커스가 핸들로 이동하므로 곧바로 방향키로 패널을 옮길 수 있습니다. 버튼, 닫기 버튼, Escape 키 중 하나로 패널을 닫으면 포커스가 버튼으로 돌아갑니다.
panel 컴포넌트는 헤더, 핸들, 버튼을 렌더링하고, open에 따라 패널을 열고 닫으며, 값을 받아 외부로 전달합니다. 이동하는 동안에는 onValueChange를, 이동이 끝나면 onValueCommit을 호출하며, 이때가 값을 저장할 시점입니다. 트리거와 본문은 페이지 자체의 마크업으로 남습니다. npx master-ui add panel 명령을 실행해 프로젝트에 복사하세요. 컴포넌트의 구성과 사용 방법은 React, Svelte, Vue에서 확인할 수 있습니다.
ui/panel.tsx
'use client'import{ useCallback, useEffect, useId, useReducer, useRef, useState,type ComponentProps,type CSSProperties,type ReactNode }from'react'import{ panel,type PanelValue }from'@master/ui/behaviors/panel.js'import{ useBehavior }from'./use-behavior'exporttype{ PanelValue }exportinterfacePanelPropsextendsOmit<ComponentProps<'div'>,'title'|'defaultValue'|'popover'|'role'|'ref'>{/** The title in the header, which names the panel. */title:ReactNode/** The name of the handle: what it moves and how, such as "Move the Layers panel with the arrow keys". */handleLabel:string/** Whether the panel is open, when this component is told. Leave it out and the trigger opens it. */open?:booleanonOpenChange?:(open:boolean)=>void/** Where the panel is, how large and whether it is folded. Keep it to put the panel back where it was. */value?:PanelValuedefaultValue?:PanelValue/** Called as the panel moves, resizes or folds. */onValueChange?:(value:PanelValue)=>void/** Called once a drag ends, a key moved it or it was folded: the moment to keep the value. */onValueCommit?:(value:PanelValue)=>void/** The button that opens the panel: spread what it is given on a button of your own. */trigger?:(attributes:{commandfor:string,command:'toggle-popover'})=>ReactNode/** More controls in the header, before the minimize and close buttons. */actions?:ReactNodeminimizeLabel?:stringcloseLabel?:string/** Leave out the corner that resizes it. */resizable?:boolean/** How far an arrow key moves or resizes the panel, in pixels. */step?:number}const measures =['x','y','width','height']asconst/** * A floating panel. The browser opens it from the trigger and puts it in the top layer; the behavior moves, * resizes, folds and stacks it. This component opens and closes it from `open`, and passes its place in and out. */exportfunctionPanel({ title, handleLabel, open, onOpenChange, value, defaultValue, onValueChange, onValueCommit, trigger, actions, minimizeLabel ='Minimize', closeLabel ='Close', resizable =true, step =16, className, id, style, children,...root }:PanelProps){const generated =useId()const name = id ?? generatedconst[first]=useState(value ?? defaultValue)const latest =useRef(first)const ref =useBehavior(panel,{ step },{ value, defaultValue,onValueChange:(next:PanelValue)=>{ latest.current= next;onValueChange?.(next)},// The panel says change once a move ends. A field in its body says change too.on:{change:(event)=>{if(event.target=== event.currentTarget)onValueCommit?.(latest.current!)}},})const element =useRef<HTMLDivElement|null>(null)const heard =useRef(onOpenChange)/** What the owner knows: the last state it set or was told. */const known =useRef(false)const[tick, again]=useReducer((count:number)=> count +1,0)useEffect(()=>{ heard.current= onOpenChange })useEffect(()=>{const popover = element.currentif(!popover || open ===undefined)returnconst shown = popover.matches(':popover-open') known.current= openif(open &&!shown) popover.showPopover()elseif(!open && shown) popover.hidePopover()},[open, tick])useEffect(()=>{const popover = element.currentif(!popover)returnconstreport=()=>{const shown = popover.matches(':popover-open')if(shown !== known.current) heard.current?.(known.current= shown)// An `open` this component is told wins: if its owner did not take the change, the panel goes back.again()} popover.addEventListener('toggle', report)return()=> popover.removeEventListener('toggle', report)},[])// The first place and size are drawn into the first render; after that the behavior writes them.const place = Object.fromEntries(measures.filter(measure =>typeof first?.[measure]==='number').map(measure =>[`--panel-${measure}`,`${first![measure]}px`]))const attach =useCallback((node:HTMLDivElement|null)=>{ element.current= nodereturnref(node)},[ref])return(<>{trigger?.({commandfor: name,command:'toggle-popover'})}<divid={name}popover="manual"role="dialog"aria-labelledby={`${name}-title`}className={className ?`panel ${className}`:'panel'}style={{...place,...style }asCSSProperties}ref={attach}{...root}><divclassName="panel-header"><buttontype="button"className="panel-handle"aria-label={handleLabel}/><h2className="panel-title"id={`${name}-title`}>{title}</h2><divclassName="panel-actions">{actions}<buttontype="button"className="btn btn-quiet btn-sm btn-square panel-minimize"aria-pressed={first?.minimized??false}aria-label={minimizeLabel}><svgclassName="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"strokeWidth="1"strokeLinecap="round"strokeLinejoin="round"aria-hidden="true"><pathd="M3 8L13 8"/></svg></button><buttontype="button"className="btn btn-quiet btn-sm btn-square"{...{commandfor: name,command:'hide-popover'}}aria-label={closeLabel}><svgclassName="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"strokeWidth="1"strokeLinecap="round"strokeLinejoin="round"aria-hidden="true"><pathd="M4 4L12 12"/><pathd="M4 12L12 4"/></svg></button></div></div><divclassName="panel-body">{children}</div>{resizable &&<spanclassName="panel-resize"aria-hidden="true"/>}</div></>)}
ui/Panel.svelte
<scriptlang="ts"module>importtype{ Snippet }from'svelte'importtype{ HTMLAttributes }from'svelte/elements'importtype{ PanelValue }from'@master/ui/behaviors/panel.js'exporttype{ PanelValue }exportinterfacePanelPropsextendsOmit<HTMLAttributes<HTMLDivElement>,'title'|'popover'|'role'>{/** The title in the header, which names the panel. */title:string/** The name of the handle: what it moves and how, such as "Move the Layers panel with the arrow keys". */handleLabel:string/** Whether the panel is open. Bind it, or leave it out and the trigger opens it. */open?:booleanonOpenChange?:(open:boolean)=>void/** Where the panel is, how large and whether it is folded. Bind it to put the panel back where it was. */value?:PanelValue/** Called as the panel moves, resizes or folds. */onValueChange?:(value:PanelValue)=>void/** Called once a drag ends, a key moved it or it was folded: the moment to keep the value. */onValueCommit?:(value:PanelValue)=>void/** The button that opens the panel: spread what it is given on a button of your own. */trigger?:Snippet<[{commandfor:string,command:'toggle-popover'}]>/** More controls in the header, before the minimize and close buttons. */actions?:SnippetminimizeLabel?:stringcloseLabel?:string/** Leave out the corner that resizes it. */resizable?:boolean/** How far an arrow key moves or resizes the panel, in pixels. */step?:number}</script><scriptlang="ts">import{ untrack }from'svelte'importtype{ Attachment }from'svelte/attachments'import{ panel }from'@master/ui/behaviors/panel.js'import{ behavior }from'./behavior.svelte.js'let{ title, handleLabel, open =$bindable(), onOpenChange, value =$bindable(), onValueChange, onValueCommit, trigger, actions, minimizeLabel ='Minimize', closeLabel ='Close', resizable =true, step =16,class: className, id, children,...root }:PanelProps=$props()const generated =$props.id()const name =$derived(id ?? generated)const first =untrack(()=> value)// Svelte writes a style again whenever its owner changes it, so it writes the place the behavior holds.let held =$state(first)constpx=(measure:number|null|undefined)=>typeof measure ==='number'?`${measure}px`:undefinedconst attach =behavior(panel,()=>({ step }),{value:()=> value,change:(next)=>{ value = held = next;onValueChange?.(next)},settled:(kept)=>{ held = kept },// The panel says change once a move ends. A field in its body says change too.on:{change:(event)=>{if(event.target=== event.currentTarget&& held)onValueCommit?.(held)}},})/** What the owner knows: the last state it set or was told. */let known =falseconstpresence:Attachment<HTMLDivElement>=(popover)=>{constreport=()=>{const shown = popover.matches(':popover-open')if(shown === known)return open = known = shownonOpenChange?.(known)} popover.addEventListener('toggle', report)$effect(()=>{if(open ===undefined)returnconst shown = popover.matches(':popover-open') known = openif(open &&!shown) popover.showPopover()elseif(!open && shown) popover.hidePopover()})return()=> popover.removeEventListener('toggle', report)}</script><!--@component A floating panel. The browser opens it from the trigger and puts it in the top layer; the behavior moves, resizes, folds and stacks it. This component opens and closes it from `open`, and passes its place in and out.-->{@rendertrigger?.({commandfor: name,command:'toggle-popover'})}<divid={name}popover="manual"role="dialog"aria-labelledby="{name}-title"class={['panel', className]}style:--panel-x={px(held?.x)}style:--panel-y={px(held?.y)}style:--panel-width={px(held?.width)}style:--panel-height={px(held?.height)}{@attach attach}{@attach presence}{...root}><divclass="panel-header"><buttontype="button"class="panel-handle"aria-label={handleLabel}></button><h2class="panel-title"id="{name}-title">{title}</h2><divclass="panel-actions">{@renderactions?.()}<buttontype="button"class="btn btn-quiet btn-sm btn-square panel-minimize"aria-pressed={first?.minimized??false}aria-label={minimizeLabel}><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M3 8L13 8"/></svg></button><buttontype="button"class="btn btn-quiet btn-sm btn-square"commandfor={name}command="hide-popover"aria-label={closeLabel}><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M4 4L12 12"/><pathd="M4 12L12 4"/></svg></button></div></div><divclass="panel-body">{@renderchildren?.()}</div>{#if resizable}<spanclass="panel-resize"aria-hidden="true"></span>{/if}</div>
ui/Panel.vue
<scriptsetuplang="ts">import{ computed, nextTick, onMounted, useId, useTemplateRef, watch }from'vue'import{ panel,type PanelValue }from'@master/ui/behaviors/panel.js'import{ useBehavior }from'./use-behavior'defineOptions({inheritAttrs:false})const{ id, title, handleLabel, minimizeLabel ='Minimize', closeLabel ='Close', resizable =true, step =16}=defineProps<{id?:string/** The title in the header, which names the panel. */title:string/** The name of the handle: what it moves and how, such as "Move the Layers panel with the arrow keys". */handleLabel:stringminimizeLabel?:stringcloseLabel?:string/** Leave out the corner that resizes it. */resizable?:boolean/** How far an arrow key moves or resizes the panel, in pixels. */step?:number}>()/** Where the panel is, how large and whether it is folded: `v-model`. Keep it to put the panel back where it was. */const model =defineModel<PanelValue>()/** Whether the panel is open: `v-model:open`. Leave it out and the trigger opens it. */const open =defineModel<boolean>('open')const emit =defineEmits<{/** The value, once a drag ends, a key moved it or it was folded: the moment to keep it. */valueCommit:[value:PanelValue]}>()defineSlots<{/** The button that opens the panel: bind what it is given on a button of your own. */trigger?:(attributes:{commandfor:string,command:'toggle-popover'})=>unknown/** More controls in the header, before the minimize and close buttons. */actions?:()=>unknowndefault?:()=>unknown}>()/* * A floating panel. The browser opens it from the trigger and puts it in the top layer; the behavior moves, * resizes, folds and stacks it. This component opens and closes it from `open`, and passes its place in and out. */const generated =useId()const name =computed(()=> id ?? generated)const first = model.valueconst root =useTemplateRef<HTMLDivElement>('root')const current =useBehavior(root, panel,()=>({ step }), model,{// The panel says change once a move ends. A field in its body says change too.change:(event)=>{const held =current()if(event.target=== root.value&& held)emit('valueCommit', held)},})// Vue writes a style again each time it renders, so it writes the place the behavior holds, not the first one.constplace=()=>{const held =current()?? firstconstpx=(measure:number|null|undefined)=>typeof measure ==='number'?`${measure}px`:undefinedreturn{'--panel-x':px(held?.x),'--panel-y':px(held?.y),'--panel-width':px(held?.width),'--panel-height':px(held?.height)}}/** What the owner knows: the last state it set or was told. */let known =falseconstsync=()=>{const popover = root.valueif(!popover || open.value===undefined)returnconst shown = popover.matches(':popover-open') known = open.valueif(open.value&&!shown) popover.showPopover()elseif(!open.value&& shown) popover.hidePopover()}constreport=()=>{const popover = root.valueif(!popover)returnconst shown = popover.matches(':popover-open')if(shown !== known) open.value= known = shown// An `open` this component is told wins: if its owner did not take the change, the panel goes back.voidnextTick(sync)}onMounted(sync)watch(open, sync,{flush:'post'})</script><template><slotname="trigger"v-bind="{commandfor: name,command:'toggle-popover'asconst}" /><div:id="name"popover="manual"role="dialog":aria-labelledby="`${name}-title`"class="panel":style="place()"ref="root"v-bind="$attrs"@toggle="report"><divclass="panel-header"><buttontype="button"class="panel-handle":aria-label="handleLabel" /><h2class="panel-title":id="`${name}-title`">{{ title }}</h2><divclass="panel-actions"><slotname="actions" /><buttontype="button"class="btn btn-quiet btn-sm btn-square panel-minimize":aria-pressed="first?.minimized??false":aria-label="minimizeLabel"><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M3 8L13 8"/></svg></button><buttontype="button"class="btn btn-quiet btn-sm btn-square":commandfor="name"command="hide-popover":aria-label="closeLabel"><svgclass="icon"viewBox="0 0 16 16"fill="none"stroke="currentColor"stroke-width="1"stroke-linecap="round"stroke-linejoin="round"aria-hidden="true"><pathd="M4 4L12 12"/><pathd="M4 12L12 4"/></svg></button></div></div><divclass="panel-body"><slot /></div><spanv-if="resizable"class="panel-resize"aria-hidden="true" /></div></template>
떠 있는 시트로, role="dialog"를 지정한 popover="manual" 요소이며 aria-labelledby로 제목을 이름으로 지정합니다. --panel-x와 --panel-y가 가리키는 위치에 뷰포트를 벗어나지 않도록 놓이며, 따로 지정하지 않으면 너비는 20rem입니다. 위치를 지정하지 않으면 위쪽 끝 모서리에 놓입니다.
panel-header
위쪽의 막대로, 시작 쪽에 제목을, 끝 쪽에 동작 버튼을 두고 둘 아래에 핸들을 깝니다. 뷰포트를 절대 벗어나지 않는 부분입니다.
panel-handle
헤더 크기의 버튼으로, 헤더의 첫 번째 요소이며 패널을 옮깁니다. 막대에서 컨트롤이 아닌 곳을 끌면 패널이 움직이고, 이 버튼에 포커스가 있으면 방향키로 패널을 옮길 수 있습니다. "방향키로 레이어 패널 옮기기"처럼 무엇을 어떻게 옮기는지 이름을 지정하세요. 포커스를 받으면 패널 전체에 링이 표시됩니다.
panel-title
한 줄로 표시하는 제목입니다. 패널의 aria-labelledby가 이 요소를 가리키게 하세요. 포인터 입력을 받지 않으므로 제목을 누르면 핸들에 전달됩니다.
panel-actions
헤더 끝 쪽, 핸들 위에 놓이는 컨트롤로, 작고 강조를 줄인 정사각형 버튼입니다.
panel-minimize
패널을 헤더만 남도록 접는 버튼입니다. 누르면 오목한 영역 안에 들어간 모양이 되며, 본문과 모서리가 숨겨집니다.
panel-body
패널의 내용으로, 가는 구분선 아래에 놓이고 둘레에 --panel-padding만큼 여백을 둡니다. 본문이 길면 패널 안에서 스크롤됩니다. 패널을 접으면 본문이 숨겨지므로 내용의 레이아웃은 본문 안의 요소에서 잡으세요.
panel-resize
포인터로 패널 크기를 조절하는 아래쪽 끝 모서리입니다. 조작 영역은 16px이며 터치 화면에서는 44px입니다. 키보드로는 핸들에서 크기를 조절하므로 보조 기술에서는 숨기세요.
/* * Panel: a floating surface the reader moves, resizes, folds to its header and closes, while the page under it * stays usable: layers beside a canvas, a color picker, an inspector, a chat. It is a popover="manual" in the * top layer, so it floats over everything without a z-index; panels stack in the order they were shown, and the * behavior brings the one the reader reaches into to the front. * * Material: the floating sheet of a popover, with the floating shadow, and the overlay shadow while it is held, * so a panel being dragged rises a step. The header is a bar of the same sheet over a hairline; its whole face is * one button, the handle, so a press anywhere on the bar that is not a control picks the panel up, and focus on * the handle rings the panel the keys move. * * Geometry: the header holds small (32px) buttons 6px from its edges, so the panel's corner is a small control's * corner plus that inset, 14px. On touch a button's 44px target reaches those 6px, to the header's edge. The panel is 20rem wide unless told otherwise, never narrower than 12rem. * * Placement is the stylesheet's. A script writes what only an event knows, the place and the size asked for * (--panel-x, --panel-y, --panel-width, --panel-height); the stylesheet clamps them to the viewport, the box a * fixed element's percentages are read from, so a panel is never wider or taller than the window, the whole of * its width stays in it and its header can never leave it. The window narrowing pushes a panel in; widening it * again lets the panel go back to the place it was given. Without a place, a panel opens at the top end corner. */@layer components.ui {.panel{--panel-x:100%;--panel-y:0px;--panel-width:20rem;--panel-height:auto;--panel-min-width:12rem;--panel-gutter:.5rem;--panel-inset:.375rem;/* The inset is added after the corner scale, so it is passed divided by it. */--panel-radius:calc(var(--radius-control-sm)+var(--panel-inset)/var(--corner-scale));--panel-padding:1rem;/* The header's height: a small button and the inset around it. The part of the panel that never leaves the viewport. */--panel-bar:calc(2rem+2*var(--panel-inset));/* The width it is drawn at: the width asked for, no less than the least, no more than the viewport gives. */--panel-drawn-width:min(max(var(--panel-min-width),var(--panel-width)),100%-2*var(--panel-gutter));--surface-color:var(--color-surface-floating);position:fixed;inset:auto;top:clamp(var(--panel-gutter),var(--panel-y),100%-var(--panel-bar)-var(--panel-gutter));left:clamp(var(--panel-gutter),var(--panel-x),100%-var(--panel-drawn-width)-var(--panel-gutter));flex-direction:column;width:var(--panel-drawn-width);height:var(--panel-height);min-height:var(--panel-bar);max-height:calc(100%-2*var(--panel-gutter));margin:0;padding:0;border:0;border-radius:calc(var(--panel-radius)*var(--corner-scale));corner-shape:var(--corner-shape);/* The header's tone and the body's scroll are finished by the panel's corner. */overflow:clip;background:var(--color-surface-floating);color:var(--color-text-body);box-shadow:var(--shadow-floating);font-size:.875rem;line-height:1.5;transform-origin:top;@apply--pop;transition-property: opacity, scale, box-shadow,overlay, display;/* With no place given, a panel from right to left opens at the top left. */&:dir(rtl){--panel-x:0px;}&:popover-open{display:flex;}/* Held by its handle or its corner: it rises to the overlay shadow, and the drag selects nothing. */&:has(.panel-handle:active:not(:disabled,[aria-disabled="true"]),.panel-resize:active:not([aria-disabled="true"])){box-shadow:var(--shadow-overlay);user-select:none;-webkit-user-select:none;}/* The keys move the whole panel, so focus on its handle rings the whole panel. */&:has(.panel-handle:focus-visible){@apply--focus-ring;}/* * Folded to its header: only as tall as the header, with no body and no corner to resize from. The body is * hidden from sight, focus and assistive technology even where a utility gives it a display of its own. */&:has(.panel-minimize[aria-pressed="true"]){height:var(--panel-bar);.panel-body,.panel-resize{display:none;visibility:hidden;}}@media(forced-colors:active){outline:1pxsolid CanvasText;outline-offset:-1px;&:has(.panel-handle:focus-visible){outline:2pxsolid Highlight;outline-offset:2px;}}}/* The header: the title at the start, the actions at the end, and the handle under both. */.panel-header{position:relative;display:flex;flex:none;align-items:center;gap:.25rem;min-height:var(--panel-bar);padding:var(--panel-inset);padding-inline-start:.875rem;}/* * The handle: a button the size of the header, under the title and the actions, so the bar is what the hand * grabs. It draws nothing of its own; its focus is drawn on the panel. */.panel-handle{position:absolute;inset:0;margin:0;padding:0;border:0;border-radius:0;outline:none;background:transparent;color:inherit;appearance:none;cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent;&:active:not(:disabled,[aria-disabled="true"]){cursor:grabbing;}/* A handle the page turned off carries nothing, so it does not offer the hand. */&:is(:disabled,[aria-disabled="true"]){cursor:default;}}/* The title takes no pointer, so a press on it reaches the handle under it. */.panel-title{flex:11auto;min-width:0;margin:0;overflow:hidden;color:var(--color-text-strong);font:var(--font-weight-control).875rem/1.25var(--font-family-sans);font-feature-settings:inherit;text-overflow:ellipsis;white-space:nowrap;pointer-events:none;}/* The controls at the end of the header, over the handle. */.panel-actions{position:relative;display:inline-flex;flex:none;align-items:center;gap:2px;margin-inline-start:auto;}/* The two stand 2px apart: on touch each target grows above and below only, so Close does not answer for Minimize. */@media(pointer:coarse){.panel-actions.btn::after{@apply--touch-target-block;}}/* The minimize button is a quiet toggle: pressed, it sits in a well, and the panel is folded to its header. */.panel-minimize{flex:none;}/* What the panel holds, under a hairline. A long body scrolls inside the panel. */.panel-body{flex:11auto;min-height:0;padding:var(--panel-padding);border-block-start:1pxsolidvar(--color-line-hair);overflow:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:var(--color-line-strong)transparent;}/* * The corner a pointer resizes from, at the bottom end: two short diagonal lines in the ink of a firm line, * on a 16px target, 44px on touch screens. The keys resize from the handle. */.panel-resize{position:absolute;inset-block-end:0;inset-inline-end:0;width:1rem;height:1rem;color:var(--color-line-mark);cursor:nwse-resize;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent;transition:colorvar(--duration-quick)var(--easing-glide);&::before{content:'';position:absolute;inset-block-end:.3125rem;inset-inline-end:.3125rem;width:.5rem;height:.5rem;background:linear-gradient(135deg,transparent38%,currentColor38%50%,transparent50%70%,currentColor70%82%,transparent82%);}&:dir(rtl){cursor:nesw-resize;&::before{scale:-11;}}@media(hover:hover){&:hover{color:var(--color-text-muted);}}&:active{color:var(--color-text-strong);}@media(pointer:coarse){width:2.75rem;height:2.75rem;color:var(--color-text-muted);}/* A corner the page turned off resizes nothing: it keeps its place in disabled ink and offers no resize. */&[aria-disabled="true"]{color:var(--color-text-disabled);cursor:default;}/* The two lines are a gradient, which forced colors would drop: kept out of them, in the system's text color. */@media(forced-colors:active){forced-color-adjust:none;color: CanvasText;}}}