menumenu_openMDC

Shape

descriptionREADMEwidgetsDemo

Material Design 3 Expressive Shape component and geometry library, ported 1:1 from Android androidx.graphics.shapes (RoundedPolygon, Morph, Shapes.kt) and Jetpack Compose MaterialShapes + MotionScheme.

Features

  • All 35 MaterialShapes: circle, square, slanted, arch, fan, arrow, semi-circle, oval, pill, triangle, diamond, clam-shell, pentagon, gem, sunny, very-sunny, cookie-4-sided, cookie-6-sided, cookie-7-sided, cookie-9-sided, cookie-12-sided, ghostish, clover-4-leaf, clover-8-leaf, burst, soft-burst, boom, soft-boom, flower, puffy, puffy-diamond, pixel-circle, pixel-triangle, bun, heart.
  • Parametric Shapes.kt Builders: polygon, star, rectangle, pill-star plus custom RoundedPolygon / vertices.
  • Interruptible Spring Transitions: Powered by Compose's analytic SpringSimulation and MotionScheme (expressive / standard × fast / default / slow). Reversing mid-flight preserves $C^1$ position and velocity continuity; switching to a third shape mid-flight snapshots the exact intermediate RoundedPolygon via Morph.toPolygon().
  • State-Driven Morphing: hover-shape, focus-shape, pressed-shape, selected-shape, and disabled-shape with priority disabled > pressed > selected > focused > hovered > base.
  • Content Clipping: Slotted media, icons, and text are clipped to the live morphed outline via clip-path: path(...).
  • Manual Scrubbing & Autoplay: Use morph-to + progress to scrub any Morph, or autoplay + sequence to cycle shapes continuously.

Usage

<!-- State-driven interactive shape toggle -->
<mdc-shape
    interactive
    toggle
    shape="square"
    hover-shape="cookie-4-sided"
    pressed-shape="soft-burst"
    selected-shape="heart"
    motion-scheme="expressive"
    motion-speed="fast"
>
    <mdc-icon name="favorite"></mdc-icon>
</mdc-shape>

<!-- Scrubbed morph -->
<mdc-shape shape="circle" morph-to="sunny" progress="0.5"></mdc-shape>
import { MaterialShapes, Morph, MotionScheme } from '@sandlada/mdc/components/shape/index'

const morph = new Morph(MaterialShapes.Circle, MaterialShapes.Heart)
const cubics = morph.asCubics(0.5)

Autoplay

Code
<div style="display: flex; flex-wrap: wrap; gap: 24px; align-items: center;">
    <mdc-shape
        autoplay
        interval="800"
        spin-per-step="45"
        motion-scheme="expressive"
        motion-speed="fast"
        variant="filled"
        color="primary"
        size="large"
    ></mdc-shape>

    <mdc-shape
        autoplay
        interval="1100"
        sequence="heart,clover-4-leaf,flower,puffy-diamond,sunny"
        motion-scheme="expressive"
        motion-speed="default"
        variant="tonal"
        color="tertiary"
        size="large"
    >
        <mdc-icon name="auto_awesome"></mdc-icon>
    </mdc-shape>
</div>

Content

Code
<div style="display: flex; flex-wrap: wrap; gap: 20px; align-items: center;">
    <mdc-shape
        interactive
        toggle
        shape="clover-4-leaf"
        hover-shape="flower"
        pressed-shape="soft-burst"
        selected-shape="heart"
        motion-scheme="expressive"
        motion-speed="fast"
        variant="transparent"
        style="width: 112px; height: 112px;"
        aria-label="Clipped gradient artwork"
    >
        <div style="width: 100%; height: 100%; background: linear-gradient(135deg, #6750a4, #e8def8, #7d5260); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,0.4);">
            MD3E
        </div>
    </mdc-shape>

    <mdc-shape
        interactive
        shape="arch"
        hover-shape="cookie-7-sided"
        pressed-shape="circle"
        variant="outlined"
        color="primary"
        style="width: 112px; height: 112px;"
        aria-label="Clipped outlined container"
    >
        <div style="width: 100%; height: 100%; background: radial-gradient(circle at 30% 30%, #ffd8e4, #6750a4); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600;">
            Clip
        </div>
    </mdc-shape>
