This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsectionRenderStrategy.tsx
More file actions
66 lines (55 loc) · 2.17 KB
/
sectionRenderStrategy.tsx
File metadata and controls
66 lines (55 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as React from 'react';
import { PageRenderStrategy } from './pageRenderStrategy';
import { ExpandableNodeRenderStrategy } from './treeView/expandableNodeRenderStrategy';
import { LeafNode } from './treeView/leafNode';
import { Constants } from '../constants';
import { Section } from '../oneNoteDataStructures/section';
import { OneNoteItemUtils } from '../oneNoteDataStructures/oneNoteItemUtils';
import { InnerGlobals } from '../props/globalProps';
import { SectionIconSvg } from './icons/sectionIcon.svg';
export class SectionRenderStrategy implements ExpandableNodeRenderStrategy {
onClickBinded = this.onClick.bind(this);
constructor(private section: Section, private globals: InnerGlobals) { }
element(): JSX.Element {
return (
<div className={this.isSelected() ? 'picker-selectedItem picker-item section' : 'picker-item section'} title={this.section.name}>
<div className='picker-icon'>
<SectionIconSvg/>
</div>
<div className='picker-label'>
<label>{this.section.name}</label>
</div>
</div>
);
}
getName(): string {
return this.section.name;
}
getId(): string {
return this.section.id;
}
getChildren(childrenLevel: number): JSX.Element[] {
const pageRenderStrategies: PageRenderStrategy[] | undefined =
this.section.pages && this.section.pages.map(page => new PageRenderStrategy(page, this.globals));
const pages = pageRenderStrategies && pageRenderStrategies.map(renderStrategy =>
<LeafNode treeViewId={Constants.TreeView.id} node={renderStrategy} globals={this.globals}
id={renderStrategy.getId()} level={childrenLevel}
ariaSelected={renderStrategy.isAriaSelected()} selected={renderStrategy.isSelected()}/>);
return pages || [] as JSX.Element[];
}
isExpanded(): boolean {
return this.section.expanded;
}
isSelected(): boolean {
return this.globals.selectedId === this.section.id;
}
isAriaSelected(): boolean {
return this.globals.ariaSelectedId ? this.globals.ariaSelectedId === this.getId() : false;
}
private onClick() {
const onSectionSelected = this.globals.callbacks.onSectionSelected;
if (!!onSectionSelected) {
onSectionSelected(this.section, OneNoteItemUtils.getAncestry(this.section));
}
}
}