@aarhus-university/au-lib-react-components 10.3.3 → 10.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +34 -44
- package/.storybook/main.js +8 -0
- package/{types/common/payloads.d.ts → .storybook/preview-head.html} +0 -0
- package/.storybook/preview.js +11 -0
- package/README.md +19 -19
- package/__tests__/jest/AUButtonComponent.test.tsx +163 -0
- package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -0
- package/__tests__/jest/helpers.test.ts +15 -0
- package/__tests__/jest/setupTests.ts +2 -0
- package/babel.config.js +8 -7
- package/build/umd/all.css +2 -2
- package/build/umd/all.js +1 -1
- package/build/umd/alphabox.js +1 -1
- package/build/umd/alphabox.js.map +1 -1
- package/build/umd/databox.js +1 -1
- package/build/umd/databox.js.map +1 -1
- package/build/umd/diagramme.js +1 -1
- package/build/umd/diagramme.js.map +1 -1
- package/build/umd/flowbox.js +1 -1
- package/build/umd/flowbox.js.map +1 -1
- package/build/umd/universe.js +1 -1
- package/build/umd/universe.js.map +1 -1
- package/package.json +107 -66
- package/src/components/AUAlertComponent.tsx +70 -70
- package/src/components/AUAutoSuggestComponent.js +158 -158
- package/src/components/AUButtonComponent.tsx +77 -0
- package/src/components/AUCalendarComponent.tsx +493 -493
- package/src/components/AUContentToggleComponent.tsx +33 -33
- package/src/components/AUDatepickerComponent.tsx +117 -117
- package/src/components/AUMobilePrefixComponent.tsx +15 -15
- package/src/components/AUModalComponent.tsx +80 -80
- package/src/components/AUReceiptComponent.tsx +33 -33
- package/src/components/AUSpinnerComponent.tsx +33 -91
- package/src/components/AUSubNavComponent.tsx +48 -48
- package/src/components/AUSubmitButtonContainerComponent.tsx +31 -31
- package/src/components/AUTabbedContentComponent.tsx +145 -145
- package/src/components/AUTableComponent.tsx +24 -24
- package/src/components/AUToastComponent.tsx +103 -103
- package/src/components/AUToolbarComponent.tsx +45 -45
- package/src/components/profile/AUProfileActions.js +128 -128
- package/src/components/profile/AUProfileAvatarComponent.js +83 -83
- package/src/components/profile/AUProfileAvatarV2Component.js +91 -91
- package/src/components/profile/AUProfileAvatarV3Component.tsx +42 -42
- package/src/components/profile/AUProfileContainerComponent.js +283 -283
- package/src/components/profile/AUProfileHooks.js +30 -30
- package/src/components/profile/AUProfileItemComponent.js +54 -54
- package/src/components/profile/AUProfileLanguageComponent.js +131 -131
- package/src/components/profile/AUProfileLoginComponent.tsx +26 -26
- package/src/components/profile/AUProfileMailComponent.js +307 -307
- package/src/components/profile/AUProfileMobileComponent.js +164 -164
- package/src/components/profile/AUProfileNameComponent.js +253 -253
- package/src/components/profile/AUProfileNextOfKinComponent.js +216 -216
- package/src/components/profile/AUProfileReducer.js +230 -230
- package/src/components/profile/AUProfileWidgetComponent.js +95 -95
- package/src/components/profile/AUProfileWidgetV2Component.js +116 -116
- package/src/components/profile/AUProfileWidgetV3Component.tsx +122 -122
- package/src/components/wrapping/AUEmbedComponent.js +47 -47
- package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +143 -143
- package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
- package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
- package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
- package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
- package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
- package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
- package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
- package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
- package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
- package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
- package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
- package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
- package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
- package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
- package/src/layout-2016/components/profile/AUProfileAvatar2016Component.js +103 -103
- package/src/layout-2016/components/universe/StaffTopComponent.js +363 -363
- package/src/layout-2016/components/universe/StudentTopComponent.js +137 -137
- package/src/layout-2016/components/universe/UniverseContainerComponent.js +65 -65
- package/src/layout-2016/lib/all.js +3 -3
- package/src/layout-2016/lib/au-alphabox.js +100 -100
- package/src/layout-2016/lib/au-databox.js +400 -400
- package/src/layout-2016/lib/au-diagramme.js +85 -85
- package/src/layout-2016/lib/au-flowbox.js +93 -93
- package/src/layout-2016/lib/universe.js +9 -9
- package/src/lib/helpers.ts +194 -194
- package/src/lib/hooks.ts +33 -33
- package/src/lib/i18n.ts +600 -600
- package/src/lib/tracking.ts +69 -69
- package/src/lib/wrapping.ts +21 -21
- package/src/styles/_settings.scss +10 -10
- package/src/styles/alphabox.scss +222 -222
- package/src/styles/app.scss +7 -7
- package/src/styles/autosuggest.scss +57 -57
- package/src/styles/databox.scss +563 -563
- package/src/styles/diagramme.scss +119 -119
- package/src/styles/flowbox.scss +72 -72
- package/src/styles/maps.scss +395 -395
- package/stories/AUButtonComponent.stories.tsx +86 -0
- package/stories/AUSpinnerComponent.stories.tsx +41 -0
- package/stories/assets/code-brackets.svg +1 -0
- package/stories/assets/colors.svg +1 -0
- package/stories/assets/comments.svg +1 -0
- package/stories/assets/direction.svg +1 -0
- package/stories/assets/flow.svg +1 -0
- package/stories/assets/plugin.svg +1 -0
- package/stories/assets/repo.svg +1 -0
- package/stories/assets/stackalt.svg +1 -0
- package/tsconfig.json +46 -46
- package/webpack.config.js +89 -89
- package/types/common/delphinus-duplicates.d.ts +0 -40
- package/types/common/interfaces/gui.d.ts +0 -52
- package/types/common/interfaces/model.d.ts +0 -29
- package/types/common/main.d.ts +0 -6
- package/types/common/package.json +0 -5
- package/types/common/props.d.ts +0 -166
package/package.json
CHANGED
|
@@ -1,66 +1,107 @@
|
|
|
1
|
-
{
|
|
2
|
-
"sideEffects": false,
|
|
3
|
-
"name": "@aarhus-university/au-lib-react-components",
|
|
4
|
-
"version": "10.
|
|
5
|
-
"description": "Library for shared React components for various applications on au.dk",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"@babel/
|
|
22
|
-
"@babel/
|
|
23
|
-
"@babel/
|
|
24
|
-
"@babel/
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"babel-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"typescript": "^
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
{
|
|
2
|
+
"sideEffects": false,
|
|
3
|
+
"name": "@aarhus-university/au-lib-react-components",
|
|
4
|
+
"version": "10.6.0",
|
|
5
|
+
"description": "Library for shared React components for various applications on au.dk",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"build": "jest && webpack --config ./webpack.config.js",
|
|
9
|
+
"storybook": "start-storybook -p 6006",
|
|
10
|
+
"build-storybook": "build-storybook"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://gitlab.au.dk/au-web-og-digital/au-lib-react-components"
|
|
15
|
+
},
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Thomas Riis Hansen",
|
|
18
|
+
"email": "trh@au.dk"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@babel/core": "^7.17.0",
|
|
22
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
23
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
|
|
24
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
|
|
25
|
+
"@babel/preset-env": "^7.16.11",
|
|
26
|
+
"@babel/preset-react": "^7.16.7",
|
|
27
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
28
|
+
"@mdx-js/react": "^2.1.2",
|
|
29
|
+
"@storybook/addon-actions": "^6.5.4",
|
|
30
|
+
"@storybook/addon-essentials": "^6.5.4",
|
|
31
|
+
"@storybook/addon-interactions": "^6.5.4",
|
|
32
|
+
"@storybook/addon-links": "^6.5.4",
|
|
33
|
+
"@storybook/builder-webpack4": "^6.5.4",
|
|
34
|
+
"@storybook/builder-webpack5": "^6.5.4",
|
|
35
|
+
"@storybook/manager-webpack4": "^6.5.4",
|
|
36
|
+
"@storybook/manager-webpack5": "^6.5.4",
|
|
37
|
+
"@storybook/react": "^6.5.4",
|
|
38
|
+
"@storybook/testing-library": "^0.0.11",
|
|
39
|
+
"@testing-library/jest-dom": "5.0.0",
|
|
40
|
+
"@testing-library/react": "13.0.0",
|
|
41
|
+
"@testing-library/user-event": "14.0.0",
|
|
42
|
+
"@types/jest": "^27.4.0",
|
|
43
|
+
"@types/testing-library__jest-dom": "5.0.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
45
|
+
"@typescript-eslint/parser": "^5.10.2",
|
|
46
|
+
"babel-eslint": "^10.1.0",
|
|
47
|
+
"babel-jest": "^27.5.1",
|
|
48
|
+
"babel-loader": "^8.2.3",
|
|
49
|
+
"css-loader": "^6.6.0",
|
|
50
|
+
"eslint": "^8.8.0",
|
|
51
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
52
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
53
|
+
"eslint-plugin-import": "^2.25.4",
|
|
54
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
55
|
+
"eslint-plugin-react": "^7.28.0",
|
|
56
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
57
|
+
"eslint-plugin-storybook": "^0.5.12",
|
|
58
|
+
"eslint-webpack-plugin": "^3.1.1",
|
|
59
|
+
"fork-ts-checker-webpack-plugin": "^7.0.0",
|
|
60
|
+
"jest": "^27.5.1",
|
|
61
|
+
"mini-css-extract-plugin": "^2.5.3",
|
|
62
|
+
"react-test-renderer": "18.1.0",
|
|
63
|
+
"sass": "^1.49.7",
|
|
64
|
+
"sass-loader": "^12.4.0",
|
|
65
|
+
"style-loader": "^3.3.1",
|
|
66
|
+
"ts-loader": "^9.2.6",
|
|
67
|
+
"typescript": "^4.5.5",
|
|
68
|
+
"webpack-cli": "^4.9.2"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@aarhus-university/au-designsystem-delphinus": "0.28.0",
|
|
72
|
+
"@aarhus-university/types": "^0.2.0",
|
|
73
|
+
"@types/google.analytics": "^0.0.42",
|
|
74
|
+
"@types/history": "^5.0.0",
|
|
75
|
+
"@types/react": "^18.0.14",
|
|
76
|
+
"@types/react-dom": "^18.0.5",
|
|
77
|
+
"@types/react-router-dom": "^5.3.3",
|
|
78
|
+
"dayjs": "^1.10.7",
|
|
79
|
+
"lodash.debounce": "^4.0.8",
|
|
80
|
+
"prop-types": "^15.8.1",
|
|
81
|
+
"query-string": "^7.1.0",
|
|
82
|
+
"react": "18.2.0",
|
|
83
|
+
"react-autosuggest": "^10.1.0",
|
|
84
|
+
"react-router-dom": "^6.2.1",
|
|
85
|
+
"regenerator-runtime": "^0.13.9",
|
|
86
|
+
"webpack": "^5.68.0",
|
|
87
|
+
"whatwg-fetch": "^3.6.2"
|
|
88
|
+
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"react": "18.2.0",
|
|
91
|
+
"react-dom": "^18.2.0"
|
|
92
|
+
},
|
|
93
|
+
"jest": {
|
|
94
|
+
"rootDir": "__tests__/jest",
|
|
95
|
+
"setupFilesAfterEnv": [
|
|
96
|
+
"./setupTests.ts"
|
|
97
|
+
],
|
|
98
|
+
"testEnvironment": "jsdom",
|
|
99
|
+
"transformIgnorePatterns": [
|
|
100
|
+
"node_modules/(?!(@aarhus-university/au-lib-react-components|@aarhus-university/au-designsystem-delphinus|node-fetch|data-uri-to-buffer|fetch-blob|formdata-polyfill)/)"
|
|
101
|
+
],
|
|
102
|
+
"testPathIgnorePatterns": [
|
|
103
|
+
"factory.ts",
|
|
104
|
+
"setupTests.ts"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
/* eslint-env browser */
|
|
3
|
-
import React, { FC } from 'react';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
|
-
|
|
6
|
-
const AUAlertComponent: FC<AUAlertComponentProps> = ({
|
|
7
|
-
message,
|
|
8
|
-
children,
|
|
9
|
-
alert,
|
|
10
|
-
buttons,
|
|
11
|
-
}: AUAlertComponentProps) => {
|
|
12
|
-
const renderButtons = (buttons || []).map((button) => (
|
|
13
|
-
<button
|
|
14
|
-
key={button.text}
|
|
15
|
-
type="button"
|
|
16
|
-
className={button.className}
|
|
17
|
-
data-icon={button.dataIcon}
|
|
18
|
-
onClick={() => {
|
|
19
|
-
button.onClick();
|
|
20
|
-
}}
|
|
21
|
-
>
|
|
22
|
-
{button.text}
|
|
23
|
-
</button>
|
|
24
|
-
));
|
|
25
|
-
|
|
26
|
-
if (alert) {
|
|
27
|
-
return (
|
|
28
|
-
<>
|
|
29
|
-
{
|
|
30
|
-
ReactDOM.createPortal(
|
|
31
|
-
<div key="0" className="theme--normal toast-notification toast-notification--attention toast-notification--persistent">
|
|
32
|
-
<div className="toast-notification__content">
|
|
33
|
-
<p dangerouslySetInnerHTML={{ __html: message }} />
|
|
34
|
-
</div>
|
|
35
|
-
{renderButtons}
|
|
36
|
-
</div>,
|
|
37
|
-
document.querySelector('body')!,
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
{children}
|
|
41
|
-
</>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!children) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return children;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
AUAlertComponent.defaultProps = {
|
|
53
|
-
buttons: [{
|
|
54
|
-
className: 'button',
|
|
55
|
-
text: 'OK',
|
|
56
|
-
dataIcon: null,
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
onClick: () => console.log('clicked on OK'),
|
|
59
|
-
}, {
|
|
60
|
-
className: 'button',
|
|
61
|
-
text: 'Annuller',
|
|
62
|
-
dataIcon: null,
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
onClick: () => console.log('clicked on cancel'),
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
AUAlertComponent.displayName = 'AUAlertComponent';
|
|
70
|
-
export default AUAlertComponent;
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
/* eslint-env browser */
|
|
3
|
+
import React, { FC } from 'react';
|
|
4
|
+
import ReactDOM from 'react-dom';
|
|
5
|
+
|
|
6
|
+
const AUAlertComponent: FC<AUAlertComponentProps> = ({
|
|
7
|
+
message,
|
|
8
|
+
children,
|
|
9
|
+
alert,
|
|
10
|
+
buttons,
|
|
11
|
+
}: AUAlertComponentProps) => {
|
|
12
|
+
const renderButtons = (buttons || []).map((button) => (
|
|
13
|
+
<button
|
|
14
|
+
key={button.text}
|
|
15
|
+
type="button"
|
|
16
|
+
className={button.className}
|
|
17
|
+
data-icon={button.dataIcon}
|
|
18
|
+
onClick={() => {
|
|
19
|
+
button.onClick();
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
{button.text}
|
|
23
|
+
</button>
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
if (alert) {
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{
|
|
30
|
+
ReactDOM.createPortal(
|
|
31
|
+
<div key="0" className="theme--normal toast-notification toast-notification--attention toast-notification--persistent">
|
|
32
|
+
<div className="toast-notification__content">
|
|
33
|
+
<p dangerouslySetInnerHTML={{ __html: message }} />
|
|
34
|
+
</div>
|
|
35
|
+
{renderButtons}
|
|
36
|
+
</div>,
|
|
37
|
+
document.querySelector('body')!,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
{children}
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!children) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return children;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
AUAlertComponent.defaultProps = {
|
|
53
|
+
buttons: [{
|
|
54
|
+
className: 'button',
|
|
55
|
+
text: 'OK',
|
|
56
|
+
dataIcon: null,
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
onClick: () => console.log('clicked on OK'),
|
|
59
|
+
}, {
|
|
60
|
+
className: 'button',
|
|
61
|
+
text: 'Annuller',
|
|
62
|
+
dataIcon: null,
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
onClick: () => console.log('clicked on cancel'),
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
AUAlertComponent.displayName = 'AUAlertComponent';
|
|
70
|
+
export default AUAlertComponent;
|
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import Autosuggest from 'react-autosuggest';
|
|
5
|
-
import debounce from 'lodash.debounce';
|
|
6
|
-
|
|
7
|
-
class AUAutoSuggestComponent extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
this.state = {
|
|
11
|
-
value: '',
|
|
12
|
-
suggestions: [],
|
|
13
|
-
noSuggestions: false,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
this.onChange = this.onChange.bind(this);
|
|
17
|
-
this.onEnter = this.onEnter.bind(this);
|
|
18
|
-
this.onSuggestionsFetchRequested = debounce(this.onSuggestionsFetchRequested.bind(this), 400);
|
|
19
|
-
this.onSuggestionsClearRequested = this.onSuggestionsClearRequested.bind(this);
|
|
20
|
-
this.onSuggestionSelected = this.onSuggestionSelected.bind(this);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
onChange(_, { newValue }) {
|
|
24
|
-
const { setQuery } = this.props;
|
|
25
|
-
this.setState({
|
|
26
|
-
value: newValue,
|
|
27
|
-
}, () => {
|
|
28
|
-
setQuery(newValue);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
onEnter(event) {
|
|
33
|
-
const { suggestions } = this.state;
|
|
34
|
-
const { setResults } = this.props;
|
|
35
|
-
if (event.key === 'Enter') {
|
|
36
|
-
setResults(suggestions);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onSuggestionsFetchRequested({ value }) {
|
|
41
|
-
const { getSuggestions, collection } = this.props;
|
|
42
|
-
getSuggestions(value, collection, (suggestions) => {
|
|
43
|
-
this.setState({
|
|
44
|
-
suggestions,
|
|
45
|
-
noSuggestions: suggestions.length === 0 && value.trim() !== '' && value.trim().length > 1,
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
onSuggestionsClearRequested() {
|
|
51
|
-
this.setState({
|
|
52
|
-
suggestions: [],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
onSuggestionSelected(event, { suggestion }) {
|
|
57
|
-
const { setResults, clearInput } = this.props;
|
|
58
|
-
setResults([suggestion]);
|
|
59
|
-
if (clearInput) {
|
|
60
|
-
this.setState({
|
|
61
|
-
value: '',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
render() {
|
|
67
|
-
const { value, suggestions, noSuggestions } = this.state;
|
|
68
|
-
const {
|
|
69
|
-
placeholder,
|
|
70
|
-
getSuggestionValue,
|
|
71
|
-
renderSuggestion,
|
|
72
|
-
id,
|
|
73
|
-
theme,
|
|
74
|
-
type,
|
|
75
|
-
initialValue,
|
|
76
|
-
disabled,
|
|
77
|
-
noResultsText,
|
|
78
|
-
} = this.props;
|
|
79
|
-
const inputProps = {
|
|
80
|
-
placeholder,
|
|
81
|
-
value: initialValue || value,
|
|
82
|
-
id,
|
|
83
|
-
type,
|
|
84
|
-
disabled,
|
|
85
|
-
'aria-label': placeholder,
|
|
86
|
-
onChange: this.onChange,
|
|
87
|
-
onKeyDown: this.onEnter,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<>
|
|
92
|
-
<Autosuggest
|
|
93
|
-
suggestions={suggestions}
|
|
94
|
-
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
|
95
|
-
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
|
|
96
|
-
onSuggestionSelected={this.onSuggestionSelected}
|
|
97
|
-
getSuggestionValue={getSuggestionValue}
|
|
98
|
-
renderSuggestion={renderSuggestion}
|
|
99
|
-
inputProps={inputProps}
|
|
100
|
-
theme={theme}
|
|
101
|
-
/>
|
|
102
|
-
{
|
|
103
|
-
(noSuggestions && noResultsText) && (
|
|
104
|
-
<p className="no-results">
|
|
105
|
-
<em>{noResultsText}</em>
|
|
106
|
-
</p>
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
</>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
AUAutoSuggestComponent.displayName = 'AUAutoSuggestComponent';
|
|
115
|
-
|
|
116
|
-
AUAutoSuggestComponent.defaultProps = {
|
|
117
|
-
id: 'autosuggest1',
|
|
118
|
-
theme: {
|
|
119
|
-
container: 'react-autosuggest__container',
|
|
120
|
-
containerOpen: 'react-autosuggest__container--open',
|
|
121
|
-
input: 'react-autosuggest__input',
|
|
122
|
-
inputOpen: 'react-autosuggest__input--open',
|
|
123
|
-
inputFocused: 'react-autosuggest__input--focused',
|
|
124
|
-
suggestionsContainer: 'react-autosuggest__suggestions-container',
|
|
125
|
-
suggestionsContainerOpen: 'react-autosuggest__suggestions-container--open',
|
|
126
|
-
suggestionsList: 'react-autosuggest__suggestions-list',
|
|
127
|
-
suggestion: 'react-autosuggest__suggestion',
|
|
128
|
-
suggestionFirst: 'react-autosuggest__suggestion--first',
|
|
129
|
-
suggestionHighlighted: 'react-autosuggest__suggestion--highlighted',
|
|
130
|
-
sectionContainer: 'react-autosuggest__section-container',
|
|
131
|
-
sectionContainerFirst: 'react-autosuggest__section-container--first',
|
|
132
|
-
sectionTitle: 'react-autosuggest__section-title',
|
|
133
|
-
},
|
|
134
|
-
clearInput: false,
|
|
135
|
-
type: 'text',
|
|
136
|
-
initialValue: '',
|
|
137
|
-
disabled: false,
|
|
138
|
-
setQuery: () => { },
|
|
139
|
-
noResultsText: '',
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
AUAutoSuggestComponent.propTypes = {
|
|
143
|
-
setQuery: PropTypes.func,
|
|
144
|
-
getSuggestions: PropTypes.func.isRequired,
|
|
145
|
-
getSuggestionValue: PropTypes.func.isRequired,
|
|
146
|
-
renderSuggestion: PropTypes.func.isRequired,
|
|
147
|
-
setResults: PropTypes.func.isRequired,
|
|
148
|
-
collection: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
|
|
149
|
-
placeholder: PropTypes.string.isRequired,
|
|
150
|
-
id: PropTypes.string,
|
|
151
|
-
theme: PropTypes.shape({}),
|
|
152
|
-
clearInput: PropTypes.bool,
|
|
153
|
-
type: PropTypes.string,
|
|
154
|
-
initialValue: PropTypes.string,
|
|
155
|
-
disabled: PropTypes.bool,
|
|
156
|
-
noResultsText: PropTypes.string,
|
|
157
|
-
};
|
|
158
|
-
export default AUAutoSuggestComponent;
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import Autosuggest from 'react-autosuggest';
|
|
5
|
+
import debounce from 'lodash.debounce';
|
|
6
|
+
|
|
7
|
+
class AUAutoSuggestComponent extends React.Component {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.state = {
|
|
11
|
+
value: '',
|
|
12
|
+
suggestions: [],
|
|
13
|
+
noSuggestions: false,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
this.onChange = this.onChange.bind(this);
|
|
17
|
+
this.onEnter = this.onEnter.bind(this);
|
|
18
|
+
this.onSuggestionsFetchRequested = debounce(this.onSuggestionsFetchRequested.bind(this), 400);
|
|
19
|
+
this.onSuggestionsClearRequested = this.onSuggestionsClearRequested.bind(this);
|
|
20
|
+
this.onSuggestionSelected = this.onSuggestionSelected.bind(this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onChange(_, { newValue }) {
|
|
24
|
+
const { setQuery } = this.props;
|
|
25
|
+
this.setState({
|
|
26
|
+
value: newValue,
|
|
27
|
+
}, () => {
|
|
28
|
+
setQuery(newValue);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onEnter(event) {
|
|
33
|
+
const { suggestions } = this.state;
|
|
34
|
+
const { setResults } = this.props;
|
|
35
|
+
if (event.key === 'Enter') {
|
|
36
|
+
setResults(suggestions);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onSuggestionsFetchRequested({ value }) {
|
|
41
|
+
const { getSuggestions, collection } = this.props;
|
|
42
|
+
getSuggestions(value, collection, (suggestions) => {
|
|
43
|
+
this.setState({
|
|
44
|
+
suggestions,
|
|
45
|
+
noSuggestions: suggestions.length === 0 && value.trim() !== '' && value.trim().length > 1,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
onSuggestionsClearRequested() {
|
|
51
|
+
this.setState({
|
|
52
|
+
suggestions: [],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
onSuggestionSelected(event, { suggestion }) {
|
|
57
|
+
const { setResults, clearInput } = this.props;
|
|
58
|
+
setResults([suggestion]);
|
|
59
|
+
if (clearInput) {
|
|
60
|
+
this.setState({
|
|
61
|
+
value: '',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
render() {
|
|
67
|
+
const { value, suggestions, noSuggestions } = this.state;
|
|
68
|
+
const {
|
|
69
|
+
placeholder,
|
|
70
|
+
getSuggestionValue,
|
|
71
|
+
renderSuggestion,
|
|
72
|
+
id,
|
|
73
|
+
theme,
|
|
74
|
+
type,
|
|
75
|
+
initialValue,
|
|
76
|
+
disabled,
|
|
77
|
+
noResultsText,
|
|
78
|
+
} = this.props;
|
|
79
|
+
const inputProps = {
|
|
80
|
+
placeholder,
|
|
81
|
+
value: initialValue || value,
|
|
82
|
+
id,
|
|
83
|
+
type,
|
|
84
|
+
disabled,
|
|
85
|
+
'aria-label': placeholder,
|
|
86
|
+
onChange: this.onChange,
|
|
87
|
+
onKeyDown: this.onEnter,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<Autosuggest
|
|
93
|
+
suggestions={suggestions}
|
|
94
|
+
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
|
95
|
+
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
|
|
96
|
+
onSuggestionSelected={this.onSuggestionSelected}
|
|
97
|
+
getSuggestionValue={getSuggestionValue}
|
|
98
|
+
renderSuggestion={renderSuggestion}
|
|
99
|
+
inputProps={inputProps}
|
|
100
|
+
theme={theme}
|
|
101
|
+
/>
|
|
102
|
+
{
|
|
103
|
+
(noSuggestions && noResultsText) && (
|
|
104
|
+
<p className="no-results">
|
|
105
|
+
<em>{noResultsText}</em>
|
|
106
|
+
</p>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
</>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
AUAutoSuggestComponent.displayName = 'AUAutoSuggestComponent';
|
|
115
|
+
|
|
116
|
+
AUAutoSuggestComponent.defaultProps = {
|
|
117
|
+
id: 'autosuggest1',
|
|
118
|
+
theme: {
|
|
119
|
+
container: 'react-autosuggest__container',
|
|
120
|
+
containerOpen: 'react-autosuggest__container--open',
|
|
121
|
+
input: 'react-autosuggest__input',
|
|
122
|
+
inputOpen: 'react-autosuggest__input--open',
|
|
123
|
+
inputFocused: 'react-autosuggest__input--focused',
|
|
124
|
+
suggestionsContainer: 'react-autosuggest__suggestions-container',
|
|
125
|
+
suggestionsContainerOpen: 'react-autosuggest__suggestions-container--open',
|
|
126
|
+
suggestionsList: 'react-autosuggest__suggestions-list',
|
|
127
|
+
suggestion: 'react-autosuggest__suggestion',
|
|
128
|
+
suggestionFirst: 'react-autosuggest__suggestion--first',
|
|
129
|
+
suggestionHighlighted: 'react-autosuggest__suggestion--highlighted',
|
|
130
|
+
sectionContainer: 'react-autosuggest__section-container',
|
|
131
|
+
sectionContainerFirst: 'react-autosuggest__section-container--first',
|
|
132
|
+
sectionTitle: 'react-autosuggest__section-title',
|
|
133
|
+
},
|
|
134
|
+
clearInput: false,
|
|
135
|
+
type: 'text',
|
|
136
|
+
initialValue: '',
|
|
137
|
+
disabled: false,
|
|
138
|
+
setQuery: () => { },
|
|
139
|
+
noResultsText: '',
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
AUAutoSuggestComponent.propTypes = {
|
|
143
|
+
setQuery: PropTypes.func,
|
|
144
|
+
getSuggestions: PropTypes.func.isRequired,
|
|
145
|
+
getSuggestionValue: PropTypes.func.isRequired,
|
|
146
|
+
renderSuggestion: PropTypes.func.isRequired,
|
|
147
|
+
setResults: PropTypes.func.isRequired,
|
|
148
|
+
collection: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
|
|
149
|
+
placeholder: PropTypes.string.isRequired,
|
|
150
|
+
id: PropTypes.string,
|
|
151
|
+
theme: PropTypes.shape({}),
|
|
152
|
+
clearInput: PropTypes.bool,
|
|
153
|
+
type: PropTypes.string,
|
|
154
|
+
initialValue: PropTypes.string,
|
|
155
|
+
disabled: PropTypes.bool,
|
|
156
|
+
noResultsText: PropTypes.string,
|
|
157
|
+
};
|
|
158
|
+
export default AUAutoSuggestComponent;
|