Skip to content

Commit 127cca9

Browse files
committed
fix: 修复ui包类型问题
1 parent 7d0169e commit 127cca9

File tree

15 files changed

+49
-63
lines changed

15 files changed

+49
-63
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
- [ ] 修复ui组件类型提示问题
21
- [ ] 添加 utils 包测试用例(集成jest/vitest)
32
- [ ] docs文档添加“更多-更新日志”,changeset管理

apps/docs/en/guide/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ bun add @mylib/ui @mylib/utils @mylib/hooks
3737
### UI Components
3838

3939
```ts
40+
// Global import
4041
import { createApp } from 'vue';
4142
import UI from '@mylib/ui';
42-
import '@mylib/ui/dist/style.css';
43+
import '@mylib/ui/style.css';
4344
const app = createApp(App);
4445
app.use(UI);
46+
// You also need to add the following configuration in tsconfig.json to get type hints:
47+
// "types": ["@mylib/ui/global.d.ts"]
4548

4649
// On-demand import
4750
import { Button } from '@mylib/ui';
48-
import '@mylib/ui/dist/style.css';
51+
import '@mylib/ui/style.css';
4952
const app = createApp(App);
5053
app.use(Button);
5154
```

apps/docs/en/packages/ui/button.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ Basic button component.
66

77
<demo vue="ui/button/basic.vue" />
88

9-
| Property | Description | Type | Default |
10-
| --- | --- | --- | --- |
11-
| type | Button type | 'primary' \| 'success' \| 'warning' \| 'danger' \| 'info' | '' |
12-
| size | Button size | 'small' \| 'medium' \| 'large' | 'medium' |
13-
| disabled | Whether to disable the button | boolean | false |
14-
| plain | Whether to use plain style | boolean | false |
15-
| round | Whether to use rounded corners | boolean | false |
9+
| Property | Description | Type | Default |
10+
| -------- | ------------------------------ | --------------------------------------------------------- | -------- |
11+
| type | Button type | 'primary' \| 'success' \| 'warning' \| 'danger' \| 'info' | '' |
12+
| size | Button size | 'small' \| 'medium' \| 'large' | 'medium' |
13+
| disabled | Whether to disable the button | boolean | false |
14+
| round | Whether to use rounded corners | boolean | false |

apps/docs/en/packages/ui/dialog.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,3 @@ The dialog can be styled using the following class names:
2323
- `.v-dialog`: Main dialog container.
2424
- `.v-dialog__overlay`: Background overlay.
2525
- `.v-dialog__content`: Dialog content area.
26-
27-
## Code Example
28-
29-
```vue
30-
<template>
31-
<VDialog v-model:open="open">
32-
<div>Dialog content</div>
33-
</VDialog>
34-
<a-button @click="open = true">Open Dialog</a-button>
35-
</template>
36-
37-
<script setup lang="ts">
38-
import { VDialog } from '@mylib/ui';
39-
import { ref } from 'vue';
40-
const open = ref(false);
41-
</script>
42-
```

apps/docs/zh/guide/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ bun add @mylib/ui @mylib/utils @mylib/hooks
3737
### UI 组件
3838

3939
```ts
40+
// 全局引入
4041
import { createApp } from 'vue';
4142
import UI from '@mylib/ui';
4243
import '@mylib/ui/style.css';
4344
const app = createApp(App);
4445
app.use(UI);
46+
// tsconfig.json还需要添加以下配置以获得类型提示:
47+
// "types": ["@mylib/ui/global.d.ts"]
4548

4649
// 按需引入
4750
import { Button } from '@mylib/ui';

apps/docs/zh/packages/ui/button.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
| type | 按钮类型 | 'primary' \| 'success' \| 'warning' \| 'danger' \| 'info' | '' |
1212
| size | 按钮大小 | 'small' \| 'medium' \| 'large' | 'medium' |
1313
| disabled | 是否禁用 | boolean | false |
14-
| plain | 是否朴素 | boolean | false |
1514
| round | 是否圆角 | boolean | false |

apps/docs/zh/packages/ui/dialog.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,3 @@
2323
- `.v-dialog`: 主弹窗容器。
2424
- `.v-dialog__overlay`: 背景遮罩。
2525
- `.v-dialog__content`: 弹窗内容区域。
26-
27-
## 代码示例
28-
29-
```vue
30-
<template>
31-
<VDialog v-model:open="open">
32-
<div>弹窗内容</div>
33-
</VDialog>
34-
<a-button @click="open = true">打开弹窗</a-button>
35-
</template>
36-
37-
<script setup lang="ts">
38-
import { VDialog } from '@mylib/ui';
39-
import { ref } from 'vue';
40-
const open = ref(false);
41-
</script>
42-
```

packages/ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"import": "./dist/es/index.mjs",
1414
"require": "./dist/lib/index.js"
1515
},
16-
"./style.css": "./dist/style.css"
16+
"./style.css": "./dist/style.css",
17+
"./*": "./dist/*"
1718
},
1819
"files": [
1920
"dist"

packages/ui/src/types/components.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/ui/src/types/global.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// // For this project development
2+
// import '@vue/runtime-core';
3+
4+
/**
5+
* 给全局引入的UI组件类型提示:
6+
* tsconfig.json需要添加以下配置:
7+
* "types": ["vite/client", "@mylib/ui/global.d.ts"]
8+
*/
9+
declare module '@vue/runtime-core' {
10+
// GlobalComponents for Volar
11+
export interface GlobalComponents {
12+
VButton: (typeof import('@mylib/ui'))['VButton'];
13+
VDialog: (typeof import('@mylib/ui'))['VDialog'];
14+
}
15+
}
16+
17+
export {};

0 commit comments

Comments
 (0)