1
+ import { html , customElement , property , state , css , when } from '@umbraco-cms/backoffice/external/lit' ;
2
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
1
3
import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app' ;
2
4
import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit' ;
3
- import { html , customElement , property , state , css } from '@umbraco-cms/backoffice/external/lit' ;
4
- import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
5
5
6
6
@customElement ( 'umb-input-upload-field-file' )
7
7
export default class UmbInputUploadFieldFileElement extends UmbLitElement {
8
- @property ( { type : String } )
8
+ #loadingText = `(${ this . localize . term ( 'general_loading' ) } ...)` ;
9
+
10
+ #serverUrl = '' ;
11
+
12
+ @property ( )
9
13
path : string = '' ;
10
14
11
15
/**
@@ -22,53 +26,39 @@ export default class UmbInputUploadFieldFileElement extends UmbLitElement {
22
26
@state ( )
23
27
label = '' ;
24
28
25
- #serverUrl = '' ;
26
-
27
- #loadingText = `(${ this . localize . term ( 'general_loading' ) } ...)` ;
28
-
29
- /**
30
- *
31
- */
32
29
constructor ( ) {
33
30
super ( ) ;
31
+
34
32
this . consumeContext ( UMB_APP_CONTEXT , ( instance ) => {
35
33
this . #serverUrl = instance . getServerUrl ( ) ;
36
- } ) . asPromise ( ) ;
34
+ } ) ;
37
35
}
38
36
39
37
protected override updated ( _changedProperties : PropertyValueMap < any > | Map < PropertyKey , unknown > ) : void {
40
38
super . updated ( _changedProperties ) ;
39
+
41
40
if ( _changedProperties . has ( 'file' ) && this . file ) {
42
41
this . extension = this . file . name . split ( '.' ) . pop ( ) ?? '' ;
43
42
this . label = this . file . name || this . #loadingText;
44
43
}
45
44
46
- if ( _changedProperties . has ( 'path' ) ) {
47
- if ( this . #serverUrl) {
48
- if ( this . file ) return ;
49
-
50
- this . extension = this . path . split ( '.' ) . pop ( ) ?? '' ;
51
- this . label = this . #serverUrl ? this . path . substring ( this . #serverUrl. length ) : this . #loadingText;
52
- }
45
+ if ( _changedProperties . has ( 'path' ) && ! this . file ) {
46
+ this . extension = this . path . split ( '.' ) . pop ( ) ?? '' ;
47
+ this . label = this . path . split ( '/' ) . pop ( ) ?? this . #loadingText;
53
48
}
54
49
}
55
50
56
- #renderLabel( ) {
57
- if ( this . path ) {
58
- // Don't make it a link if it's a temp file upload.
59
- return this . file ? this . label : html `<a id= "label" href = ${ this . path } target= "_blank" > ${ this . label } </ a> ` ;
60
- }
61
-
62
- return html `<span id= "label" > ${ this . label } </ span> ` ;
63
- }
64
-
65
51
override render ( ) {
66
52
if ( ! this . label && ! this . extension ) return html `<uui- loader> </ uui- loader> ` ;
67
53
68
54
return html `
69
55
<div id= "main" >
70
56
<uui- symbol- file id= "file-symbol" .type = ${ this . extension } > </ uui- symbol- file>
71
- ${ this . #renderLabel( ) }
57
+ ${ when (
58
+ ! this . file && this . path ,
59
+ ( ) => html `<a id= "label" href = "${ this . #serverUrl} ${ this . path } " target = "_blank" > ${ this . label } </ a> ` ,
60
+ ( ) => html `<span id= "label" > ${ this . label } </ span> ` ,
61
+ ) }
72
62
</ div>
73
63
` ;
74
64
}
@@ -81,26 +71,30 @@ export default class UmbInputUploadFieldFileElement extends UmbLitElement {
81
71
box-sizing : border-box;
82
72
color : var (--uui-color-text );
83
73
}
74
+
84
75
# file-symbol {
85
76
aspect-ratio : 1 / 1 ;
86
77
margin : auto;
87
78
max-width : 100% ;
88
79
max-height : 100% ;
89
80
}
81
+
90
82
# label {
91
83
text-align : center;
92
84
overflow : hidden;
93
85
text-overflow : ellipsis;
94
86
white-space : nowrap;
95
87
color : var (--uui-color-text );
96
- }
97
- a # label {
98
- text-decoration : none;
99
- color : var (--uui-color-interactive );
100
- }
101
- a # label : hover {
102
- text-decoration : underline;
103
- color : var (--uui-color-interactive-emphasis );
88
+
89
+ & : is (a ) {
90
+ text-decoration : none;
91
+ color : var (--uui-color-interactive );
92
+
93
+ & : hover {
94
+ text-decoration : underline;
95
+ color : var (--uui-color-interactive-emphasis );
96
+ }
97
+ }
104
98
}
105
99
` ,
106
100
] ;
0 commit comments