Skip to content

Commit

Permalink
feat(element-plus): supports icons (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jun 20, 2022
1 parent 8c9b114 commit f73d45d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/core/resolvers/element-plus.ts
Expand Up @@ -85,6 +85,13 @@ function resolveComponent(name: string, options: ElementPlusResolverOptionsResol
if (!name.match(/^El[A-Z]/))
return

if (name.match(/^ElIcon.+/)) {
return {
name: name.replace(/^ElIcon/, ''),
from: '@element-plus/icons-vue',
}
}

const partialName = kebabCase(name.slice(2))// ElTableColumn -> table-column
const { version, ssr } = options

Expand Down
10 changes: 4 additions & 6 deletions test/resolvers/__snapshots__/element-plus.test.ts.snap
Expand Up @@ -3,19 +3,17 @@
exports[`Element Plus Resolver > components and directives should be transformed 1`] = `
{
"code": "/* unplugin-vue-components disabled */import { ElLoadingDirective as __unplugin_directives_0 } from 'element-plus/es';import 'element-plus/es/components/loading/style/css';
import { Apple as __unplugin_components_1 } from '@element-plus/icons-vue';
import { ElButton as __unplugin_components_0 } from 'element-plus/es';import 'element-plus/es/components/button/style/css';
(_ctx, _cache) => {
const _component_el_button = __unplugin_components_0
const _component_el_icon_apple = __unplugin_components_1
const _directive_loading = __unplugin_directives_0
return (_openBlock(), _createElementBlock(_Fragment, null, [
_createVNode(_component_el_button, null, {
default: _withCtx(() => [
_hoisted_1
]),
_: 1 /* STABLE */
}),
_createVNode(_component_el_button),
_createVNode(_component_el_icon_apple),
_withDirectives(_createElementVNode(\\"div\\", null, null, 512 /* NEED_PATCH */), [
[_directive_loading, true]
])
Expand Down
9 changes: 3 additions & 6 deletions test/resolvers/element-plus.test.ts
Expand Up @@ -7,15 +7,12 @@ describe('Element Plus Resolver', () => {
const code = `
(_ctx, _cache) => {
const _component_el_button = _resolveComponent("el-button")
const _component_el_icon_apple = _resolveComponent("el-icon-apple")
const _directive_loading = _resolveDirective("loading")
return (_openBlock(), _createElementBlock(_Fragment, null, [
_createVNode(_component_el_button, null, {
default: _withCtx(() => [
_hoisted_1
]),
_: 1 /* STABLE */
}),
_createVNode(_component_el_button),
_createVNode(_component_el_icon_apple),
_withDirectives(_createElementVNode("div", null, null, 512 /* NEED_PATCH */), [
[_directive_loading, true]
])
Expand Down

0 comments on commit f73d45d

Please sign in to comment.