The Button component is used to trigger an action or event.
import { Button, ButtonGroup } from 'native-base';
Button : The button component with support for custom icons, spinners, etc.
ButtonGroup : Used to group buttons whose actions are related, with an option to flush them together.
const Example = () => {
return <Button onPress={() => console.log("hello world")}>PRIMARY</Button>;
};
const Example = () => {
return <Stack direction={{
base: "column",
md: "row"
}} space={1} alignItems={{
base: "center",
md: "flex-start"
}}>
{["xs", "sm", "md", "lg"].map(size => <Box>
{
}
<Button key={size} size={size}>
BUTTON
</Button>
</Box>)}
</Stack>;
};
const Example = () => {
return <VStack space={4} px={2} w="100%">
{
}
<Heading size="xs" textAlign="left">
Solid
</Heading>
<Stack direction={{
base: "column",
md: "row"
}} space={2} mx={{
base: "auto",
md: 0
}}>
<Button size="sm" onPress={() => console.log("hello world")}>
PRIMARY
</Button>
<Button size="sm" colorScheme="secondary" onPress={() => console.log("hello world")}>
SECONDARY
</Button>
<Button size="sm" isDisabled onPress={() => console.log("hello world")}>
DISABLED
</Button>
</Stack>
<Divider />
<Heading size="xs">Outline</Heading>
{
}
<Stack direction={{
base: "column",
md: "row"
}} space={2} mx={{
base: "auto",
md: 0
}}>
<Button size="sm" variant="outline" onPress={() => console.log("hello world")}>
PRIMARY
</Button>
<Button size="sm" variant="outline" colorScheme="secondary" onPress={() => console.log("hello world")}>
SECONDARY
</Button>
<Button size="sm" variant="outline" isDisabled onPress={() => console.log("hello world")}>
DISABLED
</Button>
</Stack>
<Divider />
<Heading size="xs">Link</Heading>
{
}
<Stack direction={{
base: "column",
md: "row"
}} space={2} mx={{
base: "auto",
md: 0
}}>
<Button size="sm" variant="link" onPress={() => console.log("hello world")}>
PRIMARY
</Button>
<Button size="sm" variant="link" colorScheme="secondary" onPress={() => console.log("hello world")}>
SECONDARY
</Button>
<Button size="sm" variant="link" isDisabled onPress={() => console.log("hello world")}>
DISABLED
</Button>
</Stack>
<Divider />
<Heading size="xs">Ghost</Heading>
{
}
<Stack direction={{
base: "column",
md: "row"
}} space={2} mx={{
base: "auto",
md: 0
}}>
<Button size="sm" variant="ghost" onPress={() => console.log("hello world")}>
PRIMARY
</Button>
<Button size="sm" variant="ghost" colorScheme="secondary" onPress={() => console.log("hello world")}>
SECONDARY
</Button>
<Button size="sm" variant="ghost" isDisabled onPress={() => console.log("hello world")}>
DISABLED
</Button>
</Stack>
<Divider />
<Heading size="xs">Unstyled</Heading>
{
}
<Stack direction={{
base: "column",
md: "row"
}} space={2} mx={{
base: "auto",
md: 0
}}>
<Button variant="unstyled" onPress={() => console.log("hello world")}>
Unstyled
</Button>
</Stack>
</VStack>;
};
const Example = () => {
return <Stack direction={{
base: "column",
md: "row"
}} space={2} alignItems={{
base: "center",
md: "flex-start"
}}>
<Button isLoading>Button</Button>
<Button isLoading isLoadingText="Submitting">
BUTTON
</Button>
<Button isLoading isLoadingText="Submitting" variant="outline">
BUTTON
</Button>
</Stack>;
};
const Example = () => {
return <Stack direction={{
base: "column",
md: "row"
}} space={4}>
<Button startIcon={<Icon as={MaterialCommunityIcons} name="email" size={5} />}>
Email
</Button>
<Button variant="outline" endIcon={<Icon as={Ionicons} name="arrow-forward" size={4} />}>
Call us
</Button>
</Stack>;
};
const Example = () => {
return <Button.Group variant="solid" isAttached space={6} mx={{
base: "auto",
md: 0
}}>
<Button colorScheme="teal" mr={2}>
Save
</Button>
<Button colorScheme="danger" _text={{
color: "white"
}}>
Cancel
</Button>
</Button.Group>;
};
const Example = () => {
const myRef = React.useRef({});
React.useEffect(() => {
myRef.current.setNativeProps({
borderWidth: 10,
opacity: 0.5,
borderRadius: 10
});
}, [myRef]);
return <Button size="sm" variant={"solid"} ref={myRef}>
BUTTON
</Button>;
};
Button implements
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
The color of the radio when it's checked. This should be one of the color keys in the theme (e.g."green", "red").
The variant of the button style to use.
Type: ResponsiveValue<"link" | "outline" | "ghost" | "solid" | "unstyled">
If true, the button will show a spinner.
The size of the button.
Type: ResponsiveValue<"xs" | "sm" | "md" | "lg">
The start icon element to use in the button.
Type: Element | Element[]
The end icon element to use in the button.
Type: Element | Element[]
The end icon element to use in the button.
The spinner element to use when isLoading is set to true.
If true, the button will be disabled.
Props to style the child text For providing props to Text inside Box
Props to be passed to the HStack used inside of Button.
ButtonGroup implements
,
,
,
,
,
,
,
,
,
,
,
,
,
The direction of the Stack Items.
Renders components as Box children. Accepts a JSX.Element or an array of JSX.Element.
Type: Element | Element[]
The variant of the button style to use.
Type: "link" | "ghost" | "outline" | "solid" | "unstyled"
The start icon element to use in the button.
Type: "xs" | "sm" | "md" | "lg"
The color of the radio when it's checked. This should be one of the color keys in the theme (e.g."green", "red").
If true, the button will be disabled.
If true, button will be atttached together.
NativeBase ships with a default theme for each component. Check out the default theme of the button
.
Info:
We can easily extend the button component theme using extendTheme function as described in the documentation .When Button has focus, Space or Enter activates it.