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.200" {...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
const NBBox = props => {
return <Box p={5} m={2} borderRadius="md" bg="primary.200" {...props} />;
};
function Component() {
return <>
{
}
<NBBox bg="#fdba74" />
{
}
{
}
<NBBox bgColor="lightBlue.200" py={3}>
{
}
<Text color="red.500" fontWeight="bold">
{" "}
I ❤️ NativeBase
</Text>
</NBBox>
{
}
<NBBox backgroundColor="indigo.300" />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
const NBText = props => {
return <Text m={2} {...props} />;
};
function Component() {
return <>
{
}
<NBText fontSize="md">Sample Text </NBText>
{
}
<NBText fontSize={32} textDecoration="underline">
Sample Text{" "}
</NBText>
{
}
{
}
<NBText fontSize="2em" fontWeight="bold">
Sample Text{" "}
</NBText>
{
}
<NBText textAlign={["left", "center"]}>Sample Text </NBText>
</>;
}
function Example() {
return <Center flex={1}>
<Component />
</Center>;
}
const NBBox = props => {
return <Box m={2} borderRadius="md" bg="primary.200" {...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.200" {...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 border={1} />
<NBBox borderWidth={2} borderColor="red.400" />
<NBBox border={2} borderBottomColor="red.500" borderTopWidth={7} />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
const NBBox = props => {
return <Box p={5} m={2} bg="primary.200" {...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} m={2} borderRadius="md" bg="primary.200" {...props} />;
};
function Component() {
return <>
<NBBox position="absolute" left={32} p={7} />
<NBBox bgColor="orange.300" zIndex={2} position="relative" />
<NBBox backgroundColor="indigo.300" position="absolute" right={32} p={7} />
</>;
}
function Example() {
return <NativeBaseProvider>
<Center flex={1}>
<Component />
</Center>
</NativeBaseProvider>;
}
const NBBox = props => {
return <Box p={5} m={2} borderRadius="md" bg="primary.200" {...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: "secondary.400",
fontSize: "xs",
fontWeight: "bolder"
}}>
Sample Text
</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 _pressed={{
bg: "primary.300",
_text: {
color: "secondary.400"
}
}}>
Sample Text
</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: "primary.300",
_text: {
color: "secondary.400",
fontWeight: "bold"
}
}}>
Sample Text
</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.