-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1049 from nhsuk/update-frontend
install latest version of the frontend library
- Loading branch information
Showing
10 changed files
with
263 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import AccessibleAutoComplete from 'accessible-autocomplete'; | ||
|
||
/** | ||
@typedef autocompleteConfig | ||
@type {Object} | ||
Optional param for NHS.UK functionality | ||
@property {string=} formId ID of form element containing autocomplete. | ||
Required params for accessible-autocomplete | ||
@property {string} inputId ID of the input field. | ||
@property {string} containerId ID of element in which the autocomplete will be rendered in. | ||
@property {function} source Function called on input change | ||
*/ | ||
|
||
/** | ||
* Create an autocomplete. | ||
* @param {autocompleteConfig} config | ||
*/ | ||
export default (config) => { | ||
const { formId, inputId, containerId } = config; | ||
|
||
const form = document.getElementById(formId); | ||
const input = document.getElementById(inputId); | ||
const container = document.getElementById(containerId); | ||
|
||
/** | ||
* Adds event to catch enter presses when the main input is focused and submits the form | ||
*/ | ||
const addFormEvents = () => { | ||
// Attach event to form as the original input element is cloned by autoComplete plugin | ||
form.addEventListener('keyup', ({ key }) => { | ||
// Submit search using current input value if input is focused and enter is pressed | ||
if (key === 'Enter' && document.activeElement.id === inputId) form.submit(); | ||
}); | ||
}; | ||
|
||
const initAutoComplete = () => { | ||
const defaultConfig = { | ||
confirmOnBlur: false, | ||
element: container, | ||
id: inputId, | ||
minLength: 2, | ||
name: input.name, | ||
placeholder: input.placeholder, | ||
}; | ||
|
||
// Remove original search input as it will be replaced by accessibleAutocomplete | ||
input.parentNode.removeChild(input); | ||
|
||
// Initialise accessibleAutocomplete | ||
AccessibleAutoComplete({ | ||
...defaultConfig, | ||
...config, | ||
}); | ||
}; | ||
|
||
// Add autocomplete functionality if required config options exist | ||
if (input && container && config.source) { | ||
initAutoComplete(); | ||
// If form element exists then add events to add standard form functionality | ||
if (form) addFormEvents(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* ========================================================================== | ||
COMPONENTS / #HEADER / #AUTOCOMPLETE | ||
========================================================================== */ | ||
|
||
/** | ||
* 1. IE 10 prefix for flexbox | ||
* 2. Proprietary extension so form field looks the same in Safari | ||
* 3. Custom height and width of form items | ||
* 4. Custom height and width of svg icons | ||
* 5. Custom spacing to position the search icon | ||
* 6. Drop shadow on search suggestions dopdown box, custom spread and blur | ||
* 7. Z-index to bring the dropdown to the front | ||
* 8. No current spacing at 12px so using this value | ||
* 9. Z-index to being search box to the front for focus state style | ||
* 10. Custom padding to stop text jumping on focus | ||
*/ | ||
|
||
.autocomplete-container { | ||
display: inline-block; | ||
z-index: 1; /* [9] */ | ||
|
||
@include mq($until: tablet) { | ||
display: inline; | ||
width: 100%; | ||
} | ||
} | ||
|
||
@include mq($until: tablet) { | ||
/* duplicate of .nhsuk-search__input in _header.scss, for non javascript version */ | ||
.autocomplete__input { | ||
-ms-flex-positive: 2; /* [1] */ | ||
-webkit-appearance: listbox; // sass-lint:disable-line prefixes /* [2] */ | ||
border-bottom: 1px solid $color_nhsuk-grey-3; | ||
border-bottom-left-radius: $nhsuk-border-radius; | ||
border-bottom-right-radius: 0; | ||
border-left: 1px solid $color_nhsuk-grey-3; | ||
border-right: 0; | ||
border-top: 1px solid $color_nhsuk-grey-3; | ||
border-top-left-radius: $nhsuk-border-radius; | ||
border-top-right-radius: 0; | ||
flex-grow: 2; | ||
font-size: inherit; | ||
height: 52px; /* [3] */ | ||
margin: 0; | ||
outline: none; | ||
padding: 0 nhsuk-spacing(3); | ||
width: 100%; /* [3] */ | ||
|
||
&:focus { | ||
border: $nhsuk-focus-width solid $nhsuk-focus-text-color; | ||
box-shadow: 0 0 0 $nhsuk-focus-width $nhsuk-focus-color; | ||
outline: $nhsuk-focus-width solid transparent; | ||
outline-offset: $nhsuk-focus-width; | ||
padding: 0 13px; /* [10] */ | ||
} | ||
} | ||
} | ||
|
||
@include mq($from: tablet) { | ||
/* duplicate of .nhsuk-search__input in _header.scss, for non javascript version */ | ||
.autocomplete__input { | ||
-webkit-appearance: listbox; // sass-lint:disable-line prefixes /* [2] */ | ||
border: 1px solid $color_nhsuk-white; | ||
border-bottom-left-radius: $nhsuk-border-radius; | ||
border-bottom-right-radius: 0; | ||
border-right: 0; | ||
border-top-left-radius: $nhsuk-border-radius; | ||
border-top-right-radius: 0; | ||
font-size: $nhsuk-base-font-size; | ||
height: 40px; /* [3] */ | ||
padding: 0 12px; /* [9] */ | ||
width: 200px; /* [3] */ | ||
|
||
&:focus { | ||
border: 2px solid $nhsuk-focus-text-color; | ||
box-shadow: 0 0 0 $nhsuk-focus-width $nhsuk-focus-color; | ||
outline: $nhsuk-focus-width solid transparent; | ||
outline-offset: $nhsuk-focus-width; | ||
padding: 0 11px; /* [10] */ | ||
} | ||
|
||
&::placeholder { | ||
color: $color_nhsuk-grey-2; | ||
font-size: $nhsuk-base-font-size; | ||
} | ||
} | ||
} | ||
|
||
@include mq($from: desktop) { | ||
.autocomplete__input { | ||
width: 235px; | ||
} | ||
} | ||
|
||
.autocomplete__menu { | ||
// sass-lint:disable-block no-vendor-prefixes, no-color-literals | ||
-moz-box-shadow: 0 3px 5px rgba($nhsuk-box-shadow-color, $alpha-transparency-50); /* [6] */ | ||
-webkit-box-shadow: 0 3px 5px rgba($nhsuk-box-shadow-color, $alpha-transparency-50); /* [6] */ | ||
background-color: $color_nhsuk-white; | ||
border-bottom: 1px solid $color_nhsuk-grey-4; | ||
border-bottom-left-radius: $nhsuk-border-radius; | ||
border-bottom-right-radius: $nhsuk-border-radius; | ||
border-left: 1px solid $color_nhsuk-grey-4; | ||
border-right: 1px solid $color_nhsuk-grey-4; | ||
box-shadow: 0 0 ($nhsuk-box-shadow-spread - 1) 0 rgba($nhsuk-box-shadow-color, $alpha-transparency-50); /* [6] */ | ||
list-style: none; | ||
margin-top: 2px; | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
padding: nhsuk-spacing(3); | ||
position: absolute; | ||
top: 100%; | ||
width: 100%; | ||
z-index: 1; /* [7] */ | ||
|
||
@include mq($until: tablet) { | ||
border: 0; | ||
box-shadow: none; | ||
margin: 0; | ||
padding-left: 0; | ||
padding-right: 0; | ||
position: relative; | ||
} | ||
} | ||
|
||
.autocomplete__menu--visible { | ||
display: block; | ||
} | ||
|
||
.autocomplete__menu--hidden { | ||
display: none; | ||
} | ||
|
||
.autocomplete__option { | ||
border-bottom: 1px solid $color_nhsuk-grey-5; | ||
color: $color_nhsuk-blue; | ||
cursor: pointer; | ||
font-size: $nhsuk-base-font-size; | ||
padding-bottom: 12px; /* [8] */ | ||
text-align: left; | ||
text-decoration: underline; | ||
|
||
.nhsuk-icon__search { | ||
fill: $color_nhsuk-grey-3; | ||
float: left; | ||
height: 22px; /* [4] */ | ||
margin: 2px 4px 0 0; /* [5] */ | ||
width: 22px; /* [4] */ | ||
} | ||
|
||
&:hover, | ||
&:active { | ||
text-decoration: none; | ||
} | ||
|
||
&:focus { | ||
outline: 1px solid transparent; | ||
text-decoration: none; | ||
|
||
a { | ||
@include nhsuk-focused-text(); | ||
} | ||
} | ||
|
||
@include mq($from: tablet) { | ||
&:last-child { | ||
border-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
.autocomplete__option--no-results { | ||
border-bottom: 0; | ||
color: $color_nhsuk-black; | ||
font-size: $nhsuk-base-font-size; | ||
line-height: $nhsuk-base-line-height; | ||
margin: 0; | ||
padding: 0; | ||
text-align: left; | ||
text-decoration: none; | ||
|
||
@include mq($until: tablet) { | ||
padding: nhsuk-spacing(3) 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters