Skip to content

feat(arco): add arco design vue resolver #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ We have several built-in resolvers for popular UI libraries like **Vuetify**, **
Supported Resolvers:

- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
- [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)
- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-ui.ts)
- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
Expand Down
179 changes: 179 additions & 0 deletions src/core/resolvers/arco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { ComponentResolver } from '../../types'
import { kebabCase } from '../utils'

const matchComponents = [
{
pattern: /^AnchorLink$/,
componentDir: 'anchor',
},
{
pattern: /^AvatarGroup$/,
componentDir: 'avatar',
},
{
pattern: /^BreadcrumbItem$/,
componentDir: 'breadcrumb',
},

{
pattern: /^ButtonGroup$/,
componentDir: 'button',
},
{
pattern: /^(CardMeta|CardGrid)$/,
componentDir: 'card',
},
{
pattern: /^CarouselItem$/,
componentDir: 'carousel',
},
{
pattern: /^CheckboxGroup$/,
componentDir: 'checkbox',
},
{
pattern: /^CollapseItem$/,
componentDir: 'collapse',
},
{
pattern: /^(WeekPicker|MonthPicker|YearPicker|QuarterPicker|RangePicker)$/,
componentDir: 'date-picker',
},
{
pattern: /^(Doption|Dgroup|Dsubmenu)$/,
componentDir: 'dropdown',
},
{
pattern: /^FormItem$/,
componentDir: 'form',
},
{
pattern: /^(Col|Row)$/,
componentDir: 'grid',
},

{
pattern: /^(ImagePreview|ImagePreviewGroup)$/,
componentDir: 'image',
},
{
pattern: /^(InputGroup|InputSearch|InputPassword)$/,
componentDir: 'input',
},

{
pattern: /^(LayoutHeader|LayoutContent|LayoutFooter|LayoutSider)$/,
componentDir: 'layout',
},
{
pattern: /^(ListItem|ListItemMeta)$/,
componentDir: 'list',
},
{
pattern: /^(MenuItem|MenuItemGroup|SubMenu)$/,
componentDir: 'menu',
},
{
pattern: /^RadioGroup$/,
componentDir: 'radio',
},
{
pattern: /^(Option|Optgroup)$/,
componentDir: 'select',
},

{
pattern: /^(SkeletonLine|SkeletonShape)$/,
componentDir: 'table',
},
{
pattern: /^Countdown$/,
componentDir: 'statistic',
},

{
pattern: /^Step$/,
componentDir: 'steps',
},

{
pattern: /^(Thead|Td|Th|Tr|Tbody|TableColumn)$/,
componentDir: 'table',
},

{
pattern: /^TabPane$/,
componentDir: 'tabs',
},
{
pattern: /^TimelineItem$/,
componentDir: 'timeline',
},

{
pattern: /^(TypographyParagraph|TypographyTitle|TypographyText)$/,
componentDir: 'typography',
},
]

function getComponentStyleDir(importName: string, importStyle: boolean | 'css' | 'less') {
let componentDir = kebabCase(importName)
for (const item of matchComponents) {
if (item.pattern.test(importName)) {
componentDir = item.componentDir
break
}
}
if (importStyle === 'less') return `@arco-design/web-vue/es/${componentDir}/style/index.js`
if (importStyle === 'css' || importStyle) return `@arco-design/web-vue/es/${componentDir}/style/css.js`
}

export interface ArcoResolverOptions {
/**
* import style css or less with components
*
* @default 'css'
*/
importStyle?: boolean | 'css' | 'less'
/**
* resolve icons
*
* @default false
*/
resolveIcons?: boolean
}

/**
* Resolver for Arco Design Vue
*
* Requires arco-design/web-vue@2.11.0 or later
*
* @author @flsion
* @link https://arco.design/ for arco-design
*
*/
export function ArcoResolver(
options: ArcoResolverOptions = {},
): ComponentResolver {
return {
type: 'component',
resolve: (name: string) => {
if (options.resolveIcons && name.match(/^Icon/)) {
return {
importName: name,
path: '@arco-design/web-vue/es/icon',
}
}
if (name.match(/^A/)) {
const importStyle = options.importStyle ?? 'css'

const importName = name.slice(1)
return {
importName,
path: '@arco-design/web-vue',
sideEffects: getComponentStyleDir(importName, importStyle),
}
}
},
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy