Skip to content

Commit 4f0c387

Browse files
committed
Push
1 parent 973b51d commit 4f0c387

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

documentation/docs/03-template-syntax/18-class.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ The user of this component has the same flexibility to use a mixture of objects,
7171
</Button>
7272
```
7373

74+
Svelte also exposes the `ClassValue` type, which is the type of the value that `class` can take. This is useful if you want to use a type-safe class name in component props:
75+
76+
```svelte
77+
<script lang="ts">
78+
import type { ClassValue } from 'svelte/elements';
79+
80+
const props: { class: ClassValue } = $props();
81+
</script>
82+
83+
<div class={['original', props.class]}>...</div>
84+
```
85+
7486
## The `class:` directive
7587

7688
Prior to Svelte 5.16, the `class:` directive was the most convenient way to set classes on elements conditionally.

packages/svelte/elements.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,3 +2059,5 @@ export interface SvelteHTMLElements {
20592059

20602060
[name: string]: { [name: string]: any };
20612061
}
2062+
2063+
export type ClassValue = import('clsx').ClassValue;

0 commit comments

Comments
 (0)