Style props are a way to alter the style of a component by simply passing props to it. It helps to save time by providing helpful shorthand ways to style components.
The following table shows a list of every style prop and the properties within each group.
const NBBox = props => {
return <Box borderRadius="md" bg="primary.600" {...props} />;
};
function Component() {
return <>
{
}
<NBBox m="2" p="5" />
{
}
<NBBox mx="auto" px="20" py="5" />
{
}
<NBBox m={[2, 3]} pt="10" pr="10" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
margin-left and margin-right
margin-top and margin-bottom
padding-left and padding-right
padding-top and padding-bottom
Color and background color
function NBBox(props) {
return <Box p="5" m="2" borderRadius="md" bg="primary.200" {...props} />;
}
function Component() {
return <>
{
}
<NBBox bg="#10b981" />
{
}
{
}
<NBBox bgColor="cyan.100" py="3">
{
}
<Text color="cyan.500" fontWeight="bold">
{" "}
I love NativeBase
</Text>
</NBBox>
{
}
<NBBox backgroundColor="#eab308" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
Note:
Above props can be written in the format: [color]:alpha.[opacityToken], this gets converted into RGBA color format and the opacityToken is mapped to function App() {
return <Stack space="2" alignItems="center">
<HStack space="2" alignItems="center">
<Center size="16" bg="primary.400:alpha.30" rounded="md" _text={{
color: "white"
}}>
Box 1
</Center>
<Center size="16" bg="primary.400:alpha.70" rounded="md" _text={{
color: "white"
}}>
Box 2
</Center>
<Center bg="primary.400" size="16" rounded="md" _text={{
color: "white"
}} shadow="1">
Box 3
</Center>
</HStack>
</Stack>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<App />
</Center>
</NativeBaseProvider>;
}
const NBText = props => {
return <Text m="2" {...props} />;
};
function Component() {
return <>
{
}
<NBText fontSize="2xl" fontWeight="bold">
Thank You{" "}
</NBText>
{
}
<NBText textDecoration="underline">Merci Beaucoup</NBText>
{
}
{
}
<NBText fontWeight="bold">Danke sehr </NBText>
{
}
<NBText letterSpacing="2xl">Arigatou </NBText>
</>;
}
function Example() {
return <Center flex={1}>
<Component />
</Center>;
}
const NBBox = props => {
return <Box m="2" borderRadius="md" bg="primary.600" {...props} />;
};
function Component() {
return <>
{
}
<NBBox width="100%" height="8" />
{
}
<NBBox w="100%" h="32px" />
{
}
<NBBox boxSize="12" />
{
}
<NBBox w="50%" h="8" />
{
}
<NBBox w="256" />
{
}
<NBBox w="40px" h="8" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
const NBBox = props => {
return <Box p="5" m="2" borderRadius="md" bg="primary.600" {...props} />;
};
function Component() {
return <>
{
}
<Box display="flex" flexDirection="row" justifyContent="space-between">
<NBBox />
<NBBox />
<NBBox />
</Box>
{
}
<Flex align="center" justify="center">
<NBBox />
<NBBox />
</Flex>
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
flexDirection, flexDir, *direction
const NBBox = props => {
return <Box p="5" m="2" borderRadius="md" bg="primary.200" {...props} />;
};
function Component() {
return <>
<NBBox borderWidth="1" borderColor="cyan.500" />
<NBBox borderWidth="2" borderColor="cyan.500" />
<NBBox borderColor="cyan.500" borderTopWidth="7" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
const NBBox = props => {
return <Box p="5" m="2" bg="primary.500" {...props} />;
};
function Component() {
return <>
{
}
{
}
<NBBox borderRadius="md" />
<NBBox borderRadius="full" />
{
}
<NBBox borderLeftRadius="10" />
{
}
<NBBox borderRadius="8" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
border-bottom-right-radius
border-bottom-left-radius
border-top-left-radius & border-top-right-radius
border-top-right-radius & border-bottom-right-radius
border-bottom-left-radius & border-bottom-right-radius
border-top-left-radius & border-bottom-left-radius
const NBBox = props => {
return <Box p="5" borderRadius="md" bg="primary.400" {...props} />;
};
function Component() {
return <Box justifyContent="center" alignItems="center" flexDirection="row">
<NBBox position="relative" p="7" />
<NBBox bg="yellow.400" zIndex={2} position="absolute" />
<NBBox bg="emerald.400" position="relative" p="7" />
</Box>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
const NBBox = props => {
return <Box p="5" m="2" borderRadius="md" bg="primary.500" {...props} />;
};
function Component() {
return <>
{
}
<NBBox shadow="1" />
<NBBox shadow="3" />
<NBBox shadow="5" />
<NBBox shadow="7" />
<NBBox shadow="9" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
Provides a way to pass props to child components inside Composite componets.
function App() {
return <Button _text={{
color: "primary.100",
fontSize: "md",
fontWeight: "bold",
underline: true
}}>
Save
</Button>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<App />
</Center>
</NativeBaseProvider>;
}
Passed props will be provided to
child.
Passed props will be provided to
child.
Provides a way to pass props on certain interaction.
function App() {
return <Button colorScheme="yellow" _pressed={{
bg: "yellow.600",
_text: {
color: "warmGray.50"
}
}}>
Save
</Button>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<App />
</Center>
</NativeBaseProvider>;
}
Passed props will be applied on disabled state.
Passed props will be applied on focused state.
Passed props will be applied on hovered state.
Passed props will be applied on invalid state.
Passed props will be applied on pressed state.
Provides a way to pass props bassed on Platform (android, ios or web).
function App() {
return <Button _web={{
bg: "yellow.400",
_text: {
color: "coolGray.800",
fontWeight: "medium"
},
_pressed: {
bg: "yellow.600",
_text: {
color: "warmGray.50"
}
}
}}>
Save
</Button>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<App />
</Center>
</NativeBaseProvider>;
}
Passed props will be applied on android.
Passed props will be applied on ios.
Passed props will be applied on web.