11import  {  type  ScopedElementsMap  }  from  '@open-wc/scoped-elements/lit-element.js' ; 
22import  {  Dialog  }  from  '@sl-design-system/dialog' ; 
3- import  {  Form ,  FormController ,  FormField ,  FormValidationErrors  }  from  '@sl-design-system/form' ; 
3+ import  {  Error ,  Form ,  FormController ,  FormField ,  FormValidationErrors ,  Label  }  from  '@sl-design-system/form' ; 
4+ import  {  FormatNumber  }  from  '@sl-design-system/format-number' ; 
5+ import  {  Icon  }  from  '@sl-design-system/icon' ; 
6+ import  {  InlineMessage  }  from  '@sl-design-system/inline-message' ; 
7+ import  {  Option  }  from  '@sl-design-system/listbox' ; 
8+ import  {  NumberField  }  from  '@sl-design-system/number-field' ; 
9+ import  {  Select  }  from  '@sl-design-system/select' ; 
10+ import  {  Switch  }  from  '@sl-design-system/switch' ; 
11+ import  {  TextArea  }  from  '@sl-design-system/text-area' ; 
412import  {  TextField  }  from  '@sl-design-system/text-field' ; 
5- import  {  type  CSSResultGroup ,  type  TemplateResult ,  html  }  from  'lit' ; 
13+ import  {  type  CSSResultGroup ,  type  PropertyValues ,   type   TemplateResult ,  html ,   nothing  }  from  'lit' ; 
614import  styles  from  './form-in-dialog.scss.js' ; 
715
816export  class  FormInDialog  extends  Dialog  { 
917  /** @internal  */ 
1018  static  override  get  scopedElements ( ) : ScopedElementsMap  { 
1119    return  { 
1220      ...super . scopedElements , 
21+       'sl-error' : Error , 
1322      'sl-form' : Form , 
1423      'sl-form-field' : FormField , 
1524      'sl-form-validation-errors' : FormValidationErrors , 
25+       'sl-format-number' : FormatNumber , 
26+       'sl-icon' : Icon , 
27+       'sl-inline-message' : InlineMessage , 
28+       'sl-label' : Label , 
29+       'sl-number-field' : NumberField , 
30+       'sl-option' : Option , 
31+       'sl-select' : Select , 
32+       'sl-switch' : Switch , 
33+       'sl-text-area' : TextArea , 
1634      'sl-text-field' : TextField 
1735    } ; 
1836  } 
@@ -21,21 +39,92 @@ export class FormInDialog extends Dialog {
2139  static  override  styles : CSSResultGroup  =  [ Dialog . styles ,  styles ] ; 
2240
2341  /** Controller for managing form state. */ 
24-   #form =  new  FormController ( this ) ; 
42+   #form =  new  FormController < { 
43+     type : string ; 
44+     description ?: string ; 
45+     indefinitely : boolean ; 
46+     rentalPeriodAmount ?: number ; 
47+     rentalPeriodUnit ?: string ; 
48+     amount : number ; 
49+     deposit : number ; 
50+   } > ( this ) ; 
51+ 
52+   override  firstUpdated ( changes : PropertyValues < this> ) : void { 
53+     super . firstUpdated ( changes ) ; 
54+ 
55+     this . #form. value  =  { 
56+       type : 'Small' , 
57+       indefinitely : true , 
58+       amount : 15 , 
59+       deposit : 15 
60+     } ; 
61+   } 
2562
2663  override  renderHeader ( ) : TemplateResult  { 
27-     return  super . renderHeader ( 'Form in dialog ' ) ; 
64+     return  super . renderHeader ( 'Change locker type ' ) ; 
2865  } 
2966
3067  override  renderBody ( ) : TemplateResult  { 
3168    return  html ` 
32-       < sl-form >  
33-         < sl-form-field  label ="First name ">  
34-           < sl-text-field  autofocus  name ="firstName " required > </ sl-text-field >  
69+       < sl-form  @sl-update-state =${ this . #onUpdateState} >  
70+         < sl-form-field  label ="Type ">  
71+           < sl-text-field  autofocus  name ="type " required > </ sl-text-field >  
72+         </ sl-form-field >  
73+         < sl-form-field  label ="Description ">  
74+           < sl-text-area  name ="description "> </ sl-text-area >  
75+         </ sl-form-field >  
76+         < sl-form-field  class ="rental-period ">  
77+           < sl-label  mark ="required "> Rental period</ sl-label >  
78+           < sl-switch  name ="indefinitely " reverse > Indefinitely, until the student leaves school.</ sl-switch >  
79+           < sl-number-field  
80+             aria-label ="Rental period amount " 
81+             ?disabled =${ this . #form. value ?. indefinitely }  
82+             name ="rentalPeriodAmount" 
83+             placeholder="0" 
84+             ?required=${ ! this . #form. value ?. indefinitely }  
85+           > </ sl-number-field >  
86+           < sl-select  
87+             aria-label ="Rental period unit " 
88+             ?disabled =${ this . #form. value ?. indefinitely }  
89+             name ="rentalPeriodUnit" 
90+             placeholder="Select unit" 
91+             ?required=${ ! this . #form. value ?. indefinitely }  
92+           >  
93+             < sl-option  value ="day "> Day</ sl-option >  
94+             < sl-option  value ="week "> Week</ sl-option >  
95+             < sl-option  value ="month "> Month</ sl-option >  
96+             < sl-option  value ="year "> Year</ sl-option >  
97+           </ sl-select >  
3598        </ sl-form-field >  
36-         < sl-form-field  label ="Last name ">  
37-           < sl-text-field  name ="lastName " required > </ sl-text-field >  
99+         < sl-form-field  class ="amount " label ="Amount ">  
100+           < sl-number-field  
101+             format-options ='{ "style": "currency", "currency": "EUR" } ' 
102+             min ="0 " 
103+             name ="amount " 
104+             required  
105+           > </ sl-number-field >  
38106        </ sl-form-field >  
107+         < sl-form-field  class ="deposit " label ="Deposit ">  
108+           < sl-number-field  
109+             format-options ='{ "style": "currency", "currency": "EUR" } ' 
110+             min ="0 " 
111+             name ="deposit " 
112+             required  
113+           > </ sl-number-field >  
114+         </ sl-form-field >  
115+ 
116+         ${ this . #form. controls . amount ?. dirty  
117+           ? html `  
118+               < sl-inline-message  type ="info ">  
119+                 The rental amount for < strong > already rented</ strong >  lockers will remain 
120+                 < sl-format-number  
121+                   .formatOptions =${ {  style : 'currency' ,  currency : 'EUR'  } }  
122+                   .number =${ 15 }  
123+                 > </ sl-format-number  
124+                 > . 
125+               </ sl-inline-message >  
126+             ` 
127+           : nothing }  
39128
40129        < sl-form-validation-errors  .controller =${ this . #form} > </ sl-form-validation-errors >  
41130      </ sl-form >  
@@ -54,4 +143,16 @@ export class FormInDialog extends Dialog {
54143      this . close ( ) ; 
55144    } 
56145  } 
146+ 
147+   #onUpdateState( ) : void { 
148+     const  {  indefinitely,  rentalPeriodAmount,  rentalPeriodUnit }  =  this . #form. value  ||  { } ; 
149+ 
150+     this . #form. controls . rentalPeriodAmount ?. setCustomValidity ( 
151+       indefinitely  ||  rentalPeriodAmount  ? ''  : 'Please enter a rental period amount.' 
152+     ) ; 
153+ 
154+     this . #form. controls . rentalPeriodUnit ?. setCustomValidity ( 
155+       indefinitely  ||  rentalPeriodUnit  ? ''  : 'Please select a rental period unit.' 
156+     ) ; 
157+   } 
57158} 
0 commit comments