Gradient Glow Button
A call-to-action button with a gradient fill and a soft coloured glow on hover.
6 个框架初级
A red button that arms on the first click and only deletes on the second.
<!--
Colour alone is not a safeguard - red is invisible to a red-blind user and
means nothing to a screen reader. The confirm step is the actual protection:
the first click only arms the button, the second one deletes.
-->
<button class="danger-btn" type="button" data-armed="false">
<span class="danger-btn__label" aria-live="polite">Delete project</span>
</button>
<script>
document.querySelectorAll('.danger-btn').forEach(function (button) {
var label = button.querySelector('.danger-btn__label');
var idle = label.textContent;
var timer;
function disarm() {
button.dataset.armed = 'false';
label.textContent = idle;
window.clearTimeout(timer);
}
button.addEventListener('click', function () {
if (button.dataset.armed !== 'true') {
button.dataset.armed = 'true';
label.textContent = 'Are you sure?';
// Disarm on its own so a forgotten armed button is not a landmine for
// the next person who clicks it.
timer = window.setTimeout(disarm, 4000);
return;
}
disarm();
// Real deletion goes here.
console.log('deleted');
});
// Leaving the button is a signal the user changed their mind.
button.addEventListener('blur', disarm);
});
</script>| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
children必填 | ReactNode | - | 在组件内部渲染的内容。 |
onConfirm | () => void | - | 破坏性操作被确认后触发。 |
disabled | boolean | false | 禁止交互并将控件置灰。 |
Red is not the safeguard - it is invisible to a red-blind user and means nothing to a screen reader. The confirm step is the protection, and `aria-live` is what carries it. The type omits `onClick` and exposes `onConfirm` instead, so wiring the deletion to the arming click is not expressible. It disarms on blur and after four seconds, so an armed button left alone cannot ambush the next click that lands on it.