Flex provides helpful style shorthand and is a
with
display: flex.
import { Flex, Spacer } from 'native-base';
Flex: a
with
display: flex Spacer: creates an adjustable, empty space that can be used to tune the spacing between child elements within Flex
Flex components come with some helpful shorthand props:
flexDirection is direction
justifyContent is justify
While you can pass the verbose props, using the shorthand can save you some time.
function Example() {
const [direction, setDirection] = React.useState("column");
return <Center>
<Box>
<Heading size="md" mb={3}>
Primary Shades
</Heading>
</Box>
<Button my={3} onPress={() => setDirection(direction === "row" ? "column" : "row")}>
Change Flex Direction
</Button>
<Box>
{
}
<Flex direction={direction}>
<Center size={16} bg="primary.100" _text={{
color: "gray.800"
}}>
100
</Center>
<Center size={16} bg="primary.200" _text={{
color: "white"
}}>
200
</Center>
<Center bg="primary.300" size={16} _text={{
color: "white"
}}>
300
</Center>
<Center size={16} bg="primary.400" _text={{
color: "white"
}}>
400
</Center>
</Flex>
</Box>
</Center>;
}
You can pass Spacer to add Space between Flex items.
const Example = () => {
return <Flex h={40} w={20} mt={6}>
<Center size={16} bg="primary.400" rounded="xl" _text={{
color: "white"
}}>
Box 1
</Center>
<Spacer />
<Center size={16} bg="secondary.400" rounded="xl" _text={{
color: "white"
}}>
Box 2
</Center>
</Flex>;
};
Flex implements
, so all the Box Props can be passed to it, i.e.
,
,
,
&
props from
.