Skip to content

Commit 6fac48a

Browse files
author
Shamim Hossain
committed
chore: update heading UI component
1 parent 3157195 commit 6fac48a

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
<script lang="ts">
22
import { cn } from '$lib/utils';
3+
import type { SvelteHTMLElements } from 'svelte/elements';
34
import { headingVariants, type Props } from '.';
45
5-
type $$Props = Props;
6+
export let element: $$Props['element'] = 'h1';
7+
8+
type $$Props = (
9+
| SvelteHTMLElements['h1']
10+
| SvelteHTMLElements['h2']
11+
| SvelteHTMLElements['h3']
12+
| SvelteHTMLElements['h4']
13+
| SvelteHTMLElements['h5']
14+
| SvelteHTMLElements['h6']
15+
) &
16+
Props;
617
718
let className: $$Props['class'] = undefined;
819
export let size: $$Props['size'] = 'default';
920
export { className as class };
1021
</script>
1122

12-
<h1 class={cn(headingVariants({ size, className }))} {...$$restProps}>
13-
<slot />
14-
</h1>
23+
{#if element === 'h1'}
24+
<h1 class={cn(headingVariants({ size, className }))} {...$$restProps}>
25+
<slot />
26+
</h1>
27+
{:else if element === 'h2'}
28+
<h2 class={cn(headingVariants({ size, className }))} {...$$restProps}>
29+
<slot />
30+
</h2>
31+
{:else if element === 'h3'}
32+
<h3 class={cn(headingVariants({ size, className }))} {...$$restProps}>
33+
<slot />
34+
</h3>
35+
{:else if element === 'h4'}
36+
<h4 class={cn(headingVariants({ size, className }))} {...$$restProps}>
37+
<slot />
38+
</h4>
39+
{:else if element === 'h5'}
40+
<h5 class={cn(headingVariants({ size, className }))} {...$$restProps}>
41+
<slot />
42+
</h5>
43+
{:else if element === 'h6'}
44+
<h6 class={cn(headingVariants({ size, className }))} {...$$restProps}>
45+
<slot />
46+
</h6>
47+
{/if}

src/lib/components/ui/heading/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Root from './heading.svelte';
2-
import type { HTMLInputAttributes } from 'svelte/elements';
32
import { tv, type VariantProps } from 'tailwind-variants';
43

54
const headingVariants = tv({
@@ -19,7 +18,7 @@ type Size = VariantProps<typeof headingVariants>['size'];
1918

2019
type Props = {
2120
size?: Size;
22-
class?: HTMLInputAttributes['class'];
21+
element?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
2322
};
2423

2524
export {

0 commit comments

Comments
 (0)