Skip to content

CodeButton ​

The full front-end flow of a “get code” button: click → emit oas-send → start the cooldown countdown → become resendable. Sending the request is the host's job; the component owns interaction and state.

Basic usage ​

Clicking starts the cooldown immediately (60 seconds by default); while cooling down the button is disabled and shows the remaining seconds.

cooldown=10

Waiting to send…

cooldown=3 (see the whole flow quickly)

Controlled flow (start the cooldown after the request succeeds) ​

oas-send can be intercepted with preventDefault(): the cooldown does not start automatically, and the host calls start() once the request succeeds. Below simulates a request that succeeds after 800 ms.

intercept → request → start()

Not sent

Loading and disabled ​

loading / disabled

  • loading: shows the built-in spinner, sets aria-busy="true" and blocks repeated clicks
  • disabled: not clickable and no events are dispatched

Custom content (default slot) ​

Slot content is used for the idle state; during the countdown the built-in countdown text is still shown (so custom copy cannot hide the remaining time).

default slot

Send to phone

Events ​

EventWhendetail
oas-sendClicked while clickable (preventDefault skips the cooldown){ cooldown }

API ​

oas-code-button ​

Attributes ​

AttributeDescriptionTypeDefault
cooldownCooldown seconds (default 60); invalid/non-positive values fall back with a warningstring—
disabledDisabled: not clickable and no events are dispatchedboolean—
loadingRequest in flight: spinner + aria-busy + blocks repeated clicksboolean—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
countingWhether the cooldown is running (read-only)boolean—
remainingRemaining cooldown seconds (read-only)number0

Methods ​

MethodSignatureDescription
startstart(seconds?: number): voidStart the cooldown (defaults to cooldown)
resetreset(): voidEnd the cooldown immediately and return to idle

Events ​

EventDescription
oas-sendFired on click while clickable, detail: { cooldown }; call preventDefault() to skip the automatic cooldown (host calls start() after success)

Slots ​

NameDescription
defaultCustom button content (idle state; the built-in countdown text takes over during cooldown)

Released under the MIT OR Apache-2.0 License.