1
1
import { LitElement , html , css } from 'lit' ;
2
+ import { property , state } from 'lit/decorators.js' ;
2
3
import { defineElement } from '@umbraco-ui/uui-base/lib/registration' ;
3
4
4
5
// TODO: Make sure validation messages can be seen for the whole Form Item. Make them follow the screen if form controls are taller than available screen height.
@@ -15,13 +16,64 @@ export class UUIFormItemElement extends LitElement {
15
16
static styles = [
16
17
css `
17
18
:host {
18
- /* Styles goes here */
19
+ position: relative;
20
+ display: block;
21
+ margin-top: var(--uui-size-space-5);
22
+ margin-bottom: var(--uui-size-space-5);
23
+ }
24
+ #label {
25
+ margin-top: -5px;
26
+ margin-bottom: 5px;
27
+ }
28
+ #description {
29
+ color: var(--uui-interface-contrast-disabled);
30
+ font-size: var(--uui-type-small-size);
31
+ }
32
+ #label + #description {
33
+ margin-top: -8px;
34
+ min-height: 8px;
19
35
}
20
36
` ,
21
37
] ;
38
+ /*
39
+ @property ({type: String})
40
+ label: string | null = null;
41
+ */
42
+
43
+ @property ( { type : String } )
44
+ description : string | null = null ;
45
+
46
+ @state ( )
47
+ private _labelSlotHasContent = false ;
48
+
49
+ private _labelSlotChanged = ( e : Event ) => {
50
+ this . _labelSlotHasContent =
51
+ ( e . target as HTMLSlotElement ) . assignedNodes ( { flatten : true } ) . length > 0 ;
52
+ } ;
53
+
54
+ @state ( )
55
+ private _descriptionSlotHasContent = false ;
56
+
57
+ private _descriptionSlotChanged = ( e : Event ) => {
58
+ this . _descriptionSlotHasContent =
59
+ ( e . target as HTMLSlotElement ) . assignedNodes ( { flatten : true } ) . length > 0 ;
60
+ } ;
22
61
23
62
render ( ) {
24
63
return html `
64
+ < div id ="label " style =${ this . _labelSlotHasContent ? '' : 'display: none' } >
65
+ < slot name ="label " @slotchange =${ this . _labelSlotChanged } > </ slot >
66
+ </ div >
67
+ < div
68
+ id ="description "
69
+ style =${ this . _descriptionSlotHasContent || this . description !== null
70
+ ? ''
71
+ : 'display: none' } >
72
+ ${ this . description }
73
+ < slot
74
+ name ="description "
75
+ @slotchange =${ this . _descriptionSlotChanged } > </ slot >
76
+ </ div >
25
77
< uui-form-validation-message >
26
78
< slot > </ slot >
27
79
< slot name ="message " slot ="message "> </ slot >
0 commit comments