chore(utils): improve link utils

This commit is contained in:
Benjamin Canac
2024-01-11 12:16:27 +01:00
parent 02d72df527
commit 28b736a703
4 changed files with 42 additions and 7 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -74,3 +74,4 @@ export function looseToNumber (val: any): any {
}
export * from './lodash'
export * from './link'

View File

@@ -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
}, {})
}