@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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.flattenFolders = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (c) 2022-present, NDLA.
|
|
9
9
|
*
|
|
@@ -33,8 +33,4 @@ const flattenFolders = (folders, openFolders) => {
|
|
|
33
33
|
}, flattenFolders(subfolders, openFolders));
|
|
34
34
|
}, []);
|
|
35
35
|
};
|
|
36
|
-
exports.flattenFolders = flattenFolders;
|
|
37
|
-
const treestructureId = (type, modifier) => {
|
|
38
|
-
return `${type}-treestructure-${modifier}`;
|
|
39
|
-
};
|
|
40
|
-
exports.treestructureId = treestructureId;
|
|
36
|
+
exports.flattenFolders = flattenFolders;
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "TreeStructure", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return _TreeStructure.
|
|
9
|
+
return _TreeStructure.TreeStructure;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var _TreeStructure =
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
var _TreeStructure = require("./TreeStructure");
|
|
@@ -6,28 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { ReactNode } from "react";
|
|
9
|
-
import { IFolder
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
onClose: () => void;
|
|
9
|
+
import { IFolder } from "@ndla/types-backend/myndla-api";
|
|
10
|
+
export type OnCreatedFunc = (folder: IFolder | undefined) => void;
|
|
11
|
+
export type NewFolderInputFunc = ({ onCancel, parentId, onCreate, }: {
|
|
12
|
+
onCancel: () => void;
|
|
14
13
|
parentId: string;
|
|
15
14
|
onCreate: OnCreatedFunc;
|
|
16
15
|
}) => ReactNode;
|
|
17
|
-
export interface CommonTreeStructureProps {
|
|
18
|
-
loading?: boolean;
|
|
19
|
-
targetResource?: IResource;
|
|
20
|
-
type: TreeStructureType;
|
|
21
|
-
}
|
|
22
|
-
export interface CommonFolderItemsProps extends CommonTreeStructureProps {
|
|
23
|
-
focusedFolder?: IFolder;
|
|
24
|
-
level: number;
|
|
25
|
-
maxLevel: number;
|
|
26
|
-
selectedFolder?: IFolder;
|
|
27
|
-
onCloseFolder: (id: string) => void;
|
|
28
|
-
onOpenFolder: (id: string) => void;
|
|
29
|
-
setFocusedFolder: (folder: IFolder) => void;
|
|
30
|
-
setSelectedFolder: (folder: IFolder) => void;
|
|
31
|
-
visibleFolders: IFolder[];
|
|
32
|
-
closeTree: () => void;
|
|
33
|
-
}
|
package/lib/index.d.ts
CHANGED
|
@@ -36,7 +36,6 @@ export { TagSelectorRoot, TagSelectorLabel, TagSelectorItemInput, TagSelectorTri
|
|
|
36
36
|
export { TreeStructure } from "./TreeStructure";
|
|
37
37
|
export type { TreeStructureProps } from "./TreeStructure";
|
|
38
38
|
export { BlogPostV2 } from "./BlogPost";
|
|
39
|
-
export { ProgrammeCard } from "./ProgrammeCard";
|
|
40
39
|
export { KeyFigure } from "./KeyFigure";
|
|
41
40
|
export { ContactBlock, contactBlockBackgrounds } from "./ContactBlock";
|
|
42
41
|
export type { ContactBlockBackground } from "./ContactBlock";
|
|
@@ -44,7 +43,6 @@ export type { HeartButtonType, CanonicalUrlFuncs, RenderContext } from "./Embed"
|
|
|
44
43
|
export { CampaignBlock } from "./CampaignBlock";
|
|
45
44
|
export { Grid, GridParallaxItem } from "./Grid";
|
|
46
45
|
export type { GridType } from "./Grid";
|
|
47
|
-
export type { ProgrammeV2 } from "./ProgrammeCard";
|
|
48
46
|
export { Gloss, GlossExample } from "./Gloss";
|
|
49
47
|
export { LinkBlock, LinkBlockSection } from "./LinkBlock";
|
|
50
48
|
export type { Article as ArticleType } from "./types";
|
package/lib/index.js
CHANGED
|
@@ -375,12 +375,6 @@ Object.defineProperty(exports, "PdfFile", {
|
|
|
375
375
|
return _FileList.PdfFile;
|
|
376
376
|
}
|
|
377
377
|
});
|
|
378
|
-
Object.defineProperty(exports, "ProgrammeCard", {
|
|
379
|
-
enumerable: true,
|
|
380
|
-
get: function () {
|
|
381
|
-
return _ProgrammeCard.ProgrammeCard;
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
378
|
Object.defineProperty(exports, "RelatedArticle", {
|
|
385
379
|
enumerable: true,
|
|
386
380
|
get: function () {
|
|
@@ -636,7 +630,6 @@ var _CopyParagraphButton = _interopRequireDefault(require("./CopyParagraphButton
|
|
|
636
630
|
var _TagSelector = require("./TagSelector/TagSelector");
|
|
637
631
|
var _TreeStructure = require("./TreeStructure");
|
|
638
632
|
var _BlogPost = require("./BlogPost");
|
|
639
|
-
var _ProgrammeCard = require("./ProgrammeCard");
|
|
640
633
|
var _KeyFigure = require("./KeyFigure");
|
|
641
634
|
var _ContactBlock = require("./ContactBlock");
|
|
642
635
|
var _CampaignBlock = require("./CampaignBlock");
|
|
@@ -1239,7 +1239,7 @@ const messages = {
|
|
|
1239
1239
|
loginTerms: "Log in with Feide to receive access. By logging on your accept your terms of service",
|
|
1240
1240
|
loginResourcePitch: "Do you want to favorite this resource?",
|
|
1241
1241
|
loginWelcome: "Welcome to My NDLA!",
|
|
1242
|
-
deleteAccount: "Delete
|
|
1242
|
+
deleteAccount: "Delete profile",
|
|
1243
1243
|
loginPitch: "Welcome to My NDLA! Here you can save your favourite resources from NDLA, organize them and share them with others. Log in with your Feide account to get started.",
|
|
1244
1244
|
loginPitchButton: "Log in to My NDLA",
|
|
1245
1245
|
welcome: "Welcome to my NDLA! You can now save your favourite resources from NDLA and organise them in folders with tags",
|
|
@@ -1232,7 +1232,7 @@ const messages = {
|
|
|
1232
1232
|
confirmDeleteAccount: "Er du sikker på at du vil slette kontoen?",
|
|
1233
1233
|
confirmDeleteAccountButton: "Slett konto",
|
|
1234
1234
|
myPage: "Min side",
|
|
1235
|
-
deleteAccount: "Slett
|
|
1235
|
+
deleteAccount: "Slett brukerprofil",
|
|
1236
1236
|
loginPitch: "Velkommen til Min NDLA! Her kan du lagre favorittressursene dine fra NDLA, organisere dem og dele dem med andre. Logg inn med din Feide-konto for å komme i gang.",
|
|
1237
1237
|
loginPitchButton: "Logg inn i Min NDLA",
|
|
1238
1238
|
logout: "Logg ut av Min NDLA",
|
|
@@ -1232,7 +1232,7 @@ const messages = {
|
|
|
1232
1232
|
confirmDeleteAccount: "Er du sikker på at du vil slette kontoen?",
|
|
1233
1233
|
confirmDeleteAccountButton: "Slett konto",
|
|
1234
1234
|
myPage: "Mi side",
|
|
1235
|
-
deleteAccount: "Slett
|
|
1235
|
+
deleteAccount: "Slett brukarprofil",
|
|
1236
1236
|
loginPitch: "Velkommen til Min NDLA! Her kan du lagre favorittressursane dine frå NDLA, organisere dei og dele dei med andre. Logg inn med din Feide-konto for å komme i gang.",
|
|
1237
1237
|
loginPitchButton: "Logg inn i Min NDLA",
|
|
1238
1238
|
logout: "Logg ut av Min NDLA",
|
|
@@ -1232,7 +1232,7 @@ const messages = {
|
|
|
1232
1232
|
confirmDeleteAccount: "Er du sikker på at du vil slette kontoen?",
|
|
1233
1233
|
confirmDeleteAccountButton: "Slett konto",
|
|
1234
1234
|
myPage: "Min side",
|
|
1235
|
-
deleteAccount: "Slett
|
|
1235
|
+
deleteAccount: "Slett brukerprofil",
|
|
1236
1236
|
loginPitch: "Velkommen til Min NDLA! Her kan du lagre favorittressursene dine fra NDLA, organisere dem og dele dem med andre. Logg inn med din Feide-konto for å komme i gang.",
|
|
1237
1237
|
loginPitchButton: "Logg inn i Min NDLA",
|
|
1238
1238
|
logout: "Logg ut av Min NDLA",
|
|
@@ -1232,7 +1232,7 @@ const messages = {
|
|
|
1232
1232
|
confirmDeleteAccount: "Er du sikker på at du vil slette kontoen?",
|
|
1233
1233
|
confirmDeleteAccountButton: "Slett konto",
|
|
1234
1234
|
myPage: "Min side",
|
|
1235
|
-
deleteAccount: "Slett
|
|
1235
|
+
deleteAccount: "Slett brukerprofil",
|
|
1236
1236
|
loginPitch: "Velkommen til Min NDLA! Her kan du lagre favorittressursene dine fra NDLA, organisere dem og dele dem med andre. Logg inn med din Feide-konto for å komme i gang.",
|
|
1237
1237
|
loginPitchButton: "Logg inn i Min NDLA",
|
|
1238
1238
|
logout: "Logg ut av Min NDLA",
|
package/lib/styles.css
CHANGED
|
@@ -89,6 +89,10 @@
|
|
|
89
89
|
padding-inline: 8%;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
.w_100\% {
|
|
93
|
+
width: 100%;
|
|
94
|
+
}
|
|
95
|
+
|
|
92
96
|
.pbs_xsmall {
|
|
93
97
|
padding-block-start: var(--spacing-xsmall);
|
|
94
98
|
}
|
|
@@ -109,10 +113,6 @@
|
|
|
109
113
|
color: var(--colors-text-default);
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
.w_100\% {
|
|
113
|
-
width: 100%;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
116
|
.ov-wrap_break-word {
|
|
117
117
|
overflow-wrap: break-word;
|
|
118
118
|
}
|
|
@@ -611,6 +611,18 @@
|
|
|
611
611
|
aspect-ratio: 1/1;
|
|
612
612
|
}
|
|
613
613
|
|
|
614
|
+
.max-h_inherit {
|
|
615
|
+
max-height: inherit;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
.ov_auto {
|
|
619
|
+
overflow: auto;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
.gap_10px {
|
|
623
|
+
gap: 10px;
|
|
624
|
+
}
|
|
625
|
+
|
|
614
626
|
.flex-d_column {
|
|
615
627
|
flex-direction: column;
|
|
616
628
|
}
|
|
@@ -1171,6 +1183,14 @@
|
|
|
1171
1183
|
text-decoration: underline;
|
|
1172
1184
|
}
|
|
1173
1185
|
|
|
1186
|
+
.\[\&_span\]\:ov_hidden span {
|
|
1187
|
+
overflow: hidden;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
.\[\&_span\]\:tov_ellipsis span {
|
|
1191
|
+
text-overflow: ellipsis;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1174
1194
|
.after\:content_0::after {
|
|
1175
1195
|
content: 0;
|
|
1176
1196
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
|
-
"version": "56.0.
|
|
3
|
+
"version": "56.0.15-alpha.0",
|
|
4
4
|
"description": "UI component library for NDLA",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -33,13 +33,12 @@
|
|
|
33
33
|
"types"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ndla/button": "^15.0.9-alpha.0",
|
|
37
36
|
"@ndla/core": "^5.0.2",
|
|
38
|
-
"@ndla/icons": "^8.0.
|
|
37
|
+
"@ndla/icons": "^8.0.10-alpha.0",
|
|
39
38
|
"@ndla/licenses": "^8.0.1-alpha.0",
|
|
40
|
-
"@ndla/primitives": "^1.0.
|
|
41
|
-
"@ndla/safelink": "^7.0.
|
|
42
|
-
"@ndla/styled-system": "^0.0.
|
|
39
|
+
"@ndla/primitives": "^1.0.14-alpha.0",
|
|
40
|
+
"@ndla/safelink": "^7.0.14-alpha.0",
|
|
41
|
+
"@ndla/styled-system": "^0.0.12",
|
|
43
42
|
"@ndla/util": "^4.1.0",
|
|
44
43
|
"html-react-parser": "^5.1.8",
|
|
45
44
|
"i18next-browser-languagedetector": "^7.1.0"
|
|
@@ -54,7 +53,7 @@
|
|
|
54
53
|
"react-router-dom": "> 6.0.0"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
|
-
"@ndla/preset-panda": "^0.0.
|
|
56
|
+
"@ndla/preset-panda": "^0.0.20",
|
|
58
57
|
"@ndla/types-backend": "^0.2.86",
|
|
59
58
|
"@ndla/types-embed": "^5.0.1-alpha.0",
|
|
60
59
|
"@pandacss/dev": "^0.44.0",
|
|
@@ -67,5 +66,5 @@
|
|
|
67
66
|
"publishConfig": {
|
|
68
67
|
"access": "public"
|
|
69
68
|
},
|
|
70
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "4708656585c922a4b2c2e30b095f88097c29436b"
|
|
71
70
|
}
|
package/src/Article/Article.tsx
CHANGED
|
@@ -17,6 +17,8 @@ import { styled } from "@ndla/styled-system/jsx";
|
|
|
17
17
|
|
|
18
18
|
import * as contentTypes from "../model/ContentType";
|
|
19
19
|
|
|
20
|
+
// TODO: Remove this component
|
|
21
|
+
|
|
20
22
|
interface Props extends ComponentPropsWithoutRef<"div"> {
|
|
21
23
|
size?: "xx-small" | "x-small" | "small" | "large";
|
|
22
24
|
type: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024-present, NDLA.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the GPLv3 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,42 +7,34 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
|
|
10
|
-
import { isMobile } from "react-device-detect";
|
|
11
10
|
import { useTranslation } from "react-i18next";
|
|
12
|
-
import styled from "@emotion/styled";
|
|
13
11
|
import { Meta, StoryFn } from "@storybook/react";
|
|
14
|
-
import { IconButtonV2 } from "@ndla/button";
|
|
15
|
-
import { spacing } from "@ndla/core";
|
|
16
|
-
import { Spinner } from "@ndla/icons";
|
|
17
12
|
import { CloseLine } from "@ndla/icons/action";
|
|
18
13
|
import { CheckLine } from "@ndla/icons/editor";
|
|
19
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
FieldErrorMessage,
|
|
16
|
+
FieldInput,
|
|
17
|
+
FieldLabel,
|
|
18
|
+
FieldRoot,
|
|
19
|
+
FieldHelper,
|
|
20
|
+
IconButton,
|
|
21
|
+
InputContainer,
|
|
22
|
+
Spinner,
|
|
23
|
+
} from "@ndla/primitives";
|
|
24
|
+
import { HStack, styled } from "@ndla/styled-system/jsx";
|
|
20
25
|
import { IFolder } from "@ndla/types-backend/myndla-api";
|
|
21
|
-
import { uuid } from "@ndla/util";
|
|
22
26
|
import { flattenFolders } from "./helperFunctions";
|
|
23
|
-
import TreeStructure,
|
|
27
|
+
import { TreeStructure, TreeStructureProps } from "./TreeStructure";
|
|
24
28
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
height: 250px;
|
|
33
|
-
}
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
const Row = styled.div`
|
|
37
|
-
display: flex;
|
|
38
|
-
align-items: center;
|
|
39
|
-
gap: ${spacing.xxsmall};
|
|
40
|
-
padding-right: ${spacing.xsmall};
|
|
41
|
-
`;
|
|
29
|
+
const Container = styled("div", {
|
|
30
|
+
base: {
|
|
31
|
+
display: "flex",
|
|
32
|
+
maxWidth: "surface.large",
|
|
33
|
+
maxHeight: "surface.small",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
42
36
|
|
|
43
|
-
const
|
|
44
|
-
margin: ${spacing.small};
|
|
45
|
-
`;
|
|
37
|
+
const MY_FOLDERS_ID = "folders";
|
|
46
38
|
|
|
47
39
|
const targetResource: TreeStructureProps["targetResource"] = {
|
|
48
40
|
id: "test-resource",
|
|
@@ -147,7 +139,6 @@ export default {
|
|
|
147
139
|
targetResource: targetResource,
|
|
148
140
|
label: "Velg mappe",
|
|
149
141
|
maxLevel: 5,
|
|
150
|
-
type: "picker",
|
|
151
142
|
// eslint-disable-next-line no-console
|
|
152
143
|
onSelectFolder: console.log,
|
|
153
144
|
},
|
|
@@ -157,25 +148,19 @@ export default {
|
|
|
157
148
|
} as Meta<typeof TreeStructure>;
|
|
158
149
|
|
|
159
150
|
export const Default: StoryFn<typeof TreeStructure> = ({ ...args }) => {
|
|
160
|
-
const [structure, setStructure] = useState<IFolder[]>(
|
|
161
|
-
args.type === "picker" ? FOLDER_TREE_STRUCTURE : STRUCTURE_EXAMPLE,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
useEffect(() => {
|
|
165
|
-
setStructure(args.type === "picker" ? FOLDER_TREE_STRUCTURE : STRUCTURE_EXAMPLE);
|
|
166
|
-
}, [args.type]);
|
|
151
|
+
const [structure, setStructure] = useState<IFolder[]>(FOLDER_TREE_STRUCTURE);
|
|
167
152
|
|
|
168
153
|
return (
|
|
169
|
-
<Container
|
|
154
|
+
<Container>
|
|
170
155
|
<TreeStructure
|
|
171
156
|
{...args}
|
|
172
157
|
folders={structure}
|
|
173
|
-
newFolderInput={({ parentId,
|
|
158
|
+
newFolderInput={({ parentId, onCancel, onCreate }) => (
|
|
174
159
|
<NewFolder
|
|
175
160
|
structure={structure}
|
|
176
161
|
setStructure={setStructure}
|
|
177
162
|
parentId={parentId}
|
|
178
|
-
|
|
163
|
+
onCancel={onCancel}
|
|
179
164
|
onCreate={onCreate}
|
|
180
165
|
/>
|
|
181
166
|
)}
|
|
@@ -188,8 +173,8 @@ interface NewFolderProps {
|
|
|
188
173
|
parentId: string;
|
|
189
174
|
structure: IFolder[];
|
|
190
175
|
setStructure: Dispatch<SetStateAction<IFolder[]>>;
|
|
191
|
-
|
|
192
|
-
onCreate?: (folder: IFolder
|
|
176
|
+
onCancel?: () => void;
|
|
177
|
+
onCreate?: (folder: IFolder) => void;
|
|
193
178
|
}
|
|
194
179
|
|
|
195
180
|
const generateNewFolder = (name: string, id: string, breadcrumbs: { id: string; name: string }[]): IFolder => ({
|
|
@@ -203,7 +188,7 @@ const generateNewFolder = (name: string, id: string, breadcrumbs: { id: string;
|
|
|
203
188
|
updated: "2023-03-03T08:40:23.444Z",
|
|
204
189
|
});
|
|
205
190
|
|
|
206
|
-
const NewFolder = ({ parentId,
|
|
191
|
+
const NewFolder = ({ parentId, onCancel, structure, setStructure, onCreate }: NewFolderProps) => {
|
|
207
192
|
const [name, setName] = useState("");
|
|
208
193
|
const [loading, setLoading] = useState(false);
|
|
209
194
|
const [error, setError] = useState("");
|
|
@@ -212,12 +197,6 @@ const NewFolder = ({ parentId, onClose, structure, setStructure, onCreate }: New
|
|
|
212
197
|
|
|
213
198
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
214
199
|
|
|
215
|
-
useEffect(() => {
|
|
216
|
-
if (isMobile) {
|
|
217
|
-
inputRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
218
|
-
}
|
|
219
|
-
}, []);
|
|
220
|
-
|
|
221
200
|
const onSave = async () => {
|
|
222
201
|
if (error) {
|
|
223
202
|
return;
|
|
@@ -230,7 +209,7 @@ const NewFolder = ({ parentId, onClose, structure, setStructure, onCreate }: New
|
|
|
230
209
|
setLoading(false);
|
|
231
210
|
const flattenedStructure = flattenFolders(structure);
|
|
232
211
|
const targetFolder = flattenedStructure.find((folder) => folder.id === parentId);
|
|
233
|
-
const newFolderId =
|
|
212
|
+
const newFolderId = (flattenedStructure.length + 1).toString();
|
|
234
213
|
const newFolder = generateNewFolder(name, newFolderId, targetFolder?.breadcrumbs ?? []);
|
|
235
214
|
if (targetFolder) {
|
|
236
215
|
setStructure((oldStructure) => {
|
|
@@ -240,8 +219,7 @@ const NewFolder = ({ parentId, onClose, structure, setStructure, onCreate }: New
|
|
|
240
219
|
} else {
|
|
241
220
|
setStructure((old) => [newFolder].concat(old));
|
|
242
221
|
}
|
|
243
|
-
onCreate?.(newFolder
|
|
244
|
-
onClose?.();
|
|
222
|
+
onCreate?.(newFolder);
|
|
245
223
|
};
|
|
246
224
|
|
|
247
225
|
useEffect(() => {
|
|
@@ -273,39 +251,31 @@ const NewFolder = ({ parentId, onClose, structure, setStructure, onCreate }: New
|
|
|
273
251
|
onKeyDown={(e) => {
|
|
274
252
|
if (e.key === "Escape") {
|
|
275
253
|
e.preventDefault();
|
|
276
|
-
|
|
254
|
+
onCancel?.();
|
|
277
255
|
} else if (e.key === "Enter") {
|
|
278
256
|
e.preventDefault();
|
|
279
257
|
onSave();
|
|
280
258
|
}
|
|
281
259
|
}}
|
|
282
260
|
/>
|
|
283
|
-
<
|
|
261
|
+
<HStack gap="3xsmall">
|
|
284
262
|
{!loading ? (
|
|
285
263
|
<>
|
|
286
264
|
{!error && (
|
|
287
|
-
<
|
|
288
|
-
variant={"ghost"}
|
|
289
|
-
colorTheme="light"
|
|
290
|
-
tabIndex={0}
|
|
291
|
-
aria-label={t("save")}
|
|
292
|
-
title={t("save")}
|
|
293
|
-
size="small"
|
|
294
|
-
onClick={onSave}
|
|
295
|
-
>
|
|
265
|
+
<IconButton variant="tertiary" aria-label={t("save")} title={t("save")} onClick={onSave}>
|
|
296
266
|
<CheckLine />
|
|
297
|
-
</
|
|
267
|
+
</IconButton>
|
|
298
268
|
)}
|
|
299
|
-
<
|
|
269
|
+
<IconButton aria-label={t("close")} title={t("close")} variant="tertiary" onClick={onCancel}>
|
|
300
270
|
<CloseLine />
|
|
301
|
-
</
|
|
271
|
+
</IconButton>
|
|
302
272
|
</>
|
|
303
273
|
) : (
|
|
304
274
|
<FieldHelper>
|
|
305
|
-
<
|
|
275
|
+
<Spinner size="small" aria-label={t("loading")} />
|
|
306
276
|
</FieldHelper>
|
|
307
277
|
)}
|
|
308
|
-
</
|
|
278
|
+
</HStack>
|
|
309
279
|
</InputContainer>
|
|
310
280
|
</FieldRoot>
|
|
311
281
|
);
|