-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Cowen <john.cowen@konghq.com>
- Loading branch information
Showing
5 changed files
with
93 additions
and
6 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
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 @@ | ||
# x-action |
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,75 @@ | ||
<template> | ||
<template | ||
v-if="Object.keys(props.to).length > 0" | ||
> | ||
<RouterLink | ||
:to="{ | ||
...props.to, | ||
query, | ||
}" | ||
> | ||
<slot name="default" /> | ||
</RouterLink> | ||
</template> | ||
<template | ||
v-else-if="props.href.length > 0" | ||
> | ||
<a | ||
:href="props.href" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<slot name="default" /> | ||
</a> | ||
</template> | ||
<template | ||
v-else-if="props.for.length > 0" | ||
> | ||
<label :for="props.for"> | ||
<slot name="default" /> | ||
</label> | ||
</template> | ||
<template | ||
v-else | ||
> | ||
<button type="button"> | ||
<slot name="default" /> | ||
</button> | ||
</template> | ||
</template> | ||
<script lang="ts" setup> | ||
import { computed } from 'vue' | ||
import { RouterLink } from 'vue-router' | ||
import type { RouteLocationNamedRaw } from 'vue-router' | ||
type BooleanLocationQueryValue = string | number | undefined | boolean | ||
type BooleanLocationQueryRaw = Record<string | number, BooleanLocationQueryValue | BooleanLocationQueryValue[]> | ||
type RouteLocationRawWithBooleanQuery = Omit<RouteLocationNamedRaw, 'query'> & { | ||
query?: BooleanLocationQueryRaw | ||
} | ||
const props = withDefaults(defineProps<{ | ||
href?: string | ||
to?: RouteLocationRawWithBooleanQuery | ||
for?: string | ||
}>(), { | ||
href: '', | ||
to: () => ({}), | ||
for: '', | ||
}) | ||
const query = computed(() => { | ||
return Object.entries(props.to.query ?? {}).reduce<Record<string, string | number | null | undefined>>((prev, [key, value]) => { | ||
switch (true) { | ||
case value === true: | ||
prev[key] = null | ||
break | ||
case value === false: | ||
prev[key] = undefined | ||
break | ||
default: | ||
prev[key] = value as string | number | undefined | ||
} | ||
return prev | ||
}, {}) | ||
}) | ||
</script> |
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 @@ | ||
# x-teleport |
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