导航

v2.1.0
媒体

窗口

用应用窗口框呈现截图、演示或终端。

本页内容

窗口用应用程序的外框呈现截图、简短演示或几行终端输出。它是一块顶部带横栏的凸起面板。横栏上的三个标记采用与边线相同的中性色,让外框一眼可辨是个窗口,也把色彩留给其中的内容。

窗口

<figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">Atlas · Deployments</span>  </div>  <img class="window-body object-cover w-full" style="aspect-ratio: 16 / 10" src="/demo/moonstone.svg" alt="The deployments view of Atlas"></figure>
<figure className="window max-w(520) mx-auto">  <div className="window-bar">    <span className="window-controls" aria-hidden="true"></span>    <span className="window-title">Atlas · Deployments</span>  </div>  <img className="window-body object-cover w-full" style={{ aspectRatio: '16 / 10' }} src="/demo/moonstone.svg" alt="The deployments view of Atlas" /></figure>
<figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">Atlas · Deployments</span>  </div>  <img class="window-body object-cover w-full" style="aspect-ratio: 16 / 10" src="/demo/moonstone.svg" alt="The deployments view of Atlas"></figure>
<template>  <figure class="window max-w(520) mx-auto">    <div class="window-bar">      <span class="window-controls" aria-hidden="true"></span>      <span class="window-title">Atlas · Deployments</span>    </div>    <img class="window-body object-cover w-full" style="aspect-ratio: 16 / 10" src="/demo/moonstone.svg" alt="The deployments view of Atlas">  </figure></template>

#顶部栏

window-bar 分为三处。起始端放置 window-controls,一个绘制成三个圆点的空元素。中间放置 window-title,也可以放置 window-address,呈现类似浏览器地址栏的小凹槽。window-end 容纳末端的内容。各部分均可省略,两侧放置任何内容时,中间部分都保持居中。

地址栏

<figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-address">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="3" y="7" width="10" height="7" rx="1" /><path d="M5.5 7V4.5A2.5 2.5 0 0 1 10.5 4.5V7" /><path d="M8 9.5L8 11" />      </svg>atlas.dev/deployments    </span>    <span class="window-end"><span class="badge badge-sm badge-success badge-dot">Live</span></span>  </div>  <div class="window-body flex flex-col gap-sm p-lg">    <div class="skeleton skeleton-text w(180)"></div>    <div class="skeleton skeleton-text"></div>    <div class="skeleton skeleton-text w(320)"></div>    <div class="skeleton h(96) mt-xs"></div>  </div></figure>
import LockIcon from '@master/icons-react/native/16/soft/lock'<figure className="window max-w(520) mx-auto">  <div className="window-bar">    <span className="window-controls" aria-hidden="true"></span>    <span className="window-address"><LockIcon className="icon" />atlas.dev/deployments</span>    <span className="window-end">      <span className="badge badge-sm badge-success badge-dot">Live</span>    </span>  </div>  <div className="window-body flex flex-col gap-sm p-lg">    <div className="skeleton skeleton-text w(180)"></div>    <div className="skeleton skeleton-text"></div>    <div className="skeleton skeleton-text w(320)"></div>    <div className="skeleton h(96) mt-xs"></div>  </div></figure>
<script>  import LockIcon from '@master/icons-svelte/native/16/soft/lock'</script><figure class="window max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-address"><LockIcon class="icon" />atlas.dev/deployments</span>    <span class="window-end"><span class="badge badge-sm badge-success badge-dot">Live</span></span>  </div>  <div class="window-body flex flex-col gap-sm p-lg">    <div class="skeleton skeleton-text w(180)"></div>    <div class="skeleton skeleton-text"></div>    <div class="skeleton skeleton-text w(320)"></div>    <div class="skeleton h(96) mt-xs"></div>  </div></figure>
<script setup>import LockIcon from '@master/icons-vue/native/16/soft/lock'</script><template>  <figure class="window max-w(520) mx-auto">    <div class="window-bar">      <span class="window-controls" aria-hidden="true"></span>      <span class="window-address"><LockIcon class="icon" />atlas.dev/deployments</span>      <span class="window-end">        <span class="badge badge-sm badge-success badge-dot">Live</span>      </span>    </div>    <div class="window-body flex flex-col gap-sm p-lg">      <div class="skeleton skeleton-text w(180)"></div>      <div class="skeleton skeleton-text"></div>      <div class="skeleton skeleton-text w(320)"></div>      <div class="skeleton h(96) mt-xs"></div>    </div>  </figure></template>

#内容区

window-body 没有内边距,图片或视频会紧贴外框,并沿窗口自身的圆角裁切。使用内边距工具类为文字留出空间。将类直接加在承载内容的元素上,例如 <img>、<video>、<pre> 或 <div>。

window-flat 仅保留一道轮廓并去掉阴影,适合放在托盘上,或放在内容密集的页面中与其他元素并列展示。

终端

<figure class="window window-flat max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">zsh</span>  </div>  <pre class="window-body p-md font-mono text-xs leading-lg fg-text-strong overflow-x-auto"><span class="fg-text-muted">$</span> npm install @master/css @master/ui<span class="fg-text-muted">added 2 packages in 1.4s</span><span class="fg-text-muted">$</span> npm run dev</pre></figure>
<figure class="window window-flat max-w(520) mx-auto">  <div class="window-bar">    <span class="window-controls" aria-hidden="true"></span>    <span class="window-title">zsh</span>  </div>  <pre class="window-body p-md font-mono text-xs leading-lg fg-text-strong overflow-x-auto"><span class="fg-text-muted">$</span> npm install @master/css @master/ui<span class="fg-text-muted">added 2 packages in 1.4s</span><span class="fg-text-muted">$</span> npm run dev</pre></figure>
<template>  <figure class="window window-flat max-w(520) mx-auto">    <div class="window-bar">      <span class="window-controls" aria-hidden="true"></span>      <span class="window-title">zsh</span>    </div>    <pre class="window-body p-md font-mono text-xs leading-lg fg-text-strong overflow-x-auto"><span class="fg-text-muted">$</span> npm install @master/css @master/ui<span class="fg-text-muted">added 2 packages in 1.4s</span><span class="fg-text-muted">$</span> npm run dev</pre>  </figure></template>

