# NoData

Empty state: an icon, a title, an optional description and optional actions (`children`), centered in the available space. `size="md"` is the full illustration with the icon in a framed box, for pages and panels; `size="sm"` keeps only the icon and the text, for tables, lists and cards. Its size is exposed as `data-size` for app CSS.

```ts
import { NoData } from '@likable-hair/svelte';
```

Category: simple. Source: `src/lib/components/simple/common/NoData.svelte`.

## Examples

### Empty page

The full illustration, for a page or a panel with nothing to show yet. `icon` takes an SVG path; `children` holds the actions.

```svelte
<script lang="ts">
	import { mdiCalendarBlankOutline, mdiPlus } from '@mdi/js';
	import { Button, NoData } from '@likable-hair/svelte';
</script>

<NoData
	icon={mdiCalendarBlankOutline}
	title="No appointments"
	description="The day is free. Add an appointment or share your booking link."
>
	<Button size="sm" icon={mdiPlus}>New appointment</Button>
</NoData>
```

### Compact

`size="sm"` keeps only the icon and the text, for tables, lists and cards. Without props it says "No data available".

```svelte
<script lang="ts">
	import { mdiMagnify } from '@mdi/js';
	import { NoData } from '@likable-hair/svelte';
</script>

<div class="grid">
	<section class="card">
		<h3>Recent payments</h3>
		<NoData size="sm" />
	</section>
	<section class="card">
		<h3>Clients</h3>
		<NoData size="sm" icon={mdiMagnify} title="No results for “Rossi”" description="Check the spelling or try another name." />
	</section>
</div>

<style>
	.grid {
		display: grid;
		grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
		gap: 16px;
		width: 100%;
	}

	.card {
		padding: 16px;
		border: 1px solid var(--global-color-border);
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-solid);
	}

	h3 {
		margin: 0;
		font-size: 14px;
		font-weight: 600;
	}
</style>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` |  | Main text. Defaults to "No data available", in the language of `locale`. |
| `description` | `string` |  | Secondary text under the title. |
| `icon` | `string` | `DATABASE_OFF_ICON` | SVG path of the icon. An empty string removes it. |
| `size` | `'sm' \| 'md'` | `'md'` | `md` the full illustration, `sm` only the icon and the text. |
| `locale` | `string` |  | BCP 47 locale of the texts: `it` and `en` are built in, other languages fall back to English. Defaults to the one set with `setDefaultLocale`, else `en`. |
| `class` | `string` | `''` | Extra classes on the root element. |

It also accepts the native attributes and events of `<div>` (for example `id`, `title`, `aria-label`, `onkeydown`), which are forwarded to the element.

## Snippets

| Name | Parameters | Description |
| --- | --- | --- |
| `children` |  | Actions under the text, for example a button that creates the first item. |
| `titleSnippet` | `{ title: string }` | Replaces the title. |
| `descriptionSnippet` | `{ description: string \| undefined }` | Replaces the description. |
| `iconSnippet` |  | Replaces the icon (inside the framed box with `size="md"`). |

## CSS variables

For a single instance, pass them as style props: `<NoData --no-data-icon-color="tomato">`. The `--no-data-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

| Per-instance variable | Default |
| --- | --- |
| `--no-data-gap` | `--no-data-default-gap`: `18px`<br>`--no-data-default-sm-gap`: `8px` |
| `--no-data-height` | `--no-data-default-height`: `auto` |
| `--no-data-min-height` | `--no-data-default-min-height`: `200px`<br>`--no-data-default-sm-min-height`: `120px` |
| `--no-data-padding` | `--no-data-default-padding`: `10px` |
| `--no-data-icon-size` | `--no-data-default-icon-size`: `40px`<br>`--no-data-default-sm-icon-size`: `32px` |
| `--no-data-icon-color` | `--no-data-default-icon-color`: `var(--global-color-primary)`<br>`--no-data-default-sm-icon-color`: `var(--global-color-text-3)` |
| `--no-data-icon-box-size` | `--no-data-default-icon-box-size`: `96px` |
| `--no-data-icon-border-radius` | `--no-data-default-icon-border-radius`: `var(--global-radius-xl)` |
| `--no-data-icon-border-color` | `--no-data-default-icon-border-color`: `var(--global-color-border-strong)` |
| `--no-data-icon-background` | `--no-data-default-icon-background`: `var(--global-gradient-soft)` |
| `--no-data-ring-color` | `--no-data-default-ring-color`: `var(--global-color-border-strong)` |
| `--no-data-max-width` | `--no-data-default-max-width`: `320px` |
| `--no-data-title-color` | `--no-data-default-title-color`: `var(--global-color-text)`<br>`--no-data-default-sm-title-color`: `var(--global-color-text-2)` |
| `--no-data-title-font-family` | `--no-data-default-title-font-family`: `var(--global-font-family-display)`<br>`--no-data-default-sm-title-font-family`: `var(--global-font-family)` |
| `--no-data-title-font-size` | `--no-data-default-title-font-size`: `19px`<br>`--no-data-default-sm-title-font-size`: `13px` |
| `--no-data-title-font-weight` | `--no-data-default-title-font-weight`: `600`<br>`--no-data-default-sm-title-font-weight`: `500` |
| `--no-data-description-color` | `--no-data-default-description-color`: `var(--global-color-text-3)` |
| `--no-data-description-font-size` | `--no-data-default-description-font-size`: `13px`<br>`--no-data-default-sm-description-font-size`: `12px` |
| `--no-data-actions-gap` | `--no-data-default-actions-gap`: `18px`<br>`--no-data-default-sm-actions-gap`: `12px` |
