Skip to content

Commit 8d33f2f

Browse files
committed
feat: update configuration for aliasing
1 parent 312f82a commit 8d33f2f

File tree

12 files changed

+100
-26
lines changed

12 files changed

+100
-26
lines changed

apps/playground/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { createApp } from 'vue'
33
import { createRouter, createWebHistory } from 'vue-router'
44
import App from './App.vue'
55
import routes from './routes'
6+
import antd from 'ant-design-vue'
67

78
const router = createRouter({
89
history: createWebHistory(),
910
routes,
1011
})
1112

12-
createApp(App).use(router).mount('#app')
13+
createApp(App).use(router).use(antd).mount('#app')
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div class="flex flex-col gap-2">
3-
<button class="btn btn-primary">Primary Button</button>
4-
<button class="btn btn-secondary">Default Button</button>
5-
<button class="btn btn-error">Dashed Button</button>
6-
<button class="btn btn-link">Text Button</button>
7-
<button class="btn btn-link">Link Button</button>
3+
<a-button class="btn btn-primary">Primary Button</a-button>
4+
<a-button class="btn btn-secondary">Default Button</a-button>
5+
<a-button class="btn btn-error">Dashed Button</a-button>
6+
<a-button class="btn btn-link">Text Button</a-button>
7+
<a-button class="btn btn-link">Link Button</a-button>
88
</div>
99
</template>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable @typescript-eslint/consistent-type-imports */
22
declare module 'vue' {
3-
export interface GlobalComponents {}
3+
export interface GlobalComponents {
4+
AButton: typeof import('ant-design-vue').Button
5+
}
46
}
57
export {}

apps/playground/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"compilerOptions": {
66
"paths": {
77
"@/*": ["./src/*"],
8-
"~/*": ["./assets/*"]
8+
"~/*": ["./assets/*"],
9+
"ant-design-vue": ["./../../packages/ui/src/index.ts"]
910
}
1011
}
1112
}

apps/playground/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default defineConfig({
1515
alias: {
1616
'@': resolve(__dirname, './src'),
1717
'~': resolve(__dirname, './assets'),
18+
'ant-design-vue': resolve(__dirname, '../../packages/ui/src/index.ts'),
1819
},
1920
},
2021
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<button :class="classes" @click="$emit('click', $event)">
3+
<slot></slot>
4+
</button>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import { computed } from 'vue'
9+
import { buttonProps, buttonEmits, ButtonSlots } from './meta'
10+
11+
const props = defineProps(buttonProps)
12+
13+
defineEmits(buttonEmits)
14+
defineSlots<ButtonSlots>()
15+
16+
const classes = computed(() => {
17+
return [
18+
'rounded-md px-4 py-2 cursor-pointer',
19+
props.type,
20+
{
21+
'bg-primary text-primary-content': props.type === 'primary',
22+
'bg-secondary text-secondary-content': props.type === 'secondary',
23+
},
24+
]
25+
})
26+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { App, Plugin } from 'vue'
2+
import Button from './Button.vue'
3+
4+
/* istanbul ignore next */
5+
Button.install = function (app: App) {
6+
app.component('AButton', Button)
7+
return app
8+
}
9+
10+
export default Button as typeof Button & Plugin
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { PropType, ExtractPublicPropTypes } from 'vue'
2+
3+
// Button Props
4+
export const buttonProps = {
5+
/**
6+
* Specifies the visual style variant of the button
7+
* @default 'primary'
8+
*/
9+
type: {
10+
type: String as PropType<'primary' | 'secondary'>,
11+
default: 'primary',
12+
},
13+
} as const
14+
15+
export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>
16+
17+
// Button Emits
18+
export const buttonEmits = {
19+
/**
20+
* Triggered when the button is clicked by the user
21+
* @param e - The native MouseEvent object
22+
*/
23+
click: (e: MouseEvent) => e instanceof MouseEvent,
24+
} as const
25+
26+
export type ButtonEmits = typeof buttonEmits
27+
28+
// Button Slots
29+
export const buttonSlots = {
30+
/**
31+
* Main content slot for the button text or custom content
32+
*/
33+
default: (_: any) => null as any,
34+
} as const
35+
36+
export type ButtonSlots = typeof buttonSlots

packages/ui/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Button } from './button'

packages/ui/src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { App } from 'vue'
22

3-
const components = {} as any
3+
import * as components from './components'
4+
export * from './components'
45
export const install = function (app: App) {
56
Object.keys(components).forEach(key => {
67
const component = components[key]
78
if (component.install) {
89
app.use(component)
910
}
1011
})
11-
app.config.globalProperties.$message = components.message
12-
app.config.globalProperties.$notification = components.notification
13-
app.config.globalProperties.$info = components.Modal.info
14-
app.config.globalProperties.$success = components.Modal.success
15-
app.config.globalProperties.$error = components.Modal.error
16-
app.config.globalProperties.$warning = components.Modal.warning
17-
app.config.globalProperties.$confirm = components.Modal.confirm
18-
app.config.globalProperties.$destroyAll = components.Modal.destroyAll
12+
// app.config.globalProperties.$message = components.message
13+
// app.config.globalProperties.$notification = components.notification
14+
// app.config.globalProperties.$info = components.Modal.info
15+
// app.config.globalProperties.$success = components.Modal.success
16+
// app.config.globalProperties.$error = components.Modal.error
17+
// app.config.globalProperties.$warning = components.Modal.warning
18+
// app.config.globalProperties.$confirm = components.Modal.confirm
19+
// app.config.globalProperties.$destroyAll = components.Modal.destroyAll
1920
return app
2021
}
2122

0 commit comments

Comments
 (0)