</div>

Interactive

Code
<div style="display: flex; flex-wrap: wrap; gap: 20px; align-items: center;">
    <mdc-shape
        interactive
        toggle
        shape="square"
        hover-shape="cookie-4-sided"
        focus-shape="pentagon"
        pressed-shape="soft-burst"
        selected-shape="heart"
        motion-scheme="expressive"
        motion-speed="fast"
        variant="filled"
        color="primary"
        size="large"
        aria-label="Toggle favorite shape"
    >
        <mdc-icon name="favorite"></mdc-icon>
    </mdc-shape>

    <mdc-shape
        interactive
        toggle
        shape="circle"
        hover-shape="clover-4-leaf"
        pressed-shape="sunny"
        selected-shape="flower"
        motion-scheme="expressive"
        motion-speed="default"
        variant="tonal"
        color="secondary"
        size="large"
        aria-label="Toggle bookmark shape"
    >
        <mdc-icon name="star"></mdc-icon>
    </mdc-shape>

    <mdc-shape
        interactive
        toggle
        shape="pill"
        hover-shape="gem"
        pressed-shape="diamond"
        selected-shape="cookie-9-sided"
        motion-scheme="standard"
        motion-speed="fast"
        variant="outlined"
        color="tertiary"
        size="large"
        aria-label="Standard motion scheme toggle"
    >
        <mdc-icon name="bolt"></mdc-icon>
    </mdc-shape>

    <mdc-shape
        interactive
        disabled
        shape="square"
        disabled-shape="circle"
        variant="filled"
        size="large"
        aria-label="Disabled shape"
    >
        <mdc-icon name="block"></mdc-icon>
    </mdc-shape>
</div>

Morph

Code
<div style="display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 420px;">
    <div style="display: flex; align-items: center; gap: 24px;">
        <mdc-shape
            id="scrub-shape"
            shape="circle"
            morph-to="heart"
            progress="0.5"
            variant="filled"
            color="error"
            style="width: 96px; height: 96px;"
        ></mdc-shape>
        <mdc-shape
            id="scrub-shape-2"
            shape="square"
            morph-to="soft-burst"
            progress="0.5"
            variant="tonal"
            color="tertiary"
            style="width: 96px; height: 96px;"
        ></mdc-shape>
    </div>

    <label style="display: flex; align-items: center; gap: 12px; font-size: 13px;">
        <span>Progress (<code id="scrub-val">0.50</code>)</span>
        <input
            type="range"
            min="-0.15"
            max="1.15"
            step="0.01"
            value="0.5"
            style="flex: 1;"
            oninput="
                const r = this.getRootNode();
                const v = Number(this.value);
                r.querySelector('#scrub-shape').progress = v;
                r.querySelector('#scrub-shape-2').progress = v;
                r.querySelector('#scrub-val').textContent = v.toFixed(2);
            "
        />
    </label>
</div>

Parametric

