mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-22 16:00:39 +01:00
chore(utils): improve link utils
This commit is contained in:
@@ -23,8 +23,7 @@ import { twMerge, twJoin } from 'tailwind-merge'
|
||||
import UIcon from '../elements/Icon.vue'
|
||||
import ULink from '../elements/Link.vue'
|
||||
import { useUI } from '../../composables/useUI'
|
||||
import { mergeConfig } from '../../utils'
|
||||
import { nuxtLinkProps, getNuxtLinkProps } from '../../utils/nuxt-link'
|
||||
import { mergeConfig, nuxtLinkProps, getNuxtLinkProps } from '../../utils'
|
||||
import { useInjectButtonGroup } from '../../composables/useButtonGroup'
|
||||
import type { ButtonColor, ButtonSize, ButtonVariant, Strategy } from '../../types'
|
||||
// @ts-expect-error
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<script lang="ts">
|
||||
import { isEqual } from 'ohash'
|
||||
import { defineComponent } from 'vue'
|
||||
import { nuxtLinkProps } from '../../utils/nuxt-link'
|
||||
import { nuxtLinkProps } from '../../utils'
|
||||
|
||||
export default defineComponent({
|
||||
inheritAttrs: false,
|
||||
|
||||
@@ -74,3 +74,4 @@ export function looseToNumber (val: any): any {
|
||||
}
|
||||
|
||||
export * from './lodash'
|
||||
export * from './link'
|
||||
|
||||
@@ -61,12 +61,47 @@ export const nuxtLinkProps = {
|
||||
}
|
||||
} as const
|
||||
|
||||
export const getNuxtLinkProps = (props: Record<string, unknown>) => {
|
||||
const nuxtLinkPropsKeys = Object.keys(nuxtLinkProps)
|
||||
return nuxtLinkPropsKeys.reduce((acc, key) => {
|
||||
const uLinkProps = {
|
||||
active: {
|
||||
type: Boolean,
|
||||
default: undefined
|
||||
},
|
||||
exact: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
exactQuery: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
exactHash: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
inactiveClass: {
|
||||
type: String,
|
||||
default: undefined
|
||||
}
|
||||
} as const
|
||||
|
||||
export const getNuxtLinkProps = (props) => {
|
||||
const keys = Object.keys(nuxtLinkProps)
|
||||
|
||||
return keys.reduce((acc, key) => {
|
||||
if (props[key] !== undefined) {
|
||||
acc[key] = props[key]
|
||||
}
|
||||
return acc
|
||||
}, {} as Record<string, unknown>)
|
||||
}, {})
|
||||
}
|
||||
|
||||
export const getULinkProps = (props) => {
|
||||
const keys = [...Object.keys(nuxtLinkProps), ...Object.keys(uLinkProps)]
|
||||
|
||||
return keys.reduce((acc, key) => {
|
||||
if (props[key] !== undefined) {
|
||||
acc[key] = props[key]
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
Reference in New Issue
Block a user