@stack-spot/portal-components 2.9.0 → 2.10.1
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/CHANGELOG.md +14 -0
- package/dist/components/FileTreeView/More.d.ts +23 -0
- package/dist/components/FileTreeView/More.d.ts.map +1 -0
- package/dist/components/FileTreeView/More.js +55 -0
- package/dist/components/FileTreeView/More.js.map +1 -0
- package/dist/components/FileTreeView/index.d.ts +32 -0
- package/dist/components/FileTreeView/index.d.ts.map +1 -0
- package/dist/components/FileTreeView/index.js +86 -0
- package/dist/components/FileTreeView/index.js.map +1 -0
- package/package.json +3 -2
- package/src/components/FileTreeView/More.tsx +114 -0
- package/src/components/FileTreeView/index.tsx +181 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.10.1](https://github.com/stack-spot/portal-commons/compare/portal-components@v2.10.0...portal-components@v2.10.1) (2024-11-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* Fix 1603 rotate icon of folder file tree view ([#506](https://github.com/stack-spot/portal-commons/issues/506)) ([8201989](https://github.com/stack-spot/portal-commons/commit/8201989ddc6cac28cecdd3e12b597abeb2c2fee0))
|
|
9
|
+
|
|
10
|
+
## [2.10.0](https://github.com/stack-spot/portal-commons/compare/portal-components@v2.9.0...portal-components@v2.10.0) (2024-11-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* FileTree View component ([#496](https://github.com/stack-spot/portal-commons/issues/496)) ([d66e12d](https://github.com/stack-spot/portal-commons/commit/d66e12dd34e8314f7fb49e3a9cf7b8efc3e93fb2))
|
|
16
|
+
|
|
3
17
|
## [2.9.0](https://github.com/stack-spot/portal-commons/compare/portal-components@v2.8.1...portal-components@v2.9.0) (2024-10-30)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as icons from '@citric/icons';
|
|
2
|
+
export type IconName = keyof typeof icons;
|
|
3
|
+
export type MenuOption = {
|
|
4
|
+
/**
|
|
5
|
+
* The text that will be displayed for the option.
|
|
6
|
+
*/
|
|
7
|
+
label: string;
|
|
8
|
+
/**
|
|
9
|
+
* The icon that will be displayed alongside the text.
|
|
10
|
+
*/
|
|
11
|
+
icon: IconName;
|
|
12
|
+
/**
|
|
13
|
+
* The function that will be executed when the option is clicked.
|
|
14
|
+
*/
|
|
15
|
+
onClick: VoidFunction;
|
|
16
|
+
};
|
|
17
|
+
interface Props {
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
menu: MenuOption[];
|
|
20
|
+
}
|
|
21
|
+
export declare function More({ loading, menu }: Props): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=More.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"More.d.ts","sourceRoot":"","sources":["../../../src/components/FileTreeView/More.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,eAAe,CAAA;AAMtC,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,KAAK,CAAA;AAEzC,MAAM,MAAM,UAAU,GAAG;IACzB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;CACrB,CAAA;AAED,UAAU,KAAK;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB;AA8CD,wBAAgB,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,2CAuC5C"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, IconBox, Text } from '@citric/core';
|
|
3
|
+
import * as icons from '@citric/icons';
|
|
4
|
+
import { EllipsisVertical } from '@citric/icons';
|
|
5
|
+
import { IconButton } from '@citric/ui';
|
|
6
|
+
import { theme } from '@stack-spot/portal-theme';
|
|
7
|
+
import { createElement, useState } from 'react';
|
|
8
|
+
const styles = {
|
|
9
|
+
MoreWrapper: {
|
|
10
|
+
position: 'relative',
|
|
11
|
+
'button': {
|
|
12
|
+
width: '2rem',
|
|
13
|
+
height: '2rem',
|
|
14
|
+
},
|
|
15
|
+
'.drop': {
|
|
16
|
+
zIndex: 1,
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
listStyle: 'none',
|
|
19
|
+
display: 'flex',
|
|
20
|
+
margin: '0',
|
|
21
|
+
padding: '0.25rem',
|
|
22
|
+
flexDirection: 'column',
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
alignItems: 'flex-start',
|
|
25
|
+
gap: '0.5rem',
|
|
26
|
+
borderRadius: '0.25rem',
|
|
27
|
+
border: `0.063rem solid ${theme.color.light[400]}`,
|
|
28
|
+
backgroundColor: '${theme.color.light[500]}',
|
|
29
|
+
boxShadow: '0 0 0 0.125rem ${theme.color.gray[600]}',
|
|
30
|
+
right: '2px',
|
|
31
|
+
width: 'max-content',
|
|
32
|
+
'ul': {
|
|
33
|
+
padding: 0,
|
|
34
|
+
margin: 0,
|
|
35
|
+
},
|
|
36
|
+
'.item-list-float': {
|
|
37
|
+
minWidth: '230px',
|
|
38
|
+
listStyleType: 'none',
|
|
39
|
+
padding: '8px',
|
|
40
|
+
paddingRight: '12px',
|
|
41
|
+
display: 'flex',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
cursor: 'pointer',
|
|
44
|
+
'&:hover': {
|
|
45
|
+
backgroundColor: `${theme.color.light[600]}`,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export function More({ loading, menu }) {
|
|
52
|
+
const [opened, setOpened] = useState(false);
|
|
53
|
+
return (_jsxs(Box, { sx: styles.MoreWrapper, children: [_jsx(IconButton, { color: "light", size: "sm", appearance: "circle", "aria-label": "More options", disabled: loading, onClick: () => setOpened((old) => !old), onBlur: () => setTimeout(() => setOpened(false), 200), children: _jsx(IconBox, { size: "xs", children: _jsx(EllipsisVertical, {}) }) }), opened && (_jsx("div", { className: "drop", children: _jsx("ul", { className: "drop-wrapper", children: menu.map((menuItem, key) => (_jsxs("li", { role: "button", className: "item-list-float", onClick: menuItem.onClick, children: [_jsx(IconBox, { size: "sm", children: createElement(icons[menuItem.icon]) }), _jsx(Text, { appearance: "body2", children: menuItem.label })] }, key))) }) }))] }));
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=More.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"More.js","sourceRoot":"","sources":["../../../src/components/FileTreeView/More.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,KAAK,KAAK,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAwB/C,MAAM,MAAM,GAAG;IACb,WAAW,EAAE;QACX,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE;YACR,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,MAAM;SACf;QACD,OAAO,EAAE;YACP,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,MAAM;YACjB,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,SAAS;YAClB,aAAa,EAAE,QAAQ;YACvB,c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,IAAI,EAAC,IAAI,YAChB,KAAC,gBAAgB,KAAG,GACZ,GACC,EAEX,MAAM,IAAI,CACR,cAAK,SAAS,EAAC,MAAM,YACnB,aAAI,SAAS,EAAC,cAAc,YAExB,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,CAC1B,cAAI,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,EAAW,OAAO,EAAE,QAAQ,CAAC,OAAO,aAC/E,KAAC,OAAO,IAAC,IAAI,EAAC,IAAI,YACf,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAC5B,EACV,KAAC,IAAI,IAAC,UAAU,EAAC,OAAO,YAAE,QAAQ,CAAC,KAAK,GAAQ,KAJC,GAAG,CAKjD,CACN,CAAC,GAED,GACD,CACP,IAEC,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MenuOption } from './More.js';
|
|
2
|
+
export interface FileDir {
|
|
3
|
+
/**
|
|
4
|
+
* The name of the directory or file.
|
|
5
|
+
* */
|
|
6
|
+
name: string;
|
|
7
|
+
/**
|
|
8
|
+
* dirs - An array containing the directories present in the file tree.
|
|
9
|
+
*/
|
|
10
|
+
dirs: FileDir[];
|
|
11
|
+
/**
|
|
12
|
+
* isFile - A flag indicating whether the item is a file (`true`) or a directory (`false`).
|
|
13
|
+
*/
|
|
14
|
+
isFile?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* itemLink - The URL or path link associated with the item in the file tree.
|
|
17
|
+
*/
|
|
18
|
+
itemLink: string;
|
|
19
|
+
/**
|
|
20
|
+
* The menu options that will be rendered at the end of the line for this item.
|
|
21
|
+
*/
|
|
22
|
+
menuOptions?: MenuOption[];
|
|
23
|
+
}
|
|
24
|
+
interface Props {
|
|
25
|
+
/**
|
|
26
|
+
* Represents the hierarchical structure of directories and files, providing the component with an organized view of the file system.
|
|
27
|
+
*/
|
|
28
|
+
fileTree: FileDir;
|
|
29
|
+
}
|
|
30
|
+
export declare const FileTreeView: ({ fileTree }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FileTreeView/index.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAQ,MAAM,QAAQ,CAAA;AAuEzC,MAAM,WAAW,OAAO;IACtB;;SAEK;IACL,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B;AAED,UAAU,KAAK;IACb;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,YAAY,iBAAkB,KAAK,4CAwE/C,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, IconBox, Text } from '@citric/core';
|
|
3
|
+
import { ChevronRight, Code, Folder } from '@citric/icons';
|
|
4
|
+
import { theme } from '@stack-spot/portal-theme';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { useAnchorTag } from '../../context/anchor.js';
|
|
7
|
+
import { More } from './More.js';
|
|
8
|
+
const styles = {
|
|
9
|
+
FileTreeViewWrapper: {
|
|
10
|
+
height: '100%',
|
|
11
|
+
display: 'flex',
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
margin: '16px',
|
|
14
|
+
},
|
|
15
|
+
AccordionItemWrapper: {
|
|
16
|
+
width: '100%',
|
|
17
|
+
'ul': {
|
|
18
|
+
listStyleType: 'none',
|
|
19
|
+
margin: 0,
|
|
20
|
+
padding: 0,
|
|
21
|
+
flexDirection: 'column',
|
|
22
|
+
marginLeft: '20px',
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
},
|
|
25
|
+
'li': {
|
|
26
|
+
display: 'flex',
|
|
27
|
+
listStyleType: 'none',
|
|
28
|
+
margin: '2px 0',
|
|
29
|
+
padding: 0,
|
|
30
|
+
flexDirection: 'row',
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
gap: '4px',
|
|
33
|
+
},
|
|
34
|
+
'.accordion-node-group': {
|
|
35
|
+
justifyContent: 'space-between',
|
|
36
|
+
width: '100%',
|
|
37
|
+
'&:hover': {
|
|
38
|
+
backgroundColor: `${theme.color.light[500]}`,
|
|
39
|
+
borderRadius: '4px',
|
|
40
|
+
},
|
|
41
|
+
'a': {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
alignItems: 'center',
|
|
44
|
+
textDecoration: 'underline',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
'.accordion-node': {
|
|
48
|
+
cursor: 'pointer',
|
|
49
|
+
flexDirection: 'row',
|
|
50
|
+
display: 'flex',
|
|
51
|
+
gap: '4px',
|
|
52
|
+
alignItems: 'center',
|
|
53
|
+
background: 'transparent',
|
|
54
|
+
color: 'inherit',
|
|
55
|
+
border: 'none',
|
|
56
|
+
'.icon': {
|
|
57
|
+
transition: 'transform ease-in-out 0.3s',
|
|
58
|
+
},
|
|
59
|
+
'.open': {
|
|
60
|
+
transform: 'rotate(90deg)',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
'actions': {
|
|
64
|
+
display: 'flex',
|
|
65
|
+
flexDirection: 'row',
|
|
66
|
+
gap: '4px',
|
|
67
|
+
alignItems: 'center',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
export const FileTreeView = ({ fileTree }) => {
|
|
72
|
+
const AccordionItem = ({ name, isFile, dirs, defaultOpened = false, menuOptions, itemLink }) => {
|
|
73
|
+
const Link = useAnchorTag();
|
|
74
|
+
const [opened, setOpened] = useState(defaultOpened);
|
|
75
|
+
const onExpand = () => {
|
|
76
|
+
setOpened(old => !old);
|
|
77
|
+
};
|
|
78
|
+
const FolderItem = () => (_jsxs("li", { className: "accordion-node-group", children: [_jsxs("button", { className: "accordion-node", onClick: onExpand, children: [_jsx(IconBox, { className: `icon ${opened ? 'open' : ''}`, children: _jsx(ChevronRight, {}) }), _jsx(IconBox, { children: _jsx(Folder, {}) }), _jsx(Text, { children: name !== '' ? name : '/' })] }), menuOptions &&
|
|
79
|
+
_jsx("div", { className: "actions", children: _jsx(More, { menu: menuOptions }) })] }));
|
|
80
|
+
const FileItem = () => (_jsxs("li", { className: "accordion-node-group", children: [_jsxs(Link, { href: itemLink, children: [_jsx(IconBox, { children: _jsx(Code, {}) }), _jsx(Text, { as: "label", children: name })] }), menuOptions &&
|
|
81
|
+
_jsx("div", { className: "actions", children: _jsx(More, { menu: menuOptions }) })] }));
|
|
82
|
+
return (_jsxs(Box, { sx: styles.AccordionItemWrapper, children: [isFile ? _jsx(FileItem, {}) : _jsx(FolderItem, {}), _jsx("ul", { className: "accordion-children", children: opened && !isFile && dirs && dirs.length > 0 && (_jsx(_Fragment, { children: dirs?.map((subDir, index) => (_jsx("li", { children: _jsx(AccordionItem, { ...subDir }) }, index))) })) })] }));
|
|
83
|
+
};
|
|
84
|
+
return (_jsx(Box, { sx: styles.FileTreeViewWrapper, children: _jsx(AccordionItem, { ...fileTree, defaultOpened: true }) }));
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/FileTreeView/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,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WAAW,GAAI,GACvB,IAEL,CACN,CAAA;QAED,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,CACrB,cAAI,SAAS,EAAC,sBAAsB,aAClC,MAAC,IAAI,IAAC,IAAI,EAAE,QAAQ,aAClB,KAAC,OAAO,cACN,KAAC,IAAI,KAAG,GACA,EACV,KAAC,IAAI,IAAC,EAAE,EAAC,OAAO,YAAE,IAAI,GAAQ,IACzB,EACL,WAAW;oBACX,cAAK,SAAS,EAAC,SAAS,YACtB,KAAC,IAAI,IAAC,IAAI,EAAE,WAAW,GAAI,GACvB,IAEJ,CACP,CAAA;QAED,OAAO,CACL,MAAC,GAAG,IAAC,EAAE,EAAE,MAAM,CAAC,oBAAoB,aAEhC,MAAM,CAAC,CAAC,CAAC,KAAC,QAAQ,KAAG,CAAC,CAAC,CAAC,KAAC,UAAU,KAAG,EAExC,aAAI,SAAS,EAAC,oBAAoB,YAC/B,MAAM,IAAI,CAAC,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAC/C,4BACG,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAC5B,uBACE,KAAC,aAAa,OAAK,MAAM,GAAI,IADtB,KAAK,CAER,CACP,CAAC,GACD,CACJ,GACE,IACD,CACP,CAAA;IACH,CAAC,CAAA;IAED,OAAO,CACL,KAAC,GAAG,IAAC,EAAE,EAAE,MAAM,CAAC,mBAAmC,YACjD,KAAC,aAAa,OAAK,QAAQ,EAAE,aAAa,EAAE,IAAI,GAAI,GAChD,CACP,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stack-spot/portal-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"./AnimatedHeight": "./dist/components/AnimatedHeight.js",
|
|
23
23
|
"./SearchInput": "./dist/components/form/SearchInput.js",
|
|
24
24
|
"./Select": "./dist/components/form/Select/index.js",
|
|
25
|
-
"./Stepper": "./dist/components/Stepper/index.js"
|
|
25
|
+
"./Stepper": "./dist/components/Stepper/index.js",
|
|
26
|
+
"./FileTreeView": "./dist/components/FileTreeView/index.js"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
29
|
"build": "rimraf dist && tsc && tsc-esm-fix --target='dist'",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Box, IconBox, Text } from '@citric/core'
|
|
2
|
+
import { SxProperties } from '@citric/core/dist/sx'
|
|
3
|
+
import * as icons from '@citric/icons'
|
|
4
|
+
import { EllipsisVertical } from '@citric/icons'
|
|
5
|
+
import { IconButton } from '@citric/ui'
|
|
6
|
+
import { theme } from '@stack-spot/portal-theme'
|
|
7
|
+
import { createElement, useState } from 'react'
|
|
8
|
+
|
|
9
|
+
export type IconName = keyof typeof icons
|
|
10
|
+
|
|
11
|
+
export type MenuOption = {
|
|
12
|
+
/**
|
|
13
|
+
* The text that will be displayed for the option.
|
|
14
|
+
*/
|
|
15
|
+
label: string,
|
|
16
|
+
/**
|
|
17
|
+
* The icon that will be displayed alongside the text.
|
|
18
|
+
*/
|
|
19
|
+
icon: IconName,
|
|
20
|
+
/**
|
|
21
|
+
* The function that will be executed when the option is clicked.
|
|
22
|
+
*/
|
|
23
|
+
onClick: VoidFunction,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
loading?: boolean,
|
|
28
|
+
menu: MenuOption[],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const styles = {
|
|
32
|
+
MoreWrapper: {
|
|
33
|
+
position: 'relative',
|
|
34
|
+
'button': {
|
|
35
|
+
width: '2rem',
|
|
36
|
+
height: '2rem',
|
|
37
|
+
},
|
|
38
|
+
'.drop': {
|
|
39
|
+
zIndex: 1,
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
listStyle: 'none',
|
|
42
|
+
display: 'flex',
|
|
43
|
+
margin: '0',
|
|
44
|
+
padding: '0.25rem',
|
|
45
|
+
flexDirection: 'column',
|
|
46
|
+
justifyContent: 'center',
|
|
47
|
+
alignItems: 'flex-start',
|
|
48
|
+
gap: '0.5rem',
|
|
49
|
+
borderRadius: '0.25rem',
|
|
50
|
+
border: `0.063rem solid ${theme.color.light[400]}`,
|
|
51
|
+
backgroundColor: '${theme.color.light[500]}',
|
|
52
|
+
boxShadow: '0 0 0 0.125rem ${theme.color.gray[600]}',
|
|
53
|
+
right: '2px',
|
|
54
|
+
width: 'max-content',
|
|
55
|
+
'ul': {
|
|
56
|
+
padding: 0,
|
|
57
|
+
margin: 0,
|
|
58
|
+
},
|
|
59
|
+
'.item-list-float': {
|
|
60
|
+
minWidth: '230px',
|
|
61
|
+
listStyleType: 'none',
|
|
62
|
+
padding: '8px',
|
|
63
|
+
paddingRight: '12px',
|
|
64
|
+
display: 'flex',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
cursor: 'pointer',
|
|
67
|
+
'&:hover': {
|
|
68
|
+
backgroundColor: `${theme.color.light[600]}`,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function More({ loading, menu }: Props) {
|
|
76
|
+
|
|
77
|
+
const [opened, setOpened] = useState(false)
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Box sx={styles.MoreWrapper as SxProperties}>
|
|
81
|
+
<IconButton
|
|
82
|
+
color="light"
|
|
83
|
+
size="sm"
|
|
84
|
+
appearance="circle"
|
|
85
|
+
aria-label="More options"
|
|
86
|
+
disabled={loading}
|
|
87
|
+
onClick={() => setOpened((old) => !old)}
|
|
88
|
+
onBlur={() => setTimeout(() => setOpened(false), 200)}
|
|
89
|
+
>
|
|
90
|
+
<IconBox size="xs">
|
|
91
|
+
<EllipsisVertical />
|
|
92
|
+
</IconBox>
|
|
93
|
+
</IconButton>
|
|
94
|
+
{
|
|
95
|
+
opened && (
|
|
96
|
+
<div className="drop">
|
|
97
|
+
<ul className="drop-wrapper">
|
|
98
|
+
{
|
|
99
|
+
menu.map((menuItem, key) => (
|
|
100
|
+
<li role="button" className="item-list-float" key={key} onClick={menuItem.onClick}>
|
|
101
|
+
<IconBox size="sm">
|
|
102
|
+
{createElement(icons[menuItem.icon])}
|
|
103
|
+
</IconBox>
|
|
104
|
+
<Text appearance="body2">{menuItem.label}</Text>
|
|
105
|
+
</li>
|
|
106
|
+
))
|
|
107
|
+
}
|
|
108
|
+
</ul>
|
|
109
|
+
</div>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
</Box>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
|
|
2
|
+
import { Box, IconBox, Text } from '@citric/core'
|
|
3
|
+
import { SxProperties } from '@citric/core/dist/sx'
|
|
4
|
+
import { ChevronRight, Code, Folder } from '@citric/icons'
|
|
5
|
+
import { theme } from '@stack-spot/portal-theme'
|
|
6
|
+
import { useState } from 'react'
|
|
7
|
+
import { useAnchorTag } from '../../context/anchor'
|
|
8
|
+
import { MenuOption, More } from './More'
|
|
9
|
+
|
|
10
|
+
const styles = {
|
|
11
|
+
FileTreeViewWrapper: {
|
|
12
|
+
height: '100%',
|
|
13
|
+
display: 'flex',
|
|
14
|
+
flexDirection: 'column',
|
|
15
|
+
margin: '16px',
|
|
16
|
+
},
|
|
17
|
+
AccordionItemWrapper: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
'ul': {
|
|
20
|
+
listStyleType: 'none',
|
|
21
|
+
margin: 0,
|
|
22
|
+
padding: 0,
|
|
23
|
+
flexDirection: 'column',
|
|
24
|
+
marginLeft: '20px',
|
|
25
|
+
justifyContent: 'center',
|
|
26
|
+
},
|
|
27
|
+
'li': {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
listStyleType: 'none',
|
|
30
|
+
margin: '2px 0',
|
|
31
|
+
padding: 0,
|
|
32
|
+
flexDirection: 'row',
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
gap: '4px',
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
'.accordion-node-group': {
|
|
38
|
+
justifyContent: 'space-between',
|
|
39
|
+
width: '100%',
|
|
40
|
+
'&:hover': {
|
|
41
|
+
backgroundColor: `${theme.color.light[500]}`,
|
|
42
|
+
borderRadius: '4px',
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
'a': {
|
|
46
|
+
display: 'flex',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
textDecoration: 'underline',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
'.accordion-node': {
|
|
53
|
+
cursor: 'pointer',
|
|
54
|
+
flexDirection: 'row',
|
|
55
|
+
display: 'flex',
|
|
56
|
+
gap: '4px',
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
background: 'transparent',
|
|
59
|
+
color: 'inherit',
|
|
60
|
+
border: 'none',
|
|
61
|
+
'.icon': {
|
|
62
|
+
transition: 'transform ease-in-out 0.3s',
|
|
63
|
+
},
|
|
64
|
+
'.open':{
|
|
65
|
+
transform: 'rotate(90deg)',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
'actions': {
|
|
70
|
+
display: 'flex',
|
|
71
|
+
flexDirection: 'row',
|
|
72
|
+
gap: '4px',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export interface FileDir {
|
|
80
|
+
/**
|
|
81
|
+
* The name of the directory or file.
|
|
82
|
+
* */
|
|
83
|
+
name: string,
|
|
84
|
+
/**
|
|
85
|
+
* dirs - An array containing the directories present in the file tree.
|
|
86
|
+
*/
|
|
87
|
+
dirs: FileDir[],
|
|
88
|
+
/**
|
|
89
|
+
* isFile - A flag indicating whether the item is a file (`true`) or a directory (`false`).
|
|
90
|
+
*/
|
|
91
|
+
isFile?: boolean,
|
|
92
|
+
/**
|
|
93
|
+
* itemLink - The URL or path link associated with the item in the file tree.
|
|
94
|
+
*/
|
|
95
|
+
itemLink: string,
|
|
96
|
+
/**
|
|
97
|
+
* The menu options that will be rendered at the end of the line for this item.
|
|
98
|
+
*/
|
|
99
|
+
menuOptions?: MenuOption[],
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface Props {
|
|
103
|
+
/**
|
|
104
|
+
* Represents the hierarchical structure of directories and files, providing the component with an organized view of the file system.
|
|
105
|
+
*/
|
|
106
|
+
fileTree: FileDir,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const FileTreeView = ({ fileTree }: Props) => {
|
|
110
|
+
|
|
111
|
+
const AccordionItem = ({ name, isFile, dirs, defaultOpened = false, menuOptions, itemLink }: FileDir
|
|
112
|
+
& { defaultOpened?: boolean }) => {
|
|
113
|
+
|
|
114
|
+
const Link = useAnchorTag()
|
|
115
|
+
const [opened, setOpened] = useState<boolean>(defaultOpened)
|
|
116
|
+
|
|
117
|
+
const onExpand = () => {
|
|
118
|
+
setOpened(old => !old)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const FolderItem = () => (
|
|
122
|
+
<li className="accordion-node-group">
|
|
123
|
+
<button className="accordion-node" onClick={onExpand}>
|
|
124
|
+
<IconBox className={`icon ${opened ? 'open' : ''}`} >
|
|
125
|
+
<ChevronRight />
|
|
126
|
+
</IconBox>
|
|
127
|
+
<IconBox>
|
|
128
|
+
<Folder />
|
|
129
|
+
</IconBox>
|
|
130
|
+
<Text>{name !== '' ? name : '/'}</Text>
|
|
131
|
+
</button>
|
|
132
|
+
{ menuOptions &&
|
|
133
|
+
<div className="actions">
|
|
134
|
+
<More menu={menuOptions} />
|
|
135
|
+
</div>
|
|
136
|
+
}
|
|
137
|
+
</li>
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
const FileItem = () => (
|
|
141
|
+
<li className="accordion-node-group">
|
|
142
|
+
<Link href={itemLink}>
|
|
143
|
+
<IconBox>
|
|
144
|
+
<Code />
|
|
145
|
+
</IconBox>
|
|
146
|
+
<Text as="label">{name}</Text>
|
|
147
|
+
</Link>
|
|
148
|
+
{ menuOptions &&
|
|
149
|
+
<div className="actions">
|
|
150
|
+
<More menu={menuOptions} />
|
|
151
|
+
</div>
|
|
152
|
+
}
|
|
153
|
+
</li >
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<Box sx={styles.AccordionItemWrapper}>
|
|
158
|
+
{
|
|
159
|
+
isFile ? <FileItem /> : <FolderItem />
|
|
160
|
+
}
|
|
161
|
+
<ul className="accordion-children">
|
|
162
|
+
{opened && !isFile && dirs && dirs.length > 0 && (
|
|
163
|
+
<>
|
|
164
|
+
{dirs?.map((subDir, index) => (
|
|
165
|
+
<li key={index}>{
|
|
166
|
+
<AccordionItem {...subDir} />
|
|
167
|
+
}</li>
|
|
168
|
+
))}
|
|
169
|
+
</>
|
|
170
|
+
)}
|
|
171
|
+
</ul>
|
|
172
|
+
</Box>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<Box sx={styles.FileTreeViewWrapper as SxProperties}>
|
|
178
|
+
<AccordionItem {...fileTree} defaultOpened={true} />
|
|
179
|
+
</Box>
|
|
180
|
+
)
|
|
181
|
+
}
|