SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 1 | <template> |
| 2 | <div class="search-global"> |
| 3 | <b-form-group |
| 4 | :label="$t('global.form.search')" |
Yoshie Muranaka | 129d79b | 2020-07-02 16:04:18 -0700 | [diff] [blame] | 5 | :label-for="`searchInput-${_uid}`" |
SurenNeware | 787635a | 2020-11-24 22:42:42 +0530 | [diff] [blame] | 6 | label-class="invisible" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 7 | class="mb-2" |
| 8 | > |
| 9 | <b-input-group size="md" class="align-items-center"> |
| 10 | <b-input-group-prepend> |
| 11 | <icon-search class="search-icon" /> |
| 12 | </b-input-group-prepend> |
| 13 | <b-form-input |
Yoshie Muranaka | 129d79b | 2020-07-02 16:04:18 -0700 | [diff] [blame] | 14 | :id="`searchInput-${_uid}`" |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 15 | ref="searchInput" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 16 | v-model="filter" |
Yoshie Muranaka | 129d79b | 2020-07-02 16:04:18 -0700 | [diff] [blame] | 17 | class="search-input" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 18 | type="text" |
SurenNeware | 787635a | 2020-11-24 22:42:42 +0530 | [diff] [blame] | 19 | :aria-label="$t('global.form.search')" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 20 | :placeholder="placeholder" |
| 21 | @input="onChangeInput" |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 22 | > |
| 23 | </b-form-input> |
| 24 | <b-button |
| 25 | v-if="filter" |
| 26 | variant="link" |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 27 | class="btn-icon-only input-action-btn" |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 28 | :title="$t('global.ariaLabel.clearSearch')" |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 29 | @click="onClearSearch" |
| 30 | > |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 31 | <icon-close /> |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 32 | <span class="sr-only">{{ $t('global.ariaLabel.clearSearch') }}</span> |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 33 | </b-button> |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 34 | </b-input-group> |
| 35 | </b-form-group> |
| 36 | </div> |
| 37 | </template> |
| 38 | |
| 39 | <script> |
| 40 | import IconSearch from '@carbon/icons-vue/es/search/16'; |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 41 | import IconClose from '@carbon/icons-vue/es/close/20'; |
Ed Tanous | dbd37e0 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 42 | import { useI18n } from 'vue-i18n'; |
| 43 | import i18n from '@/i18n'; |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 44 | |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 45 | export default { |
| 46 | name: 'Search', |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 47 | components: { IconSearch, IconClose }, |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 48 | props: { |
| 49 | placeholder: { |
| 50 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 51 | default: function () { |
Ed Tanous | dbd37e0 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 52 | return i18n.global.t('global.form.search'); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 53 | }, |
| 54 | }, |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 55 | }, |
| 56 | data() { |
| 57 | return { |
Ed Tanous | dbd37e0 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 58 | $t: useI18n().t, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 59 | filter: null, |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 60 | }; |
| 61 | }, |
| 62 | methods: { |
| 63 | onChangeInput() { |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 64 | this.$emit('change-search', this.filter); |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 65 | }, |
| 66 | onClearSearch() { |
| 67 | this.filter = ''; |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 68 | this.$emit('clear-search'); |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 69 | this.$refs.searchInput.focus(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 70 | }, |
| 71 | }, |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 72 | }; |
| 73 | </script> |
| 74 | |
| 75 | <style lang="scss" scoped> |
Ed Tanous | 9c72979 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 76 | @import '@/assets/styles/bmc/helpers/_index.scss'; |
| 77 | @import '@/assets/styles/bootstrap/_helpers.scss'; |
| 78 | |
Yoshie Muranaka | 129d79b | 2020-07-02 16:04:18 -0700 | [diff] [blame] | 79 | .search-input { |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 80 | padding-left: ($spacer * 2); |
| 81 | } |
| 82 | .search-icon { |
| 83 | position: absolute; |
| 84 | left: 10px; |
| 85 | top: 12px; |
| 86 | z-index: 4; |
Yoshie Muranaka | 01da818 | 2020-07-08 15:46:43 -0700 | [diff] [blame] | 87 | stroke: gray('400'); |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 88 | } |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 89 | </style> |