@ndla/ui 35.0.15 → 35.0.17

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 (48) hide show
  1. package/README.md +1 -1
  2. package/es/MyNdla/Resource/Folder.js +17 -16
  3. package/es/MyNdla/Resource/FolderMenu.js +74 -0
  4. package/es/MyNdla/SettingsMenu.js +98 -0
  5. package/es/MyNdla/index.js +3 -1
  6. package/es/Resource/BlockResource.js +8 -10
  7. package/es/Resource/ListResource.js +8 -10
  8. package/es/index.js +1 -1
  9. package/es/locale/messages-en.js +3 -1
  10. package/es/locale/messages-nb.js +3 -1
  11. package/es/locale/messages-nn.js +3 -1
  12. package/es/locale/messages-se.js +3 -1
  13. package/es/locale/messages-sma.js +3 -1
  14. package/lib/MyNdla/Resource/Folder.d.ts +4 -3
  15. package/lib/MyNdla/Resource/Folder.js +17 -16
  16. package/lib/MyNdla/Resource/FolderMenu.d.ts +16 -0
  17. package/lib/MyNdla/Resource/FolderMenu.js +81 -0
  18. package/lib/MyNdla/SettingsMenu.d.ts +15 -0
  19. package/lib/MyNdla/SettingsMenu.js +96 -0
  20. package/lib/MyNdla/index.d.ts +3 -1
  21. package/lib/MyNdla/index.js +14 -0
  22. package/lib/Resource/BlockResource.js +8 -10
  23. package/lib/Resource/ListResource.js +8 -10
  24. package/lib/index.d.ts +1 -1
  25. package/lib/index.js +6 -0
  26. package/lib/locale/messages-en.d.ts +2 -0
  27. package/lib/locale/messages-en.js +3 -1
  28. package/lib/locale/messages-nb.d.ts +2 -0
  29. package/lib/locale/messages-nb.js +3 -1
  30. package/lib/locale/messages-nn.d.ts +2 -0
  31. package/lib/locale/messages-nn.js +3 -1
  32. package/lib/locale/messages-se.d.ts +2 -0
  33. package/lib/locale/messages-se.js +3 -1
  34. package/lib/locale/messages-sma.d.ts +2 -0
  35. package/lib/locale/messages-sma.js +3 -1
  36. package/package.json +6 -6
  37. package/src/MyNdla/Resource/Folder.tsx +20 -6
  38. package/src/MyNdla/Resource/FolderMenu.tsx +102 -0
  39. package/src/MyNdla/SettingsMenu.tsx +97 -0
  40. package/src/MyNdla/index.ts +3 -1
  41. package/src/Resource/BlockResource.tsx +3 -2
  42. package/src/Resource/ListResource.tsx +4 -3
  43. package/src/index.ts +1 -1
  44. package/src/locale/messages-en.ts +3 -1
  45. package/src/locale/messages-nb.ts +3 -1
  46. package/src/locale/messages-nn.ts +3 -1
  47. package/src/locale/messages-se.ts +3 -1
  48. package/src/locale/messages-sma.ts +3 -1
@@ -13,10 +13,11 @@ import { FileDocumentOutline, Share } from '@ndla/icons/common';
13
13
  import { fonts, spacing, colors, mq, breakpoints } from '@ndla/core';
14
14
  import { css } from '@emotion/react';
15
15
  import { useTranslation } from 'react-i18next';
16
- import { MenuButton, MenuItemProps } from '@ndla/button';
16
+ import { MenuItemProps } from '@ndla/button';
17
17
  import { ResourceTitleLink } from '../../Resource/resourceComponents';
18
+ import FolderMenu from './FolderMenu';
18
19
 
19
- type LayoutType = 'list' | 'listLarger' | 'block';
20
+ export type LayoutType = 'list' | 'listLarger' | 'block';
20
21
  interface LayoutProps {
21
22
  type: LayoutType;
22
23
  }
