@aarhus-university/au-lib-react-components 10.1.0 → 10.2.2
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/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/package.json +4 -4
- package/src/components/AUAutoSuggestComponent.js +158 -158
- package/src/components/AUTabbedContentComponent.tsx +1 -1
- package/src/components/AUToastComponent.tsx +12 -13
- package/src/components/profile/AUProfileLoginComponent.tsx +26 -26
- 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/tsconfig.json +46 -46
- package/types/common/interfaces/gui.d.ts +2 -1
- package/types/common/interfaces/model.d.ts +29 -29
- package/types/common/props.d.ts +166 -165
- package/webpack.config.js +89 -89
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import AlphaBoxContentComponent from './AlphaBoxContentComponent';
|
|
5
|
-
import AUAutoSuggestComponent from '../../../components/AUAutoSuggestComponent';
|
|
6
|
-
import DataBoxSuggestionComponent from '../databox/DataBoxSuggestionComponent';
|
|
7
|
-
|
|
8
|
-
class AlphaBoxComponent extends React.Component {
|
|
9
|
-
constructor(props) {
|
|
10
|
-
super(props);
|
|
11
|
-
|
|
12
|
-
this.state = {
|
|
13
|
-
items: [],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
this.getSuggestions = this.getSuggestions.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
componentDidMount() {
|
|
20
|
-
const { box } = this.props;
|
|
21
|
-
const { data } = box;
|
|
22
|
-
if (data.mode === 'json' && data.source !== '') {
|
|
23
|
-
if (data.itemsOnly) {
|
|
24
|
-
data.source += '?itemsOnly=true';
|
|
25
|
-
}
|
|
26
|
-
fetch(data.source).then((promise) => promise.json()).then((pData) => {
|
|
27
|
-
this.setState({ items: pData.items });
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getSuggestions(value, _, callback) {
|
|
33
|
-
const { items } = this.state;
|
|
34
|
-
const inputValue = value.trim().toLowerCase();
|
|
35
|
-
const inputLength = inputValue.length;
|
|
36
|
-
callback(inputLength < 2 ? []
|
|
37
|
-
: items.filter(
|
|
38
|
-
(x) => x.name.toLowerCase().indexOf(inputValue) > -1
|
|
39
|
-
|| x.name.replace(/-/ig, ' ').toLowerCase().indexOf(inputValue) > -1
|
|
40
|
-
|| x.name.replace(/ /ig, '-').toLowerCase().indexOf(inputValue) > -1,
|
|
41
|
-
)
|
|
42
|
-
.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase(), 'da', { ignorePunctuation: true })));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
render() {
|
|
46
|
-
const { box } = this.props;
|
|
47
|
-
const { items } = this.state;
|
|
48
|
-
const { config } = box;
|
|
49
|
-
const renderLinks = config.links.map((l) => (
|
|
50
|
-
<li key={l.title}>
|
|
51
|
-
<a
|
|
52
|
-
href={l.url}
|
|
53
|
-
onClick={() => {
|
|
54
|
-
if (typeof l.onClick === 'function') {
|
|
55
|
-
l.onClick();
|
|
56
|
-
}
|
|
57
|
-
}}
|
|
58
|
-
style={{ backgroundColor: box.background.linkColor }}
|
|
59
|
-
>
|
|
60
|
-
{l.title}
|
|
61
|
-
</a>
|
|
62
|
-
</li>
|
|
63
|
-
));
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<div className="au_alphabox" style={{ backgroundColor: box.background.color }}>
|
|
67
|
-
<div>
|
|
68
|
-
<h2>
|
|
69
|
-
<a href={config.url}>{config.title}</a>
|
|
70
|
-
</h2>
|
|
71
|
-
<AlphaBoxContentComponent
|
|
72
|
-
items={items}
|
|
73
|
-
linkColor={box.background.linkColor}
|
|
74
|
-
noResultsText={config.noResultsAlphabet}
|
|
75
|
-
noResultsUri={config.noResultsUri}
|
|
76
|
-
/>
|
|
77
|
-
<AUAutoSuggestComponent
|
|
78
|
-
placeholder={box.search.placeHolder}
|
|
79
|
-
setResults={(_items) => {
|
|
80
|
-
if (_items.length >= 1 && _items[0].url) {
|
|
81
|
-
window.location.href = _items[0].url;
|
|
82
|
-
}
|
|
83
|
-
}}
|
|
84
|
-
collection={[]}
|
|
85
|
-
getSuggestions={this.getSuggestions}
|
|
86
|
-
getSuggestionValue={(suggestion) => suggestion.name}
|
|
87
|
-
renderSuggestion={(suggestion) => <DataBoxSuggestionComponent item={suggestion} />}
|
|
88
|
-
noResultsText={config.noResultsSearch}
|
|
89
|
-
/>
|
|
90
|
-
{
|
|
91
|
-
config.description !== '' && (
|
|
92
|
-
<h3>{config.description}</h3>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
{
|
|
96
|
-
config.links.length > 0 && (
|
|
97
|
-
<ul className="quicklinks resetlist">
|
|
98
|
-
{renderLinks}
|
|
99
|
-
</ul>
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
AlphaBoxComponent.propTypes = {
|
|
109
|
-
box: PropTypes.shape({
|
|
110
|
-
id: PropTypes.number.isRequired,
|
|
111
|
-
data: PropTypes.shape({
|
|
112
|
-
itemsOnly: PropTypes.bool.isRequired,
|
|
113
|
-
mode: PropTypes.string.isRequired,
|
|
114
|
-
source: PropTypes.string.isRequired,
|
|
115
|
-
}),
|
|
116
|
-
config: PropTypes.shape({
|
|
117
|
-
name: PropTypes.string.isRequired,
|
|
118
|
-
url: PropTypes.string.isRequired,
|
|
119
|
-
description: PropTypes.string.isRequired,
|
|
120
|
-
container: PropTypes.string.isRequired,
|
|
121
|
-
tracking: PropTypes.string.isRequired,
|
|
122
|
-
links: PropTypes.arrayOf(PropTypes.shape({
|
|
123
|
-
title: PropTypes.string.isRequired,
|
|
124
|
-
url: PropTypes.string.isRequired,
|
|
125
|
-
})).isRequired,
|
|
126
|
-
title: PropTypes.string.isRequired,
|
|
127
|
-
noResultsAlphabet: PropTypes.string.isRequired,
|
|
128
|
-
noResultsSearch: PropTypes.string.isRequired,
|
|
129
|
-
noResultsUri: PropTypes.string.isRequired,
|
|
130
|
-
}).isRequired,
|
|
131
|
-
background: PropTypes.shape({
|
|
132
|
-
color: PropTypes.string.isRequired,
|
|
133
|
-
linkColor: PropTypes.string.isRequired,
|
|
134
|
-
}).isRequired,
|
|
135
|
-
search: PropTypes.shape({
|
|
136
|
-
placeHolder: PropTypes.string.isRequired,
|
|
137
|
-
minLength: PropTypes.number.isRequired,
|
|
138
|
-
}).isRequired,
|
|
139
|
-
}).isRequired,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
AlphaBoxComponent.displayName = 'AlphaBoxComponent';
|
|
143
|
-
export default AlphaBoxComponent;
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import AlphaBoxContentComponent from './AlphaBoxContentComponent';
|
|
5
|
+
import AUAutoSuggestComponent from '../../../components/AUAutoSuggestComponent';
|
|
6
|
+
import DataBoxSuggestionComponent from '../databox/DataBoxSuggestionComponent';
|
|
7
|
+
|
|
8
|
+
class AlphaBoxComponent extends React.Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
|
|
12
|
+
this.state = {
|
|
13
|
+
items: [],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
this.getSuggestions = this.getSuggestions.bind(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
componentDidMount() {
|
|
20
|
+
const { box } = this.props;
|
|
21
|
+
const { data } = box;
|
|
22
|
+
if (data.mode === 'json' && data.source !== '') {
|
|
23
|
+
if (data.itemsOnly) {
|
|
24
|
+
data.source += '?itemsOnly=true';
|
|
25
|
+
}
|
|
26
|
+
fetch(data.source).then((promise) => promise.json()).then((pData) => {
|
|
27
|
+
this.setState({ items: pData.items });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getSuggestions(value, _, callback) {
|
|
33
|
+
const { items } = this.state;
|
|
34
|
+
const inputValue = value.trim().toLowerCase();
|
|
35
|
+
const inputLength = inputValue.length;
|
|
36
|
+
callback(inputLength < 2 ? []
|
|
37
|
+
: items.filter(
|
|
38
|
+
(x) => x.name.toLowerCase().indexOf(inputValue) > -1
|
|
39
|
+
|| x.name.replace(/-/ig, ' ').toLowerCase().indexOf(inputValue) > -1
|
|
40
|
+
|| x.name.replace(/ /ig, '-').toLowerCase().indexOf(inputValue) > -1,
|
|
41
|
+
)
|
|
42
|
+
.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase(), 'da', { ignorePunctuation: true })));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
render() {
|
|
46
|
+
const { box } = this.props;
|
|
47
|
+
const { items } = this.state;
|
|
48
|
+
const { config } = box;
|
|
49
|
+
const renderLinks = config.links.map((l) => (
|
|
50
|
+
<li key={l.title}>
|
|
51
|
+
<a
|
|
52
|
+
href={l.url}
|
|
53
|
+
onClick={() => {
|
|
54
|
+
if (typeof l.onClick === 'function') {
|
|
55
|
+
l.onClick();
|
|
56
|
+
}
|
|
57
|
+
}}
|
|
58
|
+
style={{ backgroundColor: box.background.linkColor }}
|
|
59
|
+
>
|
|
60
|
+
{l.title}
|
|
61
|
+
</a>
|
|
62
|
+
</li>
|
|
63
|
+
));
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className="au_alphabox" style={{ backgroundColor: box.background.color }}>
|
|
67
|
+
<div>
|
|
68
|
+
<h2>
|
|
69
|
+
<a href={config.url}>{config.title}</a>
|
|
70
|
+
</h2>
|
|
71
|
+
<AlphaBoxContentComponent
|
|
72
|
+
items={items}
|
|
73
|
+
linkColor={box.background.linkColor}
|
|
74
|
+
noResultsText={config.noResultsAlphabet}
|
|
75
|
+
noResultsUri={config.noResultsUri}
|
|
76
|
+
/>
|
|
77
|
+
<AUAutoSuggestComponent
|
|
78
|
+
placeholder={box.search.placeHolder}
|
|
79
|
+
setResults={(_items) => {
|
|
80
|
+
if (_items.length >= 1 && _items[0].url) {
|
|
81
|
+
window.location.href = _items[0].url;
|
|
82
|
+
}
|
|
83
|
+
}}
|
|
84
|
+
collection={[]}
|
|
85
|
+
getSuggestions={this.getSuggestions}
|
|
86
|
+
getSuggestionValue={(suggestion) => suggestion.name}
|
|
87
|
+
renderSuggestion={(suggestion) => <DataBoxSuggestionComponent item={suggestion} />}
|
|
88
|
+
noResultsText={config.noResultsSearch}
|
|
89
|
+
/>
|
|
90
|
+
{
|
|
91
|
+
config.description !== '' && (
|
|
92
|
+
<h3>{config.description}</h3>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
{
|
|
96
|
+
config.links.length > 0 && (
|
|
97
|
+
<ul className="quicklinks resetlist">
|
|
98
|
+
{renderLinks}
|
|
99
|
+
</ul>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
AlphaBoxComponent.propTypes = {
|
|
109
|
+
box: PropTypes.shape({
|
|
110
|
+
id: PropTypes.number.isRequired,
|
|
111
|
+
data: PropTypes.shape({
|
|
112
|
+
itemsOnly: PropTypes.bool.isRequired,
|
|
113
|
+
mode: PropTypes.string.isRequired,
|
|
114
|
+
source: PropTypes.string.isRequired,
|
|
115
|
+
}),
|
|
116
|
+
config: PropTypes.shape({
|
|
117
|
+
name: PropTypes.string.isRequired,
|
|
118
|
+
url: PropTypes.string.isRequired,
|
|
119
|
+
description: PropTypes.string.isRequired,
|
|
120
|
+
container: PropTypes.string.isRequired,
|
|
121
|
+
tracking: PropTypes.string.isRequired,
|
|
122
|
+
links: PropTypes.arrayOf(PropTypes.shape({
|
|
123
|
+
title: PropTypes.string.isRequired,
|
|
124
|
+
url: PropTypes.string.isRequired,
|
|
125
|
+
})).isRequired,
|
|
126
|
+
title: PropTypes.string.isRequired,
|
|
127
|
+
noResultsAlphabet: PropTypes.string.isRequired,
|
|
128
|
+
noResultsSearch: PropTypes.string.isRequired,
|
|
129
|
+
noResultsUri: PropTypes.string.isRequired,
|
|
130
|
+
}).isRequired,
|
|
131
|
+
background: PropTypes.shape({
|
|
132
|
+
color: PropTypes.string.isRequired,
|
|
133
|
+
linkColor: PropTypes.string.isRequired,
|
|
134
|
+
}).isRequired,
|
|
135
|
+
search: PropTypes.shape({
|
|
136
|
+
placeHolder: PropTypes.string.isRequired,
|
|
137
|
+
minLength: PropTypes.number.isRequired,
|
|
138
|
+
}).isRequired,
|
|
139
|
+
}).isRequired,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
AlphaBoxComponent.displayName = 'AlphaBoxComponent';
|
|
143
|
+
export default AlphaBoxComponent;
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { sortAlphaObj } from '../../../lib/helpers';
|
|
4
|
-
|
|
5
|
-
class AlphaBoxContentComponent extends React.Component {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props);
|
|
8
|
-
this.letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'æ', 'ø', 'å'];
|
|
9
|
-
this.state = {
|
|
10
|
-
letterIndex: -1,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
render() {
|
|
15
|
-
const { letterIndex } = this.state;
|
|
16
|
-
const {
|
|
17
|
-
items, linkColor, noResultsText, noResultsUri,
|
|
18
|
-
} = this.props;
|
|
19
|
-
|
|
20
|
-
const renderLetters = this.letters.map((l, i) => {
|
|
21
|
-
const available = items.filter(
|
|
22
|
-
(x) => x.name.toLowerCase().indexOf(l) === 0,
|
|
23
|
-
).length > 0;
|
|
24
|
-
|
|
25
|
-
let classNames = '';
|
|
26
|
-
if (available) {
|
|
27
|
-
classNames += 'available';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (i === letterIndex) {
|
|
31
|
-
classNames += ' active';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let style = {};
|
|
35
|
-
if (available) {
|
|
36
|
-
if (letterIndex === i) {
|
|
37
|
-
style = { backgroundColor: '#fff', color: linkColor };
|
|
38
|
-
} else {
|
|
39
|
-
style = { backgroundColor: linkColor };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<li
|
|
45
|
-
key={l}
|
|
46
|
-
className={classNames}
|
|
47
|
-
>
|
|
48
|
-
<button
|
|
49
|
-
type="button"
|
|
50
|
-
style={style}
|
|
51
|
-
onClick={() => {
|
|
52
|
-
if (available) {
|
|
53
|
-
this.setState({
|
|
54
|
-
letterIndex: i,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}}
|
|
58
|
-
>
|
|
59
|
-
{l}
|
|
60
|
-
</button>
|
|
61
|
-
</li>
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
let filtered = [];
|
|
66
|
-
if (letterIndex > -1) {
|
|
67
|
-
filtered = items.filter(
|
|
68
|
-
(x) => x.name.toLowerCase().indexOf(this.letters[letterIndex]) === 0,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const renderItems = filtered.sort(sortAlphaObj).map((item, i) => {
|
|
73
|
-
const key = i;
|
|
74
|
-
const renderChildren = item.children.map(
|
|
75
|
-
(c) => <li key={c.name}><a href={c.url}>{c.name}</a></li>,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
if (item.children.length > 0) {
|
|
79
|
-
return (
|
|
80
|
-
<li key={key}>
|
|
81
|
-
<a href={item.url}>{item.name}</a>
|
|
82
|
-
<ul>
|
|
83
|
-
{renderChildren}
|
|
84
|
-
</ul>
|
|
85
|
-
</li>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<li key={key}>
|
|
91
|
-
<a href={item.url}>{item.name}</a>
|
|
92
|
-
</li>
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<div className="au_alphabox_content">
|
|
98
|
-
<ul className="letters">
|
|
99
|
-
{renderLetters}
|
|
100
|
-
</ul>
|
|
101
|
-
{
|
|
102
|
-
letterIndex > -1 && (
|
|
103
|
-
<div>
|
|
104
|
-
<ul className="items">
|
|
105
|
-
{renderItems}
|
|
106
|
-
{
|
|
107
|
-
(noResultsText && noResultsUri) && (
|
|
108
|
-
<li className="no-results"><a href={noResultsUri}>{noResultsText}</a></li>
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
</ul>
|
|
112
|
-
</div>
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
</div>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
AlphaBoxContentComponent.defaultProps = {
|
|
121
|
-
noResultsText: '',
|
|
122
|
-
noResultsUri: '',
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
AlphaBoxContentComponent.propTypes = {
|
|
126
|
-
linkColor: PropTypes.string.isRequired,
|
|
127
|
-
items: PropTypes.arrayOf(PropTypes.shape({
|
|
128
|
-
name: PropTypes.string.isRequired,
|
|
129
|
-
url: PropTypes.string.isRequired,
|
|
130
|
-
})).isRequired,
|
|
131
|
-
noResultsText: PropTypes.string,
|
|
132
|
-
noResultsUri: PropTypes.string,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
AlphaBoxContentComponent.displayName = 'AlphaBoxContentComponent';
|
|
136
|
-
export default AlphaBoxContentComponent;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { sortAlphaObj } from '../../../lib/helpers';
|
|
4
|
+
|
|
5
|
+
class AlphaBoxContentComponent extends React.Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'æ', 'ø', 'å'];
|
|
9
|
+
this.state = {
|
|
10
|
+
letterIndex: -1,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
render() {
|
|
15
|
+
const { letterIndex } = this.state;
|
|
16
|
+
const {
|
|
17
|
+
items, linkColor, noResultsText, noResultsUri,
|
|
18
|
+
} = this.props;
|
|
19
|
+
|
|
20
|
+
const renderLetters = this.letters.map((l, i) => {
|
|
21
|
+
const available = items.filter(
|
|
22
|
+
(x) => x.name.toLowerCase().indexOf(l) === 0,
|
|
23
|
+
).length > 0;
|
|
24
|
+
|
|
25
|
+
let classNames = '';
|
|
26
|
+
if (available) {
|
|
27
|
+
classNames += 'available';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (i === letterIndex) {
|
|
31
|
+
classNames += ' active';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let style = {};
|
|
35
|
+
if (available) {
|
|
36
|
+
if (letterIndex === i) {
|
|
37
|
+
style = { backgroundColor: '#fff', color: linkColor };
|
|
38
|
+
} else {
|
|
39
|
+
style = { backgroundColor: linkColor };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<li
|
|
45
|
+
key={l}
|
|
46
|
+
className={classNames}
|
|
47
|
+
>
|
|
48
|
+
<button
|
|
49
|
+
type="button"
|
|
50
|
+
style={style}
|
|
51
|
+
onClick={() => {
|
|
52
|
+
if (available) {
|
|
53
|
+
this.setState({
|
|
54
|
+
letterIndex: i,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{l}
|
|
60
|
+
</button>
|
|
61
|
+
</li>
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let filtered = [];
|
|
66
|
+
if (letterIndex > -1) {
|
|
67
|
+
filtered = items.filter(
|
|
68
|
+
(x) => x.name.toLowerCase().indexOf(this.letters[letterIndex]) === 0,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const renderItems = filtered.sort(sortAlphaObj).map((item, i) => {
|
|
73
|
+
const key = i;
|
|
74
|
+
const renderChildren = item.children.map(
|
|
75
|
+
(c) => <li key={c.name}><a href={c.url}>{c.name}</a></li>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if (item.children.length > 0) {
|
|
79
|
+
return (
|
|
80
|
+
<li key={key}>
|
|
81
|
+
<a href={item.url}>{item.name}</a>
|
|
82
|
+
<ul>
|
|
83
|
+
{renderChildren}
|
|
84
|
+
</ul>
|
|
85
|
+
</li>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<li key={key}>
|
|
91
|
+
<a href={item.url}>{item.name}</a>
|
|
92
|
+
</li>
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div className="au_alphabox_content">
|
|
98
|
+
<ul className="letters">
|
|
99
|
+
{renderLetters}
|
|
100
|
+
</ul>
|
|
101
|
+
{
|
|
102
|
+
letterIndex > -1 && (
|
|
103
|
+
<div>
|
|
104
|
+
<ul className="items">
|
|
105
|
+
{renderItems}
|
|
106
|
+
{
|
|
107
|
+
(noResultsText && noResultsUri) && (
|
|
108
|
+
<li className="no-results"><a href={noResultsUri}>{noResultsText}</a></li>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
</ul>
|
|
112
|
+
</div>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
AlphaBoxContentComponent.defaultProps = {
|
|
121
|
+
noResultsText: '',
|
|
122
|
+
noResultsUri: '',
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
AlphaBoxContentComponent.propTypes = {
|
|
126
|
+
linkColor: PropTypes.string.isRequired,
|
|
127
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
|
128
|
+
name: PropTypes.string.isRequired,
|
|
129
|
+
url: PropTypes.string.isRequired,
|
|
130
|
+
})).isRequired,
|
|
131
|
+
noResultsText: PropTypes.string,
|
|
132
|
+
noResultsUri: PropTypes.string,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
AlphaBoxContentComponent.displayName = 'AlphaBoxContentComponent';
|
|
136
|
+
export default AlphaBoxContentComponent;
|