-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathDialog.tsx
More file actions
143 lines (128 loc) · 3.65 KB
/
Dialog.tsx
File metadata and controls
143 lines (128 loc) · 3.65 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* eslint no-alert: "off" */
/* eslint no-console: "off" */
import React, { Component } from 'react';
import {
HierarchicalCheckboxMenu,
Popper,
type HierarchicalCheckboxValueMap,
Button,
} from '@deephaven/components';
import SampleSection from './SampleSection';
interface DialogState {
isShown: boolean;
checkBoxMap: HierarchicalCheckboxValueMap;
}
interface Dialog {
sampleInput: React.RefObject<HTMLInputElement>;
}
class Dialog extends Component<unknown, DialogState> {
constructor(props: unknown) {
super(props);
this.sampleInput = React.createRef();
this.handleUpdateCheckboxMap = this.handleUpdateCheckboxMap.bind(this);
const parentA = [
'Parent A',
new Map([
['Child 1', true],
['Child 2', false],
]),
];
const parentB = [
'Parent B',
new Map([
['Child 3', true],
['Child 4', false],
['Child 5', true],
['Child 6', false],
]),
];
const leaf = ['Leaf Parent', true];
this.state = {
isShown: false,
checkBoxMap: new Map([parentA, parentB, leaf] as Iterable<
readonly [string, Map<string, boolean>]
>),
};
}
handleUpdateCheckboxMap(checkBoxMap: HierarchicalCheckboxValueMap): void {
this.setState({
checkBoxMap,
});
}
renderChild(): React.ReactElement {
return (
<div className="p-3">
<h4>Sample Child</h4>
<div className="form-group">
<label htmlFor="exampleInput1">
Input Label
<input
ref={this.sampleInput}
type="text"
className="form-control"
id="exampleInput1"
aria-describedby="emailHelp"
placeholder="Input Placeholder"
/>
</label>
<small className="form-text text-muted">
Help text for a form input
</small>
</div>
</div>
);
}
render(): React.ReactElement {
const { isShown, checkBoxMap } = this.state;
return (
<SampleSection name="dialog">
<h2 className="ui-title">Popover Dialog</h2>
<p>
Popover dialog that can contain interactive elements, can be set to
self close on blur.
</p>
<Button
kind="primary"
style={{ marginBottom: '1rem', marginRight: '1rem' }}
onClick={() => {
if (isShown) {
this.setState({ isShown: false });
} else {
this.setState({ isShown: true });
}
}}
>
Open Dialog
<Popper
options={{ placement: 'bottom' }}
isShown={isShown} // controls if its shown or not
onEntered={() => {
// Example setting focus on entered child
// Could also be performed within the didMount if child is a component
if (this.sampleInput.current) {
this.sampleInput.current.focus();
}
}}
onExited={() => {
this.setState({ isShown: false });
}}
closeOnBlur // if you want dialog to self close, on click outside
interactive // if popper contents will be interactable
>
{this.renderChild()}
</Popper>
</Button>
<p>
The Hierarchical Checkbox Menu uses a popover dialog to display
hierarchical groups of checkboxes.
</p>
<HierarchicalCheckboxMenu
menuText="Checkbox Menu"
valueMap={checkBoxMap}
onUpdateValueMap={this.handleUpdateCheckboxMap}
/>
</SampleSection>
);
}
}
export default Dialog;