Can I use a switch to replace the ? statements? ---
import { clsx } from 'clsx';
import { HeadingType, TextAlignment } from 'src/utils/sectionEnums';
interface Props {
headingType: HeadingType;
title?: string;
heading: string;
body?: string;
textAlignment?: 'left' | 'center' | 'right';
}
const {
headingType,
heading,
body,
title,
textAlignment = 'left',
} = Astro.props as Props;
// For backward compatibility
const isCenter = textAlignment === 'center';
const isRight = textAlignment === 'right';
<div
class={clsx(
'flex flex-col gap-4 max-w-4xl w-full',
isCenter && 'items-center text-center',
isRight && 'items-end text-right',
!isCenter && !isRight && 'items-start text-left'
)}
{
title && (
<span class="text-base font-bold text-orange-500 md:text-xl">
{title}
</span>
)
}
{
headingType === HeadingType.h1 ? (
<h1
class="text-4xl/8 font-bold md:text-5xl/12 lg:text-6xl/14"
set:html={heading}
/>
) : headingType === HeadingType.h2 ? (
<h2
class="xs:text-4xl/8 text-3xl/8 font-bold md:text-5xl/12"
set:html={heading}
/>
) : (
<h3 class="text-2xl font-bold" set:html={heading} />
)
}
{
body && (
<p class="xs:text-lg max-w-2xl text-base lg:text-xl" set:html={body} />
)
}
</div>