Code
<div style="display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 440px;">
    <div style="display: flex; flex-wrap: wrap; gap: 20px; align-items: center;">
        <mdc-shape
            id="param-star"
            shape="star"
            sides="6"
            inner-radius="0.55"
            corner-radius="0.12"
            smoothing="0.4"
            variant="filled"
            color="primary"
            style="width: 96px; height: 96px;"
        ></mdc-shape>

        <mdc-shape
            id="param-polygon"
            shape="polygon"
            sides="5"
            corner-radius="0.2"
            smoothing="0.5"
            variant="tonal"
            color="secondary"
            style="width: 96px; height: 96px;"
        ></mdc-shape>

        <mdc-shape
            id="param-pill-star"
            shape="pill-star"
            sides="8"
            inner-radius="0.72"
            corner-radius="0.08"
            aspect-ratio="1.8"
            fit="fill"
            variant="outlined"
            color="tertiary"
            style="width: 144px; height: 80px;"
        ></mdc-shape>
    </div>

    <div style="display: flex; flex-direction: column; gap: 8px; font-size: 13px;">
        <label style="display: flex; align-items: center; gap: 12px;">
            <span style="width: 110px;">Sides (<code id="param-sides-val">6</code>)</span>
            <input
                type="range"
                min="3"
                max="12"
                step="1"
                value="6"
                style="flex: 1;"
                oninput="
                    const r = this.getRootNode();
                    const v = Number(this.value);
                    r.querySelector('#param-star').sides = v;
                    r.querySelector('#param-polygon').sides = v;
                    r.querySelector('#param-sides-val').textContent = String(v);
                "
            />
        </label>
        <label style="display: flex; align-items: center; gap: 12px;">
            <span style="width: 110px;">Inner Radius (<code id="param-ir-val">0.55</code>)</span>
            <input
                type="range"
                min="0.2"
                max="0.9"
                step="0.05"
                value="0.55"
                style="flex: 1;"
                oninput="
                    const r = this.getRootNode();
                    const v = Number(this.value);
                    r.querySelector('#param-star').innerRadius = v;
                    r.querySelector('#param-ir-val').textContent = v.toFixed(2);
                "
            />
        </label>
        <label style="display: flex; align-items: center; gap: 12px;">
            <span style="width: 110px;">Rounding (<code id="param-cr-val">0.12</code>)</span>
            <input
                type="range"
                min="0"
                max="0.45"
                step="0.02"
                value="0.12"
                style="flex: 1;"
                oninput="
                    const r = this.getRootNode();
                    const v = Number(this.value);
                    r.querySelector('#param-star').cornerRadius = v;
                    r.querySelector('#param-polygon').cornerRadius = v;
                    r.querySelector('#param-cr-val').textContent = v.toFixed(2);
                "
            />
        </label>
    </div>
</div>

Shape

