Skip to content

Commit

Permalink
Merge pull request #1539 from EnergySage/ced-1863-es-button-href-prop
Browse files Browse the repository at this point in the history
fix: support href and to props for EsButton
  • Loading branch information
hroth1994 authored Oct 1, 2024
2 parents 42a900f + 6b7cd88 commit d3f400b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
18 changes: 18 additions & 0 deletions es-ds-components/components/es-button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ const props = defineProps({
type: Boolean,
default: true,
},
// Url when using button as a link
href: {
type: String,
default: null,
},
// Url when using button as a link to an internal page
to: {
type: String,
default: null,
},
});
const getRootClasses = computed(() => {
Expand All @@ -73,7 +83,15 @@ const getRootClasses = computed(() => {
</script>

<template>
<nuxt-link
v-if="props.href || props.to"
:href="props.href || undefined"
:to="props.to || undefined"
:class="getRootClasses">
<slot />
</nuxt-link>
<prime-button
v-else
:pt="{
root: { class: getRootClasses },
}">
Expand Down
14 changes: 11 additions & 3 deletions es-ds-docs/pages/molecules/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const linkExamples = ref([
]);
const propTableRows = ref([
['href', 'String', 'null', 'An external URL to navigate to when using a button as a link.'],
[
'inline',
'Boolean',
Expand All @@ -78,6 +79,7 @@ const propTableRows = ref([
],
['outline', 'Boolean', 'false', 'If true, changes to the outline version of the specified variant.'],
['size', 'String', '"md"', "The size of the button: 'md', or 'sm'."],
['to', 'String', 'null', 'An internal path to navigate to when using a button as a link'],
['variant', 'String', '"primary"', "The name of the desired button variant: 'primary', 'dark-bg', or 'link'."],
]);
Expand Down Expand Up @@ -107,11 +109,17 @@ onMounted(async () => {
<h1>Button</h1>
<p>
Extended from
<a
<nuxt-link
href="https://v3.primevue.org/button/"
target="_blank">
primevue button
</a>
PrimeVue Button
</nuxt-link>
and
<nuxt-link
href="https://nuxt.com/docs/api/components/nuxt-link"
target="_blank">
NuxtLink
</nuxt-link>
</p>
<p>
When using a button, please ensure that the copy style is
Expand Down

0 comments on commit d3f400b

Please sign in to comment.