Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CallToAction widget #205

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 40 additions & 44 deletions src/components/widgets/CallToAction.astro
Original file line number Diff line number Diff line change
@@ -1,58 +1,54 @@
---
import { Icon } from 'astro-icon/components';
import WidgetWrapper from '../ui/WidgetWrapper.astro';
import type { CallToAction, Widget } from '~/types';
import Headline from '../ui/Headline.astro';

export interface CallToAction {
text: string;
href: string;
icon?: string;
}

export interface Props {
interface Props extends Widget {
title?: string;
subtitle?: string;
description?: string;
callToAction?: string | CallToAction;
tagline?: string;
callToAction?: CallToAction;
}

const {
title = await Astro.slots.render('title'),
subtitle = await Astro.slots.render('subtitle'),
tagline = await Astro.slots.render('tagline'),
callToAction = await Astro.slots.render('callToAction'),
} = Astro.props;

id,
isDark = false,
classes = {},
bg = await Astro.slots.render('bg'),
} = Astro.props as Props;
---

<section class="relative not-prose">
<div class="max-w-6xl mx-auto px-4 sm:px-6">
<div class="py-12 md:py-20">
<div
class="max-w-3xl mx-auto text-center p-6 rounded-md shadow-xl dark:shadow-none dark:border dark:border-slate-600"
>
{
title && (
<h2
class="text-4xl md:text-4xl font-bold leading-tighter tracking-tighter mb-4 font-heading"
set:html={title}
/>
)
}
{subtitle && <p class="text-xl text-muted dark:text-slate-400" set:html={subtitle} />}
{
typeof callToAction === 'string' ? (
<Fragment set:html={callToAction} />
) : (
callToAction &&
callToAction.text &&
callToAction.href && (
<div class="mt-6 max-w-xs mx-auto">
<a class="btn btn-primary w-full sm:w-auto" href={callToAction.href} target="_blank" rel="noopener">
{callToAction.icon && <Icon name={callToAction.icon} class="w-5 h-5 mr-1 -ml-1.5" />}
{callToAction.text}
</a>
</div>
)
)
}
</div>
</div>
<WidgetWrapper id={id} isDark={isDark} containerClass={`max-w-6xl mx-auto ${classes?.container ?? ''}`} bg={bg}>
<div class="max-w-3xl mx-auto text-center p-6 rounded-md shadow-xl">
<Headline
title={title}
subtitle={subtitle}
tagline={tagline}
classes={{
container: 'mb-0 md:mb-0 dark:shadow-none dark:border dark:border-slate-600',
}}
/>
{
typeof callToAction === 'string' ? (
<Fragment set:html={callToAction} />
) : (
callToAction &&
callToAction.text &&
callToAction.href && (
<div class="mt-6 max-w-xs mx-auto">
<a class="btn btn-primary w-full sm:w-auto" href={callToAction.href} target="_blank" rel="noopener">
{callToAction.icon && <Icon name={callToAction.icon} class="w-5 h-5 mr-1 -ml-1.5" />}
{callToAction.text}
</a>
</div>
)
)
}
</div>
</section>
</WidgetWrapper>