Components/Button

Button

A control that performs an action, plus split, icon, and copy buttons.

VerifiedSince 0.3.4

Installation

pnpm add @talex-touch/tuffex
EXAMPLE.TYPESCRIPT
import { TxButton, TxSplitButton, TxIconButton, TxCopyButton } from '@talex-touch/tuffex/button'
import '@talex-touch/tuffex/button/style.css'
import '@talex-touch/tuffex/base.css' // tokens + resets, once per app

Usage

Variants

Loading demo...

Disabled

Loading demo...

Loading

The button is disabled while loading; on icon-only buttons the indicator sits over the icon.

Loading demo...

Progress and Status

Setting progress (0–100) renders a background fill and numeric readout; setting status to 'success', 'warning', or 'error' smoothly settles the fill into the semantic tone and draws the status glyph.

Loading demo...

Sizes

size has three tiers, sm, md, and lg, at 26, 32, and 38px tall.

Loading demo...

Block

block fills the container width; with loadingVariant="bar", loading shows as a sweep layer.

Loading demo...

Shapes

A non-block circle is as wide as the button is tall; the flat variant's sm is 32px.

Loading demo...

Haptics

vibrate is opt-in: a click vibrates the device and nudges the button by strength; the nudge shows even without vibration support.

Loading demo...

Split Button

TxSplitButton pairs a primary action with more actions in the menu slot.

Loading demo...

Primary + Ghost

Use primary for the main action and ghost for the secondary one.

Loading demo...

Icon Button

label supplies the accessible name, pressed a persistent toggle state, and status a semantic tone.

Loading demo...

Copy Button

A copy draws a check and morphs the label into copiedLabel; a failure draws a cross and emits error. iconOnly shows the label only while reporting.

Loading demo...

Best Practices

  • Keep one primary button per view or card; use ghost or secondary for lower-priority actions.
  • Set loading for async actions and clear it on both success and failure, so the button never sticks disabled.
  • Prefer progress and status for measurable async tasks so progress and outcome resolve inside the same button without jarring external alerts.
  • Use nativeType="submit" only inside forms; the default button never submits by accident.
  • Use TxIconButton with a label for icon-only actions; reserve pressed for persistent toggles.
  • Name the copied target in TxCopyButton's copyLabel; handle error for critical values, and set failedLabel outside English.

API Reference

TxButton

Props

ParameterTypeDefaultDescription
variant
primary
secondary
ghost
danger
success
warning
info
flat
bare
'secondary'

Visual style.

type
primary
success
warning
danger
info
text
-

Semantic alias, used only when variant is unset; text maps to ghost.

size
sm
md
lg
'md'

Heights 26 / 32 / 38px; the old values large, small, and mini are normalized at runtime.

block
boolean
false

Fills the parent width.

plain
boolean
false

Plain style.

dashed
boolean
false

Dashed border.

round
boolean
false

Rounded shape.

circle
boolean
false

Circular shape for icon-only buttons.

loading
boolean
false

Shows a loading indicator and blocks clicks.

loading-variant
spinner
bar
'spinner'

Loading style; bar renders as a sweep layer only with block.

progress
number
-
show-progress
boolean
true

Whether to display the numeric readout while progress is set and status is empty.

format-progress
(percentage: number) => string
-

Custom formatter for the numeric progress readout.

status
success
warning
error
''

Outcome status; settles the background fill into a semantic tone and draws the matching glyph.

disabled
boolean
false

Disables the button and suppresses click.

border
boolean
true

When false, drops the border color.

icon
string
-

Icon class shown before the label.

autofocus
boolean
false

Focuses the button after mount.

native-type
button
submit
reset
'button'

Native type attribute.

vibrate
boolean
false

Vibrates the device and shakes the button to match on click.

vibrate-type
light
medium
heavy
bit
success
warning
error
'light'

Vibration strength.

Parameter
variant
Type
primary
secondary
ghost
danger
success
warning
info
flat
bare
Default
'secondary'
Description

Visual style.

Parameter
type
Type
primary
success
warning
danger
info
text
Default
-
Description

Semantic alias, used only when variant is unset; text maps to ghost.

Parameter
size
Type
sm
md
lg
Default
'md'
Description

Heights 26 / 32 / 38px; the old values large, small, and mini are normalized at runtime.

Parameter
block
Type
boolean
Default
false
Description

Fills the parent width.

Parameter
plain
Type
boolean
Default
false
Description

Plain style.

Parameter
dashed
Type
boolean
Default
false
Description

Dashed border.

Parameter
round
Type
boolean
Default
false
Description

Rounded shape.

Parameter
circle
Type
boolean
Default
false
Description

Circular shape for icon-only buttons.

Parameter
loading
Type
boolean
Default
false
Description

Shows a loading indicator and blocks clicks.

Parameter
loading-variant
Type
spinner
bar
Default
'spinner'
Description

Loading style; bar renders as a sweep layer only with block.

Parameter
progress
Type
number
Default
-
Description

Progress percentage (0–100); renders a background fill and numeric readout, blocking clicks while under 100 without status.

Parameter
show-progress
Type
boolean
Default
true
Description

Whether to display the numeric readout while progress is set and status is empty.

Parameter
format-progress
Type
(percentage: number) => string
Default
-
Description

Custom formatter for the numeric progress readout.

Parameter
status
Type
success
warning
error
Default
''
Description

Outcome status; settles the background fill into a semantic tone and draws the matching glyph.

Parameter
disabled
Type
boolean
Default
false
Description

Disables the button and suppresses click.

Parameter
border
Type
boolean
Default
true
Description

