Surface
A semantic flex container with theme tints, opt-in glass, shared spacing, corner rounding and optional scrolling.
Usage
Details
Content inside the surface.
<script>
import { Surface } from 'bref-ui';
</script>
<Surface as="section" variant="soft" spacing="medium" radius="small">
<h2>Details</h2>
<p>Content inside the surface.</p>
</Surface>
Render Theme once to load the shared paint recipes. The typed surface helper applies the same
recipes to native HTML; pass glass: true for translucent material. Component styles supply padding, radius and layout.
<script>
import { Theme, surface } from 'bref-ui';
</script>
<Theme />
<button class={surface({ variant: 'filled', color: 'primary', shadow: 'small', hover: 'medium' })}>
Save
</button>
Playground
Explore paint and layout together. The preview has a fixed height for fill and scrolling.
Live preview
Settings
View generated code
<Surface
as="div"
variant="soft"
color="background"
glass={false}
spacing={'medium'}
orientation="vertical"
width="fill"
height="fit"
radius={'small'}
shadow={false}
hover={undefined}
scroll={false}
>
<strong>Surface</strong>
<span
>Long content stays readable and wraps within narrow layouts. Change the controls to explore the
container.</span
>
</Surface>
Colors and variants
Switch the shared theme control to compare light and dark. Filled uses a strong opaque color; background-tinted panels retain the foreground text color.
Contextual glass
Soft surfaces use an opaque tint. Add the glass prop when a panel sits above visual content; transparency and blur then belong to that panel alone. Keep controls inside it opaque to avoid nested blur. Reduced transparency, increased contrast and unsupported backdrop filtering use a solid fill.
The same helper also composes with native panel styling.
<Surface glass variant="soft" spacing="medium" radius="small">Panel content</Surface>
<button class={surface({ variant: 'soft', color: 'primary', hover: 'medium', glass: true })}>
Save
</button>
Spacing, dimensions and radius
- Design
- Development
Saved 0 times.
Scrolling and composition
Surface forwards native attributes and events to its root. Pass class, style, ARIA attributes and event handlers directly; content uses a Svelte children snippet. Explicit tabindex overrides the scroll focus default.
Focused 0 times.
<Surface
as="section"
id="details"
class="custom-surface"
style="font-style: italic;"
aria-label="Details"
tabindex={0}
onfocus={onFocus}
>
<p>Content inside the surface.</p>
</Surface>
Give the parent a fixed height and use height="fill" to constrain scrolling. A scrollable Surface can receive keyboard focus; use arrow keys to scroll.
Scrollable content, row 1.
Scrollable content, row 2.
Scrollable content, row 3.
Scrollable content, row 4.
Scrollable content, row 5.
Scrollable content, row 6.
Scrollable content, row 7.
Scrollable content, row 8.
Scrollable content, row 9.
Scrollable content, row 10.
Scrollable content, row 11.
Scrollable content, row 12.
<div style="height: 12rem;">
<Surface scroll height="fill">Content</Surface>
</div>
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
as | 'div' | 'section' | 'span' | No | div | Native root element. |
children | Snippet | No | Omitted | Content rendered directly inside the root. |
color | Color | No | background | Theme color; the shared recipe supplies content color. |
variant | Variant | No | neutral | Lightly tinted neutral, opaque tinted soft, or opaque filled panel. |
spacing | Size | No | Omitted | Shared padding and gap; omitted means zero. |
orientation | Orientation | No | vertical | Column, or row with centered cross-axis alignment. |
width | Dimension | No | fill | fill uses 100%; fit hugs content. |
height | Dimension | No | fit | fit uses natural height; fill uses 100% of a sized parent. |
radius | Size | `${number}rem` | `${number}%` | No | Omitted (0) | Named corner scale or an explicit rem/percentage radius. |
shadow | BaseSize | boolean | No | false | Shadow strength; true selects medium. |
hover | BaseSize | No | Omitted | Optional hover/focus treatment; does not make the root interactive. |
scroll | boolean | No | false | true sets overflow to auto; otherwise overflow stays visible. |
glass | boolean | No | false | Enable translucent paint and backdrop blur. |
Migration: pass native attributes directly to Surface; hover replaces hoverEffect. Replace capsule with a named size, a rem value, or a percentage radius. Use scroll for automatic overflow.