feat(ui): add heading component

This commit is contained in:
Jewgeni Lewash 2024-02-28 08:51:25 +01:00
parent e858b080a7
commit c76e15ff2f
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,25 @@
---
interface Props {
level?: 1 | 2 | 3 | 4 | 5 | 6;
classes?: string;
}
const { level = 2, classes = '', ...rest } = Astro.props as Props;
const HeadingTag = `h${level}` as `h${1 | 2 | 3 | 4 | 5 | 6}`;
const headingStyles = {
h1: 'text-4xl md:text-5xl lg:text-7xl font-bold',
h2: 'text-3xl md:text-4xl lg:text-5xl font-bold',
h3: 'text-2xl font-semibold',
h4: 'text-xl font-semibold',
h5: 'text-lg font-semibold',
h6: 'text-base font-semibold',
};
const classList = `${headingStyles[HeadingTag]} ${classes}`;
---
<HeadingTag class={classList.trim()} {...rest}>
<slot />
</HeadingTag>

1
src/env.d.ts vendored
View File

@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />

View File

@ -1,7 +1,10 @@
---
import BaseLayout from '@/layouts/BaseLayout.astro';
import Heading from '@/components/ui/Heading.astro';
---
<BaseLayout title="Astro Deploy">
<div class="flex items-center justify-center px-4 pt-48 dark:text-white">Hello World</div>
<div class="flex items-center justify-center px-4 pt-48 dark:text-white">
<Heading level={1} classes="text-zinc-900 dark:text-zinc-200">Hello World</Heading>
</div>
</BaseLayout>