@@ -20,10 +20,10 @@ import type { ToastManager } from './lit-toast';
20
20
import baseStyles from './styles/base' ;
21
21
import type { ConfigMapData } from './types' ;
22
22
import './comment-editor' ;
23
+ import { when } from 'lit/directives/when.js' ;
23
24
import { ofetch } from 'ofetch' ;
24
25
import type { CommentEditor } from './comment-editor' ;
25
26
import { cleanHtml } from './utils/html' ;
26
- import './base-tooltip' ;
27
27
28
28
export class BaseForm extends LitElement {
29
29
@consume ( { context : baseUrlContext } )
@@ -154,14 +154,11 @@ export class BaseForm extends LitElement {
154
154
155
155
renderAccountInfo ( ) {
156
156
return html `<div class= "form-account flex items-center gap-2" >
157
- ${
158
- this . currentUser ?. spec . avatar
159
- ? html `
160
- <div class= "form-account-avatar avatar" >
161
- <img src= ${ this . currentUser . spec . avatar } class= "size-full object-cover" / >
162
- </ div> `
163
- : ''
164
- }
157
+ ${ when (
158
+ this . currentUser ?. spec . avatar ,
159
+ ( ) => html `<div class= "form-account-avatar avatar" > <img src= ${ this . currentUser ?. spec . avatar || '' } class= "size-full object-cover" / > </ div>
160
+ `
161
+ ) }
165
162
<span class= "form-account-name text-base text-text-1 font-semibold" >
166
163
${ this . currentUser ?. spec . displayName || this . currentUser ?. metadata . name }
167
164
</ span>
@@ -198,9 +195,11 @@ export class BaseForm extends LitElement {
198
195
return html `
199
196
<for m class= "form w-full flex flex-col gap-4" @submit = "${ this . onSubmit } " >
200
197
<comment- edito r ${ ref ( this . editorRef ) } .placeholder = ${ this . configMapData ?. editor ?. placeholder } > </ comment- edito r>
201
- ${
202
- ! this . currentUser && this . allowAnonymousComments
203
- ? html `<div class= "form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center" >
198
+
199
+ ${ when (
200
+ ! this . currentUser && this . allowAnonymousComments ,
201
+ ( ) => html `
202
+ <div class= "form-inputs grid grid-cols-1 md:grid-cols-4 gap-2 items-center" >
204
203
<input
205
204
name= "displayName"
206
205
value = ${ this . customAccount . displayName }
@@ -225,45 +224,41 @@ export class BaseForm extends LitElement {
225
224
class= "input"
226
225
/ >
227
226
<a tabindex= "-1" href = ${ this . loginUrl } rel= "nofollow" class= "for m- login- link text- text-3 hover: text- text-1 text- xs transition- all select- none"> ${ msg ( '(Or login)' ) } </ a>
228
- </ div> `
229
- : ''
230
- }
227
+ </ div>
228
+ `
229
+ ) }
231
230
232
231
<div class= "form__footer" >
233
232
${ this . currentUser ? this . renderAccountInfo ( ) : '' }
234
- ${
235
- ! this . currentUser && ! this . allowAnonymousComments
236
- ? html `<butto n
233
+ ${ when (
234
+ ! this . currentUser && ! this . allowAnonymousComments ,
235
+ ( ) => html `
236
+ <butto n
237
237
@click = ${ this . handleOpenLoginPage }
238
238
class= "form-login text-xs text-text-3 hover:text-text-1 px-3 transition-all py-2 rounded-base border border-muted-3 opacity-100 hover:border-muted-4 hover:opacity-70 border-solid"
239
239
type = "butto n"
240
240
tabindex= "-1"
241
241
>
242
242
${ msg ( 'Login' ) }
243
- </ butto n> `
244
- : ''
245
- }
243
+ </ butto n>
244
+ `
245
+ ) }
246
246
<div class= "form-actions justify-end flex gap-3 flex-wrap items-center" >
247
-
248
- ${
247
+ ${ when (
249
248
! this . hidePrivateCheckbox &&
250
- this . configMapData ?. basic . enablePrivateComment
251
- ? html `
252
- <div class= "flex items-center gap-2" >
253
- <input id= "hidden" name = "hidden" type= "checkbox" / >
254
- <label for = "hidden" class = "text- xs select- none text- text-3 hover: text- text-1 transition- all"> ${ msg ( 'Private' ) } </ label>
255
- <base- to oltip content= ${ this . currentUser ? msg ( 'Currently logged in. After selecting the private option, comments will only be visible to yourself and the site administrator.' ) : msg ( 'You are currently anonymous. After selecting the private option, the comment will only be visible to the site administrator.' ) } >
256
- <i class= "i-mingcute:information-line size-3.5 text-text-3 block" > </ i>
257
- </ base- to oltip>
258
- </ div>
259
- `
260
- : ''
261
- }
262
-
263
-
264
- ${
265
- this . showCaptcha && this . captcha
266
- ? html `
249
+ this . configMapData ?. basic . enablePrivateComment ,
250
+ ( ) => html `<div class= "flex items-center gap-2" >
251
+ <input id= "hidden" name = "hidden" type= "checkbox" / >
252
+ <label for = "hidden" class = "text- xs select- none text- text-3 hover: text- text-1 transition- all"> ${ msg ( 'Private' ) } </ label>
253
+ <base- to oltip content= ${ this . currentUser ? msg ( 'Currently logged in. After selecting the private option, comments will only be visible to yourself and the site administrator.' ) : msg ( 'You are currently anonymous. After selecting the private option, the comment will only be visible to the site administrator.' ) } >
254
+ <i class= "i-mingcute:information-line size-3.5 text-text-3 block" > </ i>
255
+ </ base- to oltip>
256
+ </ div> `
257
+ ) }
258
+
259
+ ${ when (
260
+ this . showCaptcha && this . captcha ,
261
+ ( ) => html `
267
262
<div class= "form-captcha gap-2 flex items-center" >
268
263
<img
269
264
@click = ${ this . handleFetchCaptcha }
@@ -278,20 +273,20 @@ export class BaseForm extends LitElement {
278
273
class= "input "
279
274
/ >
280
275
</ div>
281
- `
282
- : ''
283
- }
276
+ `
277
+ ) }
284
278
285
279
<butto n
286
280
.disabled = ${ this . submitting }
287
281
type= "submit"
288
282
class= "for m- submit outline-none focus: shadow- input h-12 text- sm inline-flex bor der bor der- primary-1 bor der- solid items- center justify- center gap-2 bg- primary-1 text- white px-3 rounded- base hover: opacity-80 transition- all"
289
283
>
290
- ${
291
- this . submitting
292
- ? html `<icon- loading> </ icon- loading> `
293
- : html `<i class= "i-mingcute-send-line size-5" aria-hidden = "true"> </ i> `
294
- }
284
+ ${ when (
285
+ this . submitting ,
286
+ ( ) => html `<icon- loading> </ icon- loading> ` ,
287
+ ( ) =>
288
+ html `<i class= "i-mingcute-send-line size-5" aria-hidden = "true"> </ i> `
289
+ ) }
295
290
${ msg ( 'Submit' ) }
296
291
</ butto n>
297
292
</ div>
0 commit comments