@eeacms/volto-eea-design-system 0.6.5 → 0.7.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.
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { Transition } from 'semantic-ui-react';
2
3
  import {
3
4
  Container,
4
5
  Divider,
@@ -11,7 +12,7 @@ import {
11
12
  import { Link } from 'react-router-dom';
12
13
  import { useClickOutside } from '@eeacms/volto-eea-design-system/helpers';
13
14
 
14
- const createColumns = (item, length) => {
15
+ const createColumns = (item, length, renderMenuItem) => {
15
16
  let subArrays = [];
16
17
  let size = length;
17
18
  for (let i = 0; i < item.items.length; i += size) {
@@ -22,9 +23,13 @@ const createColumns = (item, length) => {
22
23
  <Grid.Column key={index}>
23
24
  <List>
24
25
  {subArray.map((arrayItem, idx) => (
25
- <Link role="listitem" className="item" to={arrayItem.url} key={idx}>
26
- {arrayItem.title}
27
- </Link>
26
+ <React.Fragment key={idx}>
27
+ {renderMenuItem(arrayItem, {
28
+ className: 'item',
29
+ role: 'listitem',
30
+ key: idx,
31
+ })}
32
+ </React.Fragment>
28
33
  ))}
29
34
  </List>
30
35
  </Grid.Column>
@@ -33,42 +38,57 @@ const createColumns = (item, length) => {
33
38
  return column;
34
39
  };
35
40
 
36
- const ItemGrid = ({ item, columns, length }) => (
41
+ const ItemGrid = ({ item, columns, length, renderMenuItem }) => (
37
42
  <>
38
- <Link className="sub-title" to={item.url}>
39
- {item.title}
40
- </Link>
41
- <Grid columns={columns}>{createColumns(item, length)}</Grid>
43
+ {renderMenuItem(item, { className: 'sub-title' })}
44
+ <Grid columns={columns}>{createColumns(item, length, renderMenuItem)}</Grid>
42
45
  </>
43
46
  );
44
47
 
45
- const Item = ({ item, icon = false, iconName }) => (
48
+ const Item = ({ item, icon = false, iconName, renderMenuItem }) => (
46
49
  <>
47
- <Link className="sub-title" to={item.url}>
48
- {item.title}
49
- </Link>
50
+ {renderMenuItem(item, { className: 'sub-title' })}
50
51
  <List className="menu-list">
51
52
  {item.items.map((listItem, index) => (
52
- <Link role="listitem" className="item" to={listItem.url} key={index}>
53
- {icon && <Icon className={iconName} />}
54
- {listItem.title}
55
- </Link>
53
+ <React.Fragment key={index}>
54
+ {renderMenuItem(
55
+ listItem,
56
+ {
57
+ className: 'item',
58
+ key: index,
59
+ role: 'listitem',
60
+ },
61
+ { children: icon && <Icon className={iconName} /> },
62
+ )}
63
+ </React.Fragment>
56
64
  ))}
57
65
  </List>
58
66
  </>
59
67
  );
60
68
 
61
- const Topics = ({ menuItem }) => (
69
+ const Topics = ({ menuItem, renderMenuItem }) => (
62
70
  <Grid>
63
71
  {menuItem.items.map((section, index) => (
64
72
  <React.Fragment key={index}>
65
73
  {section.title === 'At a glance' ? (
66
74
  <Grid.Column width={3} id="at-a-glance">
67
- <Item item={section} icon={true} iconName="ri-leaf-line" />
75
+ <Item
76
+ item={section}
77
+ icon={true}
78
+ iconName="ri-leaf-line"
79
+ key={index}
80
+ renderMenuItem={renderMenuItem}
81
+ />
68
82
  </Grid.Column>
69
83
  ) : (
70
84
  <Grid.Column width={9} key={index}>
71
- <ItemGrid item={section} columns={4} length={10} />
85
+ <ItemGrid
86
+ item={section}
87
+ columns={4}
88
+ length={10}
89
+ key={index}
90
+ renderMenuItem={renderMenuItem}
91
+ />
72
92
  </Grid.Column>
73
93
  )}
74
94
  </React.Fragment>
@@ -76,13 +96,18 @@ const Topics = ({ menuItem }) => (
76
96
  </Grid>
77
97
  );
78
98
 
79
- const Countries = ({ menuItem }) => (
99
+ const Countries = ({ menuItem, renderMenuItem }) => (
80
100
  <Grid>
81
101
  <Grid.Column width={8}>
82
102
  {menuItem.items.map((section, index) => (
83
103
  <React.Fragment key={index}>
84
104
  {section.title === 'EEA member countries' && (
85
- <ItemGrid item={section} columns={5} length={7} />
105
+ <ItemGrid
106
+ item={section}
107
+ columns={5}
108
+ length={7}
109
+ renderMenuItem={renderMenuItem}
110
+ />
86
111
  )}
87
112
  </React.Fragment>
88
113
  ))}
@@ -93,7 +118,12 @@ const Countries = ({ menuItem }) => (
93
118
  <React.Fragment key={index}>
94
119
  {section.title !== 'EEA member countries' && (
95
120
  <Grid.Column>
96
- <ItemGrid item={section} columns={2} length={3} />
121
+ <ItemGrid
122
+ item={section}
123
+ columns={2}
124
+ length={3}
125
+ renderMenuItem={renderMenuItem}
126
+ />
97
127
  </Grid.Column>
98
128
  )}
99
129
  </React.Fragment>
@@ -103,46 +133,62 @@ const Countries = ({ menuItem }) => (
103
133
  </Grid>
104
134
  );
105
135
 
106
- const StandardMegaMenuGrid = ({ menuItem }) => (
136
+ const StandardMegaMenuGrid = ({ menuItem, renderMenuItem }) => (
107
137
  <Grid columns={4}>
108
138
  {menuItem.items.map((section, index) => (
109
139
  <Grid.Column key={index}>
110
- <Item item={section} />
140
+ <Item item={section} renderMenuItem={renderMenuItem} />
111
141
  </Grid.Column>
112
142
  ))}
113
143
  </Grid>
114
144
  );
115
145
 
116
- const FirstLevelContent = ({ element }) => {
146
+ const FirstLevelContent = ({ element, renderMenuItem, pathName }) => {
117
147
  const topics = element.title === 'Topics' ? true : false;
148
+ let defaultIndex = -1;
118
149
 
119
150
  const firstLevelPanels = [];
120
151
  let content;
121
152
  if (!topics) {
122
153
  element.items.forEach((item, index) => {
123
154
  let x = {};
124
- x.key = item['@id'];
155
+ x.key = item['@id'] || item['url'];
156
+ if (pathName.indexOf(item.url) !== -1) {
157
+ defaultIndex = index;
158
+ }
125
159
  x.title = (
126
- <Accordion.Title key={`title=${index}`}>
160
+ <Accordion.Title key={`title=${index}`} index={index}>
127
161
  {item.title}
128
162
  <Icon className="ri-arrow-down-s-line" size="small" />
129
163
  </Accordion.Title>
130
164
  );
131
165
  x.content = (
132
166
  <Accordion.Content key={index}>
133
- <SecondLevelContent element={item} />
167
+ {renderMenuItem(item, { className: 'item title-item' })}
168
+ <SecondLevelContent element={item} renderMenuItem={renderMenuItem} />
134
169
  </Accordion.Content>
135
170
  );
136
171
  firstLevelPanels.push(x);
137
172
  });
138
- content = <Accordion.Accordion panels={firstLevelPanels} />;
173
+ content = (
174
+ <Accordion.Accordion
175
+ defaultActiveIndex={defaultIndex}
176
+ panels={firstLevelPanels}
177
+ />
178
+ );
139
179
  } else {
140
- content = <SecondLevelContent element={element} topics={true} />;
180
+ content = (
181
+ <SecondLevelContent
182
+ element={element}
183
+ topics={true}
184
+ renderMenuItem={renderMenuItem}
185
+ />
186
+ );
141
187
  }
142
188
  return <>{content}</>;
143
189
  };
144
190
 
145
- const SecondLevelContent = ({ element, topics = false }) => {
191
+ const SecondLevelContent = ({ element, topics = false, renderMenuItem }) => {
146
192
  let content;
147
193
  if (topics) {
148
194
  const atAGlance = element.items.find(
@@ -152,9 +198,13 @@ const SecondLevelContent = ({ element, topics = false }) => {
152
198
  <List>
153
199
  {atAGlance &&
154
200
  atAGlance.items.map((item, index) => (
155
- <Link role="listitem" className="item" to={item.url} key={index}>
156
- {item.title}
157
- </Link>
201
+ <React.Fragment key={index}>
202
+ {renderMenuItem(item, {
203
+ key: index,
204
+ role: 'listitem',
205
+ className: 'item',
206
+ })}
207
+ </React.Fragment>
158
208
  ))}
159
209
  <Link
160
210
  role="listitem"
@@ -170,9 +220,13 @@ const SecondLevelContent = ({ element, topics = false }) => {
170
220
  content = (
171
221
  <List>
172
222
  {element.items.map((item, index) => (
173
- <Link role="listitem" className="item" to={item.url} key={index}>
174
- {item.title}
175
- </Link>
223
+ <React.Fragment key={index}>
224
+ {renderMenuItem(item, {
225
+ key: index,
226
+ role: 'listitem',
227
+ className: 'item',
228
+ })}
229
+ </React.Fragment>
176
230
  ))}
177
231
  </List>
178
232
  );
@@ -181,29 +235,47 @@ const SecondLevelContent = ({ element, topics = false }) => {
181
235
  return <>{content}</>;
182
236
  };
183
237
 
184
- const NestedAccordion = ({ menuItems }) => {
238
+ const NestedAccordion = ({ menuItems, renderMenuItem, pathName }) => {
239
+ let defaultIndex = -1;
185
240
  const rootPanels = [];
186
241
  menuItems.forEach((element, index) => {
187
242
  let x = {};
188
243
  x.key = index;
244
+
245
+ if (pathName.indexOf(element.url) !== -1) {
246
+ defaultIndex = index;
247
+ }
189
248
  x.title = (
190
- <Accordion.Title key={`title-${index}`}>
249
+ <Accordion.Title key={`title-${index}`} index={index}>
191
250
  {element.title}
192
251
  <Icon className="ri-arrow-down-s-line" size="small" />
193
252
  </Accordion.Title>
194
253
  );
195
254
  x.content = (
196
255
  <Accordion.Content key={index}>
197
- <FirstLevelContent element={element} />
256
+ {renderMenuItem(element, { className: 'item' })}
257
+ <FirstLevelContent
258
+ element={element}
259
+ renderMenuItem={renderMenuItem}
260
+ pathName={pathName}
261
+ />
198
262
  </Accordion.Content>
199
263
  );
200
264
  rootPanels.push(x);
201
265
  });
202
266
 
203
- return <Accordion panels={rootPanels} />;
267
+ return <Accordion defaultActiveIndex={defaultIndex} panels={rootPanels} />;
204
268
  };
205
269
 
206
- function HeaderMenuPopUp({ menuItems, onClose, triggerRefs, activeItem }) {
270
+ function HeaderMenuPopUp({
271
+ menuItems,
272
+ renderMenuItem,
273
+ pathName,
274
+ onClose,
275
+ triggerRefs,
276
+ activeItem,
277
+ visible,
278
+ }) {
207
279
  const nodeRef = React.useRef();
208
280
  useClickOutside({ targetRefs: [nodeRef, ...triggerRefs], callback: onClose });
209
281
 
@@ -212,29 +284,38 @@ function HeaderMenuPopUp({ menuItems, onClose, triggerRefs, activeItem }) {
212
284
  );
213
285
 
214
286
  return (
215
- <div id="mega-menu" ref={nodeRef}>
216
- <Container>
217
- {menuItem && (
218
- <div className="menu-content tablet hidden mobile hidden">
219
- <h3 className="title">
220
- <Link to={menuItem.url}>{menuItem.title}</Link>
221
- </h3>
222
- <Divider fitted />
223
- {menuItem.title === 'Topics' ? (
224
- <Topics menuItem={menuItem} />
225
- ) : menuItem.title === 'Countries' ? (
226
- <Countries menuItem={menuItem} />
227
- ) : (
228
- <StandardMegaMenuGrid menuItem={menuItem} />
229
- )}
287
+ <Transition visible={visible} animation="slide down" duration={300}>
288
+ <div id="mega-menu" ref={nodeRef}>
289
+ <Container>
290
+ {menuItem && (
291
+ <div className="menu-content tablet hidden mobile hidden">
292
+ <h3 className="title">{renderMenuItem(menuItem)}</h3>
293
+ <Divider fitted />
294
+ {menuItem.title === 'Topics' ? (
295
+ <Topics menuItem={menuItem} renderMenuItem={renderMenuItem} />
296
+ ) : menuItem.title === 'Countries' ? (
297
+ <Countries
298
+ menuItem={menuItem}
299
+ renderMenuItem={renderMenuItem}
300
+ />
301
+ ) : (
302
+ <StandardMegaMenuGrid
303
+ menuItem={menuItem}
304
+ renderMenuItem={renderMenuItem}
305
+ />
306
+ )}
307
+ </div>
308
+ )}
309
+ <div className="tablet only mobile only">
310
+ <NestedAccordion
311
+ menuItems={menuItems}
312
+ renderMenuItem={renderMenuItem}
313
+ pathName={pathName}
314
+ />
230
315
  </div>
231
- )}
232
-
233
- <div className="tablet only mobile only">
234
- <NestedAccordion menuItems={menuItems} />
235
- </div>
236
- </Container>
237
- </div>
316
+ </Container>
317
+ </div>
318
+ </Transition>
238
319
  );
239
320
  }
240
321
 
@@ -3,7 +3,7 @@ import { Container, Input } from 'semantic-ui-react';
3
3
 
4
4
  import { useClickOutside } from '@eeacms/volto-eea-design-system/helpers';
5
5
 
6
- function HeaderSearchPopUp({ onClose, triggerRefs = [] }) {
6
+ function HeaderSearchPopUp({ onClose, searchInputRef, triggerRefs = [] }) {
7
7
  const nodeRef = React.useRef();
8
8
 
9
9
  useClickOutside({ targetRefs: [nodeRef, ...triggerRefs], callback: onClose });
@@ -13,6 +13,7 @@ function HeaderSearchPopUp({ onClose, triggerRefs = [] }) {
13
13
  <Container>
14
14
  <div className="wrapper">
15
15
  <Input
16
+ ref={searchInputRef}
16
17
  className="search"
17
18
  icon={{ className: 'ri-search-line', link: true }}
18
19
  placeholder="Search..."
@@ -77,23 +77,38 @@
77
77
  @main : 'eea';
78
78
  @custom : 'eea';
79
79
  /* EEA Design system custom components */
80
- @blockquote : 'eea';
81
- @quote : 'eea';
82
- @banner : 'eea';
83
- @timeline : 'eea';
84
- @footer : 'eea';
85
- @header : 'eea';
86
- @tag : 'eea';
80
+ @blockquote : 'eea';
81
+ @pullquote : 'eea';
82
+ @banner : 'eea';
83
+ @timeline : 'eea';
84
+ @footer : 'eea';
85
+ @header : 'eea';
86
+ @tag : 'eea';
87
+ @tags : 'eea';
88
+ @tagList : 'eea';
87
89
  @inpageNavigation : 'eea';
88
- @testimonial : 'eea';
89
- @avatarGrid : 'eea';
90
- @keyContent : 'eea';
90
+ @contextNavigation : 'eea';
91
+ @avatar : 'eea';
92
+ @divider : 'eea';
93
+ @testimonial : 'eea';
94
+ @avatarGrid : 'eea';
95
+ @keyContent : 'eea';
91
96
  @publicationCard : 'eea';
97
+ @contentBox : 'eea';
98
+ @reverseCardGrid : 'eea';
99
+ @relatedContent : 'eea';
100
+ @share : 'eea';
101
+ @faqContent : 'eea';
102
+ @reportCard : 'eea';
103
+ @faqFilter : 'eea';
104
+ @contentAccordion : 'eea';
92
105
  @downloadLabeledIcon :'eea';
93
106
  @newTabLabeledIcon : 'eea';
94
107
  @labeledIconGroup : 'eea';
95
108
  @languageLabeledIcon : 'eea';
96
- @relatedContent : 'eea';
109
+ @callout : 'eea';
110
+ @quote : 'eea';
111
+ @hero : 'eea';
97
112
 
98
113
  /*******************************
99
114
  Folders