AmAdvButton.vue
174 lines
| 1 | <template> |
| 2 | <el-button |
| 3 | class="am-adv-button" |
| 4 | :class="[`am-adv-button__${btnSize}`, isIconClass, customClass]" |
| 5 | :size="size" |
| 6 | :type="type" |
| 7 | :plain="plain" |
| 8 | :round="round" |
| 9 | :circle="circle" |
| 10 | :loading="loading" |
| 11 | :disabled="disabled" |
| 12 | :autofocus="autofocus" |
| 13 | :native-type="nativeType" |
| 14 | :auto-insert-space="autoInsertSpace" |
| 15 | @click="handleClick" |
| 16 | > |
| 17 | <slot v-if="(prefixIcon || Object.keys(prefixIcon).length) && !iconOnly" name="prefixIcon"> |
| 18 | <component :is="prefixIcon" v-if="typeof prefixIcon === 'object'"></component> |
| 19 | <span v-if="typeof prefixIcon === 'string'" :class="`am-icon-${prefixIcon}`"></span> |
| 20 | </slot> |
| 21 | <slot v-if="(icon || Object.keys(icon).length) && iconOnly" name="icon"> |
| 22 | <component :is="icon" v-if="typeof icon === 'object'"></component> |
| 23 | <span v-if="typeof icon === 'string'" :class="`am-icon-${icon}`"></span> |
| 24 | </slot> |
| 25 | <slot v-if="loadingIcon || Object.keys(loadingIcon).length" name="icon"> |
| 26 | <component :is="loadingIcon" v-if="typeof loadingIcon === 'object'"></component> |
| 27 | <span v-if="typeof loadingIcon === 'string'" :class="`am-icon-${loadingIcon}`"></span> |
| 28 | </slot> |
| 29 | <slot v-if="$slots.default && !iconOnly"></slot> |
| 30 | <slot v-if="(suffixIcon || Object.keys(suffixIcon).length) && !iconOnly" name="suffixIcon"> |
| 31 | <component :is="suffixIcon" v-if="typeof suffixIcon === 'object'"></component> |
| 32 | <span v-if="typeof suffixIcon === 'string'" :class="`am-icon-${suffixIcon}`"></span> |
| 33 | </slot> |
| 34 | </el-button> |
| 35 | </template> |
| 36 | |
| 37 | <script setup> |
| 38 | import { computed } from 'vue' |
| 39 | |
| 40 | /** |
| 41 | * Component Props |
| 42 | */ |
| 43 | const props = defineProps({ |
| 44 | customClass: { |
| 45 | type: String, |
| 46 | default: '', |
| 47 | }, |
| 48 | iconOnly: { |
| 49 | type: Boolean, |
| 50 | default: false, |
| 51 | }, |
| 52 | // default / medium / small / mini / micro |
| 53 | btnSize: { |
| 54 | type: String, |
| 55 | default: 'default', |
| 56 | validator(value) { |
| 57 | return ['default', 'medium', 'small', 'mini', 'micro'].includes(value) |
| 58 | }, |
| 59 | }, |
| 60 | size: { |
| 61 | // large / default / medium /small |
| 62 | type: String, |
| 63 | default: 'default', |
| 64 | }, |
| 65 | type: { |
| 66 | // primary / success / warning / danger / info / text |
| 67 | type: String, |
| 68 | default: '', |
| 69 | }, |
| 70 | nativeType: { |
| 71 | // button / submit / reset |
| 72 | type: String, |
| 73 | default: 'button', |
| 74 | }, |
| 75 | plain: { |
| 76 | type: Boolean, |
| 77 | default: false, |
| 78 | }, |
| 79 | round: { |
| 80 | type: Boolean, |
| 81 | default: false, |
| 82 | }, |
| 83 | circle: { |
| 84 | type: Boolean, |
| 85 | default: false, |
| 86 | }, |
| 87 | loading: { |
| 88 | type: Boolean, |
| 89 | default: false, |
| 90 | }, |
| 91 | disabled: { |
| 92 | type: Boolean, |
| 93 | default: false, |
| 94 | }, |
| 95 | autofocus: { |
| 96 | type: Boolean, |
| 97 | default: false, |
| 98 | }, |
| 99 | autoInsertSpace: { |
| 100 | type: Boolean, |
| 101 | }, |
| 102 | icon: { |
| 103 | type: [String, Object, Function], |
| 104 | default: '', |
| 105 | }, |
| 106 | loadingIcon: { |
| 107 | type: [String, Object, Function], |
| 108 | default: '', |
| 109 | }, |
| 110 | prefixIcon: { |
| 111 | type: [String, Object, Function], |
| 112 | default: '', |
| 113 | }, |
| 114 | suffixIcon: { |
| 115 | type: [String, Object, Function], |
| 116 | default: '', |
| 117 | }, |
| 118 | }) |
| 119 | |
| 120 | const isIconClass = computed(() => (props.iconOnly ? `am-adv-button__${props.btnSize}-icon` : '')) |
| 121 | |
| 122 | /** |
| 123 | * Component Emits |
| 124 | * */ |
| 125 | const emits = defineEmits(['click']) |
| 126 | |
| 127 | /** |
| 128 | * Component Event Handlers |
| 129 | */ |
| 130 | const handleClick = (event) => { |
| 131 | emits('click', event) |
| 132 | } |
| 133 | </script> |
| 134 | |
| 135 | <style lang="scss"> |
| 136 | $button: 'am-adv-button__'; |
| 137 | |
| 138 | // Colors |
| 139 | $defaultButtonBackgroundColor: #ffffff; |
| 140 | $defaultButtonTextColor: #1a2c37; |
| 141 | $defaultButtonBorderColor: #e0e2e4; |
| 142 | |
| 143 | #amelia-container { |
| 144 | .am-adv-button { |
| 145 | // Button sizes |
| 146 | // Default |
| 147 | &__default { |
| 148 | } |
| 149 | // Medium |
| 150 | &__medium { |
| 151 | } |
| 152 | // Mini |
| 153 | &__mini { |
| 154 | } |
| 155 | // Micro |
| 156 | &__micro { |
| 157 | height: 24px; |
| 158 | font-size: 16px; |
| 159 | transition: all 0.3s ease-in-out; |
| 160 | |
| 161 | // Only contains icon |
| 162 | &-icon { |
| 163 | width: 24px; |
| 164 | padding: 4px; |
| 165 | |
| 166 | &.is-loading { |
| 167 | width: 48px; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | </style> |
| 174 |