Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add search bar to nav bar #1533

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
9 changes: 8 additions & 1 deletion es-design-system/layouts/nav.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<template>
<div>
<es-nav-bar
v-model="searchText"
:account-content="accountContent"
:global-content="globalContent">
:global-content="globalContent"
show-search>
<template #logo>
<ds-es-logo />
</template>
Expand Down Expand Up @@ -52,6 +54,11 @@ import { getEsNavBarAccountContent, getEsNavBarGlobalContent } from '@energysage
/* eslint-disable vue/multi-word-component-names, vue/component-definition-name-casing */
export default {
name: 'NavLayout',
data() {
return {
searchText: '',
};
},
computed: {
accountContent() {
return getEsNavBarAccountContent();
Expand Down
52 changes: 51 additions & 1 deletion es-vue-base/src/lib-components/EsNavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,48 @@
<slot name="logo" />
</template>
</es-nav-bar-top-level-menu>
<div
v-if="showSearch"
class="nav-item d-none d-lg-block pt-100">
<es-button
nathanielwarner marked this conversation as resolved.
Show resolved Hide resolved
variant="link"
class="nav-link dropdown-toggle d-none d-lg-flex flex-nowrap py-100"
@click="toggleSearchBar()">
<icon-search
class="align-self-center account-icon"
width="20px"
height="20px" />
</es-button>
</div>
<!-- desktop account menu -->
<es-nav-bar-account-menu
:auth-items="accountContent.loggedIn.items"
class="d-none d-lg-block pt-100"
:logged-out="accountContent.loggedOut" />
</b-container>
<!-- mobile+desktop product menus -->
<b-container class="d-flex flex-lg-nowrap justify-content-lg-end product-menu">
<b-container v-if="searchBarOpen">
<div class="row w-100">
<es-nav-bar-search-bar
v-bind="$attrs"
v-on="$listeners">
<template #close>
<es-button
class="position-absolute"
style="right: 0"
variant="link"
@click="toggleSearchBar()">
nathanielwarner marked this conversation as resolved.
Show resolved Hide resolved
<icon-x
width="30px"
height="30px" />
</es-button>
</template>
</es-nav-bar-search-bar>
</div>
</b-container>
<b-container
v-else
class="d-flex flex-lg-nowrap justify-content-lg-end product-menu">
<div class="row">
<es-nav-bar-product-menu
v-for="product in globalContent.products"
Expand Down Expand Up @@ -225,6 +259,7 @@ import EsNavBarAccountMenu from './EsNavBarAccountMenu.vue';
import EsNavBarLink from './EsNavBarLink.vue';
import EsNavBarProductMenu from './EsNavBarProductMenu.vue';
import EsNavBarTopLevelMenu from './EsNavBarTopLevelMenu.vue';
import EsNavBarSearchBar from './EsNavBarSearchBar.vue';

export default {
name: 'EsNavBar',
Expand All @@ -234,17 +269,27 @@ export default {
EsNavBarLink,
EsNavBarProductMenu,
EsNavBarTopLevelMenu,
EsNavBarSearchBar,
},
props: {
accountContent: {
type: Object,
required: true,
},
showSearch: {
type: Boolean,
default: false,
},
globalContent: {
type: Object,
required: true,
},
},
data() {
return {
searchBarOpen: false,
};
},
mounted() {
// CUSTOM GLOBAL-NAV SCRIPT STARTS

Expand Down Expand Up @@ -403,5 +448,10 @@ export default {

// CUSTOM GLOBAL-NAV SCRIPT ENDS
},
methods: {
toggleSearchBar() {
this.searchBarOpen = !this.searchBarOpen;
},
},
};
</script>
38 changes: 38 additions & 0 deletions es-vue-base/src/lib-components/EsNavBarSearchBar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div class="align-items-center w-100 d-flex justify-content-center position-relative">
<div class="d-flex align-items-center mx-auto justify-content-center w-100">
<es-form-input
nathanielwarner marked this conversation as resolved.
Show resolved Hide resolved
id="searchBar"
class="mt-3 w-50"
v-bind="$attrs"
label-sr-only
:placeholder="label"
v-on="$listeners">
nathanielwarner marked this conversation as resolved.
Show resolved Hide resolved
<template #prefixIcon>
<icon-search />
</template>
</es-form-input>
<es-button class="ml-50">
nathanielwarner marked this conversation as resolved.
Show resolved Hide resolved
{{ buttonText }}
</es-button>
</div>
<slot name="close" />
</div>
</template>

<script lang="js">

export default {
name: 'EsNavBarSearchBar',
props: {
label: {
type: String,
default: 'Try "best solar panels"',
},
buttonText: {
type: String,
default: 'Search',
},
},
};
</script>
2 changes: 1 addition & 1 deletion es-vue-base/tests/EsZipCodeForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('EsZipCodeForm', () => {
// Simulate a delay (e.g., 2 seconds)
await new Promise((resolve) => {
setTimeout(() => {
resolve();
resolve();
}, 2000);
});

Expand Down
Loading