#无障碍

  • 外框仅作装饰。用 aria-hidden="true" 隐藏 window-controls,其中的圆点仅供装饰,没有按钮功能。
  • 如果窗口用于说明周围的正文,可以用 <figure> 包裹它。需要说明文字时,在同一容器内、窗口之后添加 <figcaption>。
  • 在截图的 alt 中描述截图。顶部栏的标题属于画面的一部分,仍需提供这段描述。
  • 请勿用此组件构建可交互的对话框。需要在页面上方打开窗口时,使用对话框。

#类名

类名说明
window采用 12px 圆角的凸起面板框架,裁切超出边缘的内容。
window-flat用于托盘上或紧凑页面中的窗口,只有一道轮廓,无阴影。与 window 一同使用
window-bar顶部横栏,起始端放标记,中间放标题或地址,末端为控件预留空间。
window-controls用一个空元素在横栏起始端绘制三个标记。为该元素设置 aria-hidden="true",使辅助技术忽略它。
window-title在栏中央单行显示标题
window-address在栏中央的小凹槽中显示地址,替代标题。
window-end横栏末端的内容
window-body窗口显示的内容,可以是图像、视频、pre 或 div,无内边距

#自定义属性

属性默认值说明
--window-radiusvar(--radius-control-lg)框架的圆角
--window-bar-height2.5rem横栏高度

#源码

@master/ui/components/window.css
/* * Window: the frame of an application around a screenshot, a demo or a few lines of a terminal. * A lifted sheet with a 12px corner. Its bar is a quieter tone over a hairline and carries three marks at * the start, drawn from one element in the ink of a line, with no hue: the frame says "this is a window" * and leaves the color to what it shows. A title stands in the middle of the bar, or an address in a small * well. The body is cut by the window's own corner, so a picture runs to the edge. */@layer components.ui {  .window {    --window-radius: var(--radius-control-lg);    --window-bar-height: 2.5rem;    --surface-color: var(--color-surface-raised);    position: relative;    display: flex;    flex-direction: column;    min-width: 0;    margin: 0;    border-radius: calc(var(--window-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    /* The bar's tone and a picture in the body are finished by the window's corner. */    overflow: clip;    background: var(--color-surface-raised);    color: var(--color-text-body);    box-shadow: var(--shadow-lifted);    /* One contour and no lift, for a window on a tray or in a dense page. */    &.window-flat {      box-shadow: var(--shadow-flat);    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* The bar: the marks at the start, the title or the address in the middle, and room for a control at the end. */  .window-bar {    display: grid;    flex: none;    /* The sides never shrink below what they hold, so a long title is cut instead of running under the marks. */    grid-template-columns: minmax(min-content, 1fr) auto minmax(min-content, 1fr);    align-items: center;    gap: .75rem;    min-height: var(--window-bar-height);    padding: 0 .875rem;    border-block-end: 1px solid var(--color-line-hair);    @apply --surface-sheet;    box-shadow: inset 0 1px 0 var(--color-highlight);  }  /* Three marks, 11px each, 8px apart: discs of the line ink with a faint edge of their own. */  .window-controls {    --window-mark: var(--color-line-strong);    display: block;    width: 3.0625rem;    height: .6875rem;    background:      radial-gradient(circle at 5.5px 50%, var(--window-mark) 5px, transparent 5.5px),      radial-gradient(circle at 24.5px 50%, var(--window-mark) 5px, transparent 5.5px),      radial-gradient(circle at 43.5px 50%, var(--window-mark) 5px, transparent 5.5px);    @media (forced-colors: active) {      --window-mark: CanvasText;      forced-color-adjust: none;    }  }  .window-title {    grid-column: 2;    max-width: 100%;    margin: 0;    overflow: hidden;    color: var(--color-text-muted);    font: var(--font-weight-control) .8125rem/1.2 var(--font-family-sans);    font-feature-settings: inherit;    text-align: center;    text-overflow: ellipsis;    white-space: nowrap;  }  /* An address instead of a title: a small well in the middle of the bar, as a browser has. */  .window-address {    --icon-size: .75rem;    display: inline-flex;    grid-column: 2;    align-items: center;    /* An address longer than the well keeps its start in view and is cut at its end. */    justify-content: safe center;    gap: .375rem;    width: min(100%, 16rem);    min-width: 0;    height: 1.625rem;    padding: 0 .75rem;    border-radius: calc((var(--window-radius) - .25rem) * var(--corner-scale));    corner-shape: var(--corner-shape);    overflow: hidden;    background: var(--color-surface-inset);    color: var(--color-text-muted);    box-shadow: var(--shadow-pressed);    font: 400 .75rem/1 var(--font-family-sans);    font-feature-settings: inherit;    text-overflow: ellipsis;    white-space: nowrap;    /* Shadows are not drawn here, so the well keeps its edge as a rule. */    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* What stands at the end of the bar. */  .window-end {    display: inline-flex;    grid-column: 3;    align-items: center;    justify-content: flex-end;    gap: .25rem;    min-width: 0;    color: var(--color-text-muted);  }  /* What the window shows. It has no padding: a picture or a video meets the frame. */  .window-body {    display: block;    flex: 1 1 auto;    min-width: 0;    min-height: 0;    margin: 0;  }}