Skip to content
Permalink
Browse files
fix(b-icon): local component lookup (#5939)
  • Loading branch information
jacobmllr95 committed Oct 21, 2020
1 parent 8a367b6 commit 4586b49d99e4239dbebe2518f57022d6e4e20224
Showing 1 changed file with 15 additions and 6 deletions.
@@ -5,6 +5,15 @@ import { pascalCase, trim } from '../utils/string'
import { BIconBlank } from './icons'
import { commonIconProps } from './helpers/icon-base'

const findIconComponent = (ctx, iconName) => {
if (!ctx) {
return null
}
const components = (ctx.$options || {}).components
const iconComponent = components[iconName]
return iconComponent || findIconComponent(ctx.$parent, iconName)
}

// Helper BIcon component
// Requires the requested icon component to be installed
export const BIcon = /*#__PURE__*/ Vue.extend({
@@ -23,13 +32,13 @@ export const BIcon = /*#__PURE__*/ Vue.extend({
},
render(h, { data, props, parent }) {
const icon = pascalCase(trim(props.icon || '')).replace(RX_ICON_PREFIX, '')
const iconName = `BIcon${icon}`

// If parent context exists, we check to see if the icon has been registered
// Either locally in the parent component, or globally at the `$root` level
// either locally in the parent component, or globally at the `$root` level
// If not registered, we render a blank icon
const components = ((parent || {}).$options || {}).components
const componentRefOrName =
icon && components ? components[iconName] || BIconBlank : icon ? iconName : BIconBlank
return h(componentRefOrName, mergeData(data, { props: { ...props, icon: null } }))
return h(
icon ? findIconComponent(parent, `BIcon${icon}`) || BIconBlank : BIconBlank,
mergeData(data, { props: { ...props, icon: null } })
)
}
})

0 comments on commit 4586b49

Please sign in to comment.