@inglorious/ui 9.1.0 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/ui",
3
- "version": "9.1.0",
3
+ "version": "9.1.1",
4
4
  "description": "A design system for Inglorious Web with render-function components and customizable themes",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -315,7 +315,7 @@
315
315
  "@iconify-icons/fa7-regular": "^2.0.0",
316
316
  "@iconify-icons/fa7-solid": "^2.0.0",
317
317
  "@iconify-icons/material-symbols": "^2.0.6",
318
- "@inglorious/charts": "12.0.0",
318
+ "@inglorious/charts": "12.1.0",
319
319
  "@inglorious/eslint-config": "1.2.0",
320
320
  "@inglorious/store": "12.0.0",
321
321
  "@inglorious/vite-plugin-jsx": "2.0.5",
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
 
@@ -83,18 +84,18 @@ export function render(props) {
83
84
  >
84
85
  ${children}
85
86
  </button>
86
- ${
87
- onFileSelect
88
- ? html`<input
89
- type="file"
90
- accept=${accept ?? ""}
91
- ?multiple=${isMultiple}
92
- ?disabled=${isDisabled}
93
- hidden
94
- @change=${(event) => handleFileChange(event, onFileSelect)}
95
- />`
96
- : nothing
97
- }
87
+ ${when(
88
+ onFileSelect,
89
+ () =>
90
+ html`<input
91
+ type="file"
92
+ accept=${accept ?? ""}
93
+ ?multiple=${isMultiple}
94
+ ?disabled=${isDisabled}
95
+ hidden
96
+ @change=${(event) => handleFileChange(event, onFileSelect)}
97
+ />`,
98
+ )}
98
99
  `
99
100
  }
100
101
 
@@ -6,6 +6,7 @@
6
6
  import { html } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
  import { Button } from "../button/index.js"
@@ -73,13 +74,12 @@ export function render(props) {
73
74
 
74
75
  return Button.render({
75
76
  children: html`
76
- ${icon ? html`<span class="iw-button-icon">${icon}</span>` : null}
77
+ ${when(icon, () => html`<span class="iw-button-icon">${icon}</span>`)}
77
78
  ${children ?? label}
78
- ${
79
- iconAfter
80
- ? html`<span class="iw-button-icon">${iconAfter}</span>`
81
- : null
82
- }
79
+ ${when(
80
+ iconAfter,
81
+ () => html`<span class="iw-button-icon">${iconAfter}</span>`,
82
+ )}
83
83
  `,
84
84
  variant: itemVariant ?? variant,
85
85
  color: itemColor ?? color,
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
 
@@ -55,14 +56,15 @@ export function render(props) {
55
56
  @change=${(event) => onChange?.(event.target.checked)}
56
57
  ${ref((element) => applyElementProps(element, rest))}
57
58
  />
58
- ${
59
- description
60
- ? html`<span class="iw-checkbox-text">
61
- <span class="iw-checkbox-label">${label}</span>
62
- <span class="iw-checkbox-description">${description}</span>
63
- </span>`
64
- : html`<span class="iw-checkbox-label">${label}</span>`
65
- }
59
+ ${when(
60
+ description,
61
+ () =>
62
+ html`<span class="iw-checkbox-text">
63
+ <span class="iw-checkbox-label">${label}</span>
64
+ <span class="iw-checkbox-description">${description}</span>
65
+ </span>`,
66
+ () => html`<span class="iw-checkbox-label">${label}</span>`,
67
+ )}
66
68
  </label>
67
69
  `
68
70
  }
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
  import { fallbackLabel } from "../../shared/fallback-label.js"
