Skip to content

Commit d6ce9a1

Browse files
committed
Add simple tooltip for events
1 parent 1e5696b commit d6ce9a1

File tree

2 files changed

+158
-9
lines changed

2 files changed

+158
-9
lines changed

web/static/css/widgets/_calendar.sass

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
+widget
77
background: $backgroundColor
88
font-size: 12px
9+
overflow: visible
910

1011
.Calendar
1112
width: 100%
@@ -111,17 +112,15 @@
111112
background: $backgroundColor
112113
color: $black
113114
margin: 1px 2px
114-
padding: 1px 8px
115-
overflow: hidden
116-
text-overflow: ellipsis
117-
white-space: nowrap
118115
text-align: left
119116
border-color: darken($backgroundColor, 15%)
120117
border-style: solid
121118
border-left-width: 0
122119
border-right-width: 0
123120
border-top-width: 1px
124121
border-bottom-width: 1px
122+
position: relative
123+
height: 20px
125124

126125
&.isStarted
127126
border-top-left-radius: 8px
@@ -131,3 +130,80 @@
131130
border-top-right-radius: 8px
132131
border-bottom-right-radius: 8px
133132
border-right-width: 1px
133+
134+
.EventTitle
135+
position: absolute
136+
left: 0
137+
right: 0
138+
bottom: 0
139+
top: 0
140+
padding: 1px 8px
141+
overflow: hidden
142+
text-overflow: ellipsis
143+
white-space: nowrap
144+
pointer-events: none
145+
146+
.EventPopOver
147+
$arrow: 10px
148+
$width: 360px
149+
150+
position: absolute
151+
z-index: 9999
152+
cursor: default
153+
pointer-events: none
154+
155+
.Content
156+
position: relative
157+
top: $arrow
158+
width: $width
159+
left: -$width / 2
160+
background: white
161+
text-align: left
162+
box-shadow: 1px 1px 10px #d0d0d0
163+
padding: 10px
164+
165+
&::before
166+
content: ''
167+
border: solid transparent
168+
height: 0
169+
width: 0
170+
position: absolute
171+
pointer-events: none
172+
border-color: transparent
173+
border-bottom-color: white
174+
border-width: $arrow
175+
margin-left: -$arrow
176+
margin-top: -$arrow
177+
178+
h2
179+
font-size: 14px
180+
font-weight: normal
181+
margin: 0
182+
float: right
183+
padding: 3px
184+
display: inline
185+
width: auto
186+
background: $borderColor
187+
188+
h3
189+
font-size: 14px
190+
font-weight: bold
191+
line-height: 23px
192+
margin: 0
193+
194+
.Title
195+
padding: 3px 5px
196+
border-radius: 8px
197+
border-color: darken($backgroundColor, 15%)
198+
border-style: solid
199+
border-width: 1px
200+
201+
.Unconfirmed
202+
color: #ccc
203+
font-weight: normal
204+
padding-left: 10px
205+
206+
table
207+
margin-top: 10px
208+
th
209+
padding-right: 5px

web/static/js/widgets/calendar/index.js

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ function formatWeekLabel(date) {
160160
return moment(date).isoWeek()
161161
}
162162

163+
function formatEventDate(event) {
164+
if (event.allDay) {
165+
return `${moment(event.start).format("L")} - ${moment(event.end).format("L")}`
166+
}
167+
return moment(event.start).format("LLL")
168+
}
169+
163170
const LabelCells = React.createClass({
164171
render(){
165172
return (
@@ -290,13 +297,13 @@ function isUnconfirmed(event) {
290297
}
291298

292299
function colorizeEvent(event) {
293-
const color = utils.hex2components(event.color)
300+
const color = utils.hex2components(event.color)
294301
const border = utils.lightenColor(color, 0.85)
295302
const borderRgba = utils.components2rgba(border)
296303

297304
if(isUnconfirmed(event)) {
298-
const alternate = utils.lightenColor(color, 1.2)
299-
const altRgba = utils.components2rgba(alternate)
305+
const alternate = utils.lightenColor(color, 1.2)
306+
const altRgba = utils.components2rgba(alternate)
300307
return {
301308
background: `repeating-linear-gradient(
302309
45deg,
@@ -316,6 +323,9 @@ function colorizeEvent(event) {
316323
}
317324

318325
const Event = React.createClass({
326+
getInitialState() {
327+
return { tooltip: null }
328+
},
319329
render(){
320330
const {event, from, to} = this.props
321331
const className = classnames("Event", {
@@ -329,8 +339,71 @@ const Event = React.createClass({
329339
borderColor: event.color
330340
}
331341
return (
332-
<div className={className} style={colorizeEvent(event)}>
333-
{event.title}
342+
<div
343+
className={className}
344+
style={colorizeEvent(event)}
345+
onMouseMove={this._onEnter}
346+
onMouseEnter={this._onEnter}
347+
onMouseOut={this._onExit}
348+
>
349+
<div className="EventTitle">{event.title}</div>
350+
<EventPopOver
351+
event={event}
352+
position={this.state.tooltip}
353+
/>
354+
</div>
355+
)
356+
},
357+
_onEnter(e) {
358+
const tooltip = {
359+
x: e.nativeEvent.offsetX,
360+
y: e.nativeEvent.offsetY
361+
}
362+
this.setState({tooltip})
363+
},
364+
_onExit() {
365+
this.setState({tooltip: null})
366+
}
367+
})
368+
369+
const EventPopOver = React.createClass({
370+
getDefaultProps: function() {
371+
return {
372+
offset: 5,
373+
}
374+
},
375+
render() {
376+
const {event, position} = this.props
377+
if (!position) return <div />
378+
379+
const style = {
380+
left: position.x,
381+
top: position.y + this.props.offset,
382+
}
383+
384+
return (
385+
<div className="EventPopOver" style={style}>
386+
<div className="Content">
387+
<h2>
388+
{event.calendar}
389+
</h2>
390+
<h3>
391+
<span className="Title" style={colorizeEvent(event)}>
392+
{event.title}
393+
</span>
394+
{isUnconfirmed(event) &&
395+
<span className="Unconfirmed">(Unconfirmed)</span>
396+
}
397+
</h3>
398+
<table>
399+
<tbody>
400+
<tr>
401+
<th>Date:</th>
402+
<td>{formatEventDate(event)}</td>
403+
</tr>
404+
</tbody>
405+
</table>
406+
</div>
334407
</div>
335408
)
336409
}

0 commit comments

Comments
 (0)