Skip to main content
Decoderen
Browse documentation

Section

Group related page content with shared vertical rhythm, a container and a surface context.

SM spacing

sm spacing

Show code
Example.astroAstro
---
import Section from '@dhekode/ui/patterns/Section.tsx';
---

<Section size="sm" surface="steel" labelledby="spacing-sm">
  <h3 id="spacing-sm">sm spacing</h3>
</Section>

MD spacing

md spacing

Show code
Example.astroAstro
---
import Section from '@dhekode/ui/patterns/Section.tsx';
---

<Section size="md" surface="steel" labelledby="spacing-md">
  <h3 id="spacing-md">md spacing</h3>
</Section>

LG spacing

lg spacing

Show code
Example.astroAstro
---
import Section from '@dhekode/ui/patterns/Section.tsx';
---

<Section size="lg" surface="steel" labelledby="spacing-lg">
  <h3 id="spacing-lg">lg spacing</h3>
</Section>

Surfaces

Off-white

Paper

Steel

Navy

Ink

Show code
Example.astroAstro
---
import Section from '@dhekode/ui/patterns/Section.tsx';
---

<Section size="sm" surface="canvas" labelledby="section-canvas">
  <h3 id="section-canvas">Off-white</h3>
</Section>
<Section size="sm" surface="subtle" labelledby="section-subtle">
  <h3 id="section-subtle">Paper</h3>
</Section>
<Section size="sm" surface="steel" labelledby="section-steel">
  <h3 id="section-steel">Steel</h3>
</Section>
<Section size="sm" surface="brand" labelledby="section-brand">
  <h3 id="section-brand">Navy</h3>
</Section>
<Section size="sm" surface="inverse" labelledby="section-inverse">
  <h3 id="section-inverse">Ink</h3>
</Section>

Nested surface

Brand content

Canvas content
Show code
Example.astroAstro
---
import Section from '@dhekode/ui/patterns/Section.tsx';
---

<Section size="sm" surface="brand">
  <div class="dk-stack">
    <p>Brand content</p>
    <div class="dk-demo-inset" data-surface="canvas">Canvas content</div>
  </div>
</Section>
<style>
  .dk-demo-inset { padding: var(--dk-space-lg); }
</style>
API reference
size

Type: 'sm' | 'md' | 'lg'

Default: 'md'

Vertical spacing; exact values come from tokens.

surface

Type: 'canvas' | 'subtle' | 'steel' | 'brand' | 'inverse'

Default: 'canvas'

Sets inherited text, action and feedback roles.

id

Type: string

Default: unset

Section anchor.

labelledby

Type: string

Default: unset

ID of the heading that names the section; it is not the section ID.

className

Type: string | undefined

Default: unset

Adds classes to the React component root, after its own utilities. React components take className, not class.

Slots: Default: section content, usually beginning with SectionHeading.

Use sections for meaningful groups. Avoid nesting full Section containers merely to create a card; use a local wrapper with data-surface for that.

Original component source
packages/ui/src/patterns/Section.tsxAstro
import type { ReactNode } from 'react';
import { classNames } from '@dhekode/utils/class-names';

export interface SectionProps {
  size?: 'sm' | 'md' | 'lg' | undefined;
  surface?: 'canvas' | 'subtle' | 'steel' | 'brand' | 'inverse' | undefined;
  /** id of the heading that names this section. */
  labelledby?: string | undefined;
  id?: string | undefined;
  className?: string | undefined;
  children: ReactNode;
}

/**
 * Vertical page section with a constrained container. Its rhythm (`dk-section`, `data-size`) and
 * surface (`data-surface`) come from @dhekode/styles, so nested components follow the surface.
 */
export default function Section({
  size = 'md',
  surface = 'canvas',
  labelledby,
  id,
  className,
  children,
}: SectionProps) {
  return (
    <section
      id={id}
      className={classNames('dk-section', className)}
      data-size={size}
      data-surface={surface}
      aria-labelledby={labelledby}
    >
      <div className="dk-container">{children}</div>
    </section>
  );
}

Best practices

  • Name meaningful sections with a heading.
  • Choose surfaces for grouping and contrast; avoid adding decoration to every section.