sample-ui-component-library 0.0.6-dev → 0.0.7-dev
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/cjs/index.js +5 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +7 -7
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Editor/Editor.jsx +5 -5
- package/src/components/Editor/Editor.scss +2 -1
- package/src/components/Editor/EditorTabs/EditorTabs.jsx +32 -21
- package/src/components/Editor/EditorTabs/EditorTabs.scss +14 -3
- package/src/components/FileBrowser/FileBrowser.jsx +1 -6
- package/src/stories/Editor.stories.js +12 -1
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ export const Editor = ({systemTree, onFileSelect}) => {
|
|
|
23
23
|
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
if (activeTab) {
|
|
26
|
-
setEditorContent(
|
|
26
|
+
setEditorContent(activeTab.label);
|
|
27
27
|
}
|
|
28
28
|
}, [activeTab]);
|
|
29
29
|
|
|
@@ -31,20 +31,20 @@ export const Editor = ({systemTree, onFileSelect}) => {
|
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
if (tabs) {
|
|
33
33
|
if ((activeTab && activeTab > tabs.length) || activeTab == null) {
|
|
34
|
-
setActiveTab(tabs.length);
|
|
34
|
+
setActiveTab(tabs[tabs.length - 1]);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}, [tabs]);
|
|
38
38
|
|
|
39
39
|
const onTabClick = (event) => {
|
|
40
|
-
const
|
|
41
|
-
setActiveTab(
|
|
40
|
+
const tab = tabs.find(obj => obj.id === event.target.id);
|
|
41
|
+
setActiveTab(tab);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
45
|
<div className="editorContainer">
|
|
46
46
|
<div className="tabContainer">
|
|
47
|
-
<EditorTabs activeTab={
|
|
47
|
+
<EditorTabs activeTab={activeTab} tabs={tabs} selectTab={onTabClick} />
|
|
48
48
|
</div>
|
|
49
49
|
<div className="monacoContainer">
|
|
50
50
|
<MonacoInstance editorContent={editorContent}/>
|
|
@@ -2,9 +2,8 @@ import "./EditorTabs.scss";
|
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
|
+
import { FileEarmark } from "react-bootstrap-icons";
|
|
5
6
|
import {
|
|
6
|
-
DndContext,
|
|
7
|
-
DragOverlay,
|
|
8
7
|
useDraggable,
|
|
9
8
|
useDroppable,
|
|
10
9
|
} from "@dnd-kit/core";
|
|
@@ -15,18 +14,20 @@ import {
|
|
|
15
14
|
* @param {String} label
|
|
16
15
|
* @returns
|
|
17
16
|
*/
|
|
18
|
-
function Tab({id, label, onSelectTab}) {
|
|
17
|
+
function Tab({id, label, onSelectTab, activeTab}) {
|
|
19
18
|
const { attributes, listeners, setNodeRef, transform } = useDraggable({id});
|
|
20
19
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
:
|
|
25
|
-
|
|
20
|
+
const [tabStyle, setTabStyle] = useState();
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const bc = (activeTab && activeTab.id === id) ? "#1e1e1e": "#2d2d2d";
|
|
24
|
+
const fc = (activeTab && activeTab.id === id) ? "#FFFFFF": "#969690";
|
|
25
|
+
setTabStyle( {"backgroundColor": bc, "color": fc})
|
|
26
|
+
}, [activeTab]);
|
|
26
27
|
|
|
27
28
|
return (
|
|
28
|
-
<div ref={setNodeRef} style={
|
|
29
|
-
{label}
|
|
29
|
+
<div ref={setNodeRef} style={tabStyle} id={id} onClick={onSelectTab} className="tab" {...listeners} {...attributes}>
|
|
30
|
+
<FileEarmark className="icon" style={{ pointerEvents: "none" }}/>{label}
|
|
30
31
|
</div>
|
|
31
32
|
);
|
|
32
33
|
}
|
|
@@ -42,7 +43,7 @@ function Gutter({id}) {
|
|
|
42
43
|
<div
|
|
43
44
|
className="gutter"
|
|
44
45
|
ref={setNodeRef}
|
|
45
|
-
style={{background: isOver ? "white" : "#
|
|
46
|
+
style={{background: isOver ? "white" : "#222425"}}
|
|
46
47
|
></div>
|
|
47
48
|
);
|
|
48
49
|
}
|
|
@@ -59,19 +60,29 @@ export const EditorTabs = ({activeTab, tabs, selectTab}) => {
|
|
|
59
60
|
|
|
60
61
|
useEffect(() => {
|
|
61
62
|
if (tabs) {
|
|
62
|
-
|
|
63
|
-
tabs.forEach((tab, index) => {
|
|
64
|
-
list.push(
|
|
65
|
-
<>
|
|
66
|
-
<Gutter id={tab.id} />
|
|
67
|
-
<Tab onSelectTab={selectTab} key={tab.id} {...tab} />
|
|
68
|
-
</>
|
|
69
|
-
);
|
|
70
|
-
})
|
|
71
|
-
setTabsList(list);
|
|
63
|
+
drawTabs();
|
|
72
64
|
}
|
|
73
65
|
}, [tabs]);
|
|
74
66
|
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (activeTab) {
|
|
69
|
+
drawTabs();
|
|
70
|
+
}
|
|
71
|
+
}, [activeTab]);
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const drawTabs = () => {
|
|
75
|
+
const list = [];
|
|
76
|
+
tabs.forEach((tab, index) => {
|
|
77
|
+
list.push(<Gutter id={"position-" + index} />);
|
|
78
|
+
list.push(
|
|
79
|
+
<Tab activeTab={activeTab} onSelectTab={selectTab} key={tab.id} {...tab} />
|
|
80
|
+
);
|
|
81
|
+
})
|
|
82
|
+
list.push(<Gutter id={"position-" + tabs.length} />);
|
|
83
|
+
setTabsList(list);
|
|
84
|
+
}
|
|
85
|
+
|
|
75
86
|
return (
|
|
76
87
|
<div style={{ display: "flex", background: "#222425" }}>
|
|
77
88
|
{tabsList}
|
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
.tabs {
|
|
2
|
+
position:relative;
|
|
2
3
|
display: flex;
|
|
3
4
|
flex-direction: row;
|
|
4
5
|
background-color: #1e1e1e;
|
|
5
|
-
height:
|
|
6
|
+
height: 40px;
|
|
6
7
|
width: 100%;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
.tab {
|
|
10
11
|
padding: 0px 20px;
|
|
11
12
|
background-color: #2d2d2d;
|
|
12
|
-
color: #
|
|
13
|
+
color: #969690;
|
|
13
14
|
cursor: pointer;
|
|
14
15
|
height: 40px;
|
|
15
16
|
display:flex;
|
|
16
17
|
align-items: center;
|
|
18
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
19
|
+
font-size:14px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.tab > .icon {
|
|
23
|
+
padding-right: 7px;
|
|
24
|
+
display:flex;
|
|
25
|
+
align-items: center;
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
.gutter {
|
|
29
|
+
display:flex;
|
|
30
|
+
background-color: #2d2d2d;
|
|
20
31
|
height: 40px;
|
|
21
|
-
width:
|
|
32
|
+
width: 2px;
|
|
22
33
|
}
|
|
@@ -35,7 +35,6 @@ function useEvent(fn) {
|
|
|
35
35
|
*/
|
|
36
36
|
const TreeNode = ({id, node, onRowClick}) => {
|
|
37
37
|
const { attributes, listeners, setNodeRef, transform } = useDraggable({id});
|
|
38
|
-
|
|
39
38
|
/**
|
|
40
39
|
* Gets the appropriate icon for the node based on its type and collapsed state.
|
|
41
40
|
* @returns <JSX>
|
|
@@ -52,11 +51,7 @@ const TreeNode = ({id, node, onRowClick}) => {
|
|
|
52
51
|
* Sets the background color of the row if the node is selected.
|
|
53
52
|
*/
|
|
54
53
|
const getRowStyle = () => {
|
|
55
|
-
const style = {
|
|
56
|
-
transform: transform
|
|
57
|
-
? `translate3d(${transform.x}px, ${transform.y}px, 0)`
|
|
58
|
-
: undefined
|
|
59
|
-
};
|
|
54
|
+
const style = {};
|
|
60
55
|
if (node.selected) {
|
|
61
56
|
style["backgroundColor"] = SELECTED_FILE_COLOR;
|
|
62
57
|
}
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
DragOverlay,
|
|
8
8
|
useDraggable,
|
|
9
9
|
useDroppable,
|
|
10
|
+
PointerSensor,
|
|
11
|
+
useSensor,
|
|
12
|
+
useSensors
|
|
10
13
|
} from "@dnd-kit/core";
|
|
11
14
|
|
|
12
15
|
import fileTrees from "./data/filetree.json";
|
|
@@ -87,8 +90,16 @@ const Template = (args) => {
|
|
|
87
90
|
console.log("Drag Started");
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
const sensors = useSensors(
|
|
94
|
+
useSensor(PointerSensor, {
|
|
95
|
+
activationConstraint: {
|
|
96
|
+
distance: 8
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
|
|
90
101
|
return (
|
|
91
|
-
<DndContext onDragStart={onDragStart} onDragEnd={handleDragEnd}>
|
|
102
|
+
<DndContext sensors={sensors} onDragStart={onDragStart} onDragEnd={handleDragEnd}>
|
|
92
103
|
<div className="editorStoryWrapper">
|
|
93
104
|
<Editor {...args} />
|
|
94
105
|
</div>
|