@@ -57,20 +58,18 @@ export function render(props) {
57
58
 
58
59
  return html`
59
60
  <div class=${classMap(wrapperClasses)}>
60
- ${
61
- label
62
- ? html`
63
- <label for=${uploadId || nothing} class="iw-upload-label">
64
- ${label}
65
- ${
66
- isRequired
67
- ? html`<span class="iw-upload-required">*</span>`
68
- : null
69
- }
70
- </label>
71
- `
72
- : null
73
- }
61
+ ${when(
62
+ label,
63
+ () => html`
64
+ <label for=${uploadId || nothing} class="iw-upload-label">
65
+ ${label}
66
+ ${when(
67
+ isRequired,
68
+ () => html`<span class="iw-upload-required">*</span>`,
69
+ )}
70
+ </label>
71
+ `,
72
+ )}
74
73
 
75
74
  <div class=${classMap(fieldClasses)}>
76
75
  <input
@@ -99,19 +98,21 @@ export function render(props) {
99
98
 
100
99
  <div class="iw-upload-field-summary">${summaryText}</div>
101
100
 
102
- ${
103
- error
104
- ? html`<span
105
- id=${messageId || nothing}
106
- class="iw-upload-error-message"
107
- >${error}</span
108
- >`
109
- : hint
110
- ? html`<span id=${messageId || nothing} class="iw-upload-hint"
101
+ ${when(
102
+ error,
103
+ () =>
104
+ html`<span id=${messageId || nothing} class="iw-upload-error-message"
105
+ >${error}</span
106
+ >`,
107
+ () =>
108
+ when(
109
+ hint,
110
+ () =>
111
+ html`<span id=${messageId || nothing} class="iw-upload-hint"
111
112
  >${hint}</span
112
- >`
113
- : null
114
- }
113
+ >`,
114
+ ),
115
+ )}
115
116
  </div>
116
117
  `
117
118
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { html } from "@inglorious/web"
7
+ import { when } from "@inglorious/web/directives/when"
7
8
 
8
9
  import { Button } from "../button/index.js"
9
10
 
@@ -25,13 +26,12 @@ export function render(props) {
25
26
 
26
27
  const children = html`
27
28
  <span class="iw-icon-button-content iw-icon-button-content-${direction}">
28
- ${icon ? html`<span class="iw-button-icon">${icon}</span>` : null}
29
+ ${when(icon, () => html`<span class="iw-button-icon">${icon}</span>`)}
29
30
  ${label}
30
- ${
31
- iconAfter
32
- ? html`<span class="iw-button-icon">${iconAfter}</span>`
33
- : null
34
- }
31
+ ${when(
32
+ iconAfter,
33
+ () => html`<span class="iw-button-icon">${iconAfter}</span>`,
34
+ )}
35
35
  </span>
36
36
  `
37
37
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { html } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import {
11
12
  DEFAULT_MIN_SIZE,
@@ -84,7 +85,8 @@ export const ImageCropper = {
84
85
  @keydown=${handleKeyDown(props)}
85
86
  @wheel=${handleWheel(props)}
86
87
  >
87
- ${this.renderImage?.(props)} ${isLoaded ? this.renderFrame?.(props) : ""}
88
+ ${this.renderImage?.(props)}
89
+ ${when(isLoaded, () => this.renderFrame?.(props))}
88
90
  </div>`
89
91
  },
90
92
 
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
 
@@ -47,11 +48,10 @@ export function render(props) {
47
48
  ?disabled=${isDisabled}
48
49
  ${ref((element) => applyElementProps(element, rest))}
49
50
  >
50
- ${
51
- label
52
- ? html`<legend class="iw-radio-group-label">${label}</legend>`
53
- : null
54
- }
51
+ ${when(
52
+ label,
53
+ () => html`<legend class="iw-radio-group-label">${label}</legend>`,
54
+ )}
55
55
  ${options.map((option, index) => {
56
56
  const {
57
57
  label: optionLabel,
@@ -74,16 +74,15 @@ export function render(props) {
74
74
  @change=${(event) => onChange?.(event.target.value)}
75
75
  ${ref((element) => applyElementProps(element, optionRest))}
76
76
  />
77
- ${
78
- optionDescription
79
- ? html`<span class="iw-radio-text">
80
- <span>${optionLabel}</span>
81
- <span class="iw-radio-description"
82
- >${optionDescription}</span
83
- >
84
- </span>`
85
- : html`<span>${optionLabel}</span>`
86
- }
77
+ ${when(
78
+ optionDescription,
79
+ () =>
80
+ html`<span class="iw-radio-text">
81
+ <span>${optionLabel}</span>
82
+ <span class="iw-radio-description">${optionDescription}</span>
83
+ </span>`,
84
+ () => html`<span>${optionLabel}</span>`,
85
+ )}
87
86
  </label>
88
87
  `
89
88
  })}
@@ -52,11 +52,10 @@ export const Select = {
52
52
  () => html`
53
53
  <label for=${id || name || nothing} class="iw-select-label">
54
54
  ${label}
55
- ${
56
- isRequired
57
- ? html`<span class="iw-select-required">*</span>`
58
- : null
59
- }
55
+ ${when(
56
+ isRequired,
57
+ () => html`<span class="iw-select-required">*</span>`,
58
+ )}
60
59
  </label>
61
60
  `,
62
61
  )}
@@ -117,7 +116,7 @@ export const Select = {
117
116
  )
118
117
 
119
118
  return html`<div class="iw-select-frame" @click=${openFromArrowStrip}>
120
- ${icon ? Icon.render({ children: icon, size }) : null}
119
+ ${when(icon, () => Icon.render({ children: icon, size }))}
121
120
 
122
121
  <select
123
122
  id=${controlId || nothing}
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
  import { fallbackLabel } from "../../shared/fallback-label.js"
@@ -60,51 +61,53 @@ export function render(props) {
60
61
 
61
62
  return html`
62
63
  <div class=${classMap(classes)}>
63
- ${
64
- (label || isValueVisible) &&
65
- html`<div class="iw-slider-header">
66
- ${
67
- label
68
- ? html`<label for=${inputId || nothing}>${label}</label>`
69
- : html`<span></span>`
70
- }
71
- ${
72
- isValueVisible
73
- ? html`<output class="iw-slider-value">${shown}</output>`
74
- : null
75
- }
76
- </div>`
77
- }
78
- ${
79
- isRange
80
- ? renderRange({
81
- inputId,
82
- name,
64
+ ${when(
65
+ label || isValueVisible,
66
+ () =>
67
+ html`<div class="iw-slider-header">
68
+ ${when(
83
69
  label,
84
- value,
85
- min,
86
- max,
87
- step,
88
- isDisabled,
89
- onChange,
90
- rest,
91
- })
92
- : html`<input
93
- id=${inputId || nothing}
94
- class="iw-slider-input"
95
- aria-label=${fallbackLabel(inputId, label)}
96
- type="range"
97
- name=${name}
98
- min=${min}
99
- max=${max}
100
- step=${step}
101
- .value=${String(value)}
102
- ?disabled=${isDisabled}
103
- @input=${(event) => onChange?.(Number(event.target.value))}
104
- ${ref((element) => applyElementProps(element, rest))}
105
- />`
106
- }
107
- ${hasMarks ? renderMarks({ min, max, step }) : nothing}
70
+ () => html`<label for=${inputId || nothing}>${label}</label>`,
71
+ () => html`<span></span>`,
72
+ )}
73
+ ${when(
74
+ isValueVisible,
75
+ () => html`<output class="iw-slider-value">${shown}</output>`,
76
+ )}
77
+ </div>`,
78
+ )}
79
+ ${when(
80
+ isRange,
81
+ () =>
82
+ renderRange({
83
+ inputId,
84
+ name,
85
+ label,
86
+ value,
87
+ min,
88
+ max,
89
+ step,
90
+ isDisabled,
91
+ onChange,
92
+ rest,
93
+ }),
94
+ () =>
95
+ html`<input
96
+ id=${inputId || nothing}
97
+ class="iw-slider-input"
98
+ aria-label=${fallbackLabel(inputId, label)}
99
+ type="range"
100
+ name=${name}
101
+ min=${min}
102
+ max=${max}
103
+ step=${step}
104
+ .value=${String(value)}
105
+ ?disabled=${isDisabled}
106
+ @input=${(event) => onChange?.(Number(event.target.value))}
107
+ ${ref((element) => applyElementProps(element, rest))}
108
+ />`,
109
+ )}
110
+ ${when(hasMarks, () => renderMarks({ min, max, step }))}
108
111
  </div>
109
112
  `
110
113
  }
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
 
@@ -58,16 +59,19 @@ export function render(props) {
58
59
  <span class="iw-switch-track" aria-hidden="true">
59
60
  <span class="iw-switch-thumb"></span>
60
61
  </span>
61
- ${
62
- description
63
- ? html`<span class="iw-switch-text">
64
- ${label ? html`<span class="iw-switch-label">${label}</span>` : null}
65
- <span class="iw-switch-description">${description}</span>
66
- </span>`
67
- : label
68
- ? html`<span class="iw-switch-label">${label}</span>`
69
- : null
70
- }
62
+ ${when(
63
+ description,
64
+ () =>
65
+ html`<span class="iw-switch-text">
66
+ ${when(label, () => html`<span class="iw-switch-label">${label}</span>`)}
67
+ <span class="iw-switch-description">${description}</span>
68
+ </span>`,
69
+ () =>
70
+ when(
71
+ label,
72
+ () => html`<span class="iw-switch-label">${label}</span>`,
73
+ ),
74
+ )}
71
75
  </label>
72
76
  `
73
77
  }
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
  import { fallbackLabel } from "../../shared/fallback-label.js"
@@ -59,20 +60,18 @@ export function render(props) {
59
60
 
60
61
  return html`
61
62
  <div class=${classMap(wrapperClasses)}>
62
- ${
63
- label
64
- ? html`
65
- <label for=${textareaId || nothing} class="iw-textarea-label">
66
- ${label}
67
- ${
68
- isRequired
69
- ? html`<span class="iw-textarea-required">*</span>`
70
- : null
71
- }
72
- </label>
73
- `
74
- : null
75
- }
63
+ ${when(
64
+ label,
65
+ () => html`
66
+ <label for=${textareaId || nothing} class="iw-textarea-label">
67
+ ${label}
68
+ ${when(
69
+ isRequired,
70
+ () => html`<span class="iw-textarea-required">*</span>`,
71
+ )}
72
+ </label>
73
+ `,
74
+ )}
76
75
 
77
76
  <textarea
78
77
  id=${textareaId || nothing}
@@ -93,19 +92,23 @@ export function render(props) {
93
92
  ${ref((element) => applyElementProps(element, rest))}
94
93
  ></textarea>
95
94
 
96
- ${
97
- error
98
- ? html`<span
99
- id=${messageId || nothing}
100
- class="iw-textarea-error-message"
101
- >${error}</span
102
- >`
103
- : hint
104
- ? html`<span id=${messageId || nothing} class="iw-textarea-hint"
95
+ ${when(
96
+ error,
97
+ () =>
98
+ html`<span
99
+ id=${messageId || nothing}
100
+ class="iw-textarea-error-message"
101
+ >${error}</span
102
+ >`,
103
+ () =>
104
+ when(
105
+ hint,
106
+ () =>
107
+ html`<span id=${messageId || nothing} class="iw-textarea-hint"
105
108
  >${hint}</span
106
- >`
107
- : null
108
- }
109
+ >`,
110
+ ),
111
+ )}
109
112
  </div>
110
113
  `
111
114
  }
@@ -6,6 +6,7 @@
6
6
  import { html } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { styleMap } from "@inglorious/web/directives/style-map"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  /**
11
12
  * Renders an avatar with image, initials, or fallback content.
@@ -57,11 +58,11 @@ export function render(props) {
57
58
  style=${styleMap(styles)}
58
59
  @click=${onClick}
59
60
  >
60
- ${
61
- src
62
- ? html`<img class="iw-avatar-img" src=${src} alt=${alt} />`
63
- : (children ?? initials ?? "?")
64
- }
61
+ ${when(
62
+ src,
63
+ () => html`<img class="iw-avatar-img" src=${src} alt=${alt} />`,
64
+ () => children ?? initials ?? "?",
65
+ )}
65
66
  </span>`
66
67
  }
67
68
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { html } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
+ import { when } from "@inglorious/web/directives/when"
8
9
 
9
10
  /**
10
11
  * Renders a compact chip label with an optional leading icon and remove action.
@@ -31,14 +32,14 @@ export function render(props) {
31
32
  }
32
33
 
33
34
  return html`<span class=${classMap(classes)}>
34
- ${icon ? html`<span class="iw-chip-icon" aria-hidden="true">${icon}</span>` : null}
35
+ ${when(icon, () => html`<span class="iw-chip-icon" aria-hidden="true">${icon}</span>`)}
35
36
  <span class="iw-chip-label">${children}</span>
36
- ${
37
- isRemovable
38
- ? html`<button type="button" class="iw-chip-remove" @click=${onClick}>
39
- ×
40
- </button>`
41
- : null
42
- }
37
+ ${when(
38
+ isRemovable,
39
+ () =>
40
+ html`<button type="button" class="iw-chip-remove" @click=${onClick}>
41
+ ×
42
+ </button>`,
43
+ )}
43
44
  </span>`
44
45
  }
@@ -111,7 +111,7 @@ export const DataGrid = {
111
111
  ${column.title} ${getSortIcon(getSortDirection(props, column.id))}
112
112
  </div>
113
113
 
114
- ${column.isFilterable && Filters.render(props, column)}
114
+ ${when(column.isFilterable, () => Filters.render(props, column))}
115
115
 
116
116
  <div
117
117
  class="iw-data-grid-column-resizer"
@@ -96,11 +96,10 @@ export const List = {
96
96
  meta,
97
97
  index,
98
98
  path: [...path, index],
99
- })}${
100
- shouldDivide
101
- ? html`<li class="iw-list-divider" role="separator"></li>`
102
- : null
103
- }`
99
+ })}${when(
100
+ shouldDivide,
101
+ () => html`<li class="iw-list-divider" role="separator"></li>`,
102
+ )}`
104
103
  },
105
104
  )
106
105
 
@@ -1,4 +1,5 @@
1
1
  import { html } from "@inglorious/web"
2
+ import { when } from "@inglorious/web/directives/when"
2
3
 
3
4
  import { Typography } from "../../data-display/typography/index.js"
4
5
  import { Container } from "../../layout/container/index.js"
@@ -77,24 +78,23 @@ export const PrimitiveSection = {
77
78
  description ??
78
79
  "This section is wired for per-primitive docs and examples.",
79
80
  })}
80
- ${
81
- useCases.length
82
- ? html`
83
- <div style="margin-top: 16px; text-align: left;">
84
- ${Typography.render({
85
- variant: "body2",
86
- color: "secondary",
87
- children: "Common use cases",
88
- })}
89
- <ul style="margin: 8px 0 0; padding-left: 20px;">
90
- ${useCases.map(
91
- (useCase) => html`<li>${useCase}</li>`,
92
- )}
93
- </ul>
94
- </div>
95
- `
96
- : ""
97
- }
81
+ ${when(
82
+ useCases.length,
83
+ () => html`
84
+ <div style="margin-top: 16px; text-align: left;">
85
+ ${Typography.render({
86
+ variant: "body2",
87
+ color: "secondary",
88
+ children: "Common use cases",
89
+ })}
90
+ <ul style="margin: 8px 0 0; padding-left: 20px;">
91
+ ${useCases.map(
92
+ (useCase) => html`<li>${useCase}</li>`,
93
+ )}
94
+ </ul>
95
+ </div>
96
+ `,
97
+ )}
98
98
  </div>
99
99
  `,
100
100
  }),
@@ -6,6 +6,7 @@
6
6
  import { html } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
 
@@ -53,33 +54,32 @@ export function render(props) {
53
54
  role="alert"
54
55
  ${ref((el) => applyElementProps(el, rest))}
55
56
  >
56
- ${icon ? html`<div class="iw-alert-icon">${icon}</div>` : null}
57
+ ${when(icon, () => html`<div class="iw-alert-icon">${icon}</div>`)}
57
58
  <div class="iw-alert-content">
58
- ${title ? html`<div class="iw-alert-title">${title}</div>` : null}
59
- ${
60
- content
61
- ? html`<div class="iw-alert-description">${content}</div>`
62
- : null
63
- }
59
+ ${when(title, () => html`<div class="iw-alert-title">${title}</div>`)}
60
+ ${when(
61
+ content,
62
+ () => html`<div class="iw-alert-description">${content}</div>`,
63
+ )}
64
64
  </div>
65
- ${
66
- hasTrailing
67
- ? html`<div class="iw-alert-trailing">
68
- ${action ? html`<div class="iw-alert-action">${action}</div>` : null}
69
- ${
70
- onClose
71
- ? html`<button
72
- type="button"
73
- class="iw-alert-close"
74
- aria-label="Dismiss"
75
- @click=${onClose}
76
- >
77
- ×
78
- </button>`
79
- : null
80
- }
81
- </div>`
82
- : null
83
- }
65
+ ${when(
66
+ hasTrailing,
67
+ () =>
68
+ html`<div class="iw-alert-trailing">
69
+ ${when(action, () => html`<div class="iw-alert-action">${action}</div>`)}
70
+ ${when(
71
+ onClose,
72
+ () =>
73
+ html`<button
74
+ type="button"
75
+ class="iw-alert-close"
76
+ aria-label="Dismiss"
77
+ @click=${onClose}
78
+ >
79
+ ×
80
+ </button>`,
81
+ )}
82
+ </div>`,
83
+ )}
84
84
  </div>`
85
85
  }
@@ -6,6 +6,7 @@
6
6
  import { html, nothing } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { syncDialog } from "../../shared/top-layer.js"
11
12
 
@@ -82,42 +83,43 @@ export function render(props) {
82
83
  ${ref((element) => syncDialog(element, { isOpen, isModal, onClose }))}
83
84
  >
84
85
  <div class="iw-dialog-surface">
85
- ${
86
- (title || onClose) &&
87
- html`<div class="iw-dialog-header">
88
- ${
89
- title
90
- ? html`<div id=${titleId || nothing} class="iw-dialog-title">
86
+ ${when(
87
+ title || onClose,
88
+ () =>
89
+ html`<div class="iw-dialog-header">
90
+ ${when(
91
+ title,
92
+ () =>
93
+ html`<div id=${titleId || nothing} class="iw-dialog-title">
91
94
  ${title}
92
- </div>`
93
- : null
94
- }
95
- ${
96
- onClose
97
- ? html`<button
95
+ </div>`,
96
+ )}
97
+ ${when(
98
+ onClose,
99
+ () =>
100
+ html`<button
98
101
  type="button"
99
102
  class="iw-dialog-close"
100
103
  aria-label="Close"
101
104
  @click=${onClose}
102
105
  >
103
106
  ×
104
- </button>`
105
- : null
106
- }
107
- </div>`
108
- }
109
- ${
110
- description
111
- ? html`<div
112
- id=${descriptionId || nothing}
113
- class="iw-dialog-description"
114
- >
115
- ${description}
116
- </div>`
117
- : null
118
- }
119
- ${children ? html`<div class="iw-dialog-body">${children}</div>` : null}
120
- ${actions ? html`<div class="iw-dialog-actions">${actions}</div>` : null}
107
+ </button>`,
108
+ )}
109
+ </div>`,
110
+ )}
111
+ ${when(
112
+ description,
113
+ () =>
114
+ html`<div
115
+ id=${descriptionId || nothing}
116
+ class="iw-dialog-description"
117
+ >
118
+ ${description}
119
+ </div>`,
120
+ )}
121
+ ${when(children, () => html`<div class="iw-dialog-body">${children}</div>`)}
122
+ ${when(actions, () => html`<div class="iw-dialog-actions">${actions}</div>`)}
121
123
  </div>
122
124
  </dialog>`
123
125
  }
@@ -6,6 +6,7 @@
6
6
  import { html } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { syncPopover } from "../../shared/top-layer.js"
11
12
 
@@ -49,19 +50,19 @@ export function render(props) {
49
50
  >
50
51
  <div class="iw-snackbar-content">
51
52
  <span class="iw-snackbar-message">${message}</span>
52
- ${action ? html`<span class="iw-snackbar-action">${action}</span>` : null}
53
- ${
54
- onClose
55
- ? html`<button
56
- type="button"
57
- class="iw-snackbar-close"
58
- aria-label="Dismiss"
59
- @click=${onClose}
60
- >
61
- ×
62
- </button>`
63
- : null
64
- }
53
+ ${when(action, () => html`<span class="iw-snackbar-action">${action}</span>`)}
54
+ ${when(
55
+ onClose,
56
+ () =>
57
+ html`<button
58
+ type="button"
59
+ class="iw-snackbar-close"
60
+ aria-label="Dismiss"
61
+ @click=${onClose}
62
+ >
63
+ ×
64
+ </button>`,
65
+ )}
65
66
  </div>
66
67
  </div>`
67
68
  }
@@ -7,6 +7,7 @@
7
7
  import { html } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
9
  import { ref } from "@inglorious/web/directives/ref"
10
+ import { when } from "@inglorious/web/directives/when"
10
11
 
11
12
  import { applyElementProps } from "../../shared/apply-element-props.js"
12
13
 
@@ -79,18 +80,16 @@ export const BottomNavigation = {
79
80
  props.onChange?.(currentValue)
80
81
  }}
81
82
  >
82
- ${
83
- action.icon
84
- ? html`<span class="iw-bottom-navigation-icon">${action.icon}</span>`
85
- : null
86
- }
87
- ${
88
- props.hasLabels
89
- ? html`<span class="iw-bottom-navigation-label"
90
- >${action.label}</span
91
- >`
92
- : null
93
- }
83
+ ${when(
84
+ action.icon,
85
+ () =>
86
+ html`<span class="iw-bottom-navigation-icon">${action.icon}</span>`,
87
+ )}
88
+ ${when(
89
+ props.hasLabels,
90
+ () =>
91
+ html`<span class="iw-bottom-navigation-label">${action.label}</span>`,
92
+ )}
94
93
  </button>`
95
94
  },
96
95
  }
@@ -7,6 +7,7 @@
7
7
  import { html } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
9
  import { ref } from "@inglorious/web/directives/ref"
10
+ import { when } from "@inglorious/web/directives/when"
10
11
 
11
12
  import { applyElementProps } from "../../shared/apply-element-props.js"
12
13
 
@@ -51,13 +52,13 @@ export const Breadcrumbs = {
51
52
  <ol class="iw-breadcrumbs-list">
52
53
  ${items.map(
53
54
  (item, index) =>
54
- html`${this.renderItem(item, index, props)}${
55
- index < items.length - 1
56
- ? html`<li class="iw-breadcrumbs-separator" aria-hidden="true">
57
- ${separator}
58
- </li>`
59
- : null
60
- }`,
55
+ html`${this.renderItem(item, index, props)}${when(
56
+ index < items.length - 1,
57
+ () =>
58
+ html`<li class="iw-breadcrumbs-separator" aria-hidden="true">
59
+ ${separator}
60
+ </li>`,
61
+ )}`,
61
62
  )}
62
63
  </ol>
63
64
  </nav>`
@@ -75,24 +76,26 @@ export const Breadcrumbs = {
75
76
  const isLast = index === props.items.length - 1
76
77
 
77
78
  return html`<li class="iw-breadcrumbs-item iw-typography">
78
- ${
79
- item.href && !isLast
80
- ? html`<a
81
- href=${item.href}
82
- class="iw-breadcrumbs-link"
83
- @click=${item.onClick ?? null}
84
- >
85
- ${item.label}
86
- </a>`
87
- : html`<span
88
- class=${classMap({
89
- "iw-breadcrumbs-current": isLast,
90
- })}
91
- aria-current=${isLast ? "page" : "false"}
92
- >
93
- ${item.label}
94
- </span>`
95
- }
79
+ ${when(
80
+ item.href && !isLast,
81
+ () =>
82
+ html`<a
83
+ href=${item.href}
84
+ class="iw-breadcrumbs-link"
85
+ @click=${item.onClick ?? null}
86
+ >
87
+ ${item.label}
88
+ </a>`,
89
+ () =>
90
+ html`<span
91
+ class=${classMap({
92
+ "iw-breadcrumbs-current": isLast,
93
+ })}
94
+ aria-current=${isLast ? "page" : "false"}
95
+ >
96
+ ${item.label}
97
+ </span>`,
98
+ )}
96
99
  </li>`
97
100
  },
98
101
  }
@@ -7,6 +7,7 @@
7
7
  import { html, nothing } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
9
  import { ref } from "@inglorious/web/directives/ref"
10
+ import { when } from "@inglorious/web/directives/when"
10
11
 
11
12
  import { Button } from "../../controls/button/index.js"
12
13
  import { anchorName } from "../../shared/anchor.js"
@@ -138,17 +139,15 @@ export const Menu = {
138
139
  props.onItemClick?.(item.value ?? index, item)
139
140
  }}
140
141
  >
141
- ${
142
- item.icon
143
- ? html`<span class="iw-menu-item-icon">${item.icon}</span>`
144
- : null
145
- }
142
+ ${when(
143
+ item.icon,
144
+ () => html`<span class="iw-menu-item-icon">${item.icon}</span>`,
145
+ )}
146
146
  <span class="iw-menu-item-label">${item.label}</span>
147
- ${
148
- item.trailing
149
- ? html`<span class="iw-menu-item-trailing">${item.trailing}</span>`
150
- : null
151
- }
147
+ ${when(
148
+ item.trailing,
149
+ () => html`<span class="iw-menu-item-trailing">${item.trailing}</span>`,
150
+ )}
152
151
  </button>`
153
152
  },
154
153
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  import { html } from "@inglorious/web"
9
9
  import { classMap } from "@inglorious/web/directives/class-map"
10
+ import { when } from "@inglorious/web/directives/when"
10
11
 
11
12
  import { Button } from "../../controls/button/index.js"
12
13
 
@@ -52,15 +53,13 @@ export const Pagination = {
52
53
  class=${classMap({ "iw-pagination": true, ...extraClasses })}
53
54
  aria-label="Pagination"
54
55
  >
55
- ${
56
- isFirstButtonVisible
57
- ? this.renderControl(props, {
58
- label: "«",
59
- target: 1,
60
- isDisabled: page <= PRETTY_PAGE || isDisabled,
61
- })
62
- : null
63
- }
56
+ ${when(isFirstButtonVisible, () =>
57
+ this.renderControl(props, {
58
+ label: "«",
59
+ target: 1,
60
+ isDisabled: page <= PRETTY_PAGE || isDisabled,
61
+ }),
62
+ )}
64
63
  ${this.renderControl(props, {
65
64
  label: "‹",
66
65
  target: Math.max(PRETTY_PAGE, page - PRETTY_PAGE),
@@ -72,15 +71,13 @@ export const Pagination = {
72
71
  target: Math.min(count, page + PRETTY_PAGE),
73
72
  isDisabled: page >= count || isDisabled,
74
73
  })}
75
- ${
76
- isLastButtonVisible
77
- ? this.renderControl(props, {
78
- label: "»",
79
- target: count,
80
- isDisabled: page >= count || isDisabled,
81
- })
82
- : null
83
- }
74
+ ${when(isLastButtonVisible, () =>
75
+ this.renderControl(props, {
76
+ label: "»",
77
+ target: count,
78
+ isDisabled: page >= count || isDisabled,
79
+ }),
80
+ )}
84
81
  </nav>`
85
82
  },
86
83
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { html } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  export const Stepper = {
11
12
  /**
@@ -67,11 +68,10 @@ export const Stepper = {
67
68
  <span class="iw-stepper-indicator">${completed ? "✓" : index + 1}</span>
68
69
  <span class="iw-stepper-content">
69
70
  <span class="iw-stepper-label">${step.label}</span>
70
- ${
71
- step.optional
72
- ? html`<span class="iw-stepper-optional">${step.optional}</span>`
73
- : null
74
- }
71
+ ${when(
72
+ step.optional,
73
+ () => html`<span class="iw-stepper-optional">${step.optional}</span>`,
74
+ )}
75
75
  </span>
76
76
  </li>`
77
77
  },
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { html, nothing } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  export const Tabs = {
11
12
  /**
@@ -88,7 +89,7 @@ export const Tabs = {
88
89
  props.onChange?.(tabValue)
89
90
  }}
90
91
  >
91
- ${item.icon ? html`<span class="iw-tab-icon">${item.icon}</span>` : null}
92
+ ${when(item.icon, () => html`<span class="iw-tab-icon">${item.icon}</span>`)}
92
93
  <span>${item.label}</span>
93
94
  </button>`
94
95
  },
@@ -7,6 +7,7 @@
7
7
  import { html, nothing } from "@inglorious/web"
8
8
  import { classMap } from "@inglorious/web/directives/class-map"
9
9
  import { ref } from "@inglorious/web/directives/ref"
10
+ import { when } from "@inglorious/web/directives/when"
10
11
 
11
12
  import { applyElementProps } from "../../shared/apply-element-props.js"
12
13
 
@@ -104,7 +105,7 @@ export const Accordion = {
104
105
  if (isDisabled) event.preventDefault()
105
106
  }}
106
107
  >
107
- ${icon ? html`<span class="iw-accordion-icon">${icon}</span>` : null}
108
+ ${when(icon, () => html`<span class="iw-accordion-icon">${icon}</span>`)}
108
109
  <span class="iw-accordion-title">${title}</span>
109
110
  <span class="iw-accordion-caret" aria-hidden="true">▾</span>
110
111
  </summary>
@@ -6,6 +6,7 @@
6
6
  import { html } from "@inglorious/web"
7
7
  import { classMap } from "@inglorious/web/directives/class-map"
8
8
  import { ref } from "@inglorious/web/directives/ref"
9
+ import { when } from "@inglorious/web/directives/when"
9
10
 
10
11
  import { applyElementProps } from "../../shared/apply-element-props.js"
11
12
 
@@ -95,8 +96,8 @@ export const Card = {
95
96
  [`iw-card-header-padding-${headerPadding}`]: headerPadding !== "md",
96
97
  })}
97
98
  >
98
- ${title ? html`<h3 class="iw-card-title">${title}</h3>` : null}
99
- ${subtitle ? html`<p class="iw-card-subtitle">${subtitle}</p>` : null}
99
+ ${when(title, () => html`<h3 class="iw-card-title">${title}</h3>`)}
100
+ ${when(subtitle, () => html`<p class="iw-card-subtitle">${subtitle}</p>`)}
100
101
  </div>`
101
102
  },
102
103