Div

Wrapper around <View /> of react native. It accepts every props that is available for <View />

import { Div, Text } from "react-native-magnus";

<Div p="xl" shadow="sm" rounded="md">
  <Text textAlign="center">This is a Div</Text>
</Div>;

You can also import Box which is an alias to Div. This is done because many users are familiar with styled system and those will like using Box instead of Div.

Background Colors

<Div h={40} w={40} bg="pink500"></Div>
<Div h={40} w={40} bg="green500"></Div>
<Div h={40} w={40} bg="teal500"></Div>
<Div h={40} w={40} bg="yellow500"></Div>
<Div h={40} w={40} bg="red500"></Div>
<Div h={40} w={40} bg="blue500"></Div>
<Div h={40} w={40} bg="gray500"></Div>

You can check complete list of colors from here

Borders

<Div h={40} w={40} bg="green200" borderColor="green500" borderWidth={1} />
<Div h={40} w={40} bg="yellow200" borderColor="yellow500" borderWidth={1} />
<Div h={40} w={40} bg="red200" borderColor="red500" borderWidth={1} />
<Div h={40} w={40} bg="blue200" borderColor="blue500" borderWidth={1} />
<Div h={40} w={40} bg="gray200" borderColor="gray500" borderWidth={1} />

Shadows

<Div h={40} w={40} rounded="md" shadow="xs"></Div>
<Div h={40} w={40} rounded="md" shadow="sm"></Div>
<Div h={40} w={40} rounded="md" shadow="md"></Div>
<Div h={40} w={40} rounded="md" shadow="lg"></Div>
<Div h={40} w={40} rounded="md" shadow="xl"></Div>
<Div h={40} w={40} rounded="md" shadow="2xl"></Div>

Border radius

<Div h={40} w={40} bg="teal500"></Div>
<Div h={40} w={40} bg="teal500" rounded="sm"></Div>
<Div h={40} w={40} bg="teal500" rounded="md"></Div>
<Div h={40} w={40} bg="teal500" rounded="lg"></Div>
<Div h={40} w={40} bg="teal500" rounded="xl"></Div>

Flex

<Div row m="xl">
  <Div h={40} flex={3} bg="red500" />
  <Div h={40} flex={1} mx="sm" bg="yellow500" />
  <Div h={40} flex={2} bg="green500" />
</Div>

Example #1

See it on Snack

<Div m="xl">
  <Div>
    <Div
      rounded="xl"
      h={150}
      bgImg={{
        uri:
          "https://images.unsplash.com/photo-1512917774080-9991f1c4c750?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
      }}
    >
      <Div
        bg="pink500"
        rounded="md"
        row
        flexWrap="wrap"
        px="md"
        m="lg"
        alignSelf="flex-start"
      >
        <Text color="white" fontSize="sm">
          2 Rooms
        </Text>
      </Div>
    </Div>
    <Div row alignItems="center">
      <Div flex={1}>
        <Text fontWeight="bold" fontSize="xl" mt="sm">
          Sunny Apartment
        </Text>
        <Text color="gray500" fontSize="sm">
          Gurgoan, India
        </Text>
      </Div>
      <Div row alignItems="center">
        <Text color="blue500" fontWeight="bold" fontSize="xl">
          $500
        </Text>
        <Text color="gray500" ml="md">
          / per day
        </Text>
      </Div>
    </Div>
  </Div>
</Div>

Props

PropertyDescriptionTypeDefault
mmargin`stringnumber`
mtmargin top`stringnumber`
mrmargin right`stringnumber`
mbmargin bottom`stringnumber`
mlmargin margin left`stringnumber`
mxmargin horizonal`stringnumber`
mymargin vertical`stringnumber`
ppadding`stringnumber`
ptpadding top`stringnumber`
prpadding right`stringnumber`
pbpadding bottom`stringnumber`
plpadding margin left`stringnumber`
pxpadding horizonal`stringnumber`
pypadding vertical`stringnumber`
hheightnumber-
wwidthnumber-
bgbackground colorstring-
minHmininmum heightnumber-
minWminimum widthstring-
bgImgbackground imageImageSourcePropType-
bgModeresize mode for background image`“contain”“cover”
roundedborder radius`stringnumber`
roundedTopborder radius top`stringnumber`
roundedBottomborder radius bottom`stringnumber`
roundedLeftborder radius left`stringnumber`
roundedRightborder radius right`stringnumber`
borderColorcolor for borderstring-
borderTopColorcolor for border topstring-
borderRightColorcolor for border rightstring-
borderLeftColorcolor for border leftstring-
borderBottomColorcolor for border bottomstring-
borderWidthwidth for bordernumber-
borderTopWidthwidth for border topnumber-
borderRightWidthwidth for border rightnumber-
borderLeftWidthwidth for border leftnumber-
borderBottomWidthwidth for border bottomnumber-
flexflex property for containernumber-
rowmakes flex direction to row when trueboolean-
shadowdescribe the depth of shadownumber-
shadowColorcolor for shadowstring-
justifyContentdescribes how to align children within the main axis of their container`“flex-start”“flex-end”
alignItemsdescribes how to align children along the cross axis of their container`“flex-start”“flex-end”
flexDircontrols the direction in which children of a node are laid out`“row”“column”
flexWrapcontrols what happens when children overflow the size of the container along the main axis`“wrap”“nowrap”
positionused to position the childrens`absolute”“relative”`
topnumber of logical pixels to offset the top edge of this component.number-
rightnumber of logical pixels to offset the right edge of this component.number-
bottomnumber of logical pixels to offset the bottom edge of this component.number-
leftnumber of logical pixels to offset the left edge of this component.number-
opacityopacity of divnumber-
alignSelfalignment for the selected item inside the flexible container.`‘auto’‘flex-start’
overflowcontrols how children are measured and displayed`“visible”“scroll”