Skip to content

Commit

Permalink
feat: search template (#199)
Browse files Browse the repository at this point in the history
* update breadcrumb to use text instead of an icon

* new search template

* update search js location

Co-authored-by: Nathan Rogan <nathan.rogan@wmca.org.uk>
  • Loading branch information
rolorogan and nathan-rogan authored Jul 5, 2021
1 parent cf0872d commit 0687c44
Show file tree
Hide file tree
Showing 15 changed files with 1,193 additions and 1,560 deletions.
2,467 changes: 941 additions & 1,526 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,63 +59,63 @@
"build:netlify": "npm run build:all --build=netlify"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@babel/standalone": "^7.14.7",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/standalone": "^7.13.11",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@zeplin/cli": "^1.1.12",
"autoprefixer": "^10.2.6",
"@zeplin/cli": "^1.1.6",
"autoprefixer": "^10.2.5",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"browser-sync": "^2.27.4",
"browser-sync": "^2.26.14",
"del": "^6.0.0",
"dompurify": "^2.2.9",
"eslint": "^7.30.0",
"dompurify": "^2.2.7",
"eslint": "^7.22.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-html": "^6.1.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"glob": "^7.1.7",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"glob": "^7.1.6",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^8.0.0",
"gulp-changed": "^4.0.3",
"gulp-autoprefixer": "^7.0.1",
"gulp-changed": "^4.0.2",
"gulp-cheerio": "^1.0.0",
"gulp-clean-css": "^4.3.0",
"gulp-concat": "^2.6.1",
"gulp-data": "^1.3.1",
"gulp-eslint": "^6.0.0",
"gulp-flatten": "^0.4.0",
"gulp-format-html": "^1.2.5",
"gulp-htmlhint": "^4.0.1",
"gulp-htmlhint": "^4.0.0",
"gulp-htmlmin": "^5.0.1",
"gulp-imagemin": "^7.1.0",
"gulp-load-plugins": "^2.0.7",
"gulp-load-plugins": "^2.0.6",
"gulp-merge-json": "^2.1.1",
"gulp-nunjucks-render": "^2.2.3",
"gulp-plumber": "^1.2.1",
"gulp-react-native-stylesheet-css": "^1.4.4",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.1.3",
"gulp-sass": "^5.0.0",
"gulp-replace": "^1.0.0",
"gulp-sass": "^4.1.0",
"gulp-sass-lint": "^1.4.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-svgmin": "^4.0.1",
"gulp-svgstore": "^8.0.0",
"gulp-svgmin": "^3.0.0",
"gulp-svgstore": "^7.0.1",
"gulp-uglify-es": "^2.0.0",
"marked": "^2.1.3",
"node-sass": "^6.0.1",
"npm-check-updates": "^11.8.1",
"marked": "^2.0.1",
"node-sass": "^5.0.0",
"npm-check-updates": "^11.3.0",
"nunjucks": "^3.2.3",
"nunjucks-markdown": "^2.0.1",
"prettier": "^2.3.2",
"sass": "^1.35.1",
"semantic-release": "^17.4.4",
"prettier": "^2.2.1",
"sass": "^1.32.8",
"semantic-release": "^17.4.2",
"webpack-stream": "^6.1.2"
},
"dependencies": {
"iframe-resizer": "^4.3.2",
"iframe-resizer": "^4.3.1",
"path": "^0.12.7"
}
}
2 changes: 1 addition & 1 deletion src/wmcads/components/breadcrumb/_breadcrumb.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ And we show the current page breadcrumb at all times.
{#- Link back to homepage #}
<li class="wmcads-breadcrumb__list-item">
<a href="/" class="wmcads-breadcrumb__link">
<i class="fal fa-home-alt" aria-hidden="true"></i>
Home
</a>
</li>
{#- If pageTitle != same as section, then we can show section breadcrumb #}
Expand Down
4 changes: 2 additions & 2 deletions src/wmcads/components/link/link/_link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

// prevent icon resizing
.wmcads-link__chevron {
flex: 0 0 1rem;
flex: 0 0 1.5rem;
}
}

&__chevron {
width: 1.5rem;
height: 1rem;
height: 1.5rem;
fill: get-color(primary);

&--left {
Expand Down
2 changes: 1 addition & 1 deletion src/wmcads/patterns/search/pagination/_pagination.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{# Imports #}
{% from "../../../components/breadcrumb/_breadcrumb.njk" import wmcadsBreadcrumb %}

<div class="wmcads-pagination">
<div class="wmcads-pagination wmcads-m-t-xl">
<ol class="wmcads-pagination__nav">
{% for i in range(1, params.pageCount + 1) -%}
{% if(i == params.activePage - 1) %}
Expand Down
2 changes: 1 addition & 1 deletion src/wmcads/patterns/search/search-bar/_search-bar.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% macro wmcadsSearchbar(params) %}

<form class="wmcads-search-bar">
<input aria-label="Search" type="text" class="wmcads-search-bar__input wmcads-fe-input" placeholder="Search for tickets, timetables, travel advice">
<input aria-label="Search" type="text" class="wmcads-search-bar__input wmcads-fe-input" placeholder="Site search">
<button class="wmcads-search-bar__btn" types="submit">
<svg><title>Search</title><use xlink:href="#wmcads-general-search" href="#wmcads-general-search"></use></svg>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
classModifiers: "wmcads-hide-mobile"
}) | trim
}}
<p class="wmcads-search-result__date">{{params.date | safe}}</p>
<p class="wmcads-search-result__excerpt">{{params.excerpt | safe}}</p>
</div>

