diff --git a/app/assets/javascript/native-header.js b/app/assets/javascript/native-header.js new file mode 100644 index 0000000..1a60273 --- /dev/null +++ b/app/assets/javascript/native-header.js @@ -0,0 +1,16 @@ +class NativeHeader { + static moduleName = 'app-native-header' + + constructor($root) { + this.$root = $root + window.addEventListener('scroll', this.onScroll.bind(this), { passive: true }) + } + + onScroll() { + this.$root.classList.toggle('stuck', window.scrollY > 0) + } +} + +document.querySelectorAll(`[data-module="${NativeHeader.moduleName}"]`).forEach(($root) => { + new NativeHeader($root) +}) diff --git a/app/assets/sass/main.scss b/app/assets/sass/main.scss index 73a44a4..30ba927 100755 --- a/app/assets/sass/main.scss +++ b/app/assets/sass/main.scss @@ -4,4 +4,7 @@ $nhsuk-assets-path: "/nhsuk-frontend/assets/"; @import "nhsuk-frontend/dist/nhsuk"; @import "nhsapp-frontend/dist/nhsapp"; +// Add styles for components which mock the native app +@import "native-header"; + // Add your custom CSS/Sass styles below. diff --git a/app/assets/sass/native-header.scss b/app/assets/sass/native-header.scss new file mode 100644 index 0000000..088f0eb --- /dev/null +++ b/app/assets/sass/native-header.scss @@ -0,0 +1,58 @@ + +//// +/// Mocks up the fixed navigation header shown in the NHS App native wrapper, +/// allowing prototype screens to be previewed in context. +/// +/// @group components/native-header +//// + +.app-native-header { + -webkit-tap-highlight-color: transparent; + background-color: $nhsuk-body-background-colour; + padding: nhsuk-spacing(2) 0; + position: sticky; + top: 0; + transition: background-color 0.2s ease; + width: 100%; + z-index: 1; + + &.stuck { + background-color: nhsuk-tint($nhsuk-body-background-colour, 60%); + border-bottom: $nhsuk-border-width-form-element solid rgba($nhsuk-text-colour, 0.1); + } +} + +.app-native-header__inner { + align-items: center; + display: flex; + justify-content: space-between; +} + +.app-native-header__help-link { + @include nhsuk-font-size(16); + + border: $nhsuk-border-width-form-element solid $nhsuk-border-colour; + border-radius: nhsuk-spacing(2); + color: $nhsuk-link-colour; + display: block; + font-weight: $nhsuk-font-weight-bold; + padding: nhsuk-spacing(1) nhsuk-spacing(2); + text-decoration: none; + + &:hover, + &:visited { + color: $nhsuk-link-colour; + } + + &:active { + opacity: 0.5; + } +} + +.app-native-header__logo { + padding: nhsuk-spacing(2) 0; + + &:active { + opacity: 0.5; + } +} \ No newline at end of file diff --git a/app/views/_includes/native-header.html b/app/views/_includes/native-header.html new file mode 100644 index 0000000..234ec80 --- /dev/null +++ b/app/views/_includes/native-header.html @@ -0,0 +1,13 @@ +
+
+ + App help +
+
\ No newline at end of file diff --git a/app/views/_includes/web-header.html b/app/views/_includes/web-header.html new file mode 100644 index 0000000..3083aa2 --- /dev/null +++ b/app/views/_includes/web-header.html @@ -0,0 +1,38 @@ +{{ header({ + service: { + text: "App", + href: "/" + }, + account: { + classes: "nhsapp-u-hide-until-tablet", + items: [ + { + text: "App help", + href: "#" + }, + { + text: "Log out", + href: "#" + } + ] + }, + navigation: { + items: [ + { + href: "/", + text: "Home", + current: (section == "Home") + }, + { + href: "/messages", + text: "Messages", + current: (section == "Messages") + }, + { + href: "/profile", + text: "Profile", + current: (section == "Profile") + } + ] + } +}) }} diff --git a/app/views/layout.html b/app/views/layout.html index ed12c1a..1a22562 100755 --- a/app/views/layout.html +++ b/app/views/layout.html @@ -28,44 +28,7 @@ {% endblock %} {% block header %} - {{ header({ - service: { - text: "App", - href: "/" - }, - account: { - classes: "nhsapp-u-hide-until-tablet", - items: [ - { - text: "App help", - href: "#" - }, - { - text: "Log out", - href: "#" - } - ] - }, - navigation: { - items: [ - { - href: "/", - text: "Home", - current: (section == "Home") - }, - { - href: "/messages", - text: "Messages", - current: (section == "Messages") - }, - { - href: "/profile", - text: "Profile", - current: (section == "Profile") - } - ] - } - }) }} + {% include "_includes/" + ("web" if data.web and data.web !== 'no' else "native") + "-header.html" %} {% endblock %} {% block footer %} @@ -88,5 +51,6 @@ {% block bodyEnd %} {{ super() }} + {% block pageScripts %}{% endblock %} {% endblock %}