Fix Button to render a <button> tag if the 'type' attribute exists. Issue #299
This commit is contained in:
@ -6,21 +6,35 @@ import type { CallToAction } from '~/types';
|
|||||||
const {
|
const {
|
||||||
variant = 'secondary',
|
variant = 'secondary',
|
||||||
target,
|
target,
|
||||||
text = Astro.slots.render("default"),
|
text = Astro.slots.render('default'),
|
||||||
icon = '',
|
icon = '',
|
||||||
class: className = '',
|
class: className = '',
|
||||||
|
type,
|
||||||
...rest
|
...rest
|
||||||
} = Astro.props as CallToAction;
|
} = Astro.props as CallToAction;
|
||||||
|
|
||||||
const variants = {
|
const variants = {
|
||||||
primary: 'btn-primary' ,
|
primary: 'btn-primary',
|
||||||
secondary: 'btn-secondary',
|
secondary: 'btn-secondary',
|
||||||
tertiary: 'btn btn-tertiary',
|
tertiary: 'btn btn-tertiary',
|
||||||
link: 'cursor-pointer hover:text-primary',
|
link: 'cursor-pointer hover:text-primary',
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
<a class={twMerge(variants[variant] || '', className)} {...target ? { target: target, rel: 'noopener noreferrer' } : {}} {...rest}>
|
{
|
||||||
<Fragment set:html={text} />
|
type === 'button' || type === 'submit' || type === 'reset' ? (
|
||||||
{icon && <Icon name={icon} class="w-5 h-5 ml-1 -mr-1.5 rtl:mr-1 rtl:-ml-1.5 inline-block" />}
|
<button type={type} class={twMerge(variants[variant] || '', className)} {...rest}>
|
||||||
</a>
|
<Fragment set:html={text} />
|
||||||
|
{icon && <Icon name={icon} class="w-5 h-5 ml-1 -mr-1.5 rtl:mr-1 rtl:-ml-1.5 inline-block" />}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<a
|
||||||
|
class={twMerge(variants[variant] || '', className)}
|
||||||
|
{...(target ? { target: target, rel: 'noopener noreferrer' } : {})}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
<Fragment set:html={text} />
|
||||||
|
{icon && <Icon name={icon} class="w-5 h-5 ml-1 -mr-1.5 rtl:mr-1 rtl:-ml-1.5 inline-block" />}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
1
src/types.d.ts
vendored
1
src/types.d.ts
vendored
@ -180,6 +180,7 @@ export interface CallToAction extends HTMLAttributes<a> {
|
|||||||
text?: string;
|
text?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
classes?: Record<string, string>;
|
classes?: Record<string, string>;
|
||||||
|
type?: 'button' | 'submit' | 'reset';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ItemGrid {
|
export interface ItemGrid {
|
||||||
|
Reference in New Issue
Block a user