Skip to content

Commit ee57be8

Browse files
committed
update
1 parent 70dd09c commit ee57be8

File tree

18 files changed

+307
-12
lines changed

18 files changed

+307
-12
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# zero
2-
一个基于vue-cli 4开发的UI库demo
1+
# zero-ui
2+
一个基于vue-cli 4开发的UI库demo
3+
4+
组件代码参考以下仓库:
5+
- [element](https://github.com/ElemeFE/element)
6+
- [ele-next](https://github.com/a631807682/ele-next)

examples/App.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
<script lang="ts">
55
import { defineComponent } from 'vue'
66
export default defineComponent({
7-
name: 'App',
8-
components: {
9-
}
7+
name: 'App'
108
})
119
</script>
1210
<style>

examples/views/Home.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<template>
22
<div class="home">
3-
<el-alert type="success">123</el-alert>
3+
<el-container>
4+
<el-aside>
5+
</el-aside>
6+
<el-main>
7+
<el-avatar icon="el-icon-user-solid"></el-avatar>
8+
<el-alert type="success">123</el-alert>
9+
</el-main>
10+
</el-container>
411
</div>
512
</template>
613
<script lang="ts">
7-
import { defineComponent } from 'vue'
14+
import { defineComponent, ref } from 'vue'
15+
// @ts-ignore
16+
import { components } from 'zero-ui'
817
export default defineComponent({
918
name: 'Home'
1019
})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
},
2828
"dependencies": {
2929
"core-js": "^3.6.5",
30+
"resize-observer-polyfill": "^1.5.1",
3031
"sass": "^1.26.10",
32+
"throttle-debounce": "^2.2.1",
3133
"vue": "^3.0.0-0",
3234
"vue-router": "^4.0.0-0",
3335
"vuex": "^4.0.0-0"

packages/aside/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { App } from 'vue'
2+
import Component from './src/index.vue'
3+
export const install = function (app: App) {
4+
app.component(Component.name as string, Component)
5+
}
6+
7+
export default Component

packages/aside/src/index.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<aside class="el-aside" :style="{ width }">
3+
<slot></slot>
4+
</aside>
5+
</template>
6+
7+
<script lang="ts">
8+
import { defineComponent } from 'vue'
9+
export default defineComponent({
10+
name: 'ElAside',
11+
12+
componentName: 'ElAside',
13+
14+
props: {
15+
width: {
16+
type: String,
17+
default: '300px'
18+
}
19+
}
20+
})
21+
</script>
22+
<style lang="scss">
23+
@import 'theme/aside.scss';
24+
</style>

packages/avatar/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { App } from 'vue'
2+
import Component from './src/index.vue'
3+
export const install = function (app: App) {
4+
app.component(Component.name as string, Component)
5+
}
6+
7+
export default Component

packages/avatar/src/index.vue

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
<script lang="tsx">
3+
import { ref, defineComponent, computed, PropType, reactive, h, Slot } from 'vue'
4+
import { AvatarSize, AvatarShape, AvatarFit } from './type'
5+
export default defineComponent({
6+
name: 'ElAvatar',
7+
8+
props: {
9+
size: {
10+
type: [Number, String] as PropType<AvatarSize>,
11+
validator: (val: number | string): boolean => {
12+
if (typeof val === 'string') {
13+
return ['large', 'medium', 'small'].includes(val)
14+
}
15+
return typeof val === 'number'
16+
}
17+
},
18+
shape: {
19+
type: String as PropType<AvatarShape>,
20+
default: 'circle',
21+
validator: (val: string): boolean => {
22+
return ['circle', 'square'].includes(val)
23+
},
24+
},
25+
icon: String,
26+
src: String,
27+
alt: String,
28+
srcSet: String,
29+
error: Function,
30+
fit: {
31+
type: String,
32+
default: 'cover'
33+
}
34+
},
35+
36+
setup(props, cxt) {
37+
const isImageExist = ref(true)
38+
39+
const avatarClass = computed(() => {
40+
const { size, icon, shape } = props
41+
let classList = ['el-avatar']
42+
43+
if (size && typeof size === 'string') {
44+
classList.push(`el-avatar--${size}`)
45+
}
46+
47+
if (icon) {
48+
classList.push('el-avatar--icon')
49+
}
50+
51+
if (shape) {
52+
classList.push(`el-avatar--${shape}`)
53+
}
54+
console.log(classList)
55+
return classList.join(' ')
56+
})
57+
58+
const handleError = () => {
59+
const { error } = props
60+
const errorFlag = error ? error() : undefined
61+
if (errorFlag !== false) {
62+
isImageExist.value = false
63+
}
64+
}
65+
66+
const renderAvatar = () => {
67+
const { icon, src, alt, srcSet, fit } = props
68+
if (isImageExist.value && src) {
69+
return h('img', {
70+
src,
71+
alt,
72+
style: {
73+
'object-fit': fit,
74+
},
75+
srcSet,
76+
onError: handleError,
77+
})
78+
}
79+
80+
if (icon) {
81+
return h('i', { class: icon })
82+
}
83+
const slot = cxt.slots.default as Slot
84+
return slot ? slot() : ''
85+
}
86+
87+
return () => {
88+
const { size } = props
89+
const sizeStyle =
90+
typeof size === 'number'
91+
? {
92+
height: `${size}px`,
93+
width: `${size}px`,
94+
lineHeight: `${size}px`,
95+
}
96+
: {}
97+
return (
98+
<span class={ avatarClass.value } style={ sizeStyle }>
99+
{
100+
renderAvatar()
101+
}
102+
</span>
103+
)
104+
}
105+
}
106+
})
107+
</script>
108+
<style lang="scss">
109+
@import 'theme/avatar.scss';
110+
</style>

packages/avatar/src/type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type AvatarSize = number | 'large' | 'medium' | 'small'
2+
export type AvatarShape = 'circle' | 'square'
3+
export type AvatarFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down'

packages/component.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { App, ref } from "vue";
2+
3+
/** ElementUI component common definition */
4+
export declare class ElementUIComponent extends Plugin {
5+
/** Install component into Vue */
6+
static install(app: App): void;
7+
}
8+
9+
/** Component size definition for button, input, etc */
10+
export type ElementUIComponentSize = "large" | "medium" | "small" | "mini";
11+
12+
/** Horizontal alignment */
13+
export type ElementUIHorizontalAlignment = "left" | "center" | "right";
14+
15+
export type ElementUIProp = {
16+
size: ElementUIComponentSize | "";
17+
zIndex: Number;
18+
};
19+
20+
export const ElementUIOptions = ref({
21+
size: "",
22+
zIndex: 2000,
23+
});

0 commit comments

Comments
 (0)