@ndla/ui 56.0.13-alpha.0 → 56.0.15-alpha.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/dist/panda.buildinfo.json +7 -2
- package/dist/styles.css +24 -4
- package/es/Article/Article.js +4 -1
- package/es/ContentTypeBadge/ContentTypeBadge.js +2 -0
- package/es/TreeStructure/TreeStructure.js +292 -181
- package/es/TreeStructure/helperFunctions.js +0 -3
- package/es/TreeStructure/index.js +1 -2
- package/es/index.js +0 -1
- package/es/locale/messages-en.js +1 -1
- package/es/locale/messages-nb.js +1 -1
- package/es/locale/messages-nn.js +1 -1
- package/es/locale/messages-se.js +1 -1
- package/es/locale/messages-sma.js +1 -1
- package/es/styles.css +24 -4
- package/lib/Article/Article.js +4 -1
- package/lib/ContentTypeBadge/ContentTypeBadge.js +2 -0
- package/lib/TreeStructure/TreeStructure.d.ts +7 -6
- package/lib/TreeStructure/TreeStructure.js +293 -180
- package/lib/TreeStructure/helperFunctions.d.ts +0 -2
- package/lib/TreeStructure/helperFunctions.js +2 -6
- package/lib/TreeStructure/index.d.ts +1 -2
- package/lib/TreeStructure/index.js +2 -3
- package/lib/TreeStructure/types.d.ts +4 -22
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -7
- package/lib/locale/messages-en.js +1 -1
- package/lib/locale/messages-nb.js +1 -1
- package/lib/locale/messages-nn.js +1 -1
- package/lib/locale/messages-se.js +1 -1
- package/lib/locale/messages-sma.js +1 -1
- package/lib/styles.css +24 -4
- package/package.json +7 -8
- package/src/Article/Article.tsx +4 -1
- package/src/ContentTypeBadge/ContentTypeBadge.tsx +2 -0
- package/src/TreeStructure/TreeStructure.stories.tsx +38 -68
- package/src/TreeStructure/TreeStructure.tsx +307 -194
- package/src/TreeStructure/helperFunctions.ts +0 -5
- package/src/TreeStructure/index.ts +1 -2
- package/src/TreeStructure/types.ts +4 -25
- package/src/index.ts +0 -3
- package/src/locale/messages-en.ts +1 -1
- package/src/locale/messages-nb.ts +1 -1
- package/src/locale/messages-nn.ts +1 -1
- package/src/locale/messages-se.ts +1 -1
- package/src/locale/messages-sma.ts +1 -1
- package/es/ProgrammeCard/ProgrammeCard.js +0 -51
- package/es/ProgrammeCard/index.js +0 -9
- package/es/TreeStructure/AddFolderButton.js +0 -80
- package/es/TreeStructure/ComboboxButton.js +0 -127
- package/es/TreeStructure/FolderItem.js +0 -225
- package/es/TreeStructure/FolderItems.js +0 -95
- package/es/TreeStructure/arrowNavigation.js +0 -35
- package/lib/ProgrammeCard/ProgrammeCard.d.ts +0 -23
- package/lib/ProgrammeCard/ProgrammeCard.js +0 -58
- package/lib/ProgrammeCard/index.d.ts +0 -9
- package/lib/ProgrammeCard/index.js +0 -13
- package/lib/TreeStructure/AddFolderButton.d.ts +0 -17
- package/lib/TreeStructure/AddFolderButton.js +0 -85
- package/lib/TreeStructure/ComboboxButton.d.ts +0 -27
- package/lib/TreeStructure/ComboboxButton.js +0 -134
- package/lib/TreeStructure/FolderItem.d.ts +0 -17
- package/lib/TreeStructure/FolderItem.js +0 -230
- package/lib/TreeStructure/FolderItems.d.ts +0 -22
- package/lib/TreeStructure/FolderItems.js +0 -100
- package/lib/TreeStructure/arrowNavigation.d.ts +0 -10
- package/lib/TreeStructure/arrowNavigation.js +0 -42
- package/src/ProgrammeCard/ProgrammeCard.stories.tsx +0 -35
- package/src/ProgrammeCard/ProgrammeCard.tsx +0 -78
- package/src/ProgrammeCard/index.tsx +0 -10
- package/src/TreeStructure/AddFolderButton.tsx +0 -79
- package/src/TreeStructure/ComboboxButton.tsx +0 -172
- package/src/TreeStructure/FolderItem.tsx +0 -307
- package/src/TreeStructure/FolderItems.tsx +0 -121
- package/src/TreeStructure/arrowNavigation.ts +0 -54
|
@@ -1,78 +0,0 @@
|
|
|
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 styled from "@emotion/styled";
|
|
10
|
-
import { spacing, colors, misc, breakpoints, mq, fonts } from "@ndla/core";
|
|
11
|
-
import { SafeLink } from "@ndla/safelink";
|
|
12
|
-
|
|
13
|
-
interface Image {
|
|
14
|
-
src: string;
|
|
15
|
-
alt: string;
|
|
16
|
-
}
|
|
17
|
-
export interface Programme {
|
|
18
|
-
id: string;
|
|
19
|
-
title: {
|
|
20
|
-
title: string;
|
|
21
|
-
language: string;
|
|
22
|
-
};
|
|
23
|
-
narrowImage?: Image;
|
|
24
|
-
wideImage?: Image;
|
|
25
|
-
url: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const StyledCardContainer = styled(SafeLink)`
|
|
29
|
-
display: flex;
|
|
30
|
-
flex-direction: column;
|
|
31
|
-
background-color: ${colors.background.default};
|
|
32
|
-
border-radius: ${misc.borderRadius};
|
|
33
|
-
box-shadow: none;
|
|
34
|
-
|
|
35
|
-
&:hover,
|
|
36
|
-
&:focus-visible {
|
|
37
|
-
text-decoration: underline ${colors.text.primary};
|
|
38
|
-
text-underline-offset: 3px;
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
|
-
|
|
42
|
-
const StyledImg = styled.img`
|
|
43
|
-
display: block;
|
|
44
|
-
flex: 1;
|
|
45
|
-
border-radius: ${misc.borderRadius} ${misc.borderRadius} 0 0;
|
|
46
|
-
width: 100%;
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const StyledTitle = styled.span`
|
|
50
|
-
display: flex;
|
|
51
|
-
min-height: 70px;
|
|
52
|
-
align-items: center;
|
|
53
|
-
padding-left: ${spacing.nsmall};
|
|
54
|
-
margin-top: auto;
|
|
55
|
-
|
|
56
|
-
border: 1px solid ${colors.brand.lighter};
|
|
57
|
-
border-radius: 0 0 ${misc.borderRadius} ${misc.borderRadius};
|
|
58
|
-
|
|
59
|
-
font-weight: ${fonts.weight.semibold};
|
|
60
|
-
color: ${colors.text.primary};
|
|
61
|
-
${fonts.sizes("16px", "24px")};
|
|
62
|
-
|
|
63
|
-
${mq.range({ from: breakpoints.tablet })} {
|
|
64
|
-
${fonts.sizes("16px", "18px")};
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
const ProgrammeCard = ({ title, narrowImage, wideImage, url }: Programme) => {
|
|
69
|
-
return (
|
|
70
|
-
<StyledCardContainer to={url}>
|
|
71
|
-
{narrowImage && <StyledImg height={280} width={250} src={narrowImage.src} alt={narrowImage.alt} />}
|
|
72
|
-
{wideImage && <StyledImg height={330} width={120} src={wideImage.src} alt={wideImage.alt} />}
|
|
73
|
-
<StyledTitle>{title.title}</StyledTitle>
|
|
74
|
-
</StyledCardContainer>
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default ProgrammeCard;
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
export { default as ProgrammeCard } from "./ProgrammeCard";
|
|
10
|
-
export type { Programme as ProgrammeV2 } from "./ProgrammeCard";
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022-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 { useRef } from "react";
|
|
10
|
-
import { useTranslation } from "react-i18next";
|
|
11
|
-
import styled from "@emotion/styled";
|
|
12
|
-
import { ButtonV2 as Button } from "@ndla/button";
|
|
13
|
-
import { AddLine } from "@ndla/icons/action";
|
|
14
|
-
import { IFolder } from "@ndla/types-backend/myndla-api";
|
|
15
|
-
|
|
16
|
-
interface AddFolderButtonProps {
|
|
17
|
-
canAddFolder: boolean;
|
|
18
|
-
focusedFolder?: IFolder;
|
|
19
|
-
setNewFolderParentId: (id?: string) => void;
|
|
20
|
-
setShowTree: (value: boolean) => void;
|
|
21
|
-
loading?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const StyledAddFolderButton = styled(Button)`
|
|
25
|
-
&,
|
|
26
|
-
&:disabled {
|
|
27
|
-
border-color: transparent;
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
const StyledPlus = styled(AddLine)`
|
|
32
|
-
height: 24px;
|
|
33
|
-
width: 24px;
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
const AddFolderButton = ({
|
|
37
|
-
canAddFolder,
|
|
38
|
-
loading,
|
|
39
|
-
setNewFolderParentId,
|
|
40
|
-
focusedFolder,
|
|
41
|
-
setShowTree,
|
|
42
|
-
}: AddFolderButtonProps) => {
|
|
43
|
-
const { t } = useTranslation();
|
|
44
|
-
const ref = useRef<HTMLButtonElement>(null);
|
|
45
|
-
const tooltip = loading
|
|
46
|
-
? t("loading")
|
|
47
|
-
: canAddFolder
|
|
48
|
-
? t("myNdla.newFolderUnder", { folderName: focusedFolder?.name })
|
|
49
|
-
: t("treeStructure.maxFoldersAlreadyAdded");
|
|
50
|
-
return (
|
|
51
|
-
<StyledAddFolderButton
|
|
52
|
-
ref={ref}
|
|
53
|
-
variant="outline"
|
|
54
|
-
shape="pill"
|
|
55
|
-
disabled={loading || !canAddFolder}
|
|
56
|
-
title={tooltip}
|
|
57
|
-
aria-label={tooltip}
|
|
58
|
-
onMouseDown={(e) => {
|
|
59
|
-
e.preventDefault();
|
|
60
|
-
e.stopPropagation();
|
|
61
|
-
ref.current?.focus();
|
|
62
|
-
}}
|
|
63
|
-
onMouseUp={(e) => {
|
|
64
|
-
e.preventDefault();
|
|
65
|
-
e.stopPropagation();
|
|
66
|
-
ref.current?.focus();
|
|
67
|
-
}}
|
|
68
|
-
onClick={(e) => {
|
|
69
|
-
e.currentTarget.focus();
|
|
70
|
-
setNewFolderParentId(focusedFolder?.id);
|
|
71
|
-
setShowTree(true);
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
<StyledPlus /> {t("myNdla.newFolder")}
|
|
75
|
-
</StyledAddFolderButton>
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default AddFolderButton;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022-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 { KeyboardEvent, forwardRef } from "react";
|
|
10
|
-
import styled from "@emotion/styled";
|
|
11
|
-
import { ButtonV2 as Button, IconButtonV2 as IconButton } from "@ndla/button";
|
|
12
|
-
import { breakpoints, colors, mq, spacing } from "@ndla/core";
|
|
13
|
-
import { ArrowUpShortLine, ArrowDownShortLine } from "@ndla/icons/common";
|
|
14
|
-
import { IFolder } from "@ndla/types-backend/myndla-api";
|
|
15
|
-
import { useForwardedRef } from "@ndla/util";
|
|
16
|
-
import { arrowNavigation } from "./arrowNavigation";
|
|
17
|
-
import { treestructureId } from "./helperFunctions";
|
|
18
|
-
import { TreeStructureType } from "./types";
|
|
19
|
-
import ContentLoader from "../ContentLoader";
|
|
20
|
-
|
|
21
|
-
const StyledRow = styled.div`
|
|
22
|
-
display: flex;
|
|
23
|
-
padding: ${spacing.xxsmall};
|
|
24
|
-
align-items: center;
|
|
25
|
-
&[data-open="true"] {
|
|
26
|
-
border-bottom: 1px solid ${colors.brand.tertiary};
|
|
27
|
-
}
|
|
28
|
-
`;
|
|
29
|
-
const StyledSelectedFolder = styled(Button)`
|
|
30
|
-
flex: 1;
|
|
31
|
-
justify-content: flex-start;
|
|
32
|
-
color: ${colors.black};
|
|
33
|
-
border: none;
|
|
34
|
-
:hover,
|
|
35
|
-
:focus {
|
|
36
|
-
background: none;
|
|
37
|
-
box-shadow: none;
|
|
38
|
-
border-color: transparent;
|
|
39
|
-
}
|
|
40
|
-
:focus-visible {
|
|
41
|
-
outline: none;
|
|
42
|
-
}
|
|
43
|
-
${mq.range({ until: breakpoints.tablet })} {
|
|
44
|
-
min-height: 4rem;
|
|
45
|
-
max-height: 4rem;
|
|
46
|
-
text-align: start;
|
|
47
|
-
}
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
interface Props {
|
|
51
|
-
showTree: boolean;
|
|
52
|
-
type: TreeStructureType;
|
|
53
|
-
label?: string;
|
|
54
|
-
focusedFolder?: IFolder;
|
|
55
|
-
selectedFolder?: IFolder;
|
|
56
|
-
setSelectedFolder: (folder: IFolder) => void;
|
|
57
|
-
loading?: boolean;
|
|
58
|
-
onToggleTree: (open: boolean) => void;
|
|
59
|
-
flattenedFolders: IFolder[];
|
|
60
|
-
onOpenFolder: (id: string) => void;
|
|
61
|
-
onCloseFolder: (id: string) => void;
|
|
62
|
-
setFocusedFolder: (folder: IFolder) => void;
|
|
63
|
-
ariaDescribedby?: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const ComboboxButton = forwardRef<HTMLButtonElement, Props>(
|
|
67
|
-
(
|
|
68
|
-
{
|
|
69
|
-
showTree,
|
|
70
|
-
type,
|
|
71
|
-
label,
|
|
72
|
-
focusedFolder,
|
|
73
|
-
selectedFolder,
|
|
74
|
-
setSelectedFolder,
|
|
75
|
-
onToggleTree,
|
|
76
|
-
flattenedFolders,
|
|
77
|
-
setFocusedFolder,
|
|
78
|
-
onOpenFolder,
|
|
79
|
-
onCloseFolder,
|
|
80
|
-
loading,
|
|
81
|
-
ariaDescribedby,
|
|
82
|
-
},
|
|
83
|
-
ref,
|
|
84
|
-
) => {
|
|
85
|
-
const innerRef = useForwardedRef(ref);
|
|
86
|
-
|
|
87
|
-
const onKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
88
|
-
if (e.key === "Enter") {
|
|
89
|
-
onToggleTree(!showTree);
|
|
90
|
-
if (showTree && focusedFolder) {
|
|
91
|
-
setSelectedFolder(focusedFolder);
|
|
92
|
-
}
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (e.key === "Escape") {
|
|
96
|
-
onToggleTree(false);
|
|
97
|
-
e.preventDefault();
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (["ArrowUp", "ArrowDown"].includes(e.key) && !showTree) {
|
|
101
|
-
onToggleTree(true);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (focusedFolder) {
|
|
105
|
-
arrowNavigation(e, focusedFolder.id, flattenedFolders, setFocusedFolder, onOpenFolder, onCloseFolder);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<StyledRow
|
|
111
|
-
data-open={showTree}
|
|
112
|
-
onMouseDown={(e) => {
|
|
113
|
-
if (!e.defaultPrevented) {
|
|
114
|
-
e.preventDefault();
|
|
115
|
-
e.stopPropagation();
|
|
116
|
-
onToggleTree(!showTree);
|
|
117
|
-
innerRef.current?.focus();
|
|
118
|
-
}
|
|
119
|
-
}}
|
|
120
|
-
>
|
|
121
|
-
{loading && (
|
|
122
|
-
<ContentLoader width={1000} height={40}>
|
|
123
|
-
<rect x="15" y="0" width="1000" rx="3" ry="3" r="15" height="40" />
|
|
124
|
-
</ContentLoader>
|
|
125
|
-
)}
|
|
126
|
-
{!loading && (
|
|
127
|
-
<StyledSelectedFolder
|
|
128
|
-
ref={innerRef}
|
|
129
|
-
tabIndex={0}
|
|
130
|
-
id={treestructureId(type, "combobox")}
|
|
131
|
-
role="combobox"
|
|
132
|
-
aria-controls={treestructureId(type, "popup")}
|
|
133
|
-
aria-haspopup="tree"
|
|
134
|
-
aria-expanded={showTree}
|
|
135
|
-
aria-labelledby={label ? treestructureId(type, "label") : undefined}
|
|
136
|
-
aria-activedescendant={focusedFolder ? treestructureId(type, focusedFolder.id) : undefined}
|
|
137
|
-
aria-describedby={ariaDescribedby}
|
|
138
|
-
variant="ghost"
|
|
139
|
-
colorTheme="light"
|
|
140
|
-
fontWeight="normal"
|
|
141
|
-
shape="sharp"
|
|
142
|
-
onKeyDown={onKeyDown}
|
|
143
|
-
onClick={() => {
|
|
144
|
-
innerRef.current?.focus();
|
|
145
|
-
onToggleTree(showTree);
|
|
146
|
-
}}
|
|
147
|
-
>
|
|
148
|
-
{selectedFolder?.name}
|
|
149
|
-
</StyledSelectedFolder>
|
|
150
|
-
)}
|
|
151
|
-
<IconButton
|
|
152
|
-
disabled={loading}
|
|
153
|
-
aria-busy={loading}
|
|
154
|
-
aria-hidden
|
|
155
|
-
aria-label=""
|
|
156
|
-
tabIndex={-1}
|
|
157
|
-
variant="ghost"
|
|
158
|
-
colorTheme="greyLighter"
|
|
159
|
-
size="small"
|
|
160
|
-
onClick={() => {
|
|
161
|
-
innerRef.current?.focus();
|
|
162
|
-
onToggleTree(!showTree);
|
|
163
|
-
}}
|
|
164
|
-
>
|
|
165
|
-
{showTree ? <ArrowUpShortLine /> : <ArrowDownShortLine />}
|
|
166
|
-
</IconButton>
|
|
167
|
-
</StyledRow>
|
|
168
|
-
);
|
|
169
|
-
},
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
export default ComboboxButton;
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022-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 { CSSProperties, KeyboardEvent, useEffect, useMemo, useRef } from "react";
|
|
10
|
-
import { useTranslation } from "react-i18next";
|
|
11
|
-
import styled from "@emotion/styled";
|
|
12
|
-
import { ButtonV2 as Button } from "@ndla/button";
|
|
13
|
-
import { colors, spacing, animations, misc, fonts } from "@ndla/core";
|
|
14
|
-
import { ArrowDownShortLine } from "@ndla/icons/common";
|
|
15
|
-
import { FolderUserFill } from "@ndla/icons/contentType";
|
|
16
|
-
import { CheckLine, FolderLine } from "@ndla/icons/editor";
|
|
17
|
-
import { SafeLink } from "@ndla/safelink";
|
|
18
|
-
import { IFolder } from "@ndla/types-backend/myndla-api";
|
|
19
|
-
import { arrowNavigation } from "./arrowNavigation";
|
|
20
|
-
import { treestructureId } from "./helperFunctions";
|
|
21
|
-
import { CommonFolderItemsProps } from "./types";
|
|
22
|
-
|
|
23
|
-
const OpenButton = styled.span`
|
|
24
|
-
display: flex;
|
|
25
|
-
align-items: center;
|
|
26
|
-
justify-content: center;
|
|
27
|
-
align-self: stretch;
|
|
28
|
-
color: ${colors.brand.tertiary};
|
|
29
|
-
${misc.transition.default};
|
|
30
|
-
cursor: pointer;
|
|
31
|
-
&:hover {
|
|
32
|
-
color: ${colors.brand.primary};
|
|
33
|
-
}
|
|
34
|
-
svg {
|
|
35
|
-
width: 24px;
|
|
36
|
-
height: 24px;
|
|
37
|
-
transform: rotate(-90deg);
|
|
38
|
-
}
|
|
39
|
-
&[data-open="true"] {
|
|
40
|
-
svg {
|
|
41
|
-
transform: rotate(0deg);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
&[data-hide-arrow="true"] {
|
|
45
|
-
visibility: hidden;
|
|
46
|
-
}
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const StyledName = styled.span`
|
|
50
|
-
white-space: nowrap;
|
|
51
|
-
overflow: hidden;
|
|
52
|
-
text-overflow: ellipsis;
|
|
53
|
-
grid-column-start: 2;
|
|
54
|
-
text-align: left;
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
const IconWrapper = styled.div`
|
|
58
|
-
display: flex;
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
const FolderIconWrapper = styled.div`
|
|
62
|
-
svg {
|
|
63
|
-
height: 24px;
|
|
64
|
-
width: 24px;
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
const FolderName = styled(Button)`
|
|
69
|
-
display: grid;
|
|
70
|
-
grid-template-columns: auto 1fr auto;
|
|
71
|
-
padding-left: calc(0.75 * ${spacing.normal} * var(--level));
|
|
72
|
-
gap: ${spacing.xxsmall};
|
|
73
|
-
border: none;
|
|
74
|
-
outline: none;
|
|
75
|
-
color: ${colors.text.primary};
|
|
76
|
-
transition: ${animations.durations.superFast};
|
|
77
|
-
word-break: break-word;
|
|
78
|
-
|
|
79
|
-
&:hover {
|
|
80
|
-
box-shadow: none;
|
|
81
|
-
outline: none;
|
|
82
|
-
background: ${colors.brand.lightest};
|
|
83
|
-
color: ${colors.text.primary};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
&[data-focused="true"] {
|
|
87
|
-
background: ${colors.brand.lightest};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
&[data-selected="true"] {
|
|
91
|
-
background: ${colors.brand.lighter};
|
|
92
|
-
&:hover {
|
|
93
|
-
background: ${colors.brand.light};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
&[data-creating="true"][data-focused="true"] {
|
|
98
|
-
color: ${colors.brand.primary};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
&[data-creating="true"] {
|
|
102
|
-
background: none;
|
|
103
|
-
}
|
|
104
|
-
`;
|
|
105
|
-
|
|
106
|
-
const StyledCheck = styled(CheckLine)`
|
|
107
|
-
color: ${colors.support.green};
|
|
108
|
-
`;
|
|
109
|
-
|
|
110
|
-
const FolderNameLink = styled(SafeLink)`
|
|
111
|
-
display: grid;
|
|
112
|
-
align-items: center;
|
|
113
|
-
grid-template-columns: ${spacing.medium} 1fr auto;
|
|
114
|
-
padding: ${spacing.small} ${spacing.xxsmall};
|
|
115
|
-
padding-left: calc(0.75 * ${spacing.normal} * var(--level));
|
|
116
|
-
gap: ${spacing.xxsmall};
|
|
117
|
-
cursor: pointer;
|
|
118
|
-
|
|
119
|
-
border: none;
|
|
120
|
-
box-shadow: none;
|
|
121
|
-
color: ${colors.text.primary};
|
|
122
|
-
${fonts.sizes("16px")};
|
|
123
|
-
transition: ${animations.durations.superFast};
|
|
124
|
-
word-break: break-word;
|
|
125
|
-
&[data-selected="true"] {
|
|
126
|
-
color: ${colors.brand.primary};
|
|
127
|
-
font-weight: ${fonts.weight.semibold};
|
|
128
|
-
}
|
|
129
|
-
&:hover,
|
|
130
|
-
&:focus {
|
|
131
|
-
color: ${colors.brand.primary};
|
|
132
|
-
}
|
|
133
|
-
`;
|
|
134
|
-
|
|
135
|
-
interface Props extends CommonFolderItemsProps {
|
|
136
|
-
isOpen: boolean;
|
|
137
|
-
folder: IFolder;
|
|
138
|
-
isCreatingFolder?: boolean;
|
|
139
|
-
index: number;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const FolderItem = ({
|
|
143
|
-
focusedFolder,
|
|
144
|
-
folder,
|
|
145
|
-
isOpen,
|
|
146
|
-
level,
|
|
147
|
-
loading,
|
|
148
|
-
selectedFolder,
|
|
149
|
-
onCloseFolder,
|
|
150
|
-
onOpenFolder,
|
|
151
|
-
setFocusedFolder,
|
|
152
|
-
setSelectedFolder,
|
|
153
|
-
targetResource,
|
|
154
|
-
visibleFolders,
|
|
155
|
-
maxLevel,
|
|
156
|
-
isCreatingFolder,
|
|
157
|
-
type,
|
|
158
|
-
closeTree,
|
|
159
|
-
index,
|
|
160
|
-
}: Props) => {
|
|
161
|
-
const { t } = useTranslation();
|
|
162
|
-
const { id, name } = folder;
|
|
163
|
-
const ref = useRef<HTMLButtonElement & HTMLAnchorElement>(null);
|
|
164
|
-
const selected = selectedFolder ? selectedFolder.id === id : false;
|
|
165
|
-
|
|
166
|
-
const levelVariable = useMemo(() => ({ "--level": level }) as unknown as CSSProperties, [level]);
|
|
167
|
-
|
|
168
|
-
const focused = focusedFolder?.id === id;
|
|
169
|
-
|
|
170
|
-
const handleClickFolder = () => {
|
|
171
|
-
if (!selected) {
|
|
172
|
-
setSelectedFolder(folder);
|
|
173
|
-
}
|
|
174
|
-
setFocusedFolder(folder);
|
|
175
|
-
if (type === "picker") {
|
|
176
|
-
if (selected) {
|
|
177
|
-
closeTree();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
useEffect(() => {
|
|
183
|
-
if (focusedFolder?.id === id && !isCreatingFolder) {
|
|
184
|
-
if (type === "navigation") {
|
|
185
|
-
ref.current?.focus();
|
|
186
|
-
}
|
|
187
|
-
if (type === "picker") {
|
|
188
|
-
ref.current?.scrollIntoView({
|
|
189
|
-
behavior: "smooth",
|
|
190
|
-
block: "start",
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}, [focusedFolder, ref, id, isCreatingFolder, type]);
|
|
195
|
-
|
|
196
|
-
const linkPath = `/minndla/folders/${id}`;
|
|
197
|
-
|
|
198
|
-
const containsResource =
|
|
199
|
-
targetResource && folder.resources.some((resource) => resource.resourceId === targetResource.resourceId);
|
|
200
|
-
|
|
201
|
-
const emptyFolder = folder.subfolders.length === 0;
|
|
202
|
-
const isMaxDepth = level > maxLevel;
|
|
203
|
-
const hideArrow = isMaxDepth || emptyFolder;
|
|
204
|
-
|
|
205
|
-
const FolderIcon = folder.status === "shared" ? FolderUserFill : FolderLine;
|
|
206
|
-
|
|
207
|
-
const tabable = selected || focused || (!focusedFolder && !folder.parentId && index === 0);
|
|
208
|
-
|
|
209
|
-
return type === "navigation" ? (
|
|
210
|
-
<FolderNameLink
|
|
211
|
-
role="treeitem"
|
|
212
|
-
aria-owns={folder.subfolders.length ? treestructureId(type, `subfolders-${folder.id}`) : undefined}
|
|
213
|
-
aria-expanded={isMaxDepth || emptyFolder ? undefined : isOpen}
|
|
214
|
-
aria-current={selected ? "page" : undefined}
|
|
215
|
-
aria-describedby={containsResource ? `alreadyAdded-${folder.id}` : undefined}
|
|
216
|
-
ref={ref}
|
|
217
|
-
style={levelVariable}
|
|
218
|
-
onKeyDown={(e: KeyboardEvent<HTMLElement>) => {
|
|
219
|
-
if (e.key === "Enter") {
|
|
220
|
-
setSelectedFolder(folder);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
arrowNavigation(e, id, visibleFolders, setFocusedFolder, onOpenFolder, onCloseFolder);
|
|
224
|
-
}}
|
|
225
|
-
to={loading ? "" : linkPath}
|
|
226
|
-
tabIndex={tabable ? 0 : -1}
|
|
227
|
-
data-selected={selected}
|
|
228
|
-
onFocus={() => setFocusedFolder(folder)}
|
|
229
|
-
onClick={handleClickFolder}
|
|
230
|
-
>
|
|
231
|
-
<OpenButton
|
|
232
|
-
aria-hidden
|
|
233
|
-
tabIndex={-1}
|
|
234
|
-
data-open={isOpen}
|
|
235
|
-
data-hide-arrow={hideArrow}
|
|
236
|
-
onClick={(e) => {
|
|
237
|
-
e.stopPropagation();
|
|
238
|
-
e.preventDefault();
|
|
239
|
-
ref.current?.focus();
|
|
240
|
-
if (isOpen) {
|
|
241
|
-
onCloseFolder(id);
|
|
242
|
-
} else {
|
|
243
|
-
onOpenFolder(id);
|
|
244
|
-
}
|
|
245
|
-
}}
|
|
246
|
-
>
|
|
247
|
-
<ArrowDownShortLine />
|
|
248
|
-
</OpenButton>
|
|
249
|
-
<StyledName>{name}</StyledName>
|
|
250
|
-
</FolderNameLink>
|
|
251
|
-
) : (
|
|
252
|
-
<FolderName
|
|
253
|
-
tabIndex={-1}
|
|
254
|
-
role="treeitem"
|
|
255
|
-
id={treestructureId(type, folder.id)}
|
|
256
|
-
aria-expanded={isMaxDepth || emptyFolder ? undefined : isOpen}
|
|
257
|
-
aria-selected={selected}
|
|
258
|
-
data-focused={focusedFolder?.id === folder.id}
|
|
259
|
-
aria-describedby={containsResource ? `alreadyAdded-${folder.id}` : undefined}
|
|
260
|
-
aria-label={`${name}${folder.status === "shared" ? `, ${t("myNdla.folder.sharing.shared")}` : ""}`}
|
|
261
|
-
variant="ghost"
|
|
262
|
-
shape="sharp"
|
|
263
|
-
fontWeight="normal"
|
|
264
|
-
colorTheme="light"
|
|
265
|
-
ref={ref}
|
|
266
|
-
style={levelVariable}
|
|
267
|
-
data-selected={selected}
|
|
268
|
-
disabled={loading}
|
|
269
|
-
onFocus={() => setFocusedFolder(focusedFolder || folder)}
|
|
270
|
-
onClick={handleClickFolder}
|
|
271
|
-
data-creating={isCreatingFolder}
|
|
272
|
-
>
|
|
273
|
-
<IconWrapper>
|
|
274
|
-
<OpenButton
|
|
275
|
-
aria-hidden
|
|
276
|
-
tabIndex={-1}
|
|
277
|
-
data-open={isOpen}
|
|
278
|
-
data-hide-arrow={hideArrow}
|
|
279
|
-
onClick={(e) => {
|
|
280
|
-
e.stopPropagation();
|
|
281
|
-
setFocusedFolder(folder);
|
|
282
|
-
if (isOpen) {
|
|
283
|
-
onCloseFolder(id);
|
|
284
|
-
} else {
|
|
285
|
-
onOpenFolder(id);
|
|
286
|
-
}
|
|
287
|
-
}}
|
|
288
|
-
>
|
|
289
|
-
<ArrowDownShortLine />
|
|
290
|
-
</OpenButton>
|
|
291
|
-
<FolderIconWrapper>
|
|
292
|
-
<FolderIcon />
|
|
293
|
-
</FolderIconWrapper>
|
|
294
|
-
</IconWrapper>
|
|
295
|
-
<StyledName>{name}</StyledName>
|
|
296
|
-
{containsResource && (
|
|
297
|
-
<StyledCheck
|
|
298
|
-
aria-label={t("myNdla.alreadyInFolder")}
|
|
299
|
-
id={`alreadyAdded-${folder.id}`}
|
|
300
|
-
title={t("myNdla.alreadyInFolder")}
|
|
301
|
-
/>
|
|
302
|
-
)}
|
|
303
|
-
</FolderName>
|
|
304
|
-
);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
export default FolderItem;
|