Skip to content

Commit c3eaf88

Browse files
committed
initial autosuggest impl using downshift
1 parent 32d5b0d commit c3eaf88

File tree

19 files changed

+1412
-1300
lines changed

19 files changed

+1412
-1300
lines changed

config/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import fs from 'fs';
33
import autoprefixer from 'autoprefixer';
4-
import commonjs from 'rollup-plugin-commonjs';
4+
import commonjs from '@rollup/plugin-commonjs';
55
import { nodeResolve } from '@rollup/plugin-node-resolve';
66
import postcss from 'rollup-plugin-postcss';
77
import babel from 'rollup-plugin-babel';
@@ -17,6 +17,7 @@ const globals = {
1717
'react-dom': 'ReactDOM',
1818
classnames: 'cx',
1919
'prop-types': 'PropTypes',
20+
'react-is': 'react-is',
2021
i18next: 'i18next',
2122
'react-autosuggest': 'Autosuggest',
2223
'react-sortablejs': 'reactSortablejs',

digitransit-component/packages/digitransit-component-autosuggest-panel/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@digitransit-component/digitransit-component-autosuggest-panel",
3-
"version": "7.0.4",
3+
"version": "8.0.0",
44
"description": "digitransit-component autosuggest-panel module",
55
"main": "index.js",
66
"files": [
@@ -28,17 +28,16 @@
2828
"author": "Digitransit Authors",
2929
"license": "(AGPL-3.0 OR EUPL-1.2)",
3030
"peerDependencies": {
31-
"@digitransit-component/digitransit-component-autosuggest": "^6.0.4",
31+
"@digitransit-component/digitransit-component-autosuggest": "^7.0.0",
3232
"@digitransit-component/digitransit-component-icon": "^1.2.0",
3333
"@hsl-fi/sass": "^0.2.0",
3434
"classnames": "2.5.1",
35+
"downshift": "9.0.10",
3536
"i18next": "^22.5.1",
3637
"lodash": "4.17.21",
3738
"lodash-es": "4.17.21",
3839
"prop-types": "^15.8.1",
3940
"react": "^16.13.0",
40-
"react-autosuggest": "^10.0.0",
41-
"react-autowhatever": "10.2.1",
4241
"react-i18next": "^12.3.1",
4342
"react-sortablejs": "2.0.11"
4443
}

digitransit-component/packages/digitransit-component-autosuggest/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@digitransit-component/digitransit-component-autosuggest",
3-
"version": "6.0.4",
3+
"version": "7.0.0",
44
"description": "digitransit-component autosuggest module",
55
"main": "index.js",
66
"files": [
@@ -40,13 +40,13 @@
4040
"@digitransit-component/digitransit-component-suggestion-item": "^2.3.1",
4141
"@hsl-fi/sass": "^0.2.0",
4242
"classnames": "2.5.1",
43+
"downshift": "9.0.10",
4344
"i18next": "^22.5.1",
4445
"lodash": "4.17.21",
4546
"lodash-es": "4.17.21",
4647
"luxon": "^3.6.1",
4748
"prop-types": "^15.8.1",
4849
"react": "^16.13.0",
49-
"react-autosuggest": "^10.0.0",
5050
"react-i18next": "^12.3.1",
5151
"react-modal": "~3.11.2"
5252
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import Icon from '@digitransit-component/digitransit-component-icon';
3+
import { useTranslation } from 'react-i18next';
4+
import PropTypes from 'prop-types';
5+
6+
/**
7+
* Input clear button element
8+
* @typedef {object} ClearButtonProps
9+
* @property {string} color // hex color string
10+
* @property {string} lng // language, eg. 'fi'
11+
* @property {() => void} clearInput
12+
* @property {() => void} [onKeyDown]
13+
* @param {ClearButtonProps} props
14+
* @returns {JSX.Element}
15+
*/
16+
export const ClearButton = ({ color, lng, clearInput, onKeyDown, styles }) => {
17+
const [t] = useTranslation();
18+
return (
19+
<button
20+
type="button"
21+
className={styles['clear-input']}
22+
onClick={clearInput}
23+
aria-label={t('clear-button-label', { lng })}
24+
onKeyDown={onKeyDown}
25+
>
26+
<Icon img="close" color={color} />
27+
</button>
28+
);
29+
};
30+
31+
ClearButton.propTypes = {
32+
color: PropTypes.string.isRequired,
33+
lng: PropTypes.string.isRequired,
34+
clearInput: PropTypes.func.isRequired,
35+
onKeyDown: PropTypes.func.isRequired,
36+
styles: PropTypes.objectOf(PropTypes.string).isRequired,
37+
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import cx from 'classnames';
4+
import { ClearButton } from './ClearButton';
5+
6+
export function Input({
7+
id,
8+
lng,
9+
value,
10+
placeholder,
11+
required,
12+
getInputProps,
13+
getLabelProps,
14+
clearInput,
15+
ariaLabel,
16+
inputRef,
17+
styles,
18+
renderLabel,
19+
isMobile,
20+
inputClassName,
21+
transportMode,
22+
clearButtonColor,
23+
autoFocus,
24+
}) {
25+
return (
26+
<div className={styles.container}>
27+
{renderLabel && (
28+
<label
29+
{...getLabelProps({
30+
className: styles['sr-only'],
31+
htmlFor: id,
32+
})}
33+
>
34+
{ariaLabel}
35+
</label>
36+
)}
37+
<input
38+
aria-label={ariaLabel}
39+
// eslint-disable-next-line jsx-a11y/no-autofocus
40+
autoFocus={autoFocus}
41+
placeholder={placeholder}
42+
required={required}
43+
className={cx(
44+
styles.input,
45+
isMobile && transportMode ? styles.thin : '',
46+
styles[id] || '',
47+
value ? styles.hasValue : '',
48+
inputClassName,
49+
)}
50+
value={value}
51+
id={id}
52+
{...getInputProps({ ref: inputRef })}
53+
/>
54+
{value && (
55+
<ClearButton
56+
lng={lng}
57+
clearInput={() => clearInput(inputRef)}
58+
styles={styles}
59+
color={clearButtonColor}
60+
onKeyDown={clearInput}
61+
/>
62+
)}
63+
</div>
64+
);
65+
}
66+
67+
Input.propTypes = {
68+
id: PropTypes.string.isRequired,
69+
lng: PropTypes.string.isRequired,
70+
placeholder: PropTypes.string.isRequired,
71+
required: PropTypes.bool.isRequired,
72+
value: PropTypes.string.isRequired,
73+
getInputProps: PropTypes.func.isRequired,
74+
getLabelProps: PropTypes.func.isRequired,
75+
clearInput: PropTypes.func.isRequired,
76+
ariaLabel: PropTypes.string.isRequired,
77+
inputRef: PropTypes.oneOfType([
78+
PropTypes.func,
79+
PropTypes.shape({ current: PropTypes.instanceOf(HTMLInputElement) }),
80+
]).isRequired,
81+
styles: PropTypes.objectOf(PropTypes.string).isRequired,
82+
renderLabel: PropTypes.bool.isRequired,
83+
isMobile: PropTypes.bool.isRequired,
84+
inputClassName: PropTypes.string.isRequired,
85+
transportMode: PropTypes.string.isRequired,
86+
clearButtonColor: PropTypes.string.isRequired,
87+
autoFocus: PropTypes.bool,
88+
};
89+
90+
Input.defaultProps = {
91+
autoFocus: false,
92+
};

digitransit-component/packages/digitransit-component-autosuggest/src/helpers/MobileNoScroll.scss renamed to digitransit-component/packages/digitransit-component-autosuggest/src/components/MobileNoScroll.scss

File renamed without changes.

digitransit-component/packages/digitransit-component-autosuggest/src/helpers/MobileSearch.scss renamed to digitransit-component/packages/digitransit-component-autosuggest/src/components/MobileSearch.scss

File renamed without changes.

0 commit comments

Comments
 (0)