1
1
import { consume } from '@lit/context' ;
2
2
import { css , html , LitElement } from 'lit' ;
3
3
import { customElement , property } from 'lit/decorators.js' ;
4
+ import { classMap } from 'lit/directives/class-map.js' ;
4
5
import { ifDefined } from 'lit/directives/if-defined.js' ;
5
- import { createRef , ref , type Ref } from 'lit/directives/ref.js' ;
6
6
import { when } from 'lit/directives/when.js' ;
7
7
import { avatars , profiles } from '../../config.js' ;
8
8
import type { DiscordMessageProps , Profile , LightTheme , DiscordTimestamp } from '../../types.js' ;
@@ -49,7 +49,6 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
49
49
}
50
50
51
51
:host([message-body-only]) {
52
- min-height: 24px !important;
53
52
margin-top: 0px !important;
54
53
padding-top: 0.125rem !important;
55
54
padding-bottom: 0.0625rem !important;
@@ -131,6 +130,11 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
131
130
width: 56px;
132
131
}
133
132
133
+ :host(:hover) .discord-message-timestamp-hover::before {
134
+ content: attr(datetime);
135
+ min-height: 24px !important;
136
+ }
137
+
134
138
:host([light-theme]) .discord-message-timestamp {
135
139
color: #747f8d;
136
140
}
@@ -248,8 +252,6 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
248
252
}
249
253
` ;
250
254
251
- protected messageBodyOnlyTimeRef : Ref < HTMLTimeElement > = createRef ( ) ;
252
-
253
255
/**
254
256
* The id of the profile data to use.
255
257
*/
@@ -381,19 +383,6 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
381
383
) ;
382
384
}
383
385
384
- protected handleMessageEnter ( ) {
385
- if ( this . messageBodyOnly && this . messageBodyOnlyTimeRef . value ) {
386
- const computedTimestamp = handleTimestamp ( this . timestamp , true , this . twentyFour ) ;
387
- this . messageBodyOnlyTimeRef . value . textContent = computedTimestamp ?? '' ;
388
- }
389
- }
390
-
391
- protected handleMessageLeave ( ) {
392
- if ( this . messageBodyOnlyTimeRef . value ) {
393
- this . messageBodyOnlyTimeRef . value . textContent = '' ;
394
- }
395
- }
396
-
397
386
protected override render ( ) {
398
387
const defaultData : Profile = {
399
388
author : this . author ,
@@ -413,29 +402,22 @@ export class DiscordMessage extends LitElement implements DiscordMessageProps, L
413
402
414
403
return html `
415
404
< slot name ="reply "> </ slot >
416
- < div class ="discord-message-inner " @mouseenter = ${ this . handleMessageEnter } @mouseleave = ${ this . handleMessageLeave } >
405
+ < div class ="discord-message-inner ">
417
406
${ when (
418
407
this . compactMode && ! this . messageBodyOnly ,
419
408
( ) => html `< time datetime ="${ ifDefined ( computedTimestamp ) } " class ="discord-message-timestamp "> ${ computedTimestamp } </ time > ` ,
420
409
( ) => null
421
410
) }
422
411
${ when (
423
- this . messageBodyOnly && ! this . compactMode ,
424
- ( ) =>
425
- html `< time
426
- ${ ref ( this . messageBodyOnlyTimeRef ) }
427
- datetime ="${ ifDefined ( computedTimestamp ) } "
428
- class ="discord-message-timestamp discord-message-body-only-indent "
429
- > </ time > ` ,
430
- ( ) => null
431
- ) }
432
- ${ when (
433
- this . compactMode && this . messageBodyOnly ,
412
+ this . messageBodyOnly ,
434
413
( ) =>
435
414
html `< time
436
- ${ ref ( this . messageBodyOnlyTimeRef ) }
437
415
datetime ="${ ifDefined ( computedTimestamp ) } "
438
- class ="discord-message-timestamp "
416
+ class =${ classMap ( {
417
+ 'discord-message-timestamp' : true ,
418
+ 'discord-message-timestamp-hover' : true ,
419
+ 'discord-message-body-only-indent' : ! this . compactMode
420
+ } ) }
439
421
> </ time > ` ,
440
422
( ) => null
441
423
) }
0 commit comments