ModeChip
A button that names the current mode and morphs when it changes.
Usage
Basic
Loading demo...
Tones
muted has no fill; the other tones fill with their hue's -light-9 tint, and info uses the primary hue.
Loading demo...
Best Practices
- Don't add
aria-pressedto a chip whose label changes with the mode; keep it for a fixed-label chip that toggles one mode. Addaria-haspopupwhen a click opens a mode menu. - Use tone for risk:
mutedfor the default or safe mode,dangerfor a mode that lifts a safeguard; the label and icon must still name the mode. - Keep labels to two to four words.
- Inside ChatComposer, use the
toolbar-leftslot; in its tray, use themutedtone. - Change the mode only on a user action or a real change of context, never on a timer.
API Reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
label | string | - | Visible text and the button's accessible name. Required. |
icon | string | '' | Leading icon class; no icon box is reserved when empty. |
tone | 'muted' | 'info' | 'success' | 'warning' | 'danger' | 'muted' | Tone, reusing StatusTone. |
disabled | boolean | false | Disables the button. |
CSS Variables
| Variable | Description |
|---|---|
--tx-mode-chip-ink | Text colour, set per tone. |
--tx-mode-chip-ink-hover | Text colour on hover, set by muted only. |
--tx-mode-chip-fill | Fill. |
--tx-mode-chip-fill-hover | Fill on hover. |
Overview
- Renders a native
<button type="button">;labelis the accessible name and the icon stays out of it.clickand other native events and attributes fall through to the root. - A change to
label,icon, ortonestarts a morph: the icon swaps with a scale, the label blur-crossfades 50ms later, and the width follows; a change mid-morph restarts the clock. - Colours transition only during a morph (
.is-morphing); hover switches instantly,mutedto the primary ink and the other tones to a deeper fill. - Every tone's text measures at least 4.5:1, resting and hovered, in all four theme blocks.
- Under reduced motion every leg lands at once; without the Web Animations API, the width jumps to its new value.
- A disabled chip is semi-transparent, with a
not-allowedcursor and no hover change.
Technologies
- The label reuses
TxTextTransformer's fade mode, so text comes only fromlabeland there are no slots. - Motion reference: @flohoeller's Chatbox component clip.
- Source:
packages/tuffex/packages/components/src/mode-chip/.
查看源码
packages/tuffex/packages/components/src/mode-chip/index.ts