blob: ac8f9bfb1187b6bb745505831a0187986a7c7455 [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';
42
SurenNeware71724be2020-06-01 15:31:00 +053043export default {
44 name: 'Search',
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050045 components: { IconSearch, IconClose },
SurenNeware71724be2020-06-01 15:31:00 +053046 props: {
47 placeholder: {
48 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050049 default: function () {
SurenNeware71724be2020-06-01 15:31:00 +053050 return this.$t('global.form.search');
Derick Montague602e98a2020-10-21 16:20:00 -050051 },
52 },
SurenNeware71724be2020-06-01 15:31:00 +053053 },
54 data() {
55 return {
Derick Montague602e98a2020-10-21 16:20:00 -050056 filter: null,
SurenNeware71724be2020-06-01 15:31:00 +053057 };
58 },
59 methods: {
60 onChangeInput() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053061 this.$emit('change-search', this.filter);
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050062 },
63 onClearSearch() {
64 this.filter = '';
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053065 this.$emit('clear-search');
Dixsie Wolmers9b22b492020-09-07 21:26:06 -050066 this.$refs.searchInput.focus();
Derick Montague602e98a2020-10-21 16:20:00 -050067 },
68 },
SurenNeware71724be2020-06-01 15:31:00 +053069};
70</script>
71
72<style lang="scss" scoped>
Yoshie Muranaka129d79b2020-07-02 16:04:18 -070073.search-input {
SurenNeware71724be2020-06-01 15:31:00 +053074 padding-left: ($spacer * 2);
75}
76.search-icon {
77 position: absolute;
78 left: 10px;
79 top: 12px;
80 z-index: 4;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070081 stroke: gray('400');
SurenNeware71724be2020-06-01 15:31:00 +053082}
SurenNeware71724be2020-06-01 15:31:00 +053083</style>