mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 18:00:43 +01:00
chore(Button): use ULinkCustom with all NuxtLink props
This commit is contained in:
@@ -1,10 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component
|
<ULinkCustom :class="buttonClass" v-bind="buttonProps">
|
||||||
:is="buttonIs"
|
|
||||||
:class="buttonClass"
|
|
||||||
:aria-label="ariaLabel"
|
|
||||||
v-bind="buttonProps"
|
|
||||||
>
|
|
||||||
<slot name="leading" :disabled="disabled" :loading="loading">
|
<slot name="leading" :disabled="disabled" :loading="loading">
|
||||||
<UIcon v-if="isLeading && leadingIconName" :name="leadingIconName" :class="leadingIconClass" aria-hidden="true" />
|
<UIcon v-if="isLeading && leadingIconName" :name="leadingIconName" :class="leadingIconClass" aria-hidden="true" />
|
||||||
</slot>
|
</slot>
|
||||||
@@ -18,15 +13,16 @@
|
|||||||
<slot name="trailing" :disabled="disabled" :loading="loading">
|
<slot name="trailing" :disabled="disabled" :loading="loading">
|
||||||
<UIcon v-if="isTrailing && trailingIconName" :name="trailingIconName" :class="trailingIconClass" aria-hidden="true" />
|
<UIcon v-if="isTrailing && trailingIconName" :name="trailingIconName" :class="trailingIconClass" aria-hidden="true" />
|
||||||
</slot>
|
</slot>
|
||||||
</component>
|
</ULinkCustom>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, useSlots } from 'vue'
|
import { computed, defineComponent, useSlots } from 'vue'
|
||||||
import type { PropType } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
import type { RouteLocationRaw } from 'vue-router'
|
|
||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
|
import { pick } from 'lodash-es'
|
||||||
import UIcon from '../elements/Icon.vue'
|
import UIcon from '../elements/Icon.vue'
|
||||||
|
import ULinkCustom from '../elements/LinkCustom.vue'
|
||||||
import { classNames } from '../../utils'
|
import { classNames } from '../../utils'
|
||||||
import { NuxtLink } from '#components'
|
import { NuxtLink } from '#components'
|
||||||
import { useAppConfig } from '#imports'
|
import { useAppConfig } from '#imports'
|
||||||
@@ -39,9 +35,10 @@ import appConfig from '#build/app.config'
|
|||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
UIcon,
|
UIcon,
|
||||||
NuxtLink
|
ULinkCustom
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
...NuxtLink.props,
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'button'
|
default: 'button'
|
||||||
@@ -114,18 +111,6 @@ export default defineComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
to: {
|
|
||||||
type: [String, Object] as PropType<string | RouteLocationRaw>,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
target: {
|
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
ariaLabel: {
|
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
square: {
|
square: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
@@ -143,25 +128,9 @@ export default defineComponent({
|
|||||||
// TODO: Remove
|
// TODO: Remove
|
||||||
const appConfig = useAppConfig()
|
const appConfig = useAppConfig()
|
||||||
|
|
||||||
const ui = computed<Partial<typeof appConfig.ui.button>>(() => defu({}, props.ui, appConfig.ui.button))
|
|
||||||
|
|
||||||
const slots = useSlots()
|
const slots = useSlots()
|
||||||
|
|
||||||
const buttonIs = computed(() => {
|
const ui = computed<Partial<typeof appConfig.ui.button>>(() => defu({}, props.ui, appConfig.ui.button))
|
||||||
if (props.to) {
|
|
||||||
return 'NuxtLink'
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'button'
|
|
||||||
})
|
|
||||||
|
|
||||||
const buttonProps = computed(() => {
|
|
||||||
if (props.to) {
|
|
||||||
return { to: props.to, target: props.target }
|
|
||||||
} else {
|
|
||||||
return { disabled: props.disabled || props.loading, type: props.type }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const isLeading = computed(() => {
|
const isLeading = computed(() => {
|
||||||
return (props.icon && props.leading) || (props.icon && !props.trailing) || (props.loading && !props.trailing) || props.leadingIcon
|
return (props.icon && props.leading) || (props.icon && !props.trailing) || (props.loading && !props.trailing) || props.leadingIcon
|
||||||
@@ -173,6 +142,14 @@ export default defineComponent({
|
|||||||
|
|
||||||
const isSquare = computed(() => props.square || (!slots.default && !props.label))
|
const isSquare = computed(() => props.square || (!slots.default && !props.label))
|
||||||
|
|
||||||
|
const buttonProps = computed(() => {
|
||||||
|
if (props.to) {
|
||||||
|
return pick(props, Object.keys(NuxtLink.props))
|
||||||
|
} else {
|
||||||
|
return { disabled: props.disabled || props.loading, type: props.type }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const buttonClass = computed(() => {
|
const buttonClass = computed(() => {
|
||||||
const variant = ui.value.color?.[props.color as string]?.[props.variant as string] || ui.value.variant[props.variant]
|
const variant = ui.value.color?.[props.color as string]?.[props.variant as string] || ui.value.variant[props.variant]
|
||||||
|
|
||||||
@@ -221,11 +198,10 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buttonIs,
|
|
||||||
buttonProps,
|
|
||||||
isLeading,
|
isLeading,
|
||||||
isTrailing,
|
isTrailing,
|
||||||
isSquare,
|
isSquare,
|
||||||
|
buttonProps,
|
||||||
buttonClass,
|
buttonClass,
|
||||||
leadingIconName,
|
leadingIconName,
|
||||||
trailingIconName,
|
trailingIconName,
|
||||||
|
|||||||
Reference in New Issue
Block a user