Code
<div style="display: flex; flex-direction: column; gap: 20px; width: 100%;">
    <div style="display: flex; align-items: center; gap: 24px; flex-wrap: wrap;">
        <mdc-shape
            id="gallery-hero"
            shape="circle"
            variant="tonal"
            color="primary"
            motion-scheme="expressive"
            motion-speed="fast"
            style="width: 112px; height: 112px;"
        ></mdc-shape>
        <div style="display: flex; flex-direction: column; gap: 6px;">
            <div style="font-weight: 600;">35 Jetpack Compose MaterialShapes</div>
            <div style="font-size: 13px; opacity: 0.78;">
                Click any shape below to morph with an underdamped Expressive spring:
                <code id="gallery-active-name">circle</code>
            </div>
        </div>
    </div>

    <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px;">
        <mdc-shape interactive shape="circle" variant="surface" size="medium" title="circle" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'circle'; r.querySelector('#gallery-active-name').textContent = 'circle';"></mdc-shape>
        <mdc-shape interactive shape="square" variant="surface" size="medium" title="square" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'square'; r.querySelector('#gallery-active-name').textContent = 'square';"></mdc-shape>
        <mdc-shape interactive shape="slanted" variant="surface" size="medium" title="slanted" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'slanted'; r.querySelector('#gallery-active-name').textContent = 'slanted';"></mdc-shape>
        <mdc-shape interactive shape="arch" variant="surface" size="medium" title="arch" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'arch'; r.querySelector('#gallery-active-name').textContent = 'arch';"></mdc-shape>
        <mdc-shape interactive shape="fan" variant="surface" size="medium" title="fan" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'fan'; r.querySelector('#gallery-active-name').textContent = 'fan';"></mdc-shape>
        <mdc-shape interactive shape="arrow" variant="surface" size="medium" title="arrow" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'arrow'; r.querySelector('#gallery-active-name').textContent = 'arrow';"></mdc-shape>
        <mdc-shape interactive shape="semi-circle" variant="surface" size="medium" title="semi-circle" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'semi-circle'; r.querySelector('#gallery-active-name').textContent = 'semi-circle';"></mdc-shape>
        <mdc-shape interactive shape="oval" variant="surface" size="medium" title="oval" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'oval'; r.querySelector('#gallery-active-name').textContent = 'oval';"></mdc-shape>
        <mdc-shape interactive shape="pill" variant="surface" size="medium" title="pill" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'pill'; r.querySelector('#gallery-active-name').textContent = 'pill';"></mdc-shape>
        <mdc-shape interactive shape="triangle" variant="surface" size="medium" title="triangle" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'triangle'; r.querySelector('#gallery-active-name').textContent = 'triangle';"></mdc-shape>
        <mdc-shape interactive shape="diamond" variant="surface" size="medium" title="diamond" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'diamond'; r.querySelector('#gallery-active-name').textContent = 'diamond';"></mdc-shape>
        <mdc-shape interactive shape="clam-shell" variant="surface" size="medium" title="clam-shell" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'clam-shell'; r.querySelector('#gallery-active-name').textContent = 'clam-shell';"></mdc-shape>
        <mdc-shape interactive shape="pentagon" variant="surface" size="medium" title="pentagon" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'pentagon'; r.querySelector('#gallery-active-name').textContent = 'pentagon';"></mdc-shape>
        <mdc-shape interactive shape="gem" variant="surface" size="medium" title="gem" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'gem'; r.querySelector('#gallery-active-name').textContent = 'gem';"></mdc-shape>
        <mdc-shape interactive shape="sunny" variant="surface" size="medium" title="sunny" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'sunny'; r.querySelector('#gallery-active-name').textContent = 'sunny';"></mdc-shape>
        <mdc-shape interactive shape="very-sunny" variant="surface" size="medium" title="very-sunny" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'very-sunny'; r.querySelector('#gallery-active-name').textContent = 'very-sunny';"></mdc-shape>
        <mdc-shape interactive shape="cookie-4-sided" variant="surface" size="medium" title="cookie-4-sided" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'cookie-4-sided'; r.querySelector('#gallery-active-name').textContent = 'cookie-4-sided';"></mdc-shape>
        <mdc-shape interactive shape="cookie-6-sided" variant="surface" size="medium" title="cookie-6-sided" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'cookie-6-sided'; r.querySelector('#gallery-active-name').textContent = 'cookie-6-sided';"></mdc-shape>
        <mdc-shape interactive shape="cookie-7-sided" variant="surface" size="medium" title="cookie-7-sided" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'cookie-7-sided'; r.querySelector('#gallery-active-name').textContent = 'cookie-7-sided';"></mdc-shape>
        <mdc-shape interactive shape="cookie-9-sided" variant="surface" size="medium" title="cookie-9-sided" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'cookie-9-sided'; r.querySelector('#gallery-active-name').textContent = 'cookie-9-sided';"></mdc-shape>
        <mdc-shape interactive shape="cookie-12-sided" variant="surface" size="medium" title="cookie-12-sided" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'cookie-12-sided'; r.querySelector('#gallery-active-name').textContent = 'cookie-12-sided';"></mdc-shape>
        <mdc-shape interactive shape="ghostish" variant="surface" size="medium" title="ghostish" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'ghostish'; r.querySelector('#gallery-active-name').textContent = 'ghostish';"></mdc-shape>
        <mdc-shape interactive shape="clover-4-leaf" variant="surface" size="medium" title="clover-4-leaf" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'clover-4-leaf'; r.querySelector('#gallery-active-name').textContent = 'clover-4-leaf';"></mdc-shape>
        <mdc-shape interactive shape="clover-8-leaf" variant="surface" size="medium" title="clover-8-leaf" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'clover-8-leaf'; r.querySelector('#gallery-active-name').textContent = 'clover-8-leaf';"></mdc-shape>
        <mdc-shape interactive shape="burst" variant="surface" size="medium" title="burst" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'burst'; r.querySelector('#gallery-active-name').textContent = 'burst';"></mdc-shape>
        <mdc-shape interactive shape="soft-burst" variant="surface" size="medium" title="soft-burst" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'soft-burst'; r.querySelector('#gallery-active-name').textContent = 'soft-burst';"></mdc-shape>
        <mdc-shape interactive shape="boom" variant="surface" size="medium" title="boom" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'boom'; r.querySelector('#gallery-active-name').textContent = 'boom';"></mdc-shape>
        <mdc-shape interactive shape="soft-boom" variant="surface" size="medium" title="soft-boom" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'soft-boom'; r.querySelector('#gallery-active-name').textContent = 'soft-boom';"></mdc-shape>
        <mdc-shape interactive shape="flower" variant="surface" size="medium" title="flower" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'flower'; r.querySelector('#gallery-active-name').textContent = 'flower';"></mdc-shape>
        <mdc-shape interactive shape="puffy" variant="surface" size="medium" title="puffy" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'puffy'; r.querySelector('#gallery-active-name').textContent = 'puffy';"></mdc-shape>
        <mdc-shape interactive shape="puffy-diamond" variant="surface" size="medium" title="puffy-diamond" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'puffy-diamond'; r.querySelector('#gallery-active-name').textContent = 'puffy-diamond';"></mdc-shape>
        <mdc-shape interactive shape="pixel-circle" variant="surface" size="medium" title="pixel-circle" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'pixel-circle'; r.querySelector('#gallery-active-name').textContent = 'pixel-circle';"></mdc-shape>
        <mdc-shape interactive shape="pixel-triangle" variant="surface" size="medium" title="pixel-triangle" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'pixel-triangle'; r.querySelector('#gallery-active-name').textContent = 'pixel-triangle';"></mdc-shape>
        <mdc-shape interactive shape="bun" variant="surface" size="medium" title="bun" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'bun'; r.querySelector('#gallery-active-name').textContent = 'bun';"></mdc-shape>
        <mdc-shape interactive shape="heart" variant="surface" size="medium" title="heart" onclick="const r = this.getRootNode(); r.querySelector('#gallery-hero').shape = 'heart'; r.querySelector('#gallery-active-name').textContent = 'heart';"></mdc-shape>
    </div>
