# Center

## Usage

`Center` puts its content in a flex container and aligns it to the middle of that box on one axis or on both. It is layout only: it paints nothing, draws no border, and adds no role or accessible name to the content, so empty states, loading screens, and login forms all fit without any extra markup.

By default it centers on both axes:

```vue
<script setup lang="ts">
import { Center } from '@astryx-vue/core/Center'
</script>

<template>
  <Center :height="200">
    <p>Nothing here yet</p>
  </Center>
</template>
```

Everything in the slot is centered as one block: `Center` never distributes space between several children. When you need to arrange multiple items along a direction, use `Stack` instead.

`axis` selects which axis is centered. `both` (the default) centers the main and the cross axis, `horizontal` centers the inline direction only, and `vertical` centers the block direction only. The two single-axis values are named after horizontal writing; they end up on flex alignment, so in vertical writing they follow the flex main and cross axes. Centering an axis only shows when that axis has space to give, which is why `both` and `vertical` usually need a `height` — without one the container is only as tall as its content and looks exactly like an uncentered box.

```vue
<script setup lang="ts">
import { Center } from '@astryx-vue/core/Center'
import { Spinner } from '@astryx-vue/core/Spinner'
</script>

<template>
  <Center axis="vertical" :height="240">
    <Spinner />
  </Center>
</template>
```

The size of the container comes from `width`, `height`, `maxWidth`, and `minHeight`. Numbers are interpreted as pixels and strings pass through as CSS values, so `width="100%"` and `maxWidth="70rem"` both work. Padding uses the same spacing scale as `Stack`: `padding` sets all four edges, `paddingInline` and `paddingBlock` override their own axis, and `paddingInlineStart`, `paddingInlineEnd`, `paddingBlockStart`, and `paddingBlockEnd` override a single edge. The most specific input wins, and `0` is a real value, so it can clear the inset set by a broader one.

`isInline` renders the container as `inline-flex`. It then takes part in the surrounding line of text instead of breaking the line box, which is what you want for a fixed-size box that centers an icon or a badge.

### Anatomy

- **Container**: A flexbox wrapper that aligns its children to the center along the chosen axis.
- **Content**: Anything passed in the default slot to Center. Typically a card, form, spinner, or empty state message.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Use a single-axis value only in horizontal writing, or after checking which writing mode is active. Outside horizontal writing, a single-axis value follows the flex main and cross axes rather than the name of the prop. |
| Do | Give `height` when you use `axis="vertical"` or the default `both` in horizontal writing. Centering needs space to distribute, and a container that is only as tall as its content shows no change. |
| Do | Use `isInline` for small elements such as icons and badges. The box stays inside the current line, so the text around it is not broken. |
| Do | Keep the semantic structure and the accessible names on the content. `Center` is a layout-only container: it adds no role and no label, so the content stays responsible for both. |
| Don't | Wrap whole page sections in `Center`. Page structure belongs to the surrounding layout; `Center` solves the centering of one block. |
| Don't | Use `Center` for horizontal lists of items. Several items in a row are clearer with `Stack` and `hAlign="center"`. |

## Examples

### Horizontal

A formatting toolbar centered on the horizontal axis. In vertical writing, that axis follows flex rather than a guaranteed physical horizontal.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Center } from '@astryx-vue/core/Center'
import { IconButton } from '@astryx-vue/core/IconButton'
import { HStack } from '@astryx-vue/core/Stack'

const tools = [
  { label: 'Bold', icon: 'i-carbon-text-bold' },
  { label: 'Italic', icon: 'i-carbon-text-italic' },
  { label: 'Underline', icon: 'i-carbon-text-underline' },
  { label: 'List', icon: 'i-carbon-list' },
  { label: 'Link', icon: 'i-carbon-link' },
  { label: 'Image', icon: 'i-carbon-image' },
]
</script>

<template>
  <Card :padding="2" :width="520">
    <Center axis="horizontal" width="100%">
      <HStack align="center" :gap="0">
        <IconButton
          v-for="tool in tools"
          :key="tool.label"
          :label="tool.label"
          size="sm"
          variant="ghost"
        >
          <span class="css-icon css-icon--sm" :class="tool.icon" />
        </IconButton>
      </HStack>
    </Center>
  </Card>
</template>
```

### Inside a card

An empty state centered both ways inside a fixed-height card. The height is what gives Center room to center.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Center } from '@astryx-vue/core/Center'
import { Icon } from '@astryx-vue/core/Icon'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Card :width="400">
    <Center :height="200">
      <VStack :gap="2" h-align="center">
        <Icon color="secondary" icon="i-heroicons-inbox" size="lg" />
        <Text type="body" weight="bold">
          No messages yet
        </Text>
        <Text color="secondary" type="supporting">
          Messages from your team will appear here.
        </Text>
      </VStack>
    </Center>
  </Card>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `axis` | `'both' \| 'horizontal' \| 'vertical'` | `'both'` | Which axis to center. both centers the main and the cross axis, horizontal centers the inline direction only, and vertical centers the block direction only. A single-axis value ends up on flex alignment, so outside horizontal writing it follows the flex main and cross axes. |
| `width` | `number \| string` | — | Container width. Numbers are interpreted as pixels, strings pass through as CSS values. |
| `height` | `number \| string` | — | Container height. Numbers are interpreted as pixels. Vertical centering needs height to distribute, so the default both and vertical usually use it. |
| `maxWidth` | `number \| string` | — | Maximum container width. Numbers are interpreted as pixels. |
| `minHeight` | `number \| string` | — | Minimum container height. Numbers are interpreted as pixels. |
| `padding` | `SpacingStep` | — | Inner padding on all four edges, using the Astryx spacing scale. |
| `paddingInline` | `SpacingStep` | — | Inline-axis padding; overrides padding on that axis. |
| `paddingInlineStart` | `SpacingStep` | — | Inline-start padding; overrides that edge only, and takes precedence over paddingInline and padding. The physical edge follows writing mode and direction. |
| `paddingInlineEnd` | `SpacingStep` | — | Inline-end padding; overrides that edge only, and takes precedence over paddingInline and padding. The physical edge follows writing mode and direction. |
| `paddingBlock` | `SpacingStep` | — | Block-axis padding; overrides padding on that axis. |
| `paddingBlockStart` | `SpacingStep` | — | Block-start padding; overrides that edge only, and takes precedence over paddingBlock and padding. The physical edge follows writing mode. |
| `paddingBlockEnd` | `SpacingStep` | — | Block-end padding; overrides that edge only, and takes precedence over paddingBlock and padding. The physical edge follows writing mode. |
| `isInline` | `boolean` | `false` | Render as inline-flex, so the container stays in a line of text. Useful for centering small elements such as icons and badges. |

`SpacingStep` accepts these values:

```ts
type SpacingStep = 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10
```

## Slots

| Name | Description |
| --- | --- |
| `default` | The content to center. It is centered as one block: Center adds no space between several children and changes none of their semantics, colors, or reading order. |

## Native attributes

The root element is a `<div>`.

The following go to the root element:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes.
- `class`.
- `style`.
- Native event listeners.

`Center` writes its own `data-axis` on the root element to reflect the axis in effect; a `data-axis` passed in by a consumer does not replace it.
