@ndla/ui 23.0.0 → 24.0.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.
Files changed (95) hide show
  1. package/es/Article/ArticleAuthorContent.js +2 -4
  2. package/es/AuthorInfo/AuthorInfo.js +29 -16
  3. package/es/ContentCard/ContentCard.js +66 -25
  4. package/es/FileList/File.js +34 -8
  5. package/es/FileList/FileList.js +29 -3
  6. package/es/InfoBox/InfoBox.js +10 -3
  7. package/es/InfoWidget/InfoWidget.js +67 -22
  8. package/es/Portrait/Portrait.js +19 -13
  9. package/es/Search/ActiveFilterContent.js +4 -14
  10. package/es/Search/ActiveFilters.js +8 -19
  11. package/es/Search/SearchField.js +31 -52
  12. package/es/Search/SearchResult.js +113 -136
  13. package/es/Search/ToggleSearchButton.js +34 -43
  14. package/es/Search/index.js +2 -8
  15. package/es/all.css +1 -1
  16. package/es/index-javascript.js +0 -1
  17. package/es/index.js +2 -1
  18. package/lib/Article/ArticleAuthorContent.js +9 -4
  19. package/lib/AuthorInfo/AuthorInfo.d.ts +1 -11
  20. package/lib/AuthorInfo/AuthorInfo.js +36 -20
  21. package/lib/ContentCard/ContentCard.d.ts +1 -15
  22. package/lib/ContentCard/ContentCard.js +60 -28
  23. package/lib/FileList/File.js +36 -12
  24. package/lib/FileList/FileList.js +28 -5
  25. package/lib/InfoBox/InfoBox.js +11 -4
  26. package/lib/InfoWidget/InfoWidget.js +61 -25
  27. package/lib/Portrait/Portrait.js +19 -14
  28. package/lib/Search/ActiveFilterContent.d.ts +13 -0
  29. package/lib/Search/ActiveFilterContent.js +4 -15
  30. package/lib/Search/ActiveFilters.d.ts +13 -0
  31. package/lib/Search/ActiveFilters.js +8 -20
  32. package/lib/Search/SearchField.d.ts +19 -0
  33. package/lib/Search/SearchField.js +32 -56
  34. package/lib/Search/SearchResult.d.ts +36 -0
  35. package/lib/Search/SearchResult.js +116 -159
  36. package/lib/Search/ToggleSearchButton.d.ts +16 -0
  37. package/lib/Search/ToggleSearchButton.js +36 -46
  38. package/lib/Search/index.d.ts +12 -0
  39. package/lib/Search/index.js +0 -54
  40. package/lib/SearchTypeResult/SearchTypeHeader.d.ts +1 -1
  41. package/lib/all.css +1 -1
  42. package/lib/index-javascript.js +0 -74
  43. package/lib/index.d.ts +1 -0
  44. package/lib/index.js +38 -1
  45. package/package.json +5 -5
  46. package/src/Article/ArticleAuthorContent.tsx +1 -1
  47. package/src/AuthorInfo/AuthorInfo.tsx +53 -19
  48. package/src/ContentCard/ContentCard.tsx +127 -35
  49. package/src/FileList/File.tsx +47 -17
  50. package/src/FileList/FileList.tsx +37 -8
  51. package/src/InfoBox/InfoBox.tsx +24 -4
  52. package/src/InfoWidget/InfoWidget.tsx +83 -34
  53. package/src/Portrait/Portrait.tsx +25 -10
  54. package/src/Search/{ActiveFilterContent.jsx → ActiveFilterContent.tsx} +11 -12
  55. package/src/Search/{ActiveFilters.jsx → ActiveFilters.tsx} +20 -17
  56. package/src/Search/{SearchField.jsx → SearchField.tsx} +58 -68
  57. package/src/Search/SearchResult.tsx +360 -0
  58. package/src/Search/ToggleSearchButton.tsx +73 -0
  59. package/src/Search/component.search.scss +0 -4
  60. package/src/Search/index.ts +16 -0
  61. package/src/all.scss +0 -1
  62. package/src/index-javascript.js +0 -15
  63. package/src/index.ts +2 -0
  64. package/src/main.scss +0 -6
  65. package/es/Search/SearchFilter.js +0 -72
  66. package/es/Search/SearchFilterList.js +0 -115
  67. package/es/Search/SearchOverlay.js +0 -39
  68. package/es/Search/SearchPage.js +0 -178
  69. package/es/Search/SearchPopoverFilter.js +0 -152
  70. package/es/Search/SearchResultAuthor.js +0 -51
  71. package/lib/Search/SearchFilter.js +0 -88
  72. package/lib/Search/SearchFilterList.js +0 -137
  73. package/lib/Search/SearchOverlay.js +0 -62
  74. package/lib/Search/SearchPage.js +0 -207
  75. package/lib/Search/SearchPopoverFilter.js +0 -172
  76. package/lib/Search/SearchResultAuthor.js +0 -60
  77. package/src/AuthorInfo/component.author-info.scss +0 -54
  78. package/src/ContentCard/component.content-card.scss +0 -109
  79. package/src/FileList/component.file-list.scss +0 -102
  80. package/src/InfoBox/component.info-box.scss +0 -21
  81. package/src/InfoWidget/component.info-widget.scss +0 -52
  82. package/src/Portrait/component.portrait.scss +0 -29
  83. package/src/Search/SearchFilter.jsx +0 -82
  84. package/src/Search/SearchFilterList.jsx +0 -110
  85. package/src/Search/SearchOverlay.jsx +0 -38
  86. package/src/Search/SearchPage.jsx +0 -178
  87. package/src/Search/SearchPopoverFilter.jsx +0 -109
  88. package/src/Search/SearchResult.jsx +0 -239
  89. package/src/Search/SearchResultAuthor.jsx +0 -54
  90. package/src/Search/ToggleSearchButton.jsx +0 -64
  91. package/src/Search/component.search-filter.scss +0 -67
  92. package/src/Search/component.search-overlay.scss +0 -103
  93. package/src/Search/component.search-page.scss +0 -125
  94. package/src/Search/component.search-result-author.scss +0 -65
  95. package/src/Search/index.js +0 -34
@@ -0,0 +1,360 @@
1
+ import React, { ElementType, Fragment, ReactNode } from 'react';
2
+ import { ChevronRight } from '@ndla/icons/common';
3
+ import { uuid } from '@ndla/util';
4
+ import { useTranslation } from 'react-i18next';
5
+ import Tooltip from '@ndla/tooltip';
6
+ import SafeLink from '@ndla/safelink';
7
+ import { Spinner } from '@ndla/icons';
8
+ import styled from '@emotion/styled';
9
+ import { fonts, mq, spacing, breakpoints, colors, spacingUnit } from '@ndla/core';
10
+
11
+ interface ItemType {
12
+ id: string | number;
13
+ title?: string;
14
+ url?: string | { href: string };
15
+ breadcrumb?: string[];
16
+ subjects?: {
17
+ title: string;
18
+ url?: string | { href: string };
19
+ breadcrumb?: string[];
20
+ }[];
21
+ additional?: boolean;
22
+ image?: ReactNode;
23
+ ingress: string;
24
+ contentTypeIcon?: string;
25
+ contentTypeLabel?: string;
26
+ children?: ReactNode;
27
+ type?: string;
28
+ }
29
+
30
+ interface SearchResultItemProps {
31
+ children?: ReactNode;
32
+ subjectsLabel: string;
33
+ additionalContentTooltip: string;
34
+ item: ItemType;
35
+ }
36
+
37
+ const StyledHeader = styled.header`
38
+ display: flex;
39
+ flex-wrap: wrap;
40
+ align-items: center;
41
+
42
+ > * {
43
+ margin: 0 ${spacing.small} ${spacing.small} 0;
44
+ }
45
+
46
+ ${mq.range({ until: breakpoints.tablet })} {
47
+ h1 {
48
+ width: 100%;
49
+ }
50
+ }
51
+ `;
52
+
53
+ const ContentTypeWrapper = styled.div`
54
+ margin: 0 ${spacing.small} ${spacing.small} 0;
55
+ display: flex;
56
+ align-items: center;
57
+ `;
58
+
59
+ const PillsWrapper = styled.div`
60
+ background: ${colors.brand.greyLightest};
61
+ margin-right: ${spacing.small};
62
+ padding: 0 ${spacingUnit / 3}px;
63
+ border-radius: 50%;
64
+ ${fonts.sizes('12px', '20px')};
65
+ font-weight: ${fonts.weight.semibold};
66
+ `;
67
+
68
+ const StyledContent = styled.div`
69
+ display: flex;
70
+ align-items: flex-start;
71
+ justify-content: space-between;
72
+ & > img,
73
+ & > picture > img {
74
+ width: 75px;
75
+ height: auto;
76
+ flex-shrink: 0;
77
+ margin: 0 0 ${spacing.small} ${spacing.small};
78
+
79
+ ${mq.range({ from: breakpoints.tabletWide })} {
80
+ width: 80px;
81
+ margin-left: ${spacing.normal};
82
+ margin-right: ${spacing.small};
83
+ }
84
+ }
85
+ `;
86
+
87
+ const StyledIngress = styled.p`
88
+ margin: 0 0 ${spacing.normal} 0;
89
+ width: 100%;
90
+ flex-grow: 1;
91
+ ${fonts.sizes('14px', '22px')};
92
+
93
+ ${mq.range({ from: breakpoints.tablet })} {
94
+ ${fonts.sizes('16px', '24px')};
95
+ max-width: 550px;
96
+ }
97
+
98
+ ${mq.range({ from: breakpoints.desktop })} {
99
+ ${fonts.sizes('18px', '26px')};
100
+ max-width: 600px;
101
+ }
102
+ `;
103
+
104
+ const StyledSubjects = styled.div`
105
+ display: flex;
106
+ align-items: center;
107
+ flex-wrap: wrap;
108
+ margin-bottom: ${spacing.normal};
109
+ ${fonts.sizes('14px', '16px')};
110
+
111
+ ${mq.range({ from: breakpoints.desktop })} {
112
+ ${fonts.sizes('16px', '18px')};
113
+ }
114
+
115
+ & > span {
116
+ text-transform: uppercase;
117
+ color: ${colors.text.light};
118
+ padding-right: ${spacing.small};
119
+ ${fonts.sizes('14px', '16px')};
120
+ }
121
+
122
+ ul {
123
+ display: flex;
124
+ align-items: center;
125
+ flex-wrap: wrap;
126
+ list-style: none;
127
+ margin: 0;
128
+ padding: 0;
129
+ }
130
+
131
+ li {
132
+ margin: 0;
133
+ position: relative;
134
+ line-height: 1rem;
135
+
136
+ padding: 0 ${spacing.xsmall} 0 0;
137
+ margin-right: ${spacing.xsmall};
138
+
139
+ ${mq.range({ from: breakpoints.desktop })} {
140
+ padding: 0 ${spacing.small} 0 0;
141
+ margin-right: ${spacing.small};
142
+ }
143
+
144
+ &::after {
145
+ content: '';
146
+ width: 1px;
147
+ height: 15px;
148
+ background: ${colors.brand.greyLight};
149
+ display: block;
150
+ position: absolute;
151
+ right: 0;
152
+ top: 3px;
153
+ }
154
+ &:first-child {
155
+ font-weight: 600;
156
+ }
157
+
158
+ &:last-child {
159
+ &:after {
160
+ display: none;
161
+ }
162
+
163
+ margin-right: 0;
164
+ }
165
+ }
166
+ `;
167
+
168
+ const StyledSearchResultItem = styled.li`
169
+ border-bottom: 1px solid ${colors.brand.greyLight};
170
+ padding: 0 ${spacing.normal} 0 ${spacing.normal};
171
+
172
+ ${mq.range({ from: breakpoints.desktop })} {
173
+ padding: 0;
174
+ }
175
+
176
+ margin: 0 0 ${spacing.normal};
177
+
178
+ &:first-child {
179
+ margin-top: ${spacing.normal};
180
+ }
181
+
182
+ &:last-child {
183
+ border-bottom: 0;
184
+ margin-bottom: 0;
185
+ }
186
+
187
+ h1 {
188
+ font-weight: 600;
189
+ ${fonts.sizes('16px', '20px')};
190
+
191
+ ${mq.range({ from: breakpoints.desktop })} {
192
+ ${fonts.sizes('22px', '28px')};
193
+ }
194
+
195
+ a {
196
+ color: ${colors.brand.dark};
197
+
198
+ &:hover,
199
+ &:focus,
200
+ &:active {
201
+ color: ${colors.brand.dark};
202
+ }
203
+ }
204
+ }
205
+ `;
206
+
207
+ const StyledBreadcrumb = styled.div`
208
+ list-style: none;
209
+ display: flex;
210
+ align-items: center;
211
+ flex-wrap: wrap;
212
+ color: ${colors.text.light};
213
+ margin-bottom: ${spacing.normal};
214
+ ${fonts.sizes('14px', '18px')};
215
+ ${mq.range({ from: breakpoints.desktop })} {
216
+ ${fonts.sizes('16px', '24px')};
217
+ }
218
+ .c-icon {
219
+ width: 12px;
220
+ height: 12px;
221
+ margin: 0 ${spacingUnit / 3}px;
222
+
223
+ ${mq.range({ from: breakpoints.desktop })} {
224
+ margin: 0 ${spacing.xsmall};
225
+ }
226
+ }
227
+ `;
228
+
229
+ export const SearchResultItem = ({
230
+ item,
231
+ subjectsLabel,
232
+ additionalContentTooltip,
233
+ children,
234
+ }: SearchResultItemProps) => {
235
+ const itemBreadcrumb = (breadcrumbs: string[] = [], itemBreadcrumb?: boolean) => {
236
+ const Breadcrumb: ElementType = itemBreadcrumb ? StyledBreadcrumb : 'div';
237
+ if (breadcrumbs.length > 0) {
238
+ return (
239
+ <Breadcrumb>
240
+ {breadcrumbs.map((breadcrumbItem, index) => {
241
+ let icon = null;
242
+ if (index !== (item.breadcrumb?.length || 0) - 1) {
243
+ icon = <ChevronRight />;
244
+ }
245
+ return (
246
+ <Fragment key={uuid()}>
247
+ <span>{breadcrumbItem}</span>
248
+ {icon}
249
+ </Fragment>
250
+ );
251
+ })}
252
+ </Breadcrumb>
253
+ );
254
+ }
255
+ };
256
+ return (
257
+ <StyledSearchResultItem key={item.id}>
258
+ <article>
259
+ <StyledHeader>
260
+ <h1>
261
+ {item.url && typeof item.url !== 'string' ? (
262
+ <a {...item.url}>{item.title}</a>
263
+ ) : (
264
+ <SafeLink to={item.url ?? ''}>{item.title}</SafeLink>
265
+ )}
266
+ </h1>
267
+ <ContentTypeWrapper>{item.contentTypeIcon}</ContentTypeWrapper>
268
+ {item.contentTypeLabel && <PillsWrapper>{item.contentTypeLabel}</PillsWrapper>}
269
+ {item.type && <PillsWrapper>{item.type}</PillsWrapper>}
270
+ {item.additional && <PillsWrapper>{additionalContentTooltip}</PillsWrapper>}
271
+ {children}
272
+ </StyledHeader>
273
+ <StyledContent>
274
+ <StyledIngress dangerouslySetInnerHTML={{ __html: item.ingress }} />
275
+ {item.image}
276
+ </StyledContent>
277
+ {(!item.subjects || item.subjects.length === 0) && itemBreadcrumb(item.breadcrumb, true)}
278
+ {item.subjects && item.subjects.length !== 0 && (
279
+ <StyledSubjects>
280
+ <span>{subjectsLabel}</span>
281
+ <ul>
282
+ {item.subjects.map((subject) => (
283
+ <li key={uuid()}>
284
+ <Tooltip tooltip={itemBreadcrumb(subject.breadcrumb)}>
285
+ {subject.url && typeof subject.url !== 'string' ? (
286
+ <a {...subject.url}>{subject.title}</a>
287
+ ) : (
288
+ <SafeLink to={subject.url ?? ''}>{subject.title}</SafeLink>
289
+ )}
290
+ </Tooltip>
291
+ </li>
292
+ ))}
293
+ </ul>
294
+ </StyledSubjects>
295
+ )}
296
+ </article>
297
+ </StyledSearchResultItem>
298
+ );
299
+ };
300
+
301
+ interface SearchResultListProps {
302
+ loading?: boolean;
303
+ results?: ItemType[];
304
+ }
305
+
306
+ const EmptyResultList = styled.article`
307
+ margin-top: ${spacing.large};
308
+ h1 {
309
+ ${fonts.sizes('22px', '32px')};
310
+ font-weight: ${fonts.weight.bold};
311
+ margin: 0 0 ${spacing.small};
312
+ }
313
+
314
+ p {
315
+ ${fonts.sizes('16px', '22px')};
316
+ margin: 0;
317
+ font-family: ${fonts.serif};
318
+
319
+ ${mq.range({ from: breakpoints.desktop })} {
320
+ ${fonts.sizes('18px', '32px')};
321
+ }
322
+ }
323
+ `;
324
+
325
+ const ResultList = styled.ul`
326
+ list-style: none;
327
+ margin: 0;
328
+ padding: 0;
329
+ ${mq.range({ from: breakpoints.desktop })} {
330
+ margin: ${spacing.medium} 0 0 0;
331
+ }
332
+ `;
333
+
334
+ export const SearchResultList = ({ results, loading }: SearchResultListProps) => {
335
+ const { t } = useTranslation();
336
+ if (loading) {
337
+ return <Spinner />;
338
+ }
339
+ if (!results) {
340
+ return <EmptyResultList />;
341
+ }
342
+ return results.length === 0 ? (
343
+ <EmptyResultList>
344
+ <h1>{t('searchPage.searchResultListMessages.noResultHeading')}</h1>
345
+ <p>{t('searchPage.searchResultListMessages.noResultDescription')}</p>
346
+ </EmptyResultList>
347
+ ) : (
348
+ <ResultList>
349
+ {results.map((item) => (
350
+ <SearchResultItem
351
+ key={`search_result_item_${typeof item.url === 'object' ? item.url.href : item.url}`}
352
+ item={item}
353
+ additionalContentTooltip={t('resource.tooltipAdditionalTopic')}
354
+ subjectsLabel={t('searchPage.searchResultListMessages.subjectsLabel')}>
355
+ {item.children}
356
+ </SearchResultItem>
357
+ ))}
358
+ </ResultList>
359
+ );
360
+ };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright (c) 2018-present, NDLA.
3
+ *
4
+ * This source code is licensed under the GPLv3 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import React from 'react';
10
+ import { spacing, spacingUnit, breakpoints, mq, misc, fonts, colors } from '@ndla/core';
11
+ import { Search } from '@ndla/icons/common';
12
+ import Button, { ButtonProps } from '@ndla/button';
13
+ import styled from '@emotion/styled';
14
+
15
+ interface Props extends ButtonProps {
16
+ hideOnNarrowScreen?: boolean;
17
+ hideOnWideScreen?: boolean;
18
+ ndlaFilm?: boolean;
19
+ }
20
+
21
+ interface StyledButtonProps {
22
+ hideOnNarrowScreen?: boolean;
23
+ hideOnWideScreen?: boolean;
24
+ ndlaFilm?: boolean;
25
+ }
26
+
27
+ const StyledButton = styled(Button)<StyledButtonProps>`
28
+ background: ${(p) => (p.ndlaFilm ? colors.ndlaFilm.filmColorBright : colors.brand.greyLighter)};
29
+ border-radius: ${misc.borderRadius};
30
+ border: 0;
31
+ display: ${(p) => (p.hideOnNarrowScreen ? 'none' : 'flex')};
32
+ color: ${(p) => (p.ndlaFilm ? '#fff' : colors.brand.primary)};
33
+ padding: ${spacing.small} ${spacingUnit * 0.75}px ${spacing.small} ${spacing.normal};
34
+ align-items: center;
35
+ margin-left: ${spacing.normal};
36
+
37
+ .c-icon {
38
+ height: 24px;
39
+ width: 24px;
40
+ }
41
+
42
+ ${fonts.sizes('16px', '32px')};
43
+
44
+ ${mq.range({ from: breakpoints.desktop })} {
45
+ display: ${(p) => (p.hideOnWideScreen ? 'none' : 'flex')};
46
+ margin-right: ${spacing.medium};
47
+ padding: ${spacing.small} ${spacing.normal};
48
+ }
49
+ &:hover,
50
+ &:focus,
51
+ &:active {
52
+ border: 0;
53
+ }
54
+ `;
55
+
56
+ const StyledSpan = styled.span`
57
+ margin-right: ${spacing.normal};
58
+ font-weight: ${fonts.weight.normal};
59
+ `;
60
+
61
+ const ToggleSearchButton = ({ children, ndlaFilm, hideOnNarrowScreen, hideOnWideScreen, ...rest }: Props) => (
62
+ <StyledButton
63
+ ndlaFilm={ndlaFilm}
64
+ hideOnNarrowScreen={hideOnNarrowScreen}
65
+ hideOnWideScreen={hideOnWideScreen}
66
+ type="button"
67
+ {...rest}>
68
+ <StyledSpan>{children}</StyledSpan>
69
+ <Search />
70
+ </StyledButton>
71
+ );
72
+
73
+ export default ToggleSearchButton;
@@ -1,6 +1,2 @@
1
1
  @import './component.search-field';
2
- @import './component.search-overlay';
3
- @import './component.search-page';
4
2
  @import './component.search-result';
5
- @import './component.search-result-author';
6
- @import './component.search-filter';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2017-present, NDLA.
3
+ *
4
+ * This source code is licensed under the GPLv3 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import SearchField from './SearchField';
10
+
11
+ import { SearchResultList, SearchResultItem } from './SearchResult';
12
+
13
+ import ActiveFilters from './ActiveFilters';
14
+ export { default as ToggleSearchButton } from './ToggleSearchButton';
15
+
16
+ export { SearchField, SearchResultItem, SearchResultList, ActiveFilters };
package/src/all.scss CHANGED
@@ -3,7 +3,6 @@
3
3
  @import './main';
4
4
  @import '~@ndla/tabs/scss/tabs';
5
5
  @import '~@ndla/core/scss/utilities';
6
- @import '~@ndla/audio-search/scss/audio-search';
7
6
  @import '~@ndla/video-search/scss/video-search';
8
7
  @import '~@ndla/button/src/all.scss';
9
8
  @import '~@ndla/tooltip/src/all.css';
@@ -8,21 +8,6 @@
8
8
 
9
9
  export { FilterList, FilterListPhone, FilterButtons } from './Filter';
10
10
 
11
- export {
12
- SearchOverlay,
13
- SearchField,
14
- SearchPage,
15
- SearchResult,
16
- SearchResultAuthor,
17
- SearchResultList,
18
- SearchResultItem,
19
- SearchFilter,
20
- SearchFilterList,
21
- SearchPopoverFilter,
22
- ActiveFilters,
23
- ToggleSearchButton,
24
- } from './Search';
25
-
26
11
  export { default as TopicIntroductionList } from './TopicIntroductionList';
27
12
  export { default as TopicMenu, TopicMenuButton } from './TopicMenu';
28
13
  export {
package/src/index.ts CHANGED
@@ -245,3 +245,5 @@ export type { Snack, SnackContext } from './SnackBar';
245
245
  export { InfoBlock } from './InfoBlock';
246
246
  export { TreeStructure } from './TreeStructure';
247
247
  export type { FolderType, TreeStructureProps, TreeStructureMenuProps } from './TreeStructure';
248
+
249
+ export { SearchField, SearchResultList, SearchResultItem, ActiveFilters, ToggleSearchButton } from './Search';
package/src/main.scss CHANGED
@@ -16,7 +16,6 @@
16
16
  @import 'Aside/component.aside';
17
17
  @import 'Article/component.footnotes';
18
18
  @import 'NoContentBox/component.no-content-box.scss';
19
- @import 'Portrait/component.portrait.scss';
20
19
  @import 'global/components/component.logo';
21
20
  @import 'MediaList/component.medialist';
22
21
  @import 'RelatedArticleList/component.related-articles';
@@ -31,12 +30,7 @@
31
30
  @import 'Translation/component.translation-box';
32
31
  @import 'Search/component.search';
33
32
  @import 'Subject/component.subject';
34
- @import 'InfoBox/component.info-box';
35
33
  @import 'CompetenceGoals/component.competence-goals';
36
- @import 'ContentCard/component.content-card';
37
- @import 'InfoWidget/component.info-widget';
38
34
  @import 'Carousel/component.carousel';
39
- @import 'FileList/component.file-list';
40
35
  @import 'SectionHeading/component.section-heading';
41
- @import 'AuthorInfo/component.author-info';
42
36
  @import 'NDLAFilm/component.film-movielist';
@@ -1,72 +0,0 @@
1
- import React from 'react';
2
- import BEMHelper from 'react-bem-helper';
3
- import PropTypes from 'prop-types';
4
- import { FilterList } from '../Filter';
5
- import { jsx as ___EmotionJSX } from "@emotion/core";
6
- var searchFilterClasses = BEMHelper({
7
- prefix: 'c-',
8
- name: 'search-filter',
9
- outputIsString: true
10
- });
11
- var valueShape = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
12
-
13
- var SearchFilter = function SearchFilter(_ref) {
14
- var label = _ref.label,
15
- options = _ref.options,
16
- values = _ref.values,
17
- defaultVisibleCount = _ref.defaultVisibleCount,
18
- showLabel = _ref.showLabel,
19
- hideLabel = _ref.hideLabel,
20
- narrowScreenOnly = _ref.narrowScreenOnly,
21
- contextFilter = _ref.contextFilter,
22
- onChange = _ref.onChange,
23
- noFilterSelectedLabel = _ref.noFilterSelectedLabel,
24
- children = _ref.children;
25
- var modifiers = [];
26
-
27
- if (narrowScreenOnly) {
28
- modifiers.push('narrow-screen-only');
29
- }
30
-
31
- if (contextFilter) {
32
- modifiers.push('context-filter');
33
- }
34
-
35
- return ___EmotionJSX("div", {
36
- className: searchFilterClasses('', modifiers)
37
- }, ___EmotionJSX(FilterList, {
38
- options: options,
39
- label: label,
40
- labelNotVisible: contextFilter,
41
- values: values,
42
- defaultVisibleCount: defaultVisibleCount,
43
- modifiers: !contextFilter ? 'search' : null,
44
- showLabel: showLabel,
45
- hideLabel: hideLabel,
46
- onChange: onChange,
47
- alignedGroup: true,
48
- noFilterSelectedLabel: noFilterSelectedLabel
49
- }), children);
50
- };
51
-
52
- SearchFilter.propTypes = {
53
- label: PropTypes.string.isRequired,
54
- options: PropTypes.arrayOf(PropTypes.shape({
55
- value: valueShape.isRequired,
56
- title: PropTypes.string.isRequired,
57
- noResults: PropTypes.bool
58
- })).isRequired,
59
- values: PropTypes.arrayOf(valueShape),
60
- defaultVisibleCount: PropTypes.number,
61
- onChange: PropTypes.func,
62
- showLabel: PropTypes.string,
63
- hideLabel: PropTypes.string,
64
- narrowScreenOnly: PropTypes.bool,
65
- noFilterSelectedLabel: PropTypes.string,
66
- contextFilter: PropTypes.bool,
67
- children: PropTypes.node
68
- };
69
- SearchFilter.defaultProps = {
70
- values: []
71
- };
72
- export default SearchFilter;
@@ -1,115 +0,0 @@
1
- var _this = this;
2
-
3
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
-
5
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
-
9
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
10
-
11
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
-
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
-
15
- import React, { Fragment } from 'react';
16
- import BEMHelper from 'react-bem-helper';
17
- import PropTypes from 'prop-types';
18
- import { FilterList, ToggleItem } from '../Filter';
19
- import { jsx as ___EmotionJSX } from "@emotion/core";
20
- var searchFilterClasses = BEMHelper({
21
- prefix: 'c-',
22
- name: 'search-filter',
23
- outputIsString: true
24
- });
25
- var valueShape = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
26
-
27
- var SearchFilterList = function SearchFilterList(_ref) {
28
- var label = _ref.label,
29
- options = _ref.options,
30
- values = _ref.values,
31
- narrowScreenOnly = _ref.narrowScreenOnly,
32
- _onChange = _ref.onChange,
33
- onSubfilterChange = _ref.onSubfilterChange,
34
- preid = _ref.preid,
35
- noFilterSelectedLabel = _ref.noFilterSelectedLabel,
36
- subjectValues = _ref.subjectValues,
37
- children = _ref.children;
38
- return ___EmotionJSX("div", {
39
- className: searchFilterClasses('')
40
- }, ___EmotionJSX("div", null, options.map(function (option, index) {
41
- var itemModifiers = [];
42
- var checked = values.some(function (value) {
43
- return value === option.value;
44
- });
45
-
46
- if (!checked && index + 1 > _this.state.visibleCount) {
47
- itemModifiers.push('hidden');
48
- }
49
-
50
- var disabled = option.noResults || option.hits === 0;
51
-
52
- if (disabled) {
53
- itemModifiers.push('no-results');
54
- }
55
-
56
- return ___EmotionJSX(Fragment, {
57
- key: option.value
58
- }, ___EmotionJSX(ToggleItem, {
59
- modifiers: itemModifiers,
60
- id: preid + option.value,
61
- value: option.value,
62
- disabled: disabled,
63
- tabIndex: disabled ? -1 : 0,
64
- checked: checked,
65
- icon: option.icon,
66
- label: option.title,
67
- component: "div",
68
- onChange: function onChange(event) {
69
- var newValues = null;
70
-
71
- if (event.currentTarget.checked) {
72
- newValues = [].concat(_toConsumableArray(values), [option.value]);
73
- } else {
74
- newValues = values.filter(function (value) {
75
- return value !== option.value;
76
- });
77
- }
78
-
79
- if (_onChange) {
80
- _onChange(newValues, option.value);
81
- }
82
- }
83
- }), ___EmotionJSX("div", {
84
- className: searchFilterClasses()
85
- }, ___EmotionJSX(FilterList, {
86
- options: option.subjectFilters,
87
- label: label,
88
- labelNotVisible: true,
89
- values: subjectValues[option.value],
90
- onChange: function onChange(subjectFilters, subjectFilter) {
91
- return onSubfilterChange(option.value, subjectFilters, subjectFilter);
92
- },
93
- alignedGroup: true,
94
- noFilterSelectedLabel: noFilterSelectedLabel
95
- })));
96
- })), children);
97
- };
98
-
99
- SearchFilterList.propTypes = {
100
- label: PropTypes.string.isRequired,
101
- options: PropTypes.arrayOf(PropTypes.shape({
102
- value: valueShape.isRequired,
103
- title: PropTypes.string.isRequired,
104
- noResults: PropTypes.bool
105
- })).isRequired,
106
- values: PropTypes.arrayOf(valueShape),
107
- onChange: PropTypes.func,
108
- onSubfilterChange: PropTypes.func,
109
- noFilterSelectedLabel: PropTypes.string,
110
- children: PropTypes.node
111
- };
112
- SearchFilterList.defaultProps = {
113
- values: []
114
- };
115
- export default SearchFilterList;