Input.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <el-input ref="input" v-bind="$attrs" :class="[variant]" />
  3. </template>
  4. <script setup lang="ts">
  5. import { ref } from 'vue'
  6. import type { InputInstance } from 'element-plus'
  7. const input = ref<InputInstance>()
  8. withDefaults(
  9. defineProps<{
  10. variant?: 'outlined' | 'borderless' | 'filled' | 'underline'
  11. }>(),
  12. { variant: 'outlined' }
  13. )
  14. defineExpose({
  15. ...(input.value || {}),
  16. focus() {
  17. input.value?.focus()
  18. },
  19. blur() {
  20. input.value?.blur()
  21. },
  22. select() {
  23. input.value?.select()
  24. }
  25. })
  26. </script>
  27. <style lang="less" scoped>
  28. .borderless {
  29. :deep(.el-input__wrapper) {
  30. box-shadow: none;
  31. &:hover,
  32. &.is-focus {
  33. box-shadow: 0 0 0 1px var(--el-input-focus-border-color) inset;
  34. }
  35. }
  36. }
  37. .underline {
  38. :deep(.el-input__wrapper) {
  39. box-shadow: none;
  40. border-radius: 0;
  41. border-bottom: solid 1px var(--el-input-border-color);
  42. &:hover,
  43. &.is-focus {
  44. border-bottom: solid 1px var(--el-input-focus-border-color);
  45. }
  46. }
  47. }
  48. .filled {
  49. :deep(.el-input__wrapper) {
  50. box-shadow: none;
  51. background-color: #f5f5f5;
  52. &:hover {
  53. background-color: #f0f0f0;
  54. }
  55. &.is-focus {
  56. background-color: transparent;
  57. }
  58. }
  59. }
  60. </style>