-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
projects: add address search, zoom style and autocomplete component
- Loading branch information
Showing
23 changed files
with
1,158 additions
and
322 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
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
33 changes: 33 additions & 0 deletions
33
meinberlin/assets/scss/components_user_facing/_projects_map_info.scss
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,33 @@ | ||
.projects-map-info { | ||
font-size: $font-size-base; | ||
} | ||
|
||
.projects-map-info__wrapper { | ||
margin: 10px; | ||
bottom: 2em; | ||
display: none; | ||
|
||
.alert { | ||
margin: 0; | ||
} | ||
|
||
.container, | ||
.a4-alert__content { | ||
margin: 0; | ||
width: auto; | ||
} | ||
|
||
@media screen and (min-width: $breakpoint-tablet) { | ||
display: block; | ||
} | ||
} | ||
|
||
.projects-map-info--mobile { | ||
@media screen and (min-width: $breakpoint-tablet) { | ||
display: none; | ||
} | ||
|
||
.alert { | ||
margin: 0; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
meinberlin/assets/scss/components_user_facing/_projects_map_search.scss
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,5 @@ | ||
.projects-map-search { | ||
form { | ||
margin-bottom: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Using overflow: hidden (as used in the styleguide) causes position: sticky | ||
// to not work as expected. See https://www.terluinwebdesign.nl/en/blog/position-sticky-not-working-try-overflow-clip-not-overflow-hidden/ | ||
body { | ||
overflow: clip; | ||
} |
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,123 @@ | ||
import React, { useState } from 'react' | ||
import { classNames } from '../helpers' | ||
import useCombobox from './useCombobox' | ||
|
||
/* | ||
* Returns the item at the given index in an array, wrapping around | ||
* if index is out of bounds. | ||
*/ | ||
export const getLoopedIndex = (array, index) => { | ||
const length = array.length | ||
const wrappedIndex = ((index % length) + length) % length | ||
return array[wrappedIndex] | ||
} | ||
|
||
const defaultFilterFn = (choice, text) => choice.name.toLowerCase().includes(text.toLowerCase()) | ||
|
||
/* | ||
Choice formatting looks like: | ||
{ name: 'Swedish', value: 'sv' }, | ||
{ name: 'English', value: 'en' } | ||
Values need to be unique! | ||
*/ | ||
export const AutoComplete = ({ | ||
label, | ||
className, | ||
liClassName, | ||
comboboxClassName, | ||
choices, | ||
hideLabel, | ||
onChangeInput, | ||
filterFn, | ||
placeholder, | ||
before, | ||
after, | ||
...comboboxProps | ||
}) => { | ||
const { | ||
opened, | ||
labelId, | ||
activeItems, | ||
listboxAttrs, | ||
comboboxAttrs, | ||
getChoicesAttr | ||
} = useCombobox({ | ||
choices, | ||
...comboboxProps, | ||
isAutoComplete: true | ||
}) | ||
const [text, setText] = useState('') | ||
|
||
const classes = classNames( | ||
'form-control input__element multi-select__container', | ||
opened && 'multi-select__container--opened', | ||
className | ||
) | ||
const comboboxClasses = classNames( | ||
'form-control multi-select__combobox', | ||
comboboxClassName | ||
) | ||
|
||
const actualFilterFn = filterFn || defaultFilterFn | ||
const filteredChoices = text !== '' ? choices.filter(choice => actualFilterFn(choice, text)) : choices | ||
|
||
const onChangeHandler = (e) => { | ||
setText(e.target.value) | ||
onChangeInput?.(e.target.value) | ||
} | ||
|
||
return ( | ||
<div className="form-group multi-select multi-select--autocomplete"> | ||
<p id={labelId} className={classNames('label', hideLabel && 'aural')}> | ||
{label} | ||
</p> | ||
<div className="multi-select__input-wrapper form-control"> | ||
{before && <div className="multi-select__before">{before}</div>} | ||
{comboboxProps.isMultiple && ( | ||
<div className="multi-select__selected"> | ||
{activeItems.map((choice) => choice.name).join(', ')} | ||
</div> | ||
)} | ||
<input | ||
type="text" | ||
value={text} | ||
onChange={onChangeHandler} | ||
placeholder={placeholder} | ||
className={comboboxClasses} | ||
{...comboboxAttrs} | ||
/> | ||
{after && <div className="multi-select__after">{after}</div>} | ||
</div> | ||
{filteredChoices.length > 0 && ( | ||
<ul className={classes} {...listboxAttrs}> | ||
{ | ||
filteredChoices.map((choice) => { | ||
const { active, focused, ...attrs } = getChoicesAttr(choice) | ||
const liClasses = classNames( | ||
liClassName, | ||
'multi-select__option', | ||
active && 'multi-select__option--active', | ||
focused && 'multi-select__option--focus' | ||
) | ||
|
||
return ( | ||
// No keyboard event is needed here. Keyboard management happens | ||
// in the combobox element, where the focus is kept at all times. | ||
// see https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ | ||
// eslint-disable-next-line jsx-a11y/click-events-have-key-events | ||
<li | ||
key={choice.value} | ||
className={liClasses} | ||
{...attrs} | ||
> | ||
<span>{choice.name}</span> | ||
{active && <i className="bicon bicon-check" aria-hidden="true" />} | ||
</li> | ||
) | ||
}) | ||
} | ||
</ul> | ||
)} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.