# Size Context

## Usage

`SizeProvider` sets a default size (`sm`, `md`, or `lg`) for a whole subtree. Interactive components inside use it when they have no `size` of their own; a component with an explicit `size` is unaffected. It renders no extra element and passes its default slot through.

```ts
import { provideSize, SizeProvider, useSize } from '@astryx-vue/core/SizeContext'
```

Size resolves in this order, first match wins:

1. The explicit `size` on the component.
2. `Button` only: the size of the enclosing `ButtonGroup`.
3. The context from an enclosing `SizeProvider` or container component.
4. The component's own default.

`Toolbar`, `ButtonGroup`, and `InputGroup` provide their size automatically, so children need no per-item `size`. `Button`, `MoreMenu`, `TextInput`, `TextArea`, `Selector`, `MultiSelector`, `NumberInput`, the date inputs and `TimeInput`, `SegmentedControl`, `TabList`, `PowerSearch`, and `Tokenizer` consume it.

Like other layer-scoped context, it resets inside teleported overlay layers: menus, popovers, and similar content rendered through a Teleport do not inherit the outer size. Add another `SizeProvider` inside the layer if needed.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Set one size for a whole region with `SizeProvider`, or the `size` of `Toolbar` or `InputGroup`, instead of repeating it on every child. |
| Do | For a single exception, set `size` on that component; it always wins. |
| Don't | Expect `SizeProvider` to reach content inside overlay layers: teleported content falls back to defaults. |

## Examples

Common configurations, variations, and states.

### SizeContext — SizeProvider

The first row uses default sizes; the second is wrapped in SizeProvider value="sm", so the Button and TextInput both render small.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { SizeProvider } from '@astryx-vue/core/SizeContext'
import { TextInput } from '@astryx-vue/core/TextInput'
import { ref } from 'vue'

const defaultValue = ref('')
const smallValue = ref('')
</script>

<template>
  <div class="size-context-preview">
    <div class="size-context-preview__row">
      <Button label="Default" />
      <TextInput v-model="defaultValue" label="Default" is-label-hidden placeholder="Default" />
    </div>
    <SizeProvider value="sm">
      <div class="size-context-preview__row">
        <Button label="Small" />
        <TextInput v-model="smallValue" label="Small" is-label-hidden placeholder="Small" />
      </div>
    </SizeProvider>
  </div>
</template>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `'sm' \| 'md' \| 'lg' \| null` | `null` | The default size provided to descendants. `null` provides nothing, so children use their own default. |

## Slots

| Slot | Description |
| --- | --- |
| `default` | The subtree that reads this default size. |

## Other exports

| Export | Type | Description |
| --- | --- | --- |
| `useSize` | `(sizeProp, default = 'md') => ComputedRef` | Resolves the final size: explicit prop > context > default. |
| `provideSize` | `(size) => void` | Provides a size from `setup`; used inside container components. |
| `SizeContext` | injection key | The underlying context key. |
| `ElementSize` | `'sm' \| 'md' \| 'lg'` | The size type. |

## Native attributes

The component renders no element, so <code>class</code> and <code>style</code> are not forwarded.
