element-like 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -2
- package/dist/es/bundle.d.ts +52 -0
- package/dist/es/element-like.js +696 -0
- package/dist/es/style.css +2 -0
- package/dist/style.css +2 -0
- package/dist/umd/bundle.d.ts +52 -0
- package/dist/umd/element-like.umd.cjs +1081 -0
- package/dist/umd/style.css +2 -0
- package/docs/packaging.md +161 -0
- package/docs/usage.md +164 -0
- package/package.json +95 -4
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# element-like
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个仿 Element UI / Element Plus 的 Vue 3 组件库:从零封装常用 UI 组件,配套设计 token 体系、组件文档与单元测试。支持 npm 安装全量/按需注册,也支持 CDN `<script>` 直引。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
需要 **Vue** `^3.5.0`(peerDependency,由使用方自行安装):
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add element-like
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 快速上手
|
|
14
|
+
|
|
15
|
+
### 全量注册(推荐,对齐 element-ui 的 `Vue.use(ElementUI)`)
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createApp } from 'vue'
|
|
19
|
+
import ElementLike from 'element-like'
|
|
20
|
+
import 'element-like/style.css'
|
|
21
|
+
import App from './App.vue'
|
|
22
|
+
|
|
23
|
+
const app = createApp(App)
|
|
24
|
+
app.use(ElementLike)
|
|
25
|
+
app.mount('#app')
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
模板中直接使用小写标签,无需 import 组件:
|
|
29
|
+
|
|
30
|
+
```vue
|
|
31
|
+
<template>
|
|
32
|
+
<el-like-button type="primary" icon="paper-plane">发送</el-like-button>
|
|
33
|
+
<el-like-button type="success" icon="check">完成</el-like-button>
|
|
34
|
+
</template>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 按需注册(对齐 element-plus,tree-shaking)
|
|
38
|
+
|
|
39
|
+
具名导出为 PascalCase,`app.use` 单独注册,未用到的组件由构建工具摇树掉:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { ElLikeButton, ElLikeIcon } from 'element-like'
|
|
43
|
+
import 'element-like/style.css'
|
|
44
|
+
|
|
45
|
+
app.use(ElLikeButton)
|
|
46
|
+
app.use(ElLikeIcon)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
两种方式的模板写法完全一致;按需场景下 Button 的 `icon` 属性需要同时注册 `ElLikeIcon` 才生效。
|
|
50
|
+
|
|
51
|
+
CDN `<script>` 直引、图标机制、TypeScript 支持与常见问题等完整接入说明见 [docs/usage.md](docs/usage.md)。
|
|
52
|
+
|
|
53
|
+
## 组件列表
|
|
54
|
+
|
|
55
|
+
组件以 `ElLike-` 前缀全局注册(与 Element Plus 的 `app.use` 消费方式对齐),模板中使用小写标签 `<el-like-button>`,无需 import;按需导入的具名导出为 PascalCase(`import { ElLikeButton } from 'element-like'`,对齐 Element Plus 的 `ElButton`),导入名与模板标签一一对应。每个组件的详细用法与 API 见其目录下的 README。
|
|
56
|
+
|
|
57
|
+
- ✅ **Icon 图标** —— 对 font-awesome 的二次封装,详见 [src/components/Icon/README.md](src/components/Icon/README.md)
|
|
58
|
+
- ✅ **Button 按钮** —— 支持主题、尺寸、图标及加载状态,详见 [src/components/Button/README.md](src/components/Button/README.md)
|
|
59
|
+
- ✅ **Card 卡片** —— 支持图片、尺寸、摘要及内容插槽,详见 [src/components/Card/README.md](src/components/Card/README.md)
|
|
60
|
+
- ✅ **Dialog 对话框** —— 支持受控显示、自定义内容及关闭配置,详见 [src/components/Dialog/README.md](src/components/Dialog/README.md)
|
|
61
|
+
- ✅ **Pager 分页** —— 支持受控当前页、页码窗口折叠与省略号快速跳转,详见 [src/components/Pager/README.md](src/components/Pager/README.md)
|
|
62
|
+
- ✅ **Collapse 折叠面板** —— 含 CollapseItem,支持手风琴模式、自定义标题与禁用面板,详见 [src/components/Collapse/README.md](src/components/Collapse/README.md)
|
|
63
|
+
- ✅ **Tooltip 文字提示** —— 支持 hover / click / focus 三种触发方式、延时与手动控制、自动翻转定位,详见 [src/components/Tooltip/README.md](src/components/Tooltip/README.md)
|
|
64
|
+
- ✅ **Dropdown 下拉菜单** —— 复用 Tooltip 的显示/定位机制,选择条目触发 select 事件,详见 [src/components/Dropdown/README.md](src/components/Dropdown/README.md)
|
|
65
|
+
|
|
66
|
+
各组件的示例页(`src/views/*View.vue`)已接入路由,可在开发服务器中预览。
|
|
67
|
+
|
|
68
|
+
## 开发
|
|
69
|
+
|
|
70
|
+
### 技术栈
|
|
71
|
+
|
|
72
|
+
- **Vue 3** + **TypeScript** + **Vite**(支持 JSX/TSX)
|
|
73
|
+
- **SCSS** 设计 token 体系(CSS 自定义属性,命名对齐 Element Plus 的 `--el-*`)
|
|
74
|
+
- **Vitest** + @vue/test-utils + jsdom(单元测试)
|
|
75
|
+
- **oxlint** + **ESLint** + **Prettier**(双 linter 依次自动修复,格式化由 Prettier 负责)
|
|
76
|
+
- 图标基于 font-awesome 二次封装
|
|
77
|
+
|
|
78
|
+
### 环境要求
|
|
79
|
+
|
|
80
|
+
- Node.js `^22.18.0 || >=24.12.0`
|
|
81
|
+
- 包管理器:**pnpm**
|
|
82
|
+
|
|
83
|
+
### 常用命令
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
pnpm install # 安装依赖
|
|
87
|
+
pnpm dev # 启动开发服务器(组件示例页)
|
|
88
|
+
pnpm build # 类型检查 + 生产构建(并行)
|
|
89
|
+
pnpm build:lib # 组件库打包(ES + UMD 双格式 + 样式产物)
|
|
90
|
+
pnpm vitest run # 一次性运行单元测试(pnpm test:unit 为 watch 模式)
|
|
91
|
+
pnpm lint # oxlint + ESLint 依次自动修复
|
|
92
|
+
pnpm format # Prettier 格式化(只覆盖 src/)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 组件库打包
|
|
96
|
+
|
|
97
|
+
组件库支持以 npm 包形式发布(ES + UMD 双格式,含样式产物)。打包体系、依赖分层策略与日常维护约定(增删组件、调整依赖时的联动修改点)详见 [docs/packaging.md](docs/packaging.md)。
|
|
98
|
+
|
|
99
|
+
### 目录结构
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
src/
|
|
103
|
+
├── components/ # 组件库源码(每个组件一个目录,内含组件、props 定义与 README)
|
|
104
|
+
│ └── Icon/
|
|
105
|
+
├── views/ # 组件示例页(开发预览用,按组件一一对应)
|
|
106
|
+
├── styles/ # 设计 token(vars.scss)+ 全局重置(reset.scss),详见其 README
|
|
107
|
+
├── router/ # 示例页路由(meta.label 驱动导航,增删组件页自动同步)
|
|
108
|
+
└── __tests__/ # 单元测试
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 开发约定
|
|
112
|
+
|
|
113
|
+
- **样式**:组件样式一律通过 `var(--el-*)` 消费设计 token,禁止手写色值;token 体系的设计决策见 [src/styles/README.md](src/styles/README.md)
|
|
114
|
+
- **路径别名**:`@/*` → `./src/*`,优先使用别名而非深层相对导入
|
|
115
|
+
- **提交信息**:遵循 Conventional Commits (Angular) 规范,subject 用中文、动词开头
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// element-like 的公共类型声明:与 bundle.ts 的运行时导出逐一对应。
|
|
2
|
+
// 手写维护而非构建生成(如 vite-plugin-dts),公共 API 面小且稳定;
|
|
3
|
+
// 新增组件在 bundle.ts 登记后,须同步在此登记导出与 GlobalComponents(见 docs/packaging.md)。
|
|
4
|
+
// 除模块导出外,还通过 declare module 'vue' 增强 GlobalComponents,
|
|
5
|
+
// 让使用方模板里的 <el-like-button> 等标签获得 Volar 的组件解析与提示。
|
|
6
|
+
import type { App, Component } from 'vue'
|
|
7
|
+
|
|
8
|
+
// withInstall 装配后的组件形态:组件本身 + install 方法(app.use 直接可用)
|
|
9
|
+
export interface SFCWithInstall<T> extends Component {
|
|
10
|
+
install: (app: App) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const install: (app: App) => void
|
|
14
|
+
|
|
15
|
+
export const ElLikeIcon: SFCWithInstall<Component>
|
|
16
|
+
export const ElLikeButton: SFCWithInstall<Component>
|
|
17
|
+
export const ElLikeCard: SFCWithInstall<Component>
|
|
18
|
+
export const ElLikeDialog: SFCWithInstall<Component>
|
|
19
|
+
export const ElLikePager: SFCWithInstall<Component>
|
|
20
|
+
export const ElLikeCollapse: SFCWithInstall<Component>
|
|
21
|
+
export const ElLikeCollapseItem: SFCWithInstall<Component>
|
|
22
|
+
export const ElLikeTooltip: SFCWithInstall<Component>
|
|
23
|
+
export const ElLikeDropdown: SFCWithInstall<Component>
|
|
24
|
+
|
|
25
|
+
declare const _default: {
|
|
26
|
+
install: (app: App) => void
|
|
27
|
+
ElLikeIcon: typeof ElLikeIcon
|
|
28
|
+
ElLikeButton: typeof ElLikeButton
|
|
29
|
+
ElLikeCard: typeof ElLikeCard
|
|
30
|
+
ElLikeDialog: typeof ElLikeDialog
|
|
31
|
+
ElLikePager: typeof ElLikePager
|
|
32
|
+
ElLikeCollapse: typeof ElLikeCollapse
|
|
33
|
+
ElLikeCollapseItem: typeof ElLikeCollapseItem
|
|
34
|
+
ElLikeTooltip: typeof ElLikeTooltip
|
|
35
|
+
ElLikeDropdown: typeof ElLikeDropdown
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default _default
|
|
39
|
+
|
|
40
|
+
declare module 'vue' {
|
|
41
|
+
export interface GlobalComponents {
|
|
42
|
+
ElLikeIcon: typeof ElLikeIcon
|
|
43
|
+
ElLikeButton: typeof ElLikeButton
|
|
44
|
+
ElLikeCard: typeof ElLikeCard
|
|
45
|
+
ElLikeDialog: typeof ElLikeDialog
|
|
46
|
+
ElLikePager: typeof ElLikePager
|
|
47
|
+
ElLikeCollapse: typeof ElLikeCollapse
|
|
48
|
+
ElLikeCollapseItem: typeof ElLikeCollapseItem
|
|
49
|
+
ElLikeTooltip: typeof ElLikeTooltip
|
|
50
|
+
ElLikeDropdown: typeof ElLikeDropdown
|
|
51
|
+
}
|
|
52
|
+
}
|