Button
A pressable action, in surface, accent, or ghost style.
Use Button to trigger an action, such as loading the next preset.
import { Button } from '@soundor/components';
import { Text, View } from '@soundor/react';
import { useState } from 'react';
export default function Demo() {
const [count, setCount] = useState(0);
return (
<>
<View style={{ flexDirection: 'row', gap: 12 }}>
<Button onPress={() => setCount(count + 1)}>Surface</Button>
<Button variant="accent" onPress={() => setCount(count + 1)}>
Accent
</Button>
<Button variant="ghost" onPress={() => setCount(0)}>
Reset
</Button>
</View>
<Text style={{ fontSize: 12 }}>Pressed {count} times</Text>
</>
);
}button.tsx, running in the web runtime.SourcePass leading or trailing to add an icon or other content around the label. When children is not a string, set accessibilityLabel.
Loading
Set loading while the action the button started is under way. The label gives way to a spinner, so the button keeps its width, and presses are ignored until you clear it. Press a button to try it.
import { Button } from '@soundor/components';
import { View } from '@soundor/react';
import { useEffect, useState } from 'react';
export default function Demo() {
const [saving, setSaving] = useState<'accent' | 'surface' | null>(null);
// Stands in for work that takes a while: a save, a preset load, a render.
useEffect(() => {
if (!saving) return;
const timer = setTimeout(() => setSaving(null), 2000);
return () => clearTimeout(timer);
}, [saving]);
return (
<View style={{ flexDirection: 'row', gap: 12 }}>
<Button
variant="accent"
loading={saving === 'accent'}
onPress={() => setSaving('accent')}
>
Save preset
</Button>
<Button
loading={saving === 'surface'}
onPress={() => setSaving('surface')}
>
Render
</Button>
<Button loading>Always busy</Button>
</View>
);
}button-loading.tsx, running in the web runtime.Source<Button loading={saving} onPress={save}>
Save preset
</Button>A loading button is not disabled: it keeps its focus and its look, and assistive technology hears it as busy, still named by its label. Use disabled when the action is not available at all.
Disabled
Set disabled when the action is not available: it dims the button, drops it from the tab order and ignores presses. Turn it on and off with your own state; here Apply waits for a change.
import { Button } from '@soundor/components';
import { View } from '@soundor/react';
import { useState } from 'react';
export default function Demo() {
const [ready, setReady] = useState(false);
return (
<View style={{ gap: 14, alignItems: 'center' }}>
<View style={{ flexDirection: 'row', gap: 12 }}>
<Button disabled>Surface</Button>
<Button variant="accent" disabled>
Accent
</Button>
<Button variant="ghost" disabled>
Ghost
</Button>
</View>
{/* Available only once there is something to apply. */}
<View style={{ flexDirection: 'row', gap: 12 }}>
<Button onPress={() => setReady(!ready)}>
{ready ? 'Clear changes' : 'Make a change'}
</Button>
<Button variant="accent" disabled={!ready}>
Apply
</Button>
</View>
</View>
);
}button-disabled.tsx, running in the web runtime.Source<Button variant="accent" disabled={!dirty} onPress={apply}>
Apply
</Button>Prefer loading for an action that is under way. A disabled button that is also loading shows the spinner, dimmed, and stays unavailable after loading ends until you clear disabled.
Keyboard and accessibility
A Button is a tab stop. Enter or Space presses it. Give a button without text, such as an icon, an accessibilityLabel. See Keyboard and accessibility.