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.