blob: 5c51678c99d97ff180c3d077952681c4627d7500 [file] [log] [blame]
SurenNeware71724be2020-06-01 15:31:00 +05301<template>
2 <div class="search-global">
3 <b-form-group
4 :label="$t('global.form.search')"
Yoshie Muranaka129d79b2020-07-02 16:04:18 -07005 :label-for="`searchInput-${_uid}`"
SurenNeware787635a2020-11-24 22:42:42 +05306 label-class="invisible"
SurenNeware71724be2020-06-01 15:31:00 +05307 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 Muranaka129d79b2020-07-02 16:04:18 -070014 :id="`searchInput-${_uid}`"
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050015 ref="searchInput"
SurenNeware71724be2020-06-01 15:31:00 +053016 v-model="filter"
Yoshie Muranaka129d79b2020-07-02 16:04:18 -070017 class="search-input"
SurenNeware71724be2020-06-01 15:31:00 +053018 type="text"
SurenNeware787635a2020-11-24 22:42:42 +053019 :aria-label="$t('global.form.search')"
SurenNeware71724be2020-06-01 15:31:00 +053020 :placeholder="placeholder"
21 @input="onChangeInput"
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050022 >
23 </b-form-input>
24 <b-button
25 v-if="filter"
26 variant="link"
Dixsie Wolmers30f11f82020-11-10 16:07:56 -060027 class="btn-icon-only input-action-btn"
Dixsie Wolmers30f11f82020-11-10 16:07:56 -060028 :title="$t('global.ariaLabel.clearSearch')"
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050029 @click="onClearSearch"
30 >
Dixsie Wolmers30f11f82020-11-10 16:07:56 -060031 <icon-close />
SurenNeware6e2cb972020-12-24 20:58:16 +053032 <span class="sr-only">{{ $t('global.ariaLabel.clearSearch') }}</span>
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050033 </b-button>
SurenNeware71724be2020-06-01 15:31:00 +053034 </b-input-group>
35 </b-form-group>
36 </div>
37</template>
38
39<script>
40import IconSearch from '@carbon/icons-vue/es/search/16';
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050041import IconClose from '@carbon/icons-vue/es/close/20';
Ed Tanousdbd37e02024-03-23 14:56:34 -070042import { useI18n } from 'vue-i18n';
43import i18n from '@/i18n';
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050044
SurenNeware71724be2020-06-01 15:31:00 +053045export default {
46 name: 'Search',
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050047 components: { IconSearch, IconClose },
SurenNeware71724be2020-06-01 15:31:00 +053048 props: {
49 placeholder: {
50 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050051 default: function () {
Ed Tanousdbd37e02024-03-23 14:56:34 -070052 return i18n.global.t('global.form.search');
Derick Montague602e98a2020-10-21 16:20:00 -050053 },
54 },
SurenNeware71724be2020-06-01 15:31:00 +053055 },
56 data() {
57 return {
Ed Tanousdbd37e02024-03-23 14:56:34 -070058 $t: useI18n().t,
Derick Montague602e98a2020-10-21 16:20:00 -050059 filter: null,
SurenNeware71724be2020-06-01 15:31:00 +053060 };
61 },
62 methods: {
63 onChangeInput() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053064 this.$emit('change-search', this.filter);
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050065 },
66 onClearSearch() {
67 this.filter = '';
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053068 this.$emit('clear-search');
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050069 this.$refs.searchInput.focus();
Derick Montague602e98a2020-10-21 16:20:00 -050070 },
71 },
SurenNeware71724be2020-06-01 15:31:00 +053072};
73</script>
74
75<style lang="scss" scoped>
Ed Tanous9c729792024-03-23 14:56:34 -070076@import '@/assets/styles/bmc/helpers/_index.scss';
77@import '@/assets/styles/bootstrap/_helpers.scss';
78
Yoshie Muranaka129d79b2020-07-02 16:04:18 -070079.search-input {
SurenNeware71724be2020-06-01 15:31:00 +053080 padding-left: ($spacer * 2);
81}
82.search-icon {
83 position: absolute;
84 left: 10px;
85 top: 12px;
86 z-index: 4;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070087 stroke: gray('400');
SurenNeware71724be2020-06-01 15:31:00 +053088}
SurenNeware71724be2020-06-01 15:31:00 +053089</style>