-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<Story | ||
title="BaseButton with NuxtLink" | ||
:layout="{ | ||
type: 'single', | ||
iframe: false, | ||
}" | ||
> | ||
<Variant> | ||
<BaseButtonLink | ||
variant="primary" | ||
to="#" | ||
> | ||
Hello world | ||
</BaseButtonLink> | ||
</Variant> | ||
</Story> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<NuxtLink | ||
v-if="to" | ||
:class="computedClasses" | ||
:to="to" | ||
> | ||
<slot /> | ||
</NuxtLink> | ||
<button | ||
v-else | ||
:class="computedClasses" | ||
> | ||
<slot /> | ||
</button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const props = defineProps<{ | ||
to?: string | ||
variant: 'primary' | 'secondary' | ||
}>() | ||
const computedClasses = computed(() => ({ | ||
'btn-base': true, | ||
'btn-primary': props.variant === 'primary', | ||
})) | ||
</script> | ||
|
||
<style scoped> | ||
.btn-base { | ||
padding: 7px 14px; | ||
} | ||
.btn-primary { | ||
background: black; | ||
color: white; | ||
} | ||
</style> |
48 changes: 48 additions & 0 deletions
48
packages/histoire/src/client/app/components/sandbox/RouterLinkStub.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// From: https://github.com/vuejs/test-utils/blob/main/src/components/RouterLinkStub.ts | ||
|
||
import { defineComponent, h, computed } from 'vue' | ||
|
||
// match return type of router.resolve: RouteLocation & { href: string } | ||
const defaultRoute = { | ||
path: '/', | ||
name: undefined as string | undefined, | ||
redirectedFrom: undefined as object | undefined, | ||
params: {}, | ||
query: {}, | ||
hash: '', | ||
fullPath: '/', | ||
matched: [] as object[], | ||
meta: {}, | ||
href: '/', | ||
} | ||
|
||
// TODO: Borrow typings from vue-router-next | ||
export const RouterLinkStub = defineComponent({ | ||
name: 'RouterLinkStub', | ||
|
||
compatConfig: { MODE: 3 }, | ||
|
||
props: { | ||
to: { | ||
type: [String, Object], | ||
required: true, | ||
}, | ||
custom: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
|
||
render () { | ||
const route = computed(() => defaultRoute) | ||
// mock reasonable return values to mimic vue-router's useLink | ||
const children = this.$slots?.default?.({ | ||
route, | ||
href: computed(() => route.value.href), | ||
isActive: computed(() => false), | ||
isExactActive: computed(() => false), | ||
navigate: async () => {}, | ||
}) | ||
return this.custom ? children : h('a', undefined, children) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters