Action Button Progress Morph
操作按钮变形为进度轨
The same action surface widens into a progress track and resolves into a success mark.
Where to use it
Keep an export or publish task tied to the action that started it. Keep the progress tied to its initiating button when a single job has an obvious owner in the interface.
Practical example
On a photo proof sheet, pressing “Generate PDF” turns the same action into a progress track. Once rendering finishes, a checkmark appears where the button used to be.
AI prompt
Morph [button] into a progress surface. Keep one focusable control, map the task to idle, working, and complete states, show determinate progress and prevent concurrent restarts.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Action Button Progress Morph</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.ui { width: min(100%, 238px); display: grid; gap: 8px; position: relative; font-size: 12px; line-height: 1.35; }
.ui .surface { min-width: 0; border: 1px solid #676591; border-radius: 10px; background: #282744; padding: 8px; }
.ui .bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ui .actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 5px; }
.ui .muted { color: #cecae9; font-size: 11px; }
.ui .center { text-align: center; }
.ui .mono { font: 11px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.ui p { margin: 0; }
.ui .button { min-height: 30px; padding: 4px 7px; border-radius: 7px; border: 1px solid #79779f; background: #3d3a60; color: #f9f5ff; font-size: 11px; font-weight: 650; cursor: pointer; }
.ui .button:hover { background: #4e4976; }
.ui .primary { background: #c5eeec; border-color: #dafaee; color: #17213b; }
.ui .primary:hover { background: #e3fff9; }
.ui .button:disabled { opacity: .6; cursor: default; }
.ui .field { min-width: 0; width: 100%; border: 1px solid #79779f; border-radius: 6px; background: #1b1a31; color: #faf5ff; padding: 5px 7px; font-size: 12px; }
.ui .field::placeholder { color: #c2bcdd; }
.ui input[type="range"] { accent-color: #b8ebe0; width: 100%; min-width: 0; margin: 0; }
.ui button { font: inherit; }
.ui [hidden] { display: none !important; }
.ui progress { accent-color: #b8ebe0; }
@media (prefers-reduced-motion: reduce) {
.ui *, .ui *::after, .ui *::before { transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important; }
}
.morph-slot{height:49px;display:grid;place-items:center}.ui .morph{position:relative;isolation:isolate;overflow:hidden;width:139px;height:36px;border-radius:22px;transition:width .25s ease,background .25s ease;background:#4c4979}.morph::before{content:'';position:absolute;z-index:-1;inset:0;background:#438571;transform:scaleX(var(--progress,0));transform-origin:left center}.ui .morph[data-work]{width:99%;cursor:progress}.ui .morph[data-done]{width:70px;background:#3c6b57}.ui progress{vertical-align:middle;width:52%}
</style>
</head>
<body>
<main class="demo">
<div class="ui"><div class="morph-slot"><button class="button morph" type="button"><span>Publish sample</span></button></div><label class="muted center">Progress <progress value="0" max="100"></progress></label><p class="muted center" role="status"></p></div>
</main>
<script>
const button = document.querySelector('.morph');
const label = button.firstElementChild;
const bar = document.querySelector('progress');
const status = document.querySelector('[role=status]');
let busy = false;
button.addEventListener('click', () => {
if (busy) return;
busy = true; bar.value = 0; button.removeAttribute('data-done'); button.setAttribute('data-work', ''); button.setAttribute('aria-disabled', 'true');
label.textContent = "Publishing…"; status.textContent = label.textContent;
const timer = setInterval(() => {
bar.value = Math.min(100, bar.value + 10); button.style.setProperty('--progress', bar.value / 100);
if (bar.value < 100) return;
clearInterval(timer); busy = false; button.removeAttribute('data-work'); button.removeAttribute('aria-disabled'); button.setAttribute('data-done', ''); label.textContent = '✓'; button.setAttribute('aria-label', "Publish sample again"); status.textContent = "Published";
}, 95);
});
</script>
</body>
</html>Original example by UI Skills