(component): 新增 input 组件 prepend append 插槽

This commit is contained in:
就眠儀式 2022-07-15 12:54:13 +08:00
parent 16bdc0427a
commit c6b6f5c0a7
4 changed files with 110 additions and 52 deletions

View File

@ -10,12 +10,13 @@ export default {
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import "./index.less"; import "./index.less";
import { ref, onMounted, onUnmounted, nextTick, computed } from "vue"; import { ref, onMounted, onUnmounted, nextTick, computed, reactive } from "vue";
export interface LayAiffxProps { export interface LayAiffxProps {
offset?: number; offset?: number;
target?: HTMLElement; target?: HTMLElement;
position?: string; position?: string;
} }
const props = withDefaults(defineProps<LayAiffxProps>(), { const props = withDefaults(defineProps<LayAiffxProps>(), {
offset: 0, offset: 0,
position: "top", position: "top",

View File

@ -3,7 +3,19 @@
--input-border-color: var(--global-neutral-color-3); --input-border-color: var(--global-neutral-color-3);
} }
.layui-input { .layui-input {
width: 100%;
height: 38px;
line-height: 38px;
border-width: 1px;
border-style: solid;
border-color: var(--input-border-color);
border-radius: var(--input-border-radius);
display: inline-flex;
}
.layui-input input{
height: 38px; height: 38px;
line-height: 38px; line-height: 38px;
background-color: #fff; background-color: #fff;
@ -11,22 +23,36 @@
padding-left: 10px; padding-left: 10px;
display: inline-block; display: inline-block;
border: none; border: none;
height: 100%;
width: 100%; width: 100%;
} }
.layui-input-append {
background-color: #fafafa;
border-left: 1px solid var(--input-border-color);
display: flex;
padding: 0 15px;
flex: none;
align-items: center;
}
.layui-input-prepend {
background-color: #fafafa;
border-right: 1px solid var(--input-border-color);
display: flex;
padding: 0 15px;
flex: none;
align-items: center;
}
.layui-input-wrapper { .layui-input-wrapper {
width: 100%; width: 100%;
height: 38px;
line-height: 38px;
border-width: 1px;
border-style: solid;
display: inline-flex; display: inline-flex;
border-color: var(--input-border-color); border: none;
border-radius: var(--input-border-radius);
} }
.layui-input-wrapper:hover, .layui-input:hover,
.layui-input-wrapper:focus-within { .layui-input:focus-within {
border-color: #d2d2d2 !important; border-color: #d2d2d2 !important;
} }
@ -34,18 +60,14 @@
display: flex; display: flex;
flex: none; flex: none;
align-items: center; align-items: center;
padding: 0 15px;
} }
.layui-input-suffix { .layui-input-suffix {
display: flex; display: flex;
flex: none; flex: none;
align-items: center; align-items: center;
} padding: 0 15px;
.layui-input-prefix-icon,
.layui-input-suffix-icon {
width: 38px;
text-align: center;
} }
.layui-input-clear { .layui-input-clear {
@ -56,6 +78,6 @@
color: rgba(0, 0, 0, 0.45); color: rgba(0, 0, 0, 0.45);
} }
.layui-input::-webkit-input-placeholder { .layui-input input::-webkit-input-placeholder {
line-height: 1.3; line-height: 1.3;
} }

View File

@ -96,41 +96,50 @@ const classes = computed(() => {
</script> </script>
<template> <template>
<div class="layui-input-wrapper"> <div
<span class="layui-input-prefix" v-if="slots.prefix || props.prefixIcon"> class="layui-input"
<slot name="prefix" v-if="slots.prefix"></slot> >
<lay-icon <div class="layui-input-prepend" v-if="slots.prepend">
v-else <slot name="prepend"></slot>
:type="props.prefixIcon" </div>
class="layui-input-prefix-icon" <div class="layui-input-wrapper">
></lay-icon> <span class="layui-input-prefix" v-if="slots.prefix || props.prefixIcon">
</span> <slot name="prefix" v-if="slots.prefix"></slot>
<input <lay-icon
:type="type" v-else
:name="name" :type="props.prefixIcon"
:disabled="disabled" class="layui-input-prefix-icon"
:value="currentValue" ></lay-icon>
:placeholder="placeholder" </span>
:autofocus="autofocus" <input
:autocomplete="autocomplete" :type="type"
:readonly="readonly" :name="name"
:class="classes" :disabled="disabled"
class="layui-input" :value="currentValue"
@input="onInput" :placeholder="placeholder"
@focus="onFocus" :autofocus="autofocus"
@blur="onBlur" :autocomplete="autocomplete"
@change="onChange" :readonly="readonly"
/> :class="classes"
<span class="layui-input-suffix" v-if="slots.suffix || props.suffixIcon"> @input="onInput"
<slot name="suffix" v-if="slots.suffix"></slot> @focus="onFocus"
<lay-icon @blur="onBlur"
v-else @change="onChange"
:type="props.suffixIcon" />
class="layui-input-suffix-icon" <span class="layui-input-suffix" v-if="slots.suffix || props.suffixIcon">
></lay-icon> <slot name="suffix" v-if="slots.suffix"></slot>
</span> <lay-icon
<span class="layui-input-clear" v-if="allowClear && hasContent"> v-else
<lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon> :type="props.suffixIcon"
</span> class="layui-input-suffix-icon"
></lay-icon>
</span>
<span class="layui-input-clear" v-if="allowClear && hasContent">
<lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon>
</span>
</div>
<div class="layui-input-append" v-if="slots.append">
<slot name="append"></slot>
</div>
</div> </div>
</template> </template>

View File

@ -83,6 +83,32 @@ export default {
::: :::
::: title 拼接内容
:::
::: demo
<template>
<lay-input>
<template #prepend>0</template>
<template #append>0</template>
</lay-input>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
return {
}
}
}
</script>
:::
::: title 设置图标 ::: title 设置图标
::: :::