Skip to content

Commit 664daa6

Browse files
rafaelytakeiantfu
andauthored
feat: add PrimeVue Resolver (#98)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 89e168a commit 664daa6

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Supported Resolvers:
133133
- [Element Plus](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/element-plus.ts)
134134
- [Headless UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/headless-ui.ts)
135135
- [Naive UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/naive-ui.ts)
136+
- [Prime Vue](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/prime-vue.ts)
136137
- [Vant](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vant.ts)
137138
- [Varlet UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/varlet-ui.ts)
138139
- [Vuetify](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vuetify.ts)

src/resolvers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export * from './vuetify'
66
export * from './vueuse'
77
export * from './naive-ui'
88
export * from './varlet-ui'
9+
export * from './prime-vue'
910
export * from './view-ui'

src/resolvers/prime-vue.ts

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import { ComponentResolver } from "../types"
2+
3+
const components = [
4+
"AutoComplete",
5+
"Calendar",
6+
"CascadeSelect",
7+
"Checkbox",
8+
"Chips",
9+
"ColorPicker",
10+
"Dropdown",
11+
"Editor",
12+
"InputMask",
13+
"InputNumber",
14+
"InputSwitch",
15+
"InputText",
16+
"Knob",
17+
"Listbox",
18+
"MultiSelect",
19+
"Password",
20+
"RadioButton",
21+
"Rating",
22+
"SelectButton",
23+
"Slider",
24+
"Textarea",
25+
"ToggleButton",
26+
"TreeSelect",
27+
"TriStateCheckbox",
28+
"Button",
29+
"SplitButton",
30+
"DataTable",
31+
"Column",
32+
"ColumnGroup",
33+
"DataView",
34+
"FullCalendar",
35+
"OrderList",
36+
"OrganizationChart",
37+
"Paginator",
38+
"PickList",
39+
"Timelist",
40+
"Tree",
41+
"TreeTable",
42+
"Accordion",
43+
"AccordionTab",
44+
"Card",
45+
"DeferredContent",
46+
"Divider",
47+
"Fieldset",
48+
"Panel",
49+
"Splitter",
50+
"SplitterPanel",
51+
"ScrollPanel",
52+
"TabView",
53+
"TabPanel",
54+
"Toolbar",
55+
"ConfirmDialog",
56+
"ConfirmPopup",
57+
"Dialog",
58+
"OverlayPanel",
59+
"Sidebar",
60+
"Tooltip",
61+
"FileUpload",
62+
"Breadcrumb",
63+
"ContextMenu",
64+
"MegaMenu",
65+
"Menu",
66+
"Menubar",
67+
"PanelMenu",
68+
"Steps",
69+
"TabMenu",
70+
"TieredMenu",
71+
"Chart",
72+
"Message",
73+
"Toast",
74+
"Carousel",
75+
"Galleria",
76+
"Avatar",
77+
"AvatarGroup",
78+
"Badge",
79+
"Chip",
80+
"BlockUI",
81+
"Inplace",
82+
"ScrollTop",
83+
"Skeleton",
84+
"ProgressBar",
85+
"ProgressSpiner",
86+
"Tag",
87+
"Terminal",
88+
"TerminalService",
89+
]
90+
91+
export interface PrimeVueResolverOptions {
92+
/**
93+
* import style along with components
94+
*
95+
* @default true
96+
*/
97+
importStyle?: boolean
98+
/**
99+
* import `primeicons' icons
100+
*
101+
* requires package `primeicons`
102+
*
103+
* @default true
104+
*/
105+
importIcons?: boolean
106+
/**
107+
* imports a free theme - set theme name here (e.g. saga-blue)
108+
*
109+
* @default ''
110+
*/
111+
importTheme?: string
112+
}
113+
114+
/**
115+
* Resolver for PrimeVue - If you're using a component with the same tag as an native HTML element (e.g. button) the component must be in uppercase
116+
*
117+
* @link https://github.com/primefaces/primevue
118+
*/
119+
export const PrimeVueResolver =
120+
(options: PrimeVueResolverOptions = {}): ComponentResolver =>
121+
(name: string) => {
122+
const sideEffects = []
123+
if (options.importStyle) {
124+
sideEffects.push("primevue/resources/primevue.min.css")
125+
}
126+
if (options.importIcons) {
127+
sideEffects.push("primeicons/primeicons.css")
128+
}
129+
if (options.importTheme) {
130+
sideEffects.push(
131+
`primevue/resources/themes/${options.importTheme}/theme.css`
132+
)
133+
}
134+
if (components.includes(name)) {
135+
return {
136+
path: `primevue/${name}/${name}.vue`,
137+
sideEffects,
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)