1
+ import Color from 'color'
1
2
import { css , styled } from 'decorock'
2
- import { Component , createEffect , createSignal , For } from 'solid-js'
3
+ import { on , Component , createEffect , createSignal , For , Show } from 'solid-js'
3
4
4
5
import { classnames } from '~/web/lib/classnames'
5
6
@@ -13,6 +14,17 @@ const Container = styled.div`
13
14
font-size : 0.9rem ;
14
15
white-space : nowrap;
15
16
}
17
+
18
+ a {
19
+ color : ${ ( p ) =>
20
+ p . theme . name === 'light'
21
+ ? Color ( 'rgb(0, 255, 255)' ) . darken ( 0.25 )
22
+ : Color ( 'rgb(0, 255, 255)' ) } ;
23
+ text-underline-offset : 2px ;
24
+ & : hover {
25
+ text-decoration : underline;
26
+ }
27
+ }
16
28
`
17
29
18
30
export const Log : Component < {
@@ -22,14 +34,18 @@ export const Log: Component<{
22
34
autoScroll ?: boolean
23
35
} > = ( props ) => {
24
36
const [ ref , setRef ] = createSignal < HTMLDivElement > ( )
25
- createEffect ( ( ) => {
26
- if ( typeof props . autoScroll !== 'undefined' && ! props . autoScroll ) return
27
- props . children
28
- setTimeout ( ( ) => {
29
- const el = ref ( ) !
30
- el . scrollTop = el . scrollHeight
31
- } )
32
- } )
37
+ const [ onBottom , setOnBottom ] = createSignal ( true )
38
+
39
+ createEffect (
40
+ on (
41
+ ( ) => props . children ,
42
+ ( ) => {
43
+ const el = ref ( ) !
44
+ if ( typeof props . autoScroll !== 'undefined' && ! props . autoScroll ) return
45
+ if ( onBottom ( ) ) el . scrollTop = el . scrollHeight
46
+ } ,
47
+ ) ,
48
+ )
33
49
34
50
return (
35
51
< Container
@@ -45,8 +61,28 @@ export const Log: Component<{
45
61
overflow-y : auto;
46
62
` ,
47
63
) }
64
+ onScroll = { ( e ) => {
65
+ setOnBottom (
66
+ e . currentTarget . scrollHeight - e . currentTarget . scrollTop === e . currentTarget . clientHeight ,
67
+ )
68
+ } }
48
69
>
49
- < For each = { props . children } > { ( log ) => < p > { log } </ p > } </ For >
70
+ < For each = { props . children } >
71
+ { ( log ) => {
72
+ const logs = log . split ( / ( h t t p : \/ \/ [ ^ \s ] + ) / g)
73
+ return (
74
+ < p >
75
+ < For each = { logs } >
76
+ { ( t ) => (
77
+ < Show when = { t . match ( / ( h t t p : \/ \/ [ ^ \s ] + ) / ) } fallback = { t } >
78
+ < a href = { t } > { t } </ a >
79
+ </ Show >
80
+ ) }
81
+ </ For >
82
+ </ p >
83
+ )
84
+ } }
85
+ </ For >
50
86
</ Container >
51
87
)
52
88
}
0 commit comments