Skip to content

CdsSurface

New in v4.0

A surface is a container with a background from the tokens, sizes, positioning and a theme of its own. Take it when a block needs a design system background rather than a ready-made component: the backdrop of a panel, a plate, the base of your own component.

Storybook GitLab
Test coverage: 100% — good coverage
API in specs
12 / 12 props, events, slots and exposed members with a test
Test cases
12 unit · 0 browser
Code coverage
100% lines · 100% branches measured in v4.0.0-alpha.13
A11y (axe)
1 recommendations in 4 stories measured in v4.0.0-alpha.11

For a card with a title and actions take CdsCard, for the sections of a page take CdsLayout. CdsSurface is the lowest layer, without content or paddings of its own.

Variations ​

Color ​

The color prop sets the background from the theme tokens and picks a contrasting text color. Besides surface-*, any color of the palette and any CSS color will do. Which colors exactly hide behind the tokens is decided by the theme: the theme prop switches it for the surface and for everything inside it.

Sizes ​

The width, height, min-width, max-width, min-height and max-height props accept a number (pixels) or a string with any CSS unit.

Positioning ​

The position prop sets the CSS position, location pins the surface to an edge of the container — top end, bottom start, center. Together they build a plate on top of another block.

Scenarios ​

A summary panel ​

The surface gives the background and the sizes, while the paddings and the layout inside are up to you. The tag prop changes the tag of the wrapper — here it is section, so the block stays meaningful in the structure of the page.

API ​

Props

NameTypeDefaultDescription
colorstring | undefined—Background color of the surface
heightstring | number | undefined—Component height
locationAnchor | null | undefined—Position of the element relative to its container, for example "top left", "center", "bottom right".
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
position"absolute" | "static" | "fixed" | "relative" | "sticky" | undefined—CSS positioning of the component — the value of the position property
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
themestring | undefined—Component theme
widthstring | number | undefined—Component width

Slots

NameTypeDescription
defaultanyThe main content of the surface.