</div>

Size

Code
<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
    <mdc-shape shape="sunny" size="extra-small" variant="tonal"></mdc-shape>
    <mdc-shape shape="sunny" size="small" variant="tonal"></mdc-shape>
    <mdc-shape shape="sunny" size="medium" variant="tonal"></mdc-shape>
    <mdc-shape shape="sunny" size="large" variant="tonal"></mdc-shape>
    <mdc-shape shape="sunny" size="extra-large" variant="tonal"></mdc-shape>

    <mdc-shape
        shape="pill"
        fit="fill"
        variant="filled"
        color="secondary"
        style="width: 144px; height: 72px;"
    ><span style="font-weight: 500; font-size: 13px;">fit="fill"</span></mdc-shape>
</div>

Variant

Code
<div style="display: flex; flex-direction: column; gap: 16px;">
    <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
        <mdc-shape shape="cookie-9-sided" variant="filled" size="large"><mdc-icon name="palette"></mdc-icon></mdc-shape>
        <mdc-shape shape="cookie-9-sided" variant="tonal" size="large"><mdc-icon name="palette"></mdc-icon></mdc-shape>
        <mdc-shape shape="cookie-9-sided" variant="outlined" size="large"><mdc-icon name="palette"></mdc-icon></mdc-shape>
        <mdc-shape shape="cookie-9-sided" variant="elevated" size="large"><mdc-icon name="palette"></mdc-icon></mdc-shape>
        <mdc-shape shape="cookie-9-sided" variant="surface" size="large"><mdc-icon name="palette"></mdc-icon></mdc-shape>
        <mdc-shape shape="cookie-9-sided" variant="transparent" size="large"><mdc-icon name="palette"></mdc-icon></mdc-shape>
    </div>

    <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
        <mdc-shape shape="clover-4-leaf" variant="filled" color="primary" size="medium"></mdc-shape>
        <mdc-shape shape="clover-4-leaf" variant="filled" color="secondary" size="medium"></mdc-shape>
        <mdc-shape shape="clover-4-leaf" variant="filled" color="tertiary" size="medium"></mdc-shape>
        <mdc-shape shape="clover-4-leaf" variant="filled" color="error" size="medium"></mdc-shape>
        <mdc-shape shape="clover-4-leaf" variant="filled" color="surface" size="medium"></mdc-shape>
    </div>
</div>