Center
Centers its child both horizontally and vertically. The shortest path between "I want this thing in the middle" and a working layout.
Plain <div> (polymorphic via as); preserves the child's semantics.
Preview
tsx
import { Center, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Center minHeight="120px" padding="4" background="bg.subtle" borderRadius="md">
<Text>Centered content</Text>
</Center>
);
}
With a height floor
Section titled “With a height floor”Center needs a non-zero height to do anything meaningful in the vertical axis. Set minHeight (token or raw value) so the canvas has room to center within.
Preview
tsx
import { Center, Spinner } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Center minHeight="160px" background="bg.subtle" borderRadius="md">
<Spinner label="Loading" />
</Center>
);
}
PropTypeDefaultDescription
className
string
—
Additional class names appended after Cynosure's base classes.
style
CSSProperties
—
Inline style overrides merged last.
children
ReactNode
—
Content centred on both axes.
paddingX
—
Horizontal padding (left + right). Overrides `padding` on the X axis.
paddingY
—
Vertical padding (top + bottom). Overrides `padding` on the Y axis.
height
—
Element height. Accepts a `SpaceToken`, `LengthValue`, or named alias.
minWidth
—
Minimum width — useful for preventing flex children from collapsing.
background
—
Background colour. Use a `ColorToken` like `"bg.surface"` for theme awareness.
borderColor
—
Border colour. Pair with `borderWidth` to make the border visible.
opacity
Responsive<number | `${number}`>
—
Opacity 0–1. Use sparingly — prefer surface tokens over translucency.
overflowX
—
Horizontal-axis overflow control. Overrides `overflow` for the X axis.
display
—
CSS `display` value. `"contents"` removes the element's box from layout.
position
—
CSS `position`. Pair with `top`/`right`/`bottom`/`left` for placement.
top
—
Top inset (when positioned). Accepts a `SpaceToken`, `"auto"`, `"0"`, or `LengthValue`.
flex
Responsive<"1" | "none" | "auto" | "initial" | (string & {})>
—
Shorthand: `1 | auto | none | initial | <css>`. Resolves to `flex` on the child.
asChild
boolean
—
When `true`, renders the primitive's single React child via `Slot`,
forwarding className/style/ref/event handlers onto it.
as
ElementType
"div"
Rendered intrinsic element or component.
ref
ForwardedRef<Element>
—
Recipes
Section titled “Recipes”- Loading state inside a card:
<Center minHeight="120px"><Spinner /></Center>. - Empty state placeholder: pair
CenterwithEmptyState. Setflex="1"on the Center when it sits inside a flex parent so it claims the remaining space. - For the entire viewport: nest a
Centerinside aBox minHeight="100vh"(or use thescreensize token onminHeight).