-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(button): add disabled and loading state
- Loading branch information
1 parent
d913f91
commit ed419ef
Showing
8 changed files
with
267 additions
and
14 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
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
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,65 @@ | ||
<script lang="ts" setup> | ||
import { nuxtLinkProps } from '../../utils/link' | ||
const props = defineProps({ | ||
...nuxtLinkProps, | ||
to: { | ||
type: String, | ||
default: '', | ||
}, | ||
as: { | ||
type: String, | ||
default: 'button', | ||
}, | ||
type: { | ||
type: String, | ||
default: 'button', | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
active: { | ||
type: Boolean, | ||
default: undefined, | ||
}, | ||
activeClass: { | ||
type: String, | ||
default: undefined, | ||
}, | ||
inactiveClass: { | ||
type: String, | ||
default: undefined, | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="as" | ||
v-if="!to" | ||
:type="type" | ||
:class="active ? activeClass : inactiveClass" | ||
:disabled="disabled" | ||
v-bind="$attrs" | ||
> | ||
<slot v-bind="{ isActive: active }" /> | ||
</component> | ||
<NuxtLink v-else v-slot="{ href, target, rel, navigate, isActive, isExternal }" v-bind="props" custom> | ||
<a | ||
v-bind="$attrs" | ||
:href="!disabled ? href : undefined" | ||
:aria-disabled="disabled ? 'true' : undefined" | ||
:role="disabled ? 'link' : undefined" | ||
:rel="rel" | ||
:target="target" | ||
:class="active !== undefined ? (active ? activeClass : inactiveClass) : { [activeClass]: isActive, [inactiveClass]: !isActive }" | ||
:tabindex="!disabled ? undefined : -1" | ||
@click="(e) => (!disabled && !isExternal) && navigate(e)" | ||
> | ||
<slot v-bind="{ isActive: active !== undefined ? active : isActive }" /> | ||
</a> | ||
</NuxtLink> | ||
</template> | ||
|
||
<style scoped></style> |
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,83 @@ | ||
import type { PropType } from 'vue' | ||
import type { RouteLocationRaw } from '#vue-router' | ||
import type { NuxtLinkProps } from '#app' | ||
|
||
// NuxtLink props | ||
// ref: https://github.com/nuxt/ui/blob/51c8b8e3e59d7eceff72625650a199fcf7c6feca/src/runtime/utils/link.ts#L5-L81 | ||
export const nuxtLinkProps = { | ||
to: { | ||
type: [String, Object] as PropType<RouteLocationRaw>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
href: { | ||
type: [String, Object] as PropType<RouteLocationRaw>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
|
||
// Attributes | ||
target: { | ||
type: String as PropType<NuxtLinkProps['target']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
rel: { | ||
type: String as PropType<any>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
noRel: { | ||
type: Boolean as PropType<NuxtLinkProps['noRel']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
|
||
// Prefetching | ||
prefetch: { | ||
type: Boolean as PropType<NuxtLinkProps['prefetch']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
noPrefetch: { | ||
type: Boolean as PropType<NuxtLinkProps['noPrefetch']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
|
||
// Styling | ||
activeClass: { | ||
type: String as PropType<NuxtLinkProps['activeClass']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
exactActiveClass: { | ||
type: String as PropType<NuxtLinkProps['exactActiveClass']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
prefetchedClass: { | ||
type: String as PropType<NuxtLinkProps['prefetchedClass']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
|
||
// Vue Router's `<RouterLink>` additional props | ||
replace: { | ||
type: Boolean as PropType<NuxtLinkProps['replace']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
ariaCurrentValue: { | ||
type: String as PropType<NuxtLinkProps['ariaCurrentValue']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
|
||
// Edge cases handling | ||
external: { | ||
type: Boolean as PropType<NuxtLinkProps['external']>, | ||
default: undefined, | ||
required: false, | ||
}, | ||
} as const |
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