This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtooltip-customization.tsx
More file actions
224 lines (197 loc) · 8.97 KB
/
tooltip-customization.tsx
File metadata and controls
224 lines (197 loc) · 8.97 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { SliderComponent, SliderTickEventArgs, SliderTooltipEventArgs } from '@syncfusion/ej2-react-inputs';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import { SampleBase } from '../common/sample-base';
import { PropertyPane } from '../common/property-pane';
import { isNullOrUndefined } from '@syncfusion/ej2-base';
const slidercss = `
.sliderwrap .label-text {
font-weight: 500;
}
.content-wrapper {
width: 80%;
margin: 0 auto;
min-width: 185px;
}
.sliderwrap {
margin-top: 40px;
}
#slider01 .e-material-handle,
#out .e-material-handle,
.bootstrap #out .e-handle,
.bootstrap #slider01 .e-handle,
.fabric #out .e-handle,
.fabric #slider01 .e-handle,
.highcontrast #out .e-handle,
.highcontrast #slider01 .e-handle {
background-color: #ffd939;
border-color: #ffd939;
z-index: 1;
}
.e-bigger .content-wrapper {
width: 80%;
}
.sliderwrap label {
padding-bottom: 26px;
font-size: 13px;
font-weight: 500;
margin-top: 15px;
}
.userselect {
-webkit-user-select: none;
/* Safari 3.1+ */
-moz-user-select: none;
/* Firefox 2+ */
-ms-user-select: none;
/* IE 10+ */
user-select: none;
/* Standard syntax */
}
.e-slider-tooltip.e-tooltip-wrap.e-tooltip-cutomization.e-popup.e-slider-tooltip .e-tip-content,
.e-slider-tooltip.e-tooltip-wrap.e-tooltip-cutomization.e-popup.e-material-range .e-tip-content.e-material-tooltip-show {
color: #333;
}
.e-slider-tooltip.e-tooltip-wrap.e-tooltip-cutomization.e-popup.e-material-range .e-arrow-tip-inner {
color: #ffd939;
}
.e-slider-tooltip.e-tooltip-wrap.e-tooltip-cutomization.e-popup.e-material-range.e-slider-horizontal-before .e-arrow-tip-outer {
border-top-color: #ffd939;
}
.e-slider-tooltip.e-tooltip-wrap.e-tooltip-cutomization.e-popup.e-material-range.e-slider-horizontal-after .e-arrow-tip-outer {
border-bottom-color: #ffd939;
}
.e-slider-container .e-slider#slider01 .e-range,
.e-slider-container .e-slider#out .e-range {
background-color: #0375be;
z-index: unset;
}
.e-slider-tooltip.e-tooltip-wrap.e-popup.e-material-range.e-tooltip-cutomization,
.e-slider-tooltip.e-tooltip-wrap.e-popup.e-tooltip-cutomization {
background-color: #ffd939;
border-color: #ffd939;
}
.bootstrap .e-tooltip-cutomization.e-slider-tooltip.e-tooltip-wrap.e-popup .e-arrow-tip-outer {
border-top-color: #ffd939;
}
.bootstrap .e-tooltip-cutomization.e-slider-tooltip.e-tooltip-wrap.e-popup .e-arrow-tip-inner {
color: #ffd939;
}
`
export class TooltipCustomization extends SampleBase<{}, {}> {
// Set slider minimum and maximum values
// new Date(Year, Month, day, hours, minutes, seconds, millseconds)
public min: any = new Date(2013, 6, 13, 11).getTime();
public sliderMin: any = new Date(2013, 6, 13, 11).getTime();
public sliderMax: any = new Date(2013, 6, 13, 23).getTime();
public max: any = new Date(2013, 6, 13, 23).getTime();
// Initialize ticks with placement, largestep, smallste
public value: any = [new Date(2013, 6, 13, 12).getTime(), new Date(2013, 6, 13, 18).getTime()];
public sliderValue: any = new Date(2013, 6, 13, 17).getTime();
public ticks: object = {
placement: 'After',
// 3 * 3600000 milliseconds = 3 Hour
largeStep: 3 * 3600000,
smallStep: 3600000, showSmallTicks: true
};
// Initialize tooltip with placement
public tooltip: object = {
placement: 'Before', isVisible: true, cssClass: 'e-tooltip-cutomization'
};
public sliderTooltip: object = {
placement: 'Before', isVisible: true, cssClass: 'e-tooltip-cutomization'
};
private timeObj: SliderComponent;
private sliderObj: SliderComponent;
public tooltipChangeHandler(args: SliderTooltipEventArgs): void {
/**
* toLocaleTimeString is predefined javascript date function, which is used to
* customize the date in different format
*/
let custom: { [key: string]: string } = { hour: '2-digit', minute: '2-digit' };
// Splitting the range values from the tooltip using space into an array.
if (args.text.indexOf('-') !== -1) {
let totalMiliSeconds: string[] = args.text.split(' ');
// First part is the first handle value
let firstPart: string = totalMiliSeconds[0];
// Second part is the second handle value
let secondPart: string = totalMiliSeconds[2];
firstPart = new Date(Number(firstPart)).toLocaleTimeString('en-us', custom);
secondPart = new Date(Number(secondPart)).toLocaleTimeString('en-us', custom);
// Assigning our custom text to the tooltip value.
args.text = firstPart + ' - ' + secondPart;
} else {
args.text = 'Until ' + new Date(Number(args.text)).toLocaleTimeString('en-us', custom);
}
}
public onCreated01(args: any): void {
let element01: any = document.getElementById('slider01');
element01.ej2_instances[0].keyUp({ keyCode: 9, target: element01.ej2_instances[0].secondHandle });
element01.ej2_instances[0].secondHandle.focus();
}
public sliderTicks: any = {
placement: 'After',
// 3 * 3600000 milliseconds = 3 Hour
largeStep: 3 * 3600000,
smallStep: 3600000, showSmallTicks: true
};
public onRenderingTicks(args: SliderTickEventArgs) {
let totalMiliSeconds: number = Number(args.value);
/**
* toLocaleTimeString is predefined javascript date function, which is used to
* customize the date in different format
*/
let custom: { [key: string]: string } = { hour: '2-digit', minute: '2-digit' };
// Assigning our custom text to the tick value.
args.text = new Date(totalMiliSeconds).toLocaleTimeString('en-us', custom);
}
// Handler used to reposition the tooltip on page scroll
public onScroll(): void {
if (!isNullOrUndefined(document.getElementById('slider01')) &&
!isNullOrUndefined((document.getElementById('slider01') as any).ej2_instances[0]) && !isNullOrUndefined(document.getElementById('out')) &&
!isNullOrUndefined((document.getElementById('out') as any).ej2_instances[0])) {
let element01: any = document.getElementById('slider01');
let element02: any = document.getElementById('out');
element01.ej2_instances[0].refreshTooltip();
element02.ej2_instances[0].refreshTooltip();
}
}
render() {
if (!isNullOrUndefined(document.getElementById('right-pane'))) {
document.getElementById('right-pane').addEventListener('scroll', this.onScroll);
}
return (
<div className='control-pane'>
<style>{slidercss}</style>
<div className='col-lg-12-control-section'>
<div className="content-wrapper" >
<div className="sliderwrap">
<label className="labeltext userselect">
<span className="label-text">Background color</span>
</label>
<SliderComponent id="slider01" value={this.value} min={this.min} max={this.max} step={3600000 / 6} ticks={this.ticks} type="Range" tooltip={this.tooltip} tooltipChange={this.tooltipChangeHandler.bind(this)} ref={(slider) => { this.timeObj = slider }} created={this.onCreated01.bind(this)} renderingTicks={this.onRenderingTicks.bind(this)} />
</div>
<div className="sliderwrap">
<label className="labeltext userselect">
<span className="label-text">Color and text</span>
</label>
{/* Ticks slider element - */}
<SliderComponent id="out" value={new Date(2013, 6, 13, 17).getTime()} min={this.sliderMin} max={this.sliderMax} step={3600000 / 6} ticks={this.sliderTicks} type="MinRange" tooltip={this.sliderTooltip} tooltipChange={this.tooltipChangeHandler.bind(this)} ref={(slider) => { this.sliderObj = slider }} renderingTicks={this.onRenderingTicks.bind(this)} />
</div>
</div>
</div>
<div id="action-description">
<p>This sample demonstrates the customization of Slider's Tooltip. Drag the thumb over the bar for selecting the values
between min and max.</p>
</div>
<div id="description">
<p>In this demo, we have demonstrated the following customization of Tooltip using CSS.</p>
<ul>
<li>Background color - In this sample, Tooltip has been customized to custom color.</li>
<li>Color and text - In this sample, Tooltip and its content has been customized to custom color.</li>
</ul>
</div>
</div>
)
}
}