Skip to content

Commit

Permalink
Merge pull request #4 from EnergySage/ced-1940-nav-search-bar
Browse files Browse the repository at this point in the history
feat: nav bar with search bar
  • Loading branch information
hroth1994 authored Oct 31, 2024
2 parents 5eac775 + 2c73ecd commit 18c9ef8
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 5 deletions.
1 change: 1 addition & 0 deletions e2e/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = async () => {
'/molecules/es-progress',
'/molecules/es-progress-circle',
'/molecules/es-rating',
'/molecules/es-search-bar',
'/molecules/es-slider',
'/molecules/es-support',
'/molecules/es-tabs',
Expand Down
17 changes: 16 additions & 1 deletion es-bs-base/scss/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
}
}

.nav-button {
&:hover {
background: variables.$blue-50 !important;
}

&:focus,
&.focus {
border-color: variables.$blue-500;
}
}

//
// Tabs
//
Expand Down Expand Up @@ -263,10 +274,14 @@ $nav-hover-delay: 300ms;
}
}

.account-icon {
.account-icon, .search-icon {
fill: variables.$blue-900;
}

.search-open {
fill: variables.$blue-600 !important;
}

// On Desktop a hovers display the dropdowns
@media only screen and (min-width: $desktop-min-width) {
.nav-es-global,
Expand Down
5 changes: 5 additions & 0 deletions es-design-system/components/ds-molecules-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
Radio cards
</ds-link>
</li>
<li>
<ds-link to="/molecules/es-search-bar">
Search bar
</ds-link>
</li>
<li>
<ds-link to="/molecules/es-slider">
Slider
Expand Down
5 changes: 5 additions & 0 deletions es-design-system/components/ds-organisms-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
Nav bar
</ds-link>
</li>
<li>
<ds-link to="/organisms/es-nav-bar-with-search">
Nav bar with search
</ds-link>
</li>
<li>
<ds-link to="/organisms/es-review">
Review
Expand Down
82 changes: 82 additions & 0 deletions es-design-system/layouts/navSearch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<template>
<div>
<es-nav-bar
:account-content="accountContent"
:global-content="globalContent"
show-search>
<template #logo>
<ds-es-logo />
</template>
</es-nav-bar>

<b-navbar
class="d-xl-none mb-100"
type="dark"
variant="primary">
<b-navbar-nav>
<b-nav-item v-b-toggle.sidebar-1>
Menu
</b-nav-item>
</b-navbar-nav>
</b-navbar>
<b-sidebar
id="sidebar-1"
class="d-xl-none"
:title="`ES DS ${$config.version}`"
shadow>
<ds-link-list class="mx-100" />
</b-sidebar>
<div class="d-flex justify-content-center">
<div class="ds-side-nav d-none d-xl-block flex-shrink-0 p-100">
<ds-link-list />
</div>
<b-container class="pt-xl-100 mx-0">
<b-row class="mb-100">
<b-col cols="12">
<es-breadcrumbs :items="breadcrumbs" />
</b-col>
</b-row>
<b-row>
<b-col
cols="12">
<Nuxt />
</b-col>
</b-row>
</b-container>
</div>
</div>
</template>

<script>
import { getEsNavBarAccountContent, getEsNavBarGlobalContent } from '@energysage/es-vue-base';
/* eslint-disable vue/multi-word-component-names, vue/component-definition-name-casing */
export default {
name: 'NavSearchLayout',
computed: {
accountContent() {
return getEsNavBarAccountContent();
},
breadcrumbs() {
const paths = this.$route.path.split('/');
// Set removes dupes from path
return [...new Set(paths)].map((path) => {
let text = 'Home';
// Convert to CamelCase to be inline with component naming
if (path) {
text = path.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
text = text[0].toUpperCase() + text.slice(1);
}
return {
text,
to: `/${path}`,
};
});
},
globalContent() {
return getEsNavBarGlobalContent();
},
},
};
</script>
122 changes: 122 additions & 0 deletions es-design-system/pages/molecules/es-search-bar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<template>
<div>
<h1 class="mb-500">
Search bar
</h1>
<h2>
Basic example
</h2>
<es-search-bar class="my-500" />
<h2>
Example with open/close functionality
</h2>
<es-search-bar
v-if="showSearchBar"
class="my-500">
<template #close>
<es-button
class="position-absolute nav-button mb-3"
aria-label="Close search bar"
style="right: 0"
variant="link"
@click="toggleSearchBar()">
<icon-x
width="30px"
height="30px" />
</es-button>
</template>
</es-search-bar>
<es-button
v-else
variant="link"
aria-label="Open search bar"
class="nav-button nav-link icon-toggle d-flex flex-nowrap my-500 mx-auto"
@click="toggleSearchBar()">
<icon-search
class="align-self-center search-icon"
width="20px"
height="20px" />
</es-button>

<div class="my-500">
<h2>
EsSearchBar slots
</h2>
<ds-prop-table
:rows="slotTableRows"
:widths="slotTableWidths" />
</div>

<div class="my-500">
<h2>
EsSearchBar props
</h2>
<ds-prop-table
:rows="propTableRows"
:widths="propTableWidths" />
</div>

<ds-doc-source
:comp-code="compCode"
comp-source="es-vue-base/src/lib-components/EsSearchBar.vue"
:doc-code="docCode"
doc-source="es-design-system/pages/molecules/es-search-bar.vue" />
</div>
</template>

<script>
export default {
name: 'EsSearchBarDocs',
data() {
return {
compCode: '',
docCode: '',
showSearchBar: false,
propTableRows: [
[
'buttonText',
'Search',
'Text to display on the submit button.',
],
[
'placeholder',
'Try "best solar panels"',
'Placeholder text to display in the search input.',
],
],
propTableWidths: {
md: ['4', '2', '6'],
lg: ['3', '4', '5'],
},
slotTableRows: [
[
'close',
'n/a',
'Slot for a close button or other content to be displayed to the right of the search bar.',
],
],
slotTableWidths: {
md: ['4', '3', '5'],
lg: ['3', '4', '5'],
},
};
},
async created() {
if (this.$prism) {
/* eslint-disable import/no-webpack-loader-syntax, import/no-self-import */
const docSource = await import('!raw-loader!./es-search-bar.vue');
const compSource = await import('!raw-loader!@energysage/es-vue-base/src/lib-components/EsSearchBar.vue');
/* eslint-enable import/no-webpack-loader-syntax, import/no-self-import */
this.docCode = this.$prism.normalizeCode(docSource.default);
this.compCode = this.$prism.normalizeCode(compSource.default);
this.$prism.highlight(this);
}
},
methods: {
toggleSearchBar() {
this.showSearchBar = !this.showSearchBar;
},
},
};
</script>
71 changes: 71 additions & 0 deletions es-design-system/pages/organisms/es-nav-bar-with-search.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<template>
<div>
<h1>
EsNavBarWithSearch
</h1>
<p>
The nav bar is a specialized component intended for use outside the normal content
container. See above.
</p>

<p
v-for="index in 10"
:key="index"
class="my-800">
Sample content to increase page length; for testing the sticky nav bar.
</p>

<!-- print out EsNavBar's mounted() script here so the rip-the-nav utility can access it -->
<!-- eslint-disable vue/no-v-html -->
<pre
class="d-none"
v-html="navScriptSource" />
<!-- eslint-enable vue/no-v-html -->

<ds-doc-source
:comp-code="compCode"
comp-source="es-vue-base/src/lib-components/EsNavBar.vue"
:doc-code="docCode"
doc-source="es-design-system/pages/organisms/es-nav-bar.vue" />
</div>
</template>

<script>
export default {
name: 'EsNavBarWithSearchDocs',
// use a custom layout so the nav can be full-width at the top of the page
layout: 'navSearch',
async asyncData() {
/* eslint-disable import/no-webpack-loader-syntax, import/no-self-import */
const compSource = await import('!raw-loader!@energysage/es-vue-base/src/lib-components/EsNavBar.vue');
/* eslint-enable import/no-webpack-loader-syntax, import/no-self-import */
// retrieve EsNavBar's mounted() script here so the rip-the-nav utility can access it
const compSourceText = compSource.default;
const scriptRegex = /\/\/ CUSTOM GLOBAL-NAV SCRIPT STARTS([\s\S]+)\/\/ CUSTOM GLOBAL-NAV SCRIPT ENDS/;
const navScriptSource = compSourceText.match(scriptRegex)[0];
return {
navScriptSource,
};
},
data() {
return {
compCode: '',
docCode: '',
};
},
async created() {
if (this.$prism) {
/* eslint-disable import/no-webpack-loader-syntax, import/no-self-import */
const docSource = await import('!raw-loader!./es-nav-bar.vue');
const compSource = await import('!raw-loader!@energysage/es-vue-base/src/lib-components/EsNavBar.vue');
/* eslint-enable import/no-webpack-loader-syntax, import/no-self-import */
this.docCode = this.$prism.normalizeCode(docSource.default);
this.compCode = this.$prism.normalizeCode(compSource.default);
this.$prism.highlight(this);
}
},
};
</script>
Loading

0 comments on commit 18c9ef8

Please sign in to comment.