Components/Button

Button

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

VerifiedSince 0.3.4

Installation

EXAMPLE.BASH
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...

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

Shows copiedLabel after a successful copy and emits error on failure.

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.
  • 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, since browsers can reject writes outside a user gesture.

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.

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
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.
menuIconstringi-ri-more-2-lineDefault icon class of the menu trigger.
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.
disabledbooleanfalseDisables the button and prevents copying.
timeoutnumber1400Milliseconds before the copied state resets.
size'sm' | 'md''sm'Button size.

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 }Custom button content.

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 and loading both 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 toggles; 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 when it is unavailable; it ignores clicks while disabled or copying.
  • Under reduced motion, the vibrate shake is skipped.

Technologies

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

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).
View source
packages/tuffex/packages/components/src/button/index.ts