Skip to content

Commit

Permalink
Allow for button to automatically render as anchor tag if href is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
louisescher committed Jan 16, 2025
1 parent 3ea97e6 commit 45638fa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/studiocms_ui/src/components/Button/Button.astro
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type Props<As extends HTMLTag = 'button'> = Omit<Polymorphic<{ as: As }>, 'as'>
* Whether the button is disabled. Defaults to `false`.
*/
disabled?: boolean;
/**
* An optional href to use for the button. If provided, the button will render as an anchor tag.
*/
href?: string;
};
export type { Props };
Expand All @@ -40,10 +44,17 @@ const {
fullWidth = false,
color = 'default',
variant = 'solid',
as: As = 'button',
disabled = false,
...props
} = Astro.props;
let As: HTMLTag = 'button';
if (props.href) {
As = 'a';
} else {
As = props.as || 'button';
}
---

<As
Expand Down

0 comments on commit 45638fa

Please sign in to comment.