Skip to content

Commit

Permalink
feat(resolver): enable namespaced components
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
ferferga authored Feb 29, 2024
1 parent 50cecc2 commit f92b70b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/plugins/src/resolver/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type ComponentResolver } from 'unplugin-vue-components'
import { components } from '../../../radix-vue/constant/components'
import * as NamespacedComponents from '../namespaced'

export interface ResolverOptions {
/**
Expand All @@ -8,20 +9,28 @@ export interface ResolverOptions {
* @defaultValue ""
*/
prefix?: string
/**
* Enable the use of namespaced components
*
* @defaultValue false
*/
namespaced?: boolean
}

export default function (options: ResolverOptions = {}): ComponentResolver {
const { prefix = '' } = options
const { prefix = '', namespaced = false } = options

return {
type: 'component',
resolve: (name: string) => {
if (name.toLowerCase().startsWith(prefix.toLowerCase())) {
const componentName = name.substring(prefix.length)
if (Object.values(components).flat().includes(componentName)) {
const componentName = name.substring(prefix.length).split('.')[0]
const isNamespacedComponent = Object.keys(NamespacedComponents).includes(componentName)
const isComponent = Object.values(components).flat().includes(componentName)
if (isNamespacedComponent || isComponent) {
return {
name: componentName,
from: 'radix-vue',
from: isNamespacedComponent && namespaced ? 'radix-vue/namespaced' : 'radix-vue',
}
}
}
Expand Down

0 comments on commit f92b70b

Please sign in to comment.