📝(icon-picker): 新增 allow-clear 属性, 开启清空操作

This commit is contained in:
就眠儀式 2022-12-07 00:20:12 +08:00
parent bb30119bd3
commit f393343f03
5 changed files with 54 additions and 2 deletions

View File

@ -152,6 +152,15 @@
display: none; display: none;
} }
.layui-icon-picker-clear {
color: rgba(0, 0, 0, 0.45);
padding: 0px 0px 0px 10px;
}
.layui-icon-picker-clear:hover {
opacity: 0.6;
}
.layui-colorpicker-disabled { .layui-colorpicker-disabled {
opacity: 0.6; opacity: 0.6;
} }

View File

@ -17,6 +17,7 @@ export interface IconPickerProps {
modelValue?: string; modelValue?: string;
disabled?: boolean; disabled?: boolean;
showSearch?: boolean; showSearch?: boolean;
allowClear?: boolean;
contentClass?: string | Array<string | object> | object; contentClass?: string | Array<string | object> | object;
contentStyle?: StyleValue; contentStyle?: StyleValue;
} }
@ -38,6 +39,14 @@ const selectIcon = function (icon: string): void {
dropdownRef.value?.hide(); dropdownRef.value?.hide();
}; };
const onClear = function(): void {
emit("update:modelValue", "");
}
const hasContent = computed(() => {
return props.modelValue != null && props.modelValue != "";
})
const icones: Ref = ref([]); const icones: Ref = ref([]);
const total: Ref<number> = ref(icons.length); const total: Ref<number> = ref(icons.length);
const totalPage: Ref<number> = ref(total.value / 12); const totalPage: Ref<number> = ref(total.value / 12);
@ -155,6 +164,12 @@ const searchList = (str: string, container: any) => {
<div class="layui-inline layui-iconpicker-main"> <div class="layui-inline layui-iconpicker-main">
<i class="layui-inline layui-icon" :class="[selectedIcon]"></i> <i class="layui-inline layui-icon" :class="[selectedIcon]"></i>
</div> </div>
<span
class="layui-icon-picker-clear"
v-if="allowClear && hasContent && !disabled"
>
<lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon>
</span>
<span class="layui-inline layui-iconpicker-suffix" <span class="layui-inline layui-iconpicker-suffix"
><i ><i
class="layui-icon layui-icon-down" class="layui-icon layui-icon-down"

View File

@ -11,7 +11,7 @@ import {
useSlots, useSlots,
getCurrentInstance, getCurrentInstance,
reactive, reactive,
onBeforeUnmount, onBeforeUnmount
} from "vue"; } from "vue";
import { TabInjectKey, TabsContext } from "../tab/interface"; import { TabInjectKey, TabsContext } from "../tab/interface";

View File

@ -59,6 +59,32 @@ export default {
::: :::
::: title 选择清空
:::
::: demo 使用 lay-icon-picker 标签, 创建图标选择器
<template>
<lay-icon-picker v-model="icon" :allow-clear="true"></lay-icon-picker>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const icon = ref("layui-icon-home")
return {
icon
}
}
}
</script>
:::
::: title 开启分页 ::: title 开启分页
::: :::
@ -116,12 +142,13 @@ export default {
::: table ::: table
| | | | | | | 属性 | 说明 | 类型 | 默认值 | 可选值 |
| ---------- | -------- | --- |--- |--- | | ---------- | -------- | --- |--- |--- |
| v-model | 默认值 | -- |-- |-- | | v-model | 默认值 | -- |-- |-- |
| page | 开启分页 | -- |-- |-- | | page | 开启分页 | -- |-- |-- |
| showSearch | 启用搜索 | -- |-- |-- | | showSearch | 启用搜索 | -- |-- |-- |
| disabled | 禁用 | `boolean` |-- |-- | | disabled | 禁用 | `boolean` |-- |-- |
| allow-clear | 允许清空 | `boolean` |-- |-- |
| contentStyle | 内容自定义样式 | `StyleValue` | -- | -- | | contentStyle | 内容自定义样式 | `StyleValue` | -- | -- |
| contentClass | 内容自定义Class | `string` `Array<string \| object>` `object` | -- | -- | | contentClass | 内容自定义Class | `string` `Array<string \| object>` `object` | -- | -- |

View File

@ -16,6 +16,7 @@
<li> <li>
<h3>1.7.11 <span class="layui-badge-rim">2022-12-05</span></h3> <h3>1.7.11 <span class="layui-badge-rim">2022-12-05</span></h3>
<ul> <ul>
<li>[新增] icon-picker 组件 allow-clear 属性, 开启清空操作。</li>
<li>[修复] button 组件 夜间模式 下, 普通按钮边框高亮与背景色不一致的问题。</li> <li>[修复] button 组件 夜间模式 下, 普通按钮边框高亮与背景色不一致的问题。</li>
<li>[优化] checkbox 组件 默认主题 下, 勾选框多余的左边框。</li> <li>[优化] checkbox 组件 默认主题 下, 勾选框多余的左边框。</li>
<li>[优化] icon-picker 组件 下拉 图标, 在打开关闭时赋予不同的状态。</li> <li>[优化] icon-picker 组件 下拉 图标, 在打开关闭时赋予不同的状态。</li>