✨(component): 新增 avatar 组件 default 插槽与 icon 属性, 支持文字与图标头像
This commit is contained in:
parent
20cecb95c1
commit
35fedf2926
@ -1,18 +1,14 @@
|
|||||||
.layui-avatar {
|
.layui-avatar {
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-variant: tabular-nums;
|
font-variant: tabular-nums;
|
||||||
font-feature-settings: tnum;
|
|
||||||
border-radius: var(--global-border-radius);
|
border-radius: var(--global-border-radius);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
color: #000000d9;
|
color: #ffffff;
|
||||||
line-height: 1.5715;
|
|
||||||
list-style: none;
|
list-style: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
background: #eeeeee;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
color: #fff;
|
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
width: 32px;
|
width: 32px;
|
||||||
@ -49,7 +45,6 @@
|
|||||||
& > img {
|
& > img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: #ccc;
|
|
||||||
display: block;
|
display: block;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, useSlots } from "vue";
|
import { computed, useSlots } from "vue";
|
||||||
|
import { LayIcon } from "@layui/icons-vue";
|
||||||
export default {
|
export default {
|
||||||
name: "LayAvatar",
|
name: "LayAvatar",
|
||||||
};
|
};
|
||||||
@ -7,16 +8,19 @@ export default {
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import "./index.less";
|
import "./index.less";
|
||||||
|
|
||||||
export interface LayAvatarProps {
|
export interface LayAvatarProps {
|
||||||
src?: string;
|
src?: string;
|
||||||
size?: "xs" | "sm" | "md" | "lg";
|
size?: "xs" | "sm" | "md" | "lg";
|
||||||
radius?: boolean;
|
radius?: boolean;
|
||||||
|
icon?: string;
|
||||||
alt?: string;
|
alt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<LayAvatarProps>(), {
|
const props = withDefaults(defineProps<LayAvatarProps>(), {
|
||||||
size: "md",
|
size: "md",
|
||||||
radius: false,
|
radius: false,
|
||||||
|
icon: "layui-icon-username"
|
||||||
});
|
});
|
||||||
|
|
||||||
const classes = computed(() => {
|
const classes = computed(() => {
|
||||||
@ -30,10 +34,13 @@ const slot = useSlots();
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<span v-if="!slot.default" :class="classes">
|
<span :class="classes" v-if="slot.default">
|
||||||
<img :alt="alt" :src="src" />
|
|
||||||
</span>
|
|
||||||
<span :class="classes" v-else>
|
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</span>
|
</span>
|
||||||
|
<span v-else-if="src" :class="classes">
|
||||||
|
<img :alt="alt" :src="src" />
|
||||||
|
</span>
|
||||||
|
<span v-else :class="classes">
|
||||||
|
<lay-icon :type="icon"></lay-icon>
|
||||||
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
@ -13,7 +13,12 @@
|
|||||||
::: demo 使用 `lay-avatar` 标签, 创建头像
|
::: demo 使用 `lay-avatar` 标签, 创建头像
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<lay-avatar :src="src"></lay-avatar>
|
<lay-space>
|
||||||
|
<lay-avatar :src="src"></lay-avatar>
|
||||||
|
<lay-avatar> Bai </lay-avatar>
|
||||||
|
<lay-avatar></lay-avatar>
|
||||||
|
<lay-avatar icon="layui-icon-face-smile"></lay-avatar>
|
||||||
|
</lay-space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -310,8 +310,8 @@ export default {
|
|||||||
z-index: 99;
|
z-index: 99;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
background: #ffffff;
|
|
||||||
border-bottom: 1px solid #eeeeee;
|
border-bottom: 1px solid #eeeeee;
|
||||||
|
background: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-layout-document > .layui-layout > .layui-side {
|
.layui-layout-document > .layui-layout > .layui-side {
|
||||||
|
@ -455,9 +455,8 @@ body {
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
color: rgba(60, 60, 60, 0.7);
|
color: rgba(60, 60, 60, 0.7);
|
||||||
border: 1px solid rgba(60, 60, 60, 0.7);
|
border: 1px solid rgba(60, 60, 60, 0.7);
|
||||||
|
background: white;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
transition: all 0.5s;
|
|
||||||
-webkit-transition: all 0.5s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user