✨(component): 新增 input 组件 prepend append 插槽
This commit is contained in:
		
							parent
							
								
									16bdc0427a
								
							
						
					
					
						commit
						c6b6f5c0a7
					
				| @ -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", | ||||||
|  | |||||||
| @ -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; | ||||||
| } | } | ||||||
|  | |||||||
| @ -96,6 +96,12 @@ const classes = computed(() => { | |||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <template> | <template> | ||||||
|  |   <div | ||||||
|  |     class="layui-input" | ||||||
|  |   > | ||||||
|  |     <div class="layui-input-prepend" v-if="slots.prepend"> | ||||||
|  |       <slot name="prepend"></slot> | ||||||
|  |     </div> | ||||||
|     <div class="layui-input-wrapper"> |     <div class="layui-input-wrapper"> | ||||||
|       <span class="layui-input-prefix" v-if="slots.prefix || props.prefixIcon"> |       <span class="layui-input-prefix" v-if="slots.prefix || props.prefixIcon"> | ||||||
|         <slot name="prefix" v-if="slots.prefix"></slot> |         <slot name="prefix" v-if="slots.prefix"></slot> | ||||||
| @ -115,7 +121,6 @@ const classes = computed(() => { | |||||||
|         :autocomplete="autocomplete" |         :autocomplete="autocomplete" | ||||||
|         :readonly="readonly" |         :readonly="readonly" | ||||||
|         :class="classes" |         :class="classes" | ||||||
|       class="layui-input" |  | ||||||
|         @input="onInput" |         @input="onInput" | ||||||
|         @focus="onFocus" |         @focus="onFocus" | ||||||
|         @blur="onBlur" |         @blur="onBlur" | ||||||
| @ -133,4 +138,8 @@ const classes = computed(() => { | |||||||
|         <lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon> |         <lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon> | ||||||
|       </span> |       </span> | ||||||
|     </div> |     </div> | ||||||
|  |     <div class="layui-input-append" v-if="slots.append"> | ||||||
|  |       <slot name="append"></slot> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
| </template> | </template> | ||||||
|  | |||||||
| @ -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 设置图标 | ||||||
| ::: | ::: | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user