@@ -82,7 +83,7 @@ const FolderTitle = styled.h2`
82
83
 
83
84
  overflow: hidden;
84
85
  text-overflow: ellipsis;
85
- // Unfortunate css needed for multi-line text overflow ellipsis.
86
+ /* Unfortunate css needed for multi-line text overflow ellipsis. */
86
87
  display: -webkit-box;
87
88
  -webkit-line-clamp: 1;
88
89
  line-clamp: 1;
@@ -158,12 +159,23 @@ interface Props {
158
159
  subResources?: number;
159
160
  description?: string;
160
161
  link: string;
161
- type: LayoutType;
162
+ type?: LayoutType;
163
+ onViewTypeChange?: (type: LayoutType) => void;
162
164
  menuItems?: MenuItemProps[];
163
165
  isShared?: boolean;
164
166
  }
165
167
 
166
- const Folder = ({ id, link, title, subFolders, subResources, type = 'list', menuItems, isShared }: Props) => {
168
+ const Folder = ({
169
+ id,
170
+ link,
171
+ title,
172
+ subFolders,
173
+ subResources,
174
+ type = 'list',
175
+ menuItems,
176
+ isShared,
177
+ onViewTypeChange,
178
+ }: Props) => {
167
179
  const { t } = useTranslation();
168
180
  const Icon = isShared ? FolderShared : FolderOutlined;
169
181
 
@@ -188,7 +200,9 @@ const Folder = ({ id, link, title, subFolders, subResources, type = 'list', menu
188
200
  <Count layoutType={type} type={'folder'} count={subFolders} />
189
201
  <Count layoutType={type} type={'resource'} count={subResources} />
190
202
  </CountContainer>
191
- {menuItems && menuItems.length > 0 && <MenuButton align="end" size="small" menuItems={menuItems} />}
203
+ {menuItems && menuItems.length > 0 && (
204
+ <FolderMenu menuItems={menuItems} viewType={type} onViewTypeChange={onViewTypeChange} />
205
+ )}
192
206
  </MenuWrapper>
193
207
  </FolderWrapper>
194
208
  );
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Copyright (c) 2023-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 { MenuItemProps, ButtonV2 } from '@ndla/button';
10
+ import { FourlineHamburger, List } from '@ndla/icons/action';
11
+ import Tooltip from '@ndla/tooltip';
12
+ import styled from '@emotion/styled';
13
+ import { colors, spacing } from '@ndla/core';
14
+ import { useTranslation } from 'react-i18next';
15
+ import { LayoutType } from './Folder';
16
+ import SettingsMenu from '../SettingsMenu';
17
+
18
+ interface Props {
19
+ menuItems: MenuItemProps[];
20
+ viewType?: LayoutType;
21
+ onViewTypeChange?: (type: LayoutType) => void;
22
+ }
23
+
24
+ const ViewButtonWrapper = styled.div`
25
+ display: flex;
26
+ gap: ${spacing.small};
27
+ div,
28
+ button {
29
+ display: flex;
30
+ flex: 1;
31
+ }
32
+ `;
33
+
34
+ const ViewTypeWrapper = styled.div`
35
+ display: flex;
36
+ flex-direction: column;
37
+ gap: ${spacing.xsmall};
38
+ padding: ${spacing.small};
39
+ border-bottom: 1px solid ${colors.brand.neutral7};
40
+ border-top: 1px solid ${colors.brand.neutral7};
41
+ span {
42
+ color: ${colors.brand.primary};
43
+ }
44
+ `;
45
+
46
+ const ViewButton = styled(ButtonV2)`
47
+ background-color: transparent;
48
+ color: ${colors.brand.primary};
49
+ svg {
50
+ width: 40px;
51
+ height: 40px;
52
+ }
53
+ &[aria-current='true'] {
54
+ background-color: ${colors.brand.lightest};
55
+ }
56
+ &[aria-current='false'] {
57
+ color: ${colors.brand.light};
58
+ border-color: ${colors.brand.light};
59
+ }
60
+ `;
61
+
62
+ const FolderMenu = ({ menuItems, viewType, onViewTypeChange }: Props) => {
63
+ const { t } = useTranslation();
64
+ return (
65
+ <SettingsMenu menuItems={menuItems}>
66
+ {(_) => {
67
+ if (!viewType || !onViewTypeChange) {
68
+ return null;
69
+ }
70
+ return (
71
+ <ViewTypeWrapper>
72
+ <span>{t('myNdla.selectView')}</span>
73
+ <ViewButtonWrapper>
74
+ <Tooltip tooltip={t('myNdla.listView')}>
75
+ <ViewButton
76
+ size="large"
77
+ aria-current={viewType === 'list'}
78
+ colorTheme="primary"
79
+ onClick={() => onViewTypeChange('list')}
80
+ >
81
+ <FourlineHamburger />
82
+ </ViewButton>
83
+ </Tooltip>
84
+ <Tooltip tooltip={t('myNdla.detailView')}>
85
+ <ViewButton
86
+ size="large"
87
+ aria-current={viewType === 'listLarger'}
88
+ colorTheme="primary"
89
+ onClick={() => onViewTypeChange('listLarger')}
90
+ >
91
+ <List />
92
+ </ViewButton>
93
+ </Tooltip>
94
+ </ViewButtonWrapper>
95
+ </ViewTypeWrapper>
96
+ );
97
+ }}
98
+ </SettingsMenu>
99
+ );
100
+ };
101
+
102
+ export default FolderMenu;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Copyright (c) 2023-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 { ReactNode } from 'react';
10
+ import styled from '@emotion/styled';
11
+ import { isMobile, isTablet } from 'react-device-detect';
12
+ import { useTranslation } from 'react-i18next';
13
+ import { IconButtonV2, MenuItemProps, MenuButton, ButtonV2 } from '@ndla/button';
14
+ import { Drawer, ModalBody, ModalCloseButton, ModalHeaderV2 } from '@ndla/modal';
15
+ import { HorizontalMenu } from '@ndla/icons/contentType';
16
+ import { breakpoints, colors, misc, mq, spacing } from '@ndla/core';
17
+
18
+ interface Props {
19
+ menuItems?: MenuItemProps[];
20
+ children?: (close: () => void) => ReactNode;
21
+ }
22
+
23
+ const StyledDrawer = styled(Drawer)`
24
+ max-height: 100%;
25
+ border-top-left-radius: ${misc.borderRadius};
26
+ border-top-right-radius: ${misc.borderRadius};
27
+ ${mq.range({ until: breakpoints.tablet })} {
28
+ min-height: 20%;
29
+ }
30
+ `;
31
+
32
+ const Ul = styled.ul`
33
+ margin: 0;
34
+ padding: 0;
35
+ list-style: none;
36
+ `;
37
+
38
+ const StyledModalBody = styled(ModalBody)`
39
+ padding: 0 0 ${spacing.large} 0px;
40
+ `;
41
+
42
+ const Li = styled.li`
43
+ border-bottom: 1px solid ${colors.brand.neutral7};
44
+ `;
45
+
46
+ const SettingsMenu = ({ menuItems, children }: Props) => {
47
+ const { t } = useTranslation();
48
+ if (isMobile || isTablet) {
49
+ return (
50
+ <StyledDrawer
51
+ expands
52
+ position="bottom"
53
+ size="small"
54
+ activateButton={
55
+ <IconButtonV2 aria-label={t('myNdla.more')} colorTheme="light" variant="ghost">
56
+ <HorizontalMenu />
57
+ </IconButtonV2>
58
+ }
59
+ >
60
+ {(close) => (
61
+ <>
62
+ <ModalHeaderV2>
63
+ <h1>{t('myNdla.settings')}</h1>
64
+ <ModalCloseButton onClick={close} />
65
+ </ModalHeaderV2>
66
+ <StyledModalBody>
67
+ {children?.(close)}
68
+ {!!menuItems?.length && (
69
+ <Ul>
70
+ {menuItems.map((item, i) => (
71
+ <Li key={i}>
72
+ <ButtonV2
73
+ fontWeight="normal"
74
+ variant="ghost"
75
+ colorTheme={item.type}
76
+ onClick={(e) => {
77
+ close();
78
+ item.onClick(e);
79
+ }}
80
+ >
81
+ {item.icon}
82
+ {item.text}
83
+ </ButtonV2>
84
+ </Li>
85
+ ))}
86
+ </Ul>
87
+ )}
88
+ </StyledModalBody>
89
+ </>
90
+ )}
91
+ </StyledDrawer>
92
+ );
93
+ }
94
+ return <MenuButton align="end" size="small" menuItems={menuItems} />;
95
+ };
96
+
97
+ export default SettingsMenu;
@@ -1,3 +1,5 @@
1
1
  import Folder from './Resource/Folder';
2
2
  import FolderInput from './Resource/FolderInput';
3
- export { Folder, FolderInput };
3
+ import FolderMenu from './Resource/FolderMenu';
4
+ import SettingsMenu from './SettingsMenu';
5
+ export { Folder, FolderInput, SettingsMenu, FolderMenu };
@@ -9,7 +9,7 @@
9
9
  import styled from '@emotion/styled';
10
10
  import React from 'react';
11
11
  import { colors, fonts, spacing } from '@ndla/core';
12
- import { MenuButton, MenuItemProps } from '@ndla/button';
12
+ import { MenuItemProps } from '@ndla/button';
13
13
  import ContentTypeBadge from '../ContentTypeBadge';
14
14
  import Image from '../Image';
15
15
  import {
@@ -23,6 +23,7 @@ import {
23
23
  } from './resourceComponents';
24
24
  import ContentLoader from '../ContentLoader';
25
25
  import { contentTypeMapping } from '../model/ContentType';
26
+ import { SettingsMenu } from '../MyNdla';
26
27
 
27
28
  const BlockElementWrapper = styled.div`