When false, drops the border color.

Parameter
icon
Type
string
Default
-
Description

Icon class shown before the label.

Parameter
autofocus
Type
boolean
Default
false
Description

Focuses the button after mount.

Parameter
native-type
Type
button
submit
reset
Default
'button'
Description

Native type attribute.

Parameter
vibrate
Type
boolean
Default
false
Description

Vibrates the device and shakes the button to match on click.

Parameter
vibrate-type
Type
light
medium
heavy
bit
success
warning
error
Default
'light'
Description

Vibration strength.

Events

ParameterTypeDefaultDescription
click
(event: MouseEvent) => void
-

Fires on click unless disabled or loading.

Parameter
click
Type
(event: MouseEvent) => void
Default
-
Description

Fires on click unless disabled or loading.

Slots

SlotDescription
defaultLabel or custom content, rendered after the icon and loading indicator.

TxSplitButton

Props

PropTypeDefaultDescription
variant'primary' | 'secondary' | 'ghost' | 'danger' | 'success' | 'warning' | 'info'primaryVariant shared by the primary and menu buttons.
size'sm' | 'md' | 'lg'mdHeights 28 / 32 / 40px.
disabledbooleanfalseDisables both the primary action and the menu trigger.
loadingbooleanfalseShows the primary spinner and disables both sides.
iconstring-Icon class shown before the label while not loading.
menuIconstring-Icon class for the menu trigger; without it, a built-in vertical ellipsis is drawn.
menuDisabledbooleanfalseDisables only the menu trigger.
menuWidthnumber200Popover width, passed to TxPopover.
menuPlacement'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'right-start' | 'right-end' | 'left-start' | 'left-end'bottom-endPopover placement.
menuOffsetnumber8Popover offset in px.

Events

EventParamsDescription
click(event: MouseEvent)Fires on a primary click unless disabled or loading.
menuOpenChange(open: boolean)Fires when the menu opens or closes.

Slots

SlotPropsDescription
default-Primary action label.
menu{ close: () => void }Menu content inside the popover; call close() after a selection.
menu-icon-Replaces the menu trigger icon.

TxIconButton

Props

PropTypeDefaultDescription
iconstring''Icon name rendered through TxIcon when there is no default slot.
labelstring''Accessible name; required for icon-only use, and its absence warns in development.
size'xs' | 'sm' | 'md' | 'lg''md'Button size.
shape'square' | 'circle' | 'pill''square'Hit-area silhouette.
status'success' | 'warning' | 'danger' | 'info'-Semantic tone for icon, hover, pressed, and focus; changes no behavior or permission.
pressedboolean-Persistent toggle state; renders aria-pressed when defined.
disabledbooleanfalseNative disabled state.
nativeType'button' | 'submit' | 'reset''button'Native type attribute.

Events

EventParamsDescription
click(event: MouseEvent)Fires on click unless disabled.

Slots

SlotPropsDescription
default{ hover, pressed }Custom icon or animated content.

TxCopyButton

Props

PropTypeDefaultDescription
textstring''Text written to the clipboard.
copyLabelstring'Copy'Idle label and aria-label.
copiedLabelstring'Copied'Label and aria-label after a successful copy.
failedLabelstring-Label and aria-label after a failure. Without it, copyLabel stays (iconOnly grows no label) and the live region announces "Copy failed".
disabledbooleanfalseDisables the button and prevents copying.
timeoutnumber1400Milliseconds before the copied or failed state resets.
size'sm' | 'md''sm'Button size.
iconOnlybooleanfalseShows only the icon at rest; the label grows out while reporting.

Events

EventParamsDescription
copy(text: string)Fires after a successful clipboard write.
error(error: unknown)Fires when the clipboard write fails.

Slots

SlotPropsDescription
default{ copied, copying, failed }Custom button content; replaces the label morph.

Types

EXAMPLE.TS
import type { TxButtonEmits, TxButtonProps, TxIconButtonProps, TxSplitButtonEmits, TxSplitButtonProps } from '@talex-touch/tuffex'

export interface ButtonProps extends TxButtonProps {}
export interface ButtonEmits extends TxButtonEmits {}
export interface SplitButtonProps extends TxSplitButtonProps {}
export interface SplitButtonEmits extends TxSplitButtonEmits {}
export interface IconButtonProps extends TxIconButtonProps {}

Overview

  • variant wins over type; with neither set, the button is secondary.
  • disabled, loading, and an unfinished progress (< 100 with no status) all disable the native <button> and suppress click; a loading TxSplitButton disables both sides.
  • Non-block, non-circle buttons animate width with a FLIP transition when loading, progress, or status changes, and ease colour only inside the state-change window (.is-morphing); block with circle keeps the regular label layout.
  • An icon-only TxButton takes its name from attrs such as aria-label; TxIconButton maps label to aria-label and a boolean pressed to aria-pressed.
  • TxCopyButton uses the Clipboard API and falls back to execCommand; it ignores clicks while copying and eases colour only on a state change.
  • Under reduced motion, the vibrate shake is skipped and both TxButton status and TxCopyButton land each state as its final frame.

Technologies

  • --tx-button-height sets both the button height and the width of a non-block circle.
  • Source: packages/tuffex/packages/components/src/button/.
View source
packages/tuffex/packages/components/src/button/index.ts

Use cases

  • Page and card actions, form submits (nativeType="submit"), and drawer footers (block).
  • Table rows and toolbars (size="sm"), and icon-only actions (circle or TxIconButton).
  • A primary action with a menu of variants (TxSplitButton), and copy-to-clipboard (TxCopyButton).