1
1
import React from 'react' ;
2
2
import { Widget } from '@lumino/widgets' ;
3
3
import { showMoreOptions } from './MoreOptions' ;
4
- interface ISortSnippetProps {
5
- sortCategory : string ;
6
- }
4
+ import { checkIcon } from '@jupyterlab/ui-components' ;
5
+ import ReactDOMServer from 'react-dom/server' ;
6
+ import SortOption from './SortOption' ;
7
+
8
+ interface ISortSnippetProps { }
7
9
8
10
const SORT_TOOL = 'jp-codeSnippet-sort-tool' ;
9
11
const SORT_ICON_INACTIVE = 'jp-codeSnippet-sort-icon-inactive' ;
10
12
const SORT_ICON_ACTIVE = 'jp-codeSnippet-sort-icon-active' ;
11
13
const CODE_SNIPPET_SORT_CONTENT = 'jp-codeSnippet-sort-content' ;
12
14
const CODE_SNIPPET_SORT_SORTBY = 'jp-codeSnippet-sort-sortby' ;
13
- const CODE_SNIPPET_SORT_OPTION = 'jp-codeSnippet-sort-option ' ;
15
+ const CODE_SNIPPET_SORT_LINE = 'jp-codeSnippet-sort-line ' ;
14
16
// const CODE_SNIPPET_SORT_SELECTED = 'jp-codeSnippet-sort-selected';
15
17
16
18
/* Add on click to span and then create function to actually do the sorting*/
17
19
/* Right now the coloring of the arrows is off, make sure when dialog disappears arrow turns back to gray*/
18
20
/* Add innerHTML for the checkmark when something is clicked. When its clicked again remove the checkmark. */
19
21
22
+ interface ISortSnippetState {
23
+ optionSelected : Boolean ;
24
+ optionName : String ;
25
+ currSelected : String ;
26
+ }
27
+
20
28
class OptionsHandler extends Widget {
21
29
constructor ( display : SortTools ) {
22
30
super ( { node : display . createOptionsNode ( ) } ) ;
23
31
}
24
32
}
25
- export class SortTools extends React . Component {
33
+ export class SortTools extends React . Component <
34
+ ISortSnippetProps ,
35
+ ISortSnippetState
36
+ > {
26
37
constructor ( props : ISortSnippetProps ) {
27
38
super ( props ) ;
39
+ this . state = {
40
+ optionSelected : false ,
41
+ optionName : '' ,
42
+ currSelected : ''
43
+ } ;
28
44
this . handleClick = this . handleClick . bind ( this ) ;
29
45
}
30
46
@@ -49,35 +65,82 @@ export class SortTools extends React.Component {
49
65
public createOptionsNode ( ) : HTMLElement {
50
66
const body = document . createElement ( 'div' ) ;
51
67
body . className = 'jp-codeSnippet-sort-test-container' ;
52
- const optionsContainer = document . createElement ( 'div' ) ;
53
- optionsContainer . className = CODE_SNIPPET_SORT_CONTENT ;
54
- const sortBy = document . createElement ( 'div' ) ;
55
- sortBy . className = CODE_SNIPPET_SORT_SORTBY ;
56
- // 4 space start
57
- sortBy . textContent = ' Sort by:' ;
58
- const lastMod = document . createElement ( 'div' ) ;
59
- lastMod . className = CODE_SNIPPET_SORT_OPTION ;
60
- // const checkMark = document.createElement('span');
61
- // checkMark.className = CODE_SNIPPET_SORT_SELECTED;
62
- // copySnip.appendChild(checkMark);
63
- lastMod . textContent = ' Last Modified' ;
64
- /*copySnip.onclick = (): void => {};*/
65
- const createNew = document . createElement ( 'div' ) ;
66
- createNew . className = CODE_SNIPPET_SORT_OPTION ;
67
- createNew . textContent = ' Date Created: Newest' ;
68
- /*editSnip.onclick = (): void => {};*/
69
- const createOld = document . createElement ( 'div' ) ;
70
- createOld . className = CODE_SNIPPET_SORT_OPTION ;
71
- createOld . textContent = ' Date Created: Oldest' ;
72
- /*deleteSnip.onclick = (): void => {};*/
73
- optionsContainer . appendChild ( sortBy ) ;
74
- optionsContainer . appendChild ( lastMod ) ;
75
- optionsContainer . appendChild ( createNew ) ;
76
- optionsContainer . appendChild ( createOld ) ;
77
- body . append ( optionsContainer ) ;
68
+ body . innerHTML = ReactDOMServer . renderToStaticMarkup (
69
+ this . createOptionsNodeHelper ( )
70
+ ) ; //new
71
+ // optionsContainer.className = CODE_SNIPPET_SORT_CONTENT;
72
+ // const sortBy = document.createElement('div');
73
+ // sortBy.className = CODE_SNIPPET_SORT_SORTBY;
74
+ // sortBy.textContent = 'Sort by:';
75
+
76
+ // const divider = document.createElement('div');
77
+ // divider.className = CODE_SNIPPET_SORT_LINE;
78
+
79
+ // let lastMod = document.createElement('div');
80
+ // lastMod.className = CODE_SNIPPET_SORT_OPTION;
81
+ // lastMod.textContent = 'Last Modified';
82
+ // lastMod.onclick = (event): void => {
83
+ // lastMod.innerHTML = this.simple(event, optionsContainer);
84
+ // };
85
+ // const createNew = document.createElement('div');
86
+ // createNew.className = CODE_SNIPPET_SORT_OPTION;
87
+ // createNew.textContent = 'Date Created: Newest';
88
+ // const createOld = document.createElement('div');
89
+ // createOld.className = CODE_SNIPPET_SORT_OPTION;
90
+ // createOld.textContent = 'Date Created: Oldest';
91
+
92
+ // optionsContainer.appendChild(sortBy);
93
+ // optionsContainer.appendChild(divider);
94
+ // optionsContainer.appendChild(lastMod);
95
+ // optionsContainer.appendChild(createNew);
96
+ // optionsContainer.appendChild(createOld);
97
+ // body.append(optionsContainer);
78
98
return body ;
79
99
}
80
100
101
+ public createOptionsNodeHelper ( ) {
102
+ return (
103
+ < div className = { CODE_SNIPPET_SORT_CONTENT } id = { CODE_SNIPPET_SORT_CONTENT } >
104
+ < div className = { CODE_SNIPPET_SORT_SORTBY } > Sort by:</ div >
105
+ < div className = { CODE_SNIPPET_SORT_LINE } > </ div >
106
+ < SortOption
107
+ optionSelected = { this . state . currSelected == 'Last Modified' }
108
+ optionName = { 'Last Modified' }
109
+ > </ SortOption >
110
+ < SortOption
111
+ optionSelected = { false }
112
+ optionName = { 'Date Created: Newest' }
113
+ > </ SortOption >
114
+ < SortOption
115
+ optionSelected = { false }
116
+ optionName = { 'Date Created: Oldest' }
117
+ > </ SortOption >
118
+ </ div >
119
+ ) ;
120
+ }
121
+
122
+ simple ( event : MouseEvent , container : HTMLDivElement ) {
123
+ console . log ( event ) ;
124
+ const target = event . target as HTMLElement ;
125
+ return this . createCheck ( target . innerText ) ;
126
+ }
127
+
128
+ createCheck ( option : String ) {
129
+ //inner div, display flex
130
+ return ReactDOMServer . renderToStaticMarkup (
131
+ < div >
132
+ < checkIcon . react
133
+ className = "jupyterlab-CodeSnippets-sort-selected"
134
+ elementPosition = "center"
135
+ height = "16px"
136
+ width = "16px"
137
+ marginLeft = "2px"
138
+ />
139
+ { option }
140
+ </ div >
141
+ ) ;
142
+ }
143
+
81
144
handleClick ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) : void {
82
145
const target = event . target as HTMLElement ;
83
146
// const clickedTag = target.innerText;
0 commit comments