feat: add input suffix prefix slot

This commit is contained in:
就眠儀式 2022-03-22 15:14:10 +08:00
parent 6d3073a666
commit 794dbb77fd
5 changed files with 76 additions and 58 deletions

View File

@ -56,6 +56,33 @@ export default {
::: :::
::: title 前缀后缀
:::
::: demo
<template>
<lay-input>
<template #prefix>0</template>
<template #suffix>0</template>
</lay-input>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
return {
}
}
}
</script>
:::
::: title 事件回调 ::: title 事件回调
::: :::

View File

@ -16,6 +16,8 @@
<li> <li>
<h3>0.4.1 <span class="layui-badge-rim">2022-03-17</span></h3> <h3>0.4.1 <span class="layui-badge-rim">2022-03-17</span></h3>
<ul> <ul>
<li>[新增] input 组件 prefix 插槽, 提供前缀设置。</li>
<li>[新增] input 组件 suffix 插槽, 提供后缀设置。</li>
<li>[新增] transition 组件 type 属性, 默认为 collapse 过渡。</li> <li>[新增] transition 组件 type 属性, 默认为 collapse 过渡。</li>
<li>[新增] transition 组件 type 属性 fade 值, 提供淡出淡入效果。</li> <li>[新增] transition 组件 type 属性 fade 值, 提供淡出淡入效果。</li>
</ul> </ul>

View File

@ -10,17 +10,34 @@
.layui-input { .layui-input {
height: 38px; height: 38px;
line-height: 1.3; line-height: 38px;
line-height: 38px\9;
border-width: 1px;
border-style: solid;
background-color: #fff; background-color: #fff;
color: rgba(0, 0, 0, 0.85); color: rgba(0, 0, 0, 0.85);
border-radius: @input-border-radius;
border-color: @input-border-color;
display: block;
width: 100%;
padding-left: 10px; padding-left: 10px;
display: inline-block;
border: none;
width: 100%;
}
.layui-input-wrapper {
width: 100%;
border-width: 1px;
border-style: solid;
display: inline-flex;
border-color: @input-border-color;
border-radius: @input-border-radius;
}
.layui-input-prefix {
display: flex;
flex: none;
align-items: center;
}
.layui-input-suffix {
display: flex;
flex: none;
align-items: center;
} }
.layui-input:hover { .layui-input:hover {

View File

@ -7,8 +7,10 @@ export default {
<script setup lang="ts"> <script setup lang="ts">
import "./index.less"; import "./index.less";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useSlots } from "vue-demi";
const { t } = useI18n(); const { t } = useI18n();
const slots = useSlots();
export interface LayInputProps { export interface LayInputProps {
name?: string; name?: string;
@ -39,16 +41,24 @@ const onBlur = function () {
</script> </script>
<template> <template>
<input <div class="layui-input-wrapper">
:type="type" <span class="layui-input-prefix" v-if="slots.prefix">
:name="name" <slot name="prefix"></slot>
:value="modelValue || value" </span>
:disabled="disabled" <input
:placeholder="placeholder" :type="type"
:class="{ 'layui-disabled': disabled }" :name="name"
class="layui-input" :value="modelValue || value"
@input="onInput" :disabled="disabled"
@focus="onFocus" :placeholder="placeholder"
@blur="onBlur" :class="{ 'layui-disabled': disabled }"
/> class="layui-input"
@input="onInput"
@focus="onFocus"
@blur="onBlur"
/>
<span class="layui-input-suffix" v-if="slots.suffix">
<slot name="suffix"></slot>
</span>
</div>
</template> </template>

View File

@ -672,49 +672,11 @@ a cite {
padding-left: 35px; padding-left: 35px;
} }
.layui-input-prefix,
.layui-input-split,
.layui-input-suffix {
position: absolute;
right: 0;
top: 0;
padding: 0 10px;
width: 35px;
height: 100%;
text-align: center;
transition: all 0.3s;
cursor: pointer;
pointer-events: none;
box-sizing: border-box;
}
.layui-input-prefix {
left: 0;
border-radius: 2px 0 0 2px;
}
.layui-input-suffix {
right: 0;
border-radius: 0 2px 2px 0;
}
.layui-input-wrap .layui-input:focus + .layui-input-split { .layui-input-wrap .layui-input:focus + .layui-input-split {
border-color: @global-neutral-color-6; border-color: @global-neutral-color-6;
} }
.layui-input-prefix .layui-icon,
.layui-input-split .layui-icon,
.layui-input-suffix .layui-icon {
position: relative;
font-size: 16px;
color: rgba(0, 0, 0, 0.6);
transition: all 0.3s;
}
.layui-input-wrap .layui-input-prefix.layui-input-split {
border-width: 0 1px 0 0;
}
.layui-input-wrap-prefix .layui-form-select { .layui-input-wrap-prefix .layui-form-select {
position: static; position: static;
} }