Expand Down
5 changes: 5 additions & 0 deletions src/wmcads/patterns/search/search-result/_search-result.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
}
}

&__date {
margin: 0;
padding-top: $size-xs;
}

&__excerpt {
padding-top: $size-md;
}
Expand Down
3 changes: 3 additions & 0 deletions src/www/assets/json/merged.njk.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
},
{
"name": "Content Two Columns"
},
{
"name": "Search"
}
]
}
Expand Down
1 change: 0 additions & 1 deletion src/www/pages/templates/homepage/homepage.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.homepage {

.what-we-do {
svg {
display: block;
Expand Down
131 changes: 131 additions & 0 deletions src/www/pages/templates/search/index.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{% extends "www/_layouts/template-layout-fullwidth.njk" %}
{% set pageTitle="Search" %} {% set section = "Templates" %}
{# Imports #}
{%- from "wmcads/components/content-tiles/normal/_normal.njk" import wmcadsContentTilesNormal -%}
{% from "wmcads/components/link/link/_link.njk" import wmcadsLink %}
{% from "wmcads/components/inset-text/_inset-text.njk" import wmcadsInsetText %}
{% from "wmcads/components/icon/_icon.njk" import wmcadsIcon %}
{% from "wmcads/components/content-card/_content-card.njk" import wmcadsContentCard %}
{% from "wmcads/components/page-contents/_page-contents.njk" import wmcadsPageContents %}
{% from "wmcads/patterns/search/search-bar/_search-bar.njk" import wmcadsSearchbar %}
{% from "wmcads/patterns/search/search-filter/_search-filter.njk" import wmcadsSearchFilter %}
{% from "wmcads/patterns/search/sort/_sort.njk" import wmcadsSearchSort %}
{% from "wmcads/patterns/search/search-filter/_search-filter.njk" import wmcadsSearchFilter %}
{% from "wmcads/patterns/search/pagination/_pagination.njk" import wmcadsPagination %}
{% from "wmcads/components/breadcrumb/_breadcrumb.njk" import wmcadsBreadcrumb %}
{% from "wmcads/patterns/search/search-result/_search-result.njk" import wmcadsSearchResult %}
{# Set array of tiles #}
{% block content %}

<div class="template-search">
<div class="wmcads-container wmcads-m-b-lg">
<h1 id="wmcads-main-content" class="wmcads-hide-mobile">Search results</h1>
<div class="wmcads-col-1 wmcads-col-md-2-3 wmcads-p-r-xl">
{{wmcadsSearchbar()}}
<div class="wmcads-hide-desktop">
{{wmcadsSearchSort()}}
{{wmcadsSearchFilter(
{
accordion: [{
summaryTitle: "Topic",
options: [
"Tickets", "Transport", "Housing and Land", "Economy and Innovation", "Public Service Reform", "Digital and Culture", "Wellbeing", "Environment"
]
},
{
summaryTitle: "Page type",
options: [
"Services", "News articles", "Other/Everything else", "Campaigns", "People’s stories", "Projects/programmes"
]
},
{
summaryTitle: "Date",
options: [
"Services", "Added in the last week", "Added in the last month", "Added in the last year"
]
}
]}
)}}
</div>
</div>
</div>
<div class="wmcads-container">
<div class="wmcads-grid">
<div class="main wmcads-col-1 wmcads-col-md-2-3 wmcads-m-b-xl wmcads-p-r-lg">
<p>Found <strong>20</strong> matching results</p>
{{wmcadsSearchResult(
{
pageTitle: "HS2 Ltd",
breadcrumbs: ['Home', 'What we do', "HS2", "HS2 Ltd"],
date: "Thursday 23 August 2018",
excerpt: "High Speed Two (HS2) is the new railway that will be the backbone of Britain’s <strong>transport</strong> network. High Speed Two Limited (HS2 Ltd) is the company developing..."
}
)}}
{{wmcadsSearchResult(
{
pageTitle: "Connectivity",
breadcrumbs: ['Home', 'What we do', "HS2", "Connectivity"],
date: "Thursday 23 August 2018",
excerpt: "HS2 will place the West Midlands at the heart of the UK’s <strong>transport</strong> network, with two new stations in the region, the interchange at Solihull and the new Curzon Street..."
}
)}}
{{wmcadsSearchResult(
{
pageTitle: "New transport system will be sprinting for success at Commonwealth Games",
breadcrumbs: ['Home', 'What we do', "HS2", "New transport system will be sprinting for success..."],
date: "Thursday 23 August 2018",
excerpt: "Top athletes are not the only ones aiming to be in peak condition for the 2022 Commonwealth Games in Birmingham – the region’s <strong>transport</strong> system is also..."
}
)}}
{{wmcadsSearchResult(
{
pageTitle: "Our Vision",
breadcrumbs: ['Home', 'What we do', "HS2", "Our Vision"],
date: "Thursday 23 August 2018",
excerpt: "High Speed 2 (HS2) will have a truly transformational impact on the West Midlands. As well as the economic benefits of investment in high speed rail infrastructure..."
}
)}}
{{wmcadsSearchResult(
{
pageTitle: "Network Resilience",
breadcrumbs: ['Home', 'What we do', "HS2", "Network Resilience"],
date: "Thursday 23 August 2018",
excerpt: "We are experiencing an unprecedented level of investment in bringing much needed improvements to the way that people and goods are able to move around the West..."
}
)}}

{{wmcadsPagination({
pageCount: 8,
activePage: 1
})}}
</div>
<aside class="wmcads-col-1 wmcads-col-md-1-3 wmcads-m-b-lg wmcads-hide-mobile">
{{wmcadsSearchSort()}}
{{wmcadsSearchFilter(
{
accordion: [{
summaryTitle: "Topic",
options: [
"Tickets", "Transport", "Housing and Land", "Economy and Innovation", "Public Service Reform", "Digital and Culture", "Wellbeing", "Environment"
]
},
{
summaryTitle: "Page type",
options: [
"Services", "News articles", "Other/Everything else", "Campaigns", "People’s stories", "Projects/programmes"
]
},
{
summaryTitle: "Date",
options: [
"Services", "Added in the last week", "Added in the last month", "Added in the last year"
]
}
]}
)}}

</aside>
</div>
</div>
</div>
{% endblock %}
58 changes: 58 additions & 0 deletions src/www/pages/templates/search/search-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const searchFilterJs = () => {
const showBtn = document.getElementById('show_filter_btn');
const hideBtn = document.getElementById('hide_filter_btn');
const showResults = document.getElementById('show_results_btn');
const searchFilter = document.getElementById('search_filter');

if (searchFilter) {
const filterOptions = searchFilter.querySelectorAll('.wmcads-fe-checkboxes__input');

filterOptions.forEach(option => {
option.addEventListener('change', () => {
if ([...filterOptions].some(input => input.checked)) {
searchFilter.classList.add('wmcads-search-filter--has-inputs-checked');
} else {
searchFilter.classList.remove('wmcads-search-filter--has-inputs-checked');
}
});
});

const showFilter = (show = true) => {
if (show) {
searchFilter.classList.add('wmcads-search-filter--is-open');
searchFilter.setAttribute('aria-expanded', 'true');
} else {
searchFilter.classList.remove('wmcads-search-filter--is-open');
searchFilter.setAttribute('aria-expanded', 'false');
}
};

const clearFilters = () => {
filterOptions.forEach(option => {
option.checked = false; // eslint-disable-line no-param-reassign
});
searchFilter.classList.remove('wmcads-search-filter--has-inputs-checked');
};

showBtn.addEventListener('click', e => {
e.preventDefault();
showFilter();
});

hideBtn.addEventListener('click', e => {
e.preventDefault();
showFilter(false);
});

document.querySelectorAll('.wmcads-search-filter__clear-all').forEach(clearBtn => {
clearBtn.addEventListener('click', e => {
e.preventDefault();
clearFilters();
});
});

showResults.addEventListener('click', () => showFilter(false));
}
};

export default searchFilterJs;
19 changes: 19 additions & 0 deletions src/www/pages/templates/search/search.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.template-search {
.wmcads-p-r-xl {
@media screen and (max-width: $breakpoint-md) {
padding: 0;
}
}

.wmcads-hide-mobile {
@media screen and (max-width: $breakpoint-sm) {
display: none;
}
}

.wmcads-search-sort {
@media screen and (max-width: $breakpoint-sm) {
margin-top: $size-md;
}
}
}
1 change: 1 addition & 0 deletions src/www/pages/templates/templates.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
@import "campaign-one-column/campaign-template"; // Campaign page
@import "content-one-column/content-template"; // Content page
@import "content-two-columns/content-template"; // Content page
@import "search/search"; // Search page
3 changes: 2 additions & 1 deletion src/www/wmcads-templates.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pageContents from './pages/templates/campaign-two-columns/campaign-template';
import search from './pages/templates/search/search-template';

window.addEventListener('DOMContentLoaded', pageContents());
window.addEventListener('DOMContentLoaded', pageContents(), search());

0 comments on commit 0687c44

Please sign in to comment.