@aarhus-university/au-lib-react-components 11.3.2 → 11.4.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 -34
- package/.storybook/main.js +20 -20
- package/.storybook/preview.js +17 -17
- package/README.md +19 -19
- package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
- package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
- package/__tests__/jest/AUModalComponent.test.tsx +186 -186
- package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
- package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
- package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
- package/__tests__/jest/context.test.ts +25 -25
- package/__tests__/jest/helpers.test.ts +15 -15
- package/__tests__/jest/setupTests.ts +2 -2
- package/babel.config.js +8 -8
- package/build/umd/all.css +2 -2
- package/build/umd/all.js +1 -1
- package/build/umd/alphabox.js +1 -1
- package/build/umd/databox.js +1 -1
- package/build/umd/diagramme.js +1 -1
- package/build/umd/flowbox.js +1 -1
- package/build/umd/universe.js +1 -1
- package/build-storybook.log +367 -367
- package/package.json +114 -114
- package/src/components/AUAlertComponent.tsx +70 -70
- package/src/components/AUAutoSuggestComponent.js +158 -158
- package/src/components/AUButtonComponent.tsx +84 -84
- package/src/components/AUCalendarComponent.tsx +493 -493
- package/src/components/AUContentToggleComponent.tsx +47 -47
- package/src/components/AUDatepickerComponent.tsx +121 -121
- package/src/components/AUErrorComponent.tsx +78 -78
- package/src/components/AUMobilePrefixComponent.tsx +15 -15
- package/src/components/AUModalComponent.tsx +68 -68
- package/src/components/AUNotificationComponent.tsx +43 -43
- package/src/components/AUReceiptComponent.tsx +33 -33
- package/src/components/AUSpinnerComponent.tsx +36 -36
- package/src/components/AUStepComponent.tsx +47 -41
- package/src/components/AUSubNavComponent.tsx +48 -48
- package/src/components/AUSubmitButtonContainerComponent.tsx +29 -29
- package/src/components/AUTabbedContentComponent.tsx +145 -145
- package/src/components/AUTableComponent.tsx +24 -24
- package/src/components/AUToastComponent.tsx +104 -104
- package/src/components/AUToolbarComponent.tsx +101 -101
- package/src/components/AUTruncatorComponent.tsx +124 -129
- 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/context.tsx +51 -51
- package/src/lib/dates.ts +50 -50
- package/src/lib/helpers.ts +208 -208
- package/src/lib/hooks.ts +75 -75
- package/src/lib/i18n.ts +600 -600
- package/src/lib/portals.tsx +119 -119
- 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 +127 -127
- package/stories/AUContentToggleComponent.stories.tsx +63 -63
- package/stories/AUErrorComponent.stories.tsx +98 -98
- package/stories/AUModalComponent.stories.tsx +83 -83
- package/stories/AUNotificationComponent.stories.tsx +116 -116
- package/stories/AUSpinnerComponent.stories.tsx +41 -41
- package/stories/AUStepComponent.stories.tsx +40 -40
- package/stories/AUToolbarComponent.stories.tsx +326 -326
- package/stories/AUTruncatorComponent.stories.tsx +102 -0
- package/stories/lib/helpers.tsx +128 -128
- package/tsconfig.json +46 -46
- package/webpack.config.js +89 -89
|
@@ -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;
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
FC, MouseEvent, RefObject,
|
|
3
|
-
} from 'react';
|
|
4
|
-
|
|
5
|
-
const AUButtonComponent: FC<AUButtonComponentProps> = ({
|
|
6
|
-
label,
|
|
7
|
-
disabled,
|
|
8
|
-
size,
|
|
9
|
-
type,
|
|
10
|
-
icon,
|
|
11
|
-
iconPosition,
|
|
12
|
-
hideLabel,
|
|
13
|
-
mode,
|
|
14
|
-
btnRef,
|
|
15
|
-
classNames,
|
|
16
|
-
ariaExpanded,
|
|
17
|
-
asSubmit,
|
|
18
|
-
onClick,
|
|
19
|
-
}: AUButtonComponentProps) => {
|
|
20
|
-
const sizeClass = size === 'default' ? '' : `button--${size}`;
|
|
21
|
-
const typeClass = type === 'default' ? '' : `button--${type}`;
|
|
22
|
-
let iconClass = '';
|
|
23
|
-
if (icon) {
|
|
24
|
-
iconClass = `button--icon icon-${icon}`;
|
|
25
|
-
if (iconPosition) {
|
|
26
|
-
iconClass = `${iconClass} button--icon--${iconPosition}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (hideLabel) {
|
|
30
|
-
iconClass = `${iconClass} button--icon--hide-label`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
let modeClass = '';
|
|
34
|
-
if (mode !== 'none') {
|
|
35
|
-
modeClass = `button--${mode}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<button
|
|
40
|
-
ref={btnRef}
|
|
41
|
-
type={asSubmit ? 'submit' : 'button'}
|
|
42
|
-
disabled={disabled}
|
|
43
|
-
className={[
|
|
44
|
-
'button',
|
|
45
|
-
sizeClass,
|
|
46
|
-
typeClass,
|
|
47
|
-
iconClass,
|
|
48
|
-
modeClass,
|
|
49
|
-
disabled && mode !== 'processing' ? 'visually-disabled' : '',
|
|
50
|
-
].concat(classNames || []).join(' ').replace(/\s+/g, ' ').trim()}
|
|
51
|
-
title={icon && hideLabel ? label : undefined}
|
|
52
|
-
aria-expanded={ariaExpanded}
|
|
53
|
-
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
|
54
|
-
if (typeof onClick !== 'undefined') {
|
|
55
|
-
onClick(event, btnRef);
|
|
56
|
-
}
|
|
57
|
-
}}
|
|
58
|
-
>
|
|
59
|
-
{label}
|
|
60
|
-
</button>
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
AUButtonComponent.defaultProps = {
|
|
65
|
-
disabled: false,
|
|
66
|
-
size: 'default',
|
|
67
|
-
type: 'default',
|
|
68
|
-
icon: '',
|
|
69
|
-
iconPosition: 'left',
|
|
70
|
-
hideLabel: false,
|
|
71
|
-
mode: 'none',
|
|
72
|
-
classNames: [],
|
|
73
|
-
ariaExpanded: false,
|
|
74
|
-
asSubmit: false,
|
|
75
|
-
// eslint-disable-next-line no-console
|
|
76
|
-
onClick: (
|
|
77
|
-
event: MouseEvent<HTMLButtonElement>,
|
|
78
|
-
ref: RefObject<HTMLButtonElement> | undefined,
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
80
|
-
) => console.log(event, ref),
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
AUButtonComponent.displayName = 'AUButtonComponent';
|
|
84
|
-
export default AUButtonComponent;
|
|
1
|
+
import React, {
|
|
2
|
+
FC, MouseEvent, RefObject,
|
|
3
|
+
} from 'react';
|
|
4
|
+
|
|
5
|
+
const AUButtonComponent: FC<AUButtonComponentProps> = ({
|
|
6
|
+
label,
|
|
7
|
+
disabled,
|
|
8
|
+
size,
|
|
9
|
+
type,
|
|
10
|
+
icon,
|
|
11
|
+
iconPosition,
|
|
12
|
+
hideLabel,
|
|
13
|
+
mode,
|
|
14
|
+
btnRef,
|
|
15
|
+
classNames,
|
|
16
|
+
ariaExpanded,
|
|
17
|
+
asSubmit,
|
|
18
|
+
onClick,
|
|
19
|
+
}: AUButtonComponentProps) => {
|
|
20
|
+
const sizeClass = size === 'default' ? '' : `button--${size}`;
|
|
21
|
+
const typeClass = type === 'default' ? '' : `button--${type}`;
|
|
22
|
+
let iconClass = '';
|
|
23
|
+
if (icon) {
|
|
24
|
+
iconClass = `button--icon icon-${icon}`;
|
|
25
|
+
if (iconPosition) {
|
|
26
|
+
iconClass = `${iconClass} button--icon--${iconPosition}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (hideLabel) {
|
|
30
|
+
iconClass = `${iconClass} button--icon--hide-label`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let modeClass = '';
|
|
34
|
+
if (mode !== 'none') {
|
|
35
|
+
modeClass = `button--${mode}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<button
|
|
40
|
+
ref={btnRef}
|
|
41
|
+
type={asSubmit ? 'submit' : 'button'}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
className={[
|
|
44
|
+
'button',
|
|
45
|
+
sizeClass,
|
|
46
|
+
typeClass,
|
|
47
|
+
iconClass,
|
|
48
|
+
modeClass,
|
|
49
|
+
disabled && mode !== 'processing' ? 'visually-disabled' : '',
|
|
50
|
+
].concat(classNames || []).join(' ').replace(/\s+/g, ' ').trim()}
|
|
51
|
+
title={icon && hideLabel ? label : undefined}
|
|
52
|
+
aria-expanded={ariaExpanded}
|
|
53
|
+
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
|
54
|
+
if (typeof onClick !== 'undefined') {
|
|
55
|
+
onClick(event, btnRef);
|
|
56
|
+
}
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{label}
|
|
60
|
+
</button>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
AUButtonComponent.defaultProps = {
|
|
65
|
+
disabled: false,
|
|
66
|
+
size: 'default',
|
|
67
|
+
type: 'default',
|
|
68
|
+
icon: '',
|
|
69
|
+
iconPosition: 'left',
|
|
70
|
+
hideLabel: false,
|
|
71
|
+
mode: 'none',
|
|
72
|
+
classNames: [],
|
|
73
|
+
ariaExpanded: false,
|
|
74
|
+
asSubmit: false,
|
|
75
|
+
// eslint-disable-next-line no-console
|
|
76
|
+
onClick: (
|
|
77
|
+
event: MouseEvent<HTMLButtonElement>,
|
|
78
|
+
ref: RefObject<HTMLButtonElement> | undefined,
|
|
79
|
+
// eslint-disable-next-line no-console
|
|
80
|
+
) => console.log(event, ref),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
AUButtonComponent.displayName = 'AUButtonComponent';
|
|
84
|
+
export default AUButtonComponent;
|