Button
A control that performs an action, plus split, icon, and copy buttons.
Installation
pnpm add @talex-touch/tuffex
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
Disabled
Loading
The button is disabled while loading; on icon-only buttons the indicator sits over the icon.
Sizes
size has three tiers, sm, md, and lg, at 26, 32, and 38px tall.
Block
block fills the container width; with loadingVariant="bar", loading shows as a sweep layer.
Shapes
A non-block circle is as wide as the button is tall; the flat variant's sm is 32px.
Haptics
vibrate is opt-in: a click vibrates the device and nudges the button by strength; the nudge shows even without vibration support.
Split Button
TxSplitButton pairs a primary action with more actions in the menu slot.
Primary + Ghost
Use primary for the main action and ghost for the secondary one.
Icon Button
label supplies the accessible name, pressed a persistent toggle state, and status a semantic tone.
Copy Button
Shows copiedLabel after a successful copy and emits error on failure.
Best Practices
- Keep one primary button per view or card; use
ghostorsecondaryfor lower-priority actions. - Set
loadingfor async actions and clear it on both success and failure, so the button never sticks disabled. - Use
nativeType="submit"only inside forms; the defaultbuttonnever submits by accident. - Use
TxIconButtonwith alabelfor icon-only actions; reservepressedfor persistent toggles. - Name the copied target in
TxCopyButton'scopyLabel; handleerrorfor critical values, since browsers can reject writes outside a user gesture.
API Reference
TxButton
Props
| Parameter | Type | Default | Description |
|---|---|---|---|
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. |
Visual style.
Semantic alias, used only when variant is unset; text maps to ghost.
Heights 26 / 32 / 38px; the old values large, small, and mini are normalized at runtime.
Fills the parent width.
Plain style.
Dashed border.
Rounded shape.
Circular shape for icon-only buttons.
Shows a loading indicator and blocks clicks.
Loading style; bar renders as a sweep layer only with block.
Disables the button and suppresses click.
When false, drops the border color.
Icon class shown before the label.
Focuses the button after mount.
Native type attribute.
Vibrates the device and shakes the button to match on click.
Vibration strength.
Events
| Parameter | Type | Default | Description |
|---|---|---|---|
click | (event: MouseEvent) => void | - | Fires on click unless disabled or loading. |
Fires on click unless disabled or loading.
Slots
| Slot | Description |
|---|---|
default | Label or custom content, rendered after the icon and loading indicator. |
TxSplitButton
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'secondary' | 'ghost' | 'danger' | 'success' | 'warning' | 'info' | primary | Variant shared by the primary and menu buttons. |
size | 'sm' | 'md' | 'lg' | md | Heights 28 / 32 / 40px. |
disabled | boolean | false | Disables both the primary action and the menu trigger. |
loading | boolean | false | Shows the primary spinner and disables both sides. |
icon | string | - | Icon class shown before the label while not loading. |
menuIcon | string | i-ri-more-2-line | Default icon class of the menu trigger. |
menuDisabled | boolean | false | Disables only the menu trigger. |
menuWidth | number | 200 | Popover width, passed to TxPopover. |
menuPlacement | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'right-start' | 'right-end' | 'left-start' | 'left-end' | bottom-end | Popover placement. |
menuOffset | number | 8 | Popover offset in px. |
Events
| Event | Params | Description |
|---|---|---|
click | (event: MouseEvent) | Fires on a primary click unless disabled or loading. |
menuOpenChange | (open: boolean) | Fires when the menu opens or closes. |
Slots
| Slot | Props | Description |
|---|---|---|
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
| Prop | Type | Default | Description |
|---|---|---|---|
icon | string | '' | Icon name rendered through TxIcon when there is no default slot. |
label | string | '' | 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. |
pressed | boolean | - | Persistent toggle state; renders aria-pressed when defined. |
disabled | boolean | false | Native disabled state. |
nativeType | 'button' | 'submit' | 'reset' | 'button' | Native type attribute. |
Events
| Event | Params | Description |
|---|---|---|
click | (event: MouseEvent) | Fires on click unless disabled. |
Slots
| Slot | Props | Description |
|---|---|---|
default | { hover, pressed } | Custom icon or animated content. |
TxCopyButton
Props
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | '' | Text written to the clipboard. |
copyLabel | string | 'Copy' | Idle label and aria-label. |
copiedLabel | string | 'Copied' | Label and aria-label after a successful copy. |
disabled | boolean | false | Disables the button and prevents copying. |
timeout | number | 1400 | Milliseconds before the copied state resets. |
size | 'sm' | 'md' | 'sm' | Button size. |
Events
| Event | Params | Description |
|---|---|---|
copy | (text: string) | Fires after a successful clipboard write. |
error | (error: unknown) | Fires when the clipboard write fails. |
Slots
| Slot | Props | Description |
|---|---|---|
default | { copied, copying } | Custom button content. |
Types
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
variantwins overtype; with neither set, the button issecondary.disabledandloadingboth disable the native<button>and suppressclick; a loadingTxSplitButtondisables both sides.- Non-block, non-circle buttons animate width with a FLIP transition when
loadingtoggles;blockwithcirclekeeps the regular label layout. - An icon-only
TxButtontakes its name from attrs such asaria-label;TxIconButtonmapslabeltoaria-labeland a booleanpressedtoaria-pressed. TxCopyButtonuses the Clipboard API and falls back toexecCommandwhen it is unavailable; it ignores clicks while disabled or copying.- Under reduced motion, the
vibrateshake is skipped.
Technologies
--tx-button-heightsets 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 (circleorTxIconButton). - A primary action with a menu of variants (
TxSplitButton), and copy-to-clipboard (TxCopyButton).