28
29
  display: flex;
@@ -188,7 +189,7 @@ const BlockResource = ({
188
189
  </ContentWrapper>
189
190
  <TagsAndActionMenu>
190
191
  {tags && tags.length > 0 && <CompressedTagList tagLinkPrefix={tagLinkPrefix} tags={tags} />}
191
- {menuItems && menuItems.length > 0 && <MenuButton align="end" size="small" menuItems={menuItems} />}
192
+ {menuItems && menuItems.length > 0 && <SettingsMenu menuItems={menuItems} />}
192
193
  </TagsAndActionMenu>
193
194
  </BlockInfoWrapper>
194
195
  </BlockElementWrapper>
@@ -7,9 +7,9 @@
7
7
  */
8
8
 
9
9
  import styled from '@emotion/styled';
10
- import React, { useRef } from 'react';
10
+ import React from 'react';
11
11
  import { fonts, spacing, colors, breakpoints, mq } from '@ndla/core';
12
- import { MenuButton, MenuItemProps } from '@ndla/button';
12
+ import { MenuItemProps } from '@ndla/button';
13
13
  import Image from '../Image';
14
14
  import {
15
15
  CompressedTagList,
@@ -23,6 +23,7 @@ import {
23
23
  import ContentLoader from '../ContentLoader';
24
24
  import ContentTypeBadge from '../ContentTypeBadge';
25
25
  import { contentTypeMapping } from '../model/ContentType';
26
+ import { SettingsMenu } from '../MyNdla';
26
27
 
27
28
  const ListResourceWrapper = styled.div`
28
29
  flex: 1;
@@ -245,7 +246,7 @@ const ListResource = ({
245
246
  {showDescription && <Description description={description} loading={isLoading} />}
246
247
  <TagsandActionMenu>
247
248
  {tags && tags.length > 0 && <CompressedTagList tagLinkPrefix={tagLinkPrefix} tags={tags} />}
248
- {menuItems && menuItems.length > 0 && <MenuButton align="end" size="small" menuItems={menuItems} />}
249
+ {menuItems && menuItems.length > 0 && <SettingsMenu menuItems={menuItems} />}
249
250
  </TagsandActionMenu>
250
251
  </ListResourceWrapper>
251
252
  );
package/src/index.ts CHANGED
@@ -255,7 +255,7 @@ export { Notion, ConceptNotion } from './Notion';
255
255
  export type { NotionVisualElementType, ConceptNotionType } from './Notion';
256
256
 
257
257
  export { BannerCard } from './BannerCard';
258
- export { Folder, FolderInput } from './MyNdla';
258
+ export { Folder, FolderInput, FolderMenu } from './MyNdla';
259
259
  export { ListResource, BlockResource } from './Resource';
260
260
  export type { ListResourceProps } from './Resource';
261
261
  export type { TagType } from './TagSelector';
@@ -1101,6 +1101,7 @@ const messages = {
1101
1101
  resources_plural: '{{count}} Resources',
1102
1102
  folders: '{{count}} Folder',
1103
1103
  folders_plural: '{{count}} Folders',
1104
+ settings: 'Settings',
1104
1105
  folder: {
1105
1106
  folder: 'Folder',
1106
1107
  delete: 'Delete folder',
@@ -1138,7 +1139,7 @@ const messages = {
1138
1139
  },
1139
1140
  button: {
1140
1141
  share: 'Share folder',
1141
- preview: 'Preview shared folder',
1142
+ preview: 'Preview folder',
1142
1143
  unShare: 'Stop sharing',
1143
1144
  shareLink: 'Copy link',
1144
1145
  },
@@ -1167,6 +1168,7 @@ const messages = {
1167
1168
  examLockInfo: 'Editing content on Min NDLA is deactivated for pupils during the exam period.',
1168
1169
  help: 'Help',
1169
1170
  more: 'More options',
1171
+ selectView: 'Select view',
1170
1172
  listView: 'List view',
1171
1173
  detailView: 'Detailed listview',
1172
1174
  shortView: 'Card view',
@@ -1100,6 +1100,7 @@ const messages = {
1100
1100
  resources_plural: '{{count}} ressurser',
1101
1101
  folders: '{{count}} mappe',
1102
1102
  folders_plural: '{{count}} mapper',
1103
+ settings: 'Instillinger',
1103
1104
  folder: {
1104
1105
  folder: 'Mappe',
1105
1106
  delete: 'Slett mappe',
@@ -1136,7 +1137,7 @@ const messages = {
1136
1137
  },
1137
1138
  button: {
1138
1139
  share: 'Del mappen',
1139
- preview: 'Forhåndsvis delt mappe',
1140
+ preview: 'Forhåndsvis mappe',
1140
1141
  unShare: 'Avslutt deling',
1141
1142
  shareLink: 'Kopier lenke',
1142
1143
  },
@@ -1164,6 +1165,7 @@ const messages = {
1164
1165
  examLockInfo: 'Redigering av innhold på Min NDLA er deaktivert for elever i eksamensperioden.',
1165
1166
  help: 'Hjelp',
1166
1167
  more: 'Flere valg',
1168
+ selectView: 'Velg visning',
1167
1169
  listView: 'Listevisning',
1168
1170
  detailView: 'Detaljert listevisning',
1169
1171
  shortView: 'Kort visning',
@@ -1100,6 +1100,7 @@ const messages = {
1100
1100
  resources_plural: '{{count}} ressursar',
1101
1101
  folders: '{{count}} mappe',
1102
1102
  folders_plural: '{{count}} mapper',
1103
+ settings: 'Instillinger',
1103
1104
  folder: {
1104
1105
  folder: 'Mappe',
1105
1106
  delete: 'Slett mappe',
@@ -1136,7 +1137,7 @@ const messages = {
1136
1137
  },
1137
1138
  button: {
1138
1139
  share: 'Del mappa',
1139
- preview: 'Førehandsvis delt mappe',
1140
+ preview: 'Førehandsvis mappe',
1140
1141
  unShare: 'Avslutt deling',
1141
1142
  shareLink: 'Kopier lenke',
1142
1143
  },
@@ -1164,6 +1165,7 @@ const messages = {
1164
1165
  examLockInfo: 'Redigering av innhald på Min NDLA er deaktivert for elevar i eksamensperioden.',
1165
1166
  help: 'Hjelp',
1166
1167
  more: 'Fleire val',
1168
+ selectView: 'Velg visning',
1167
1169
  listView: 'Listevisning',
1168
1170
  detailView: 'Detaljert listevisning',
1169
1171
  shortView: 'Kortvisning',
@@ -1101,6 +1101,7 @@ const messages = {
1101
1101
  resources_plural: '{{count}} resurssat',
1102
1102
  folders: '{{count}} máhpat',
1103
1103
  folders_plural: '{{count}} mapper',
1104
+ settings: 'Instillinger',
1104
1105
  folder: {
1105
1106
  folder: 'Máhppa',
1106
1107
  delete: 'Sihko máhpa',
@@ -1137,7 +1138,7 @@ const messages = {
1137
1138
  },
1138
1139
  button: {
1139
1140
  share: 'Del mappen',
1140
- preview: 'Forhåndsvis delt mappe',
1141
+ preview: 'Forhåndsvis mappe',
1141
1142
  unShare: 'Avslutt deling',
1142
1143
  shareLink: 'Kopier lenke',
1143
1144
  },
@@ -1165,6 +1166,7 @@ const messages = {
1165
1166
  examLockInfo: 'Mu NDLA sisdoalu redigeren ii leat doaimmas ohppiide eksámenáigodagas.',
1166
1167
  help: 'Veahkki',
1167
1168
  more: 'Eanet válljejumit',
1169
+ selectView: 'Velg visning',
1168
1170
  listView: 'Oppalašlistu',
1169
1171
  detailView: 'Bienalaš oppalašlistu',
1170
1172
  shortView: 'Oanehis listu',
@@ -1104,6 +1104,7 @@ const messages = {
1104
1104
  resources_plural: '{{count}} ressurser',
1105
1105
  folders: '{{count}} mappe',
1106
1106
  folders_plural: '{{count}} mapper',
1107
+ settings: 'Instillinger',
1107
1108
  folder: {
1108
1109
  folder: 'Mappe',
1109
1110
  delete: 'Slett mappe',
@@ -1140,7 +1141,7 @@ const messages = {
1140
1141
  },
1141
1142
  button: {
1142
1143
  share: 'Del mappen',
1143
- preview: 'Forhåndsvis delt mappe',
1144
+ preview: 'Forhåndsvis mappe',
1144
1145
  unShare: 'Avslutt deling',
1145
1146
  shareLink: 'Kopier lenke',
1146
1147
  },
@@ -1169,6 +1170,7 @@ const messages = {
1169
1170
  examLockInfo: 'Redigering av innhold på Min NDLA er deaktivert for elever i eksamensperioden.',
1170
1171
  help: 'Hjelp',
1171
1172
  more: 'Flere valg',
1173
+ selectView: 'Velg visning',
1172
1174
  listView: 'Listevisning',
1173
1175
  detailView: 'Detaljert listevisning',
1174
1176
  shortView: 'Kort visning',