Button
The Button component allows users to trigger actions. It supports various styles, sizes, loading states, and can be grouped with ButtonGroup.
Installation
$ cbui-cli install @crossbuildui/button
To get started, please make sure you have installed
cbui-cli
globally and authenticated your account. This will ensure you can access all the necessary features.Import
index.tsx
1import { Button, ButtonGroup } from '@/crossbuildui/button';
2// import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; // If using icons
Button Component
ButtonGroup Component
Props Overview
Button Props
PROP | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
children | ReactNode | - | Content of the button. |
variant | ButtonVariant | 'solid' | Visual style. |
color | ButtonColor | 'default' | Semantic color. |
size | ButtonSize | 'md' | Size of the button. |
radius | ButtonRadius | 'md' | Border radius. |
fullWidth | boolean | false | Take full parent width. |
isLoading | boolean | false | Loading state. |
spinner | ReactElement | - | Custom spinner element. |
spinnerProps | ActivityIndicatorProps | - | Props for default spinner. |
startContent | ReactElement | - | Content before children. |
endContent | ReactElement | - | Content after children. |
isIconOnly | boolean | false | Style for icon-only button. |
style | StyleProp<ViewStyle> | - | Custom style for the Pressable . |
textStyle | StyleProp<TextStyle> | - | Custom style for text children. |
disabled | boolean | false | Disable the button. |
onPress | PressableProps['onPress'] | - | Callback on press. |
...PressableProps | various | - | Other props from React Native's Pressable. |
ButtonGroup Props
PROP | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
children | ReactElement<ButtonProps>[] | - | Button components to group. |
variant | ButtonVariant | - | Default variant for grouped buttons. |
color | ButtonColor | - | Default color for grouped buttons. |
size | ButtonSize | - | Default size for grouped buttons. |
radius | ButtonRadius | - | Default radius for grouped buttons (applies to outer corners if attached). |
fullWidth | boolean | false | Group takes full parent width. |
isVertical | boolean | false | Stack buttons vertically. |
isAttached | boolean | false | Attach buttons (no space, shared borders). |
style | StyleProp<ViewStyle> | - | Custom style for the group container. |
Styling
Customize appearance using:
- Button:
style
: Applied to the rootPressable
component of the button.textStyle
: Applied to theText
component if children is a string.
- ButtonGroup:
style
: Applied to the rootView
container of the group.- Individual buttons within a group can also have their own
style
prop, which will be merged with styles derived from the group (e.g., for attached borders).
index.tsx
1<Button
2 color="primary"
3 variant="solid"
4 style={{ marginVertical: 10, transform: [{ skewX: '-5deg' }] }} // Styles the outer Pressable
5 textStyle={{ fontWeight: 'bold', letterSpacing: 1 }}
6 startContent={<Icon name="star" size={18} />}
7>
8 Styled Button
9</Button>
10
11<ButtonGroup
12 style={{ padding: 10, backgroundColor: '#f0f0f0', borderRadius: 12 }}
13 isAttached
14 radius="lg"
15 color="default"
16>
17 <Button>Grouped Styled 1</Button>
18 <Button style={{borderColor: 'purple', borderWidth: 1}}>Grouped Styled 2</Button>
19</ButtonGroup>
Accessibility
The Button component is built on Pressable
and includes accessibility features:
accessibilityRole="button"
is set by default.accessibilityState
includesdisabled
andbusy
(whenisLoading
is true).- Ensure meaningful text content or provide an
accessibilityLabel
for icon-only buttons.