Center
The Center component is a layout component that centers its children both vertically and horizontally.
It has a display: flex style with justify-content: center and align-items: center.
How to use
1import { Box, Center } from '@devup-ui/react'
2
3function App() {
4 return (
5 <Center>
6 <Box bg="blue" h={25} w={25} />
7 <Box bg="blue" display="flex" h={25} w={25} />
8 <Box bg="blue" h={25} w={25} />
9 </Center>
10 )
11}
1import { Box, Center } from '@devup-ui/react'
2
3function App() {
4 return (
5 <Center>
6 <Box bg="blue" h={25} w={25} />
7 <Box bg="blue" display="flex" h={25} w={25} />
8 <Box bg="blue" h={25} w={25} />
9 </Center>
10 )
11}
The Center component defined above will render like this:
1function App() {
2 return (
3 <div className="e f g">
4 <div className="a b c"></div>
5 <div className="a b c d"></div>
6 <div className="a b c"></div>
7 </div>
8 )
9}
1function App() {
2 return (
3 <div className="e f g">
4 <div className="a b c"></div>
5 <div className="a b c d"></div>
6 <div className="a b c"></div>
7 </div>
8 )
9}
1.a { 2 background: blue; 3} 4.b { 5 height: 100px; 6} 7.c { 8 width: 100px; 9} 10.d { 11 display: flex; 12} 13.e { 14 display: flex; 15} 16.f { 17 justify-content: center; 18} 19.g { 20 align-items: center; 21}1.a { 2 background: blue; 3} 4.b { 5 height: 100px; 6} 7.c { 8 width: 100px; 9} 10.d { 11 display: flex; 12} 13.e { 14 display: flex; 15} 16.f { 17 justify-content: center; 18} 19.g { 20 align-items: center; 21}
If you pass a number without a unit to a style property, it will be automatically scaled by 4. This means 1 equals 4px, 2 equals 8px, and so on.
However, the following properties are exceptions and are not multiplied by 4:
opacityflexz-indexline-clampfont-weightline-heightscaleaspect-ratioflex-growflex-shrinkordergrid-column,grid-column-start,grid-column-endgrid-row,grid-row-start,grid-row-endanimation-iteration-counttab-size,moz-tab-size,-webkit-line-clamp
Class names and style properties are resolved in the following order:
-
Generate class names for child components.
- Compute class names and style properties coming from each child (including component defaults, utility classes, and props).
-
Remove duplicate component properties.
- Deduplicate only when both the
key:valuepair and thestyle-ordermatch.
- Deduplicate only when both the
-
If the key:value matches but the
style-orderdiffers, the property is not removed — the later/higher-priority style will take precedence.- Example: In other words, the
display: fleximplemented internally byCenterand thedisplay: flexprovided directly by the user have different style-orders, so they are not removed, and the final style is applied according to priority.
- Example: In other words, the
-
Generate the parent component’s className based on the merged result.
- After child classNames are generated and duplicates (per rules above) removed, compute/merge the parent className and final style output.