@cas-smartdesign/list-item 7.4.1 → 7.4.3

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.
@@ -7,6 +7,7 @@ declare global {
7
7
  export interface ItemData {
8
8
  caption?: string;
9
9
  description?: string;
10
+ descriptionIcon?: string;
10
11
  leftContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;
11
12
  rightContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;
12
13
  icon?: string;
@@ -22,6 +23,7 @@ export default class ListItem extends LitElement {
22
23
  static ensureDefined: () => void;
23
24
  caption: string;
24
25
  description: string;
26
+ descriptionIcon: string;
25
27
  selected: boolean;
26
28
  icon: string;
27
29
  iconBackgroundColor: string;
@@ -1,12 +1,12 @@
1
- import { LitElement as m, unsafeCSS as v, css as b, html as a, nothing as f } from "lit";
1
+ import { LitElement as m, unsafeCSS as v, css as g, html as d, nothing as h } from "lit";
2
2
  import { property as o } from "lit/decorators/property.js";
3
- import { unsafeHTML as g } from "lit/directives/unsafe-html.js";
4
- import { ifDefined as d } from "lit/directives/if-defined.js";
3
+ import { unsafeHTML as b } from "lit/directives/unsafe-html.js";
4
+ import { ifDefined as a } from "lit/directives/if-defined.js";
5
5
  import { placeholderDirective as y } from "@cas-smartdesign/image-tools";
6
- const x = ':host{display:block;contain:strict;height:50px}:host([selected]){background-color:#d3e6fa}:host(:not([selected]):hover),:host(:not([selected])[focused]){background-color:#e7f1fa}@media (forced-colors: active){:host([selected]){outline:4px solid}:host(:not([selected]):hover){outline:4px dotted}:host(:not([selected])[focused]){outline:4px dashed}}:host([enable-line-clamp]) .labels>:only-child{display:-webkit-box;overflow:hidden;-webkit-line-clamp:2;-webkit-box-orient:vertical;white-space:normal;overflow-wrap:break-word}.container{display:flex;height:100%;box-sizing:border-box}.container .level-indicator{width:7px;height:100%}.container .level-indicator.level-0{background-color:#a0c3ef}.container .level-indicator.level-1{background-color:#e7c374}.container .level-indicator.level-2{background-color:#bfd596}.container .level-indicator.level-3{background-color:#fd998d}.container .level-indicator.level-4{background-color:#c6e8f5}.container .level-indicator.level-5{background-color:#fde3a4}.container .level-indicator.level-6{background-color:#dcbfe0}.side-content{display:flex;align-items:center;flex-grow:0}.labels{display:flex;flex-direction:column;justify-content:center;flex:1 1 0px;height:100%;line-height:normal;overflow:hidden;padding:var(--sd-list-item-label-content-padding, 0 8px)}.caption,.description{width:100%;font-family:var(--sd-list-item-font-family, "Segoe UI", "Lucida Sans", Arial, sans-serif);font-style:normal;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;-webkit-user-select:none;user-select:none;text-decoration:var(--sd-list-item-text-decoration, inherit)}.caption em,.description em{font-weight:bolder}.caption{font-size:var(--sd-list-item-caption-font-size, 16px);color:var(--sd-list-item-caption-text-color, #111);font-weight:var(--sd-list-item-caption-font-weight, normal)}.description{font-size:var(--sd-list-item-description-font-size, 13px);color:var(--sd-list-item-description-text-color, #767676);font-weight:var(--sd-list-item-description-font-weight, normal)}.icon-wrapper{width:var(--sd-list-item-icon-wrapper-width, 45px);height:100%;display:flex;align-items:center;justify-content:center}.icon-wrapper .icon{min-height:var(--sd-list-item-icon-size, 24px);min-width:var(--sd-list-item-icon-size, 24px);background-repeat:no-repeat;background-position:center;background-size:cover}';
6
+ const x = ':host{display:block;contain:strict;height:50px}:host([selected]){background-color:#d3e6fa}:host(:not([selected]):hover),:host(:not([selected])[focused]){background-color:#e7f1fa}@media (forced-colors: active){:host([selected]){outline:4px solid}:host(:not([selected]):hover){outline:4px dotted}:host(:not([selected])[focused]){outline:4px dashed}}:host([enable-line-clamp]) .labels>:only-child{display:-webkit-box;overflow:hidden;-webkit-line-clamp:2;-webkit-box-orient:vertical;white-space:normal;overflow-wrap:break-word}.container{display:flex;height:100%;box-sizing:border-box}.container .level-indicator{width:7px;height:100%}.container .level-indicator.level-0{background-color:#a0c3ef}.container .level-indicator.level-1{background-color:#e7c374}.container .level-indicator.level-2{background-color:#bfd596}.container .level-indicator.level-3{background-color:#fd998d}.container .level-indicator.level-4{background-color:#c6e8f5}.container .level-indicator.level-5{background-color:#fde3a4}.container .level-indicator.level-6{background-color:#dcbfe0}.side-content{display:flex;align-items:center;flex-grow:0}.labels{display:flex;flex-direction:column;justify-content:center;flex:1 1 0px;height:100%;line-height:normal;overflow:hidden;padding:var(--sd-list-item-label-content-padding, 0 8px)}.caption,.description{width:100%;font-family:var(--sd-list-item-font-family, "Segoe UI", "Lucida Sans", Arial, sans-serif);font-style:normal;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;-webkit-user-select:none;user-select:none;text-decoration:var(--sd-list-item-text-decoration, inherit)}.caption em,.description em{font-weight:bolder}.caption{font-size:var(--sd-list-item-caption-font-size, 16px);color:var(--sd-list-item-caption-text-color, #111);font-weight:var(--sd-list-item-caption-font-weight, normal)}.description{font-size:var(--sd-list-item-description-font-size, 13px);color:var(--sd-list-item-description-text-color, #767676);font-weight:var(--sd-list-item-description-font-weight, normal)}.description.with-icon{display:flex;align-items:center;gap:4px}.description.with-icon .description-icon{width:var(--sd-list-item-description-font-size, 13px);height:var(--sd-list-item-description-font-size, 13px);background-repeat:no-repeat;background-position:bottom;background-size:90%}.icon-wrapper{width:var(--sd-list-item-icon-wrapper-width, 45px);height:100%;display:flex;align-items:center;justify-content:center}.icon-wrapper .icon{min-height:var(--sd-list-item-icon-size, 24px);min-width:var(--sd-list-item-icon-size, 24px);background-repeat:no-repeat;background-position:center;background-size:cover}';
7
7
  var w = Object.defineProperty, n = (t, r, e, l) => {
8
- for (var c = void 0, p = t.length - 1, h; p >= 0; p--)
9
- (h = t[p]) && (c = h(r, e, c) || c);
8
+ for (var c = void 0, p = t.length - 1, f; p >= 0; p--)
9
+ (f = t[p]) && (c = f(r, e, c) || c);
10
10
  return c && w(r, e, c), c;
11
11
  }, s;
12
12
  const i = (s = class extends m {
@@ -15,16 +15,16 @@ const i = (s = class extends m {
15
15
  }
16
16
  static get styles() {
17
17
  return [
18
- b`
18
+ g`
19
19
  ${v(x)}
20
20
  `
21
21
  ];
22
22
  }
23
23
  render() {
24
- return a`
24
+ return d`
25
25
  <div class="container">
26
26
  ${this.getLevelIndicators().map(
27
- (r, e) => a` <div class="level-indicator level-${e}"></div> `
27
+ (r, e) => d` <div class="level-indicator level-${e}"></div> `
28
28
  )}
29
29
  <div class="side-content">
30
30
  <slot name="left-content"></slot>
@@ -32,7 +32,12 @@ const i = (s = class extends m {
32
32
  </div>
33
33
  <div class="labels">
34
34
  ${this.renderLabel("caption", this.caption, this.captionAttrTitle)}
35
- ${this.renderLabel("description", this.description, this.descriptionAttrTitle)}
35
+ ${this.renderLabel(
36
+ "description",
37
+ this.description,
38
+ this.descriptionAttrTitle,
39
+ this.descriptionIcon
40
+ )}
36
41
  </div>
37
42
  <div class="side-content">
38
43
  <slot name="right-content"></slot>
@@ -41,23 +46,24 @@ const i = (s = class extends m {
41
46
  `;
42
47
  }
43
48
  renderIcon() {
44
- return this.icon || this.iconPlaceholder ? a`<div
49
+ return this.icon || this.iconPlaceholder ? d`<div
45
50
  class="icon-wrapper"
46
51
  @pointerdown="${this.handleIconClick}"
47
- style="background-color:${d(this.iconBackgroundColor)};"
52
+ style="background-color:${a(this.iconBackgroundColor)};"
48
53
  role="img"
49
- aria-label="${d(this.iconAttrAriaLabel)}"
50
- title="${d(this.iconAttrTitle)}"
54
+ aria-label="${a(this.iconAttrAriaLabel)}"
55
+ title="${a(this.iconAttrTitle)}"
51
56
  >
52
57
  <div class="icon" style="background-image:${y(this.icon, this.iconPlaceholder)}"></div>
53
- </div> ` : f;
58
+ </div> ` : h;
54
59
  }
55
- renderLabel(r, e, l) {
56
- return e ? a`
57
- <div class="${r}" title="${d(l)}">
58
- ${this.contentMode === "html" ? g(e) : e}
60
+ renderLabel(r, e, l, c) {
61
+ return e ? d`
62
+ <div class="${r} ${c ? "with-icon" : ""}" title="${a(l)}">
63
+ ${c ? d` <div class="${r}-icon" style="background-image:url('${c}')" aria-hidden="true"></div> ` : h}
64
+ ${this.contentMode === "html" ? b(e) : e}
59
65
  </div>
60
- ` : f;
66
+ ` : h;
61
67
  }
62
68
  updated(r) {
63
69
  super.updated(r), r.has("selected") && this.setAttribute("aria-selected", String(this.selected));
@@ -89,6 +95,9 @@ n([
89
95
  n([
90
96
  o({ type: String })
91
97
  ], i.prototype, "description");
98
+ n([
99
+ o({ type: String })
100
+ ], i.prototype, "descriptionIcon");
92
101
  n([
93
102
  o({ type: Boolean })
94
103
  ], i.prototype, "selected");
@@ -136,10 +145,10 @@ n([
136
145
  o({ type: String, attribute: "icon-attr-title" })
137
146
  ], i.prototype, "iconAttrTitle");
138
147
  let u = i;
139
- const $ = (t, r) => {
148
+ const I = (t, r) => {
140
149
  const e = document.createElement(u.ID);
141
150
  if (t) {
142
- if (e.caption = t.caption, e.description = t.description, e.icon = t.icon, e.iconBackgroundColor = t.iconBackgroundColor, e.iconPlaceholder = t.iconPlaceholder, e.level = t.level, e.disabled = t.disabled, t.contentMode && (e.contentMode = t.contentMode), t.leftContentGenerator) {
151
+ if (e.caption = t.caption, e.description = t.description, e.descriptionIcon = t.descriptionIcon, e.icon = t.icon, e.iconBackgroundColor = t.iconBackgroundColor, e.iconPlaceholder = t.iconPlaceholder, e.level = t.level, e.disabled = t.disabled, t.contentMode && (e.contentMode = t.contentMode), t.leftContentGenerator) {
143
152
  const l = t.leftContentGenerator(t, e);
144
153
  l && (l.slot = "left-content", e.appendChild(l));
145
154
  }
@@ -153,6 +162,6 @@ const $ = (t, r) => {
153
162
  u.ensureDefined();
154
163
  export {
155
164
  u as default,
156
- $ as generator
165
+ I as generator
157
166
  };
158
167
  //# sourceMappingURL=list-item.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"list-item.mjs","sources":["../list-item.ts"],"sourcesContent":["import { LitElement, html, unsafeCSS, PropertyValues, css, nothing, TemplateResult } from \"lit\";\nimport { property } from \"lit/decorators/property.js\";\nimport { unsafeHTML } from \"lit/directives/unsafe-html.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { placeholderDirective as placeholder } from \"@cas-smartdesign/image-tools\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n [ListItem.ID]: ListItem;\n }\n}\n\nimport styles from \"./styles.scss?inline\";\n\nexport interface ItemData {\n caption?: string;\n description?: string;\n leftContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n rightContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n icon?: string;\n iconBackgroundColor?: string;\n iconPlaceholder?: string;\n level?: number;\n contentMode?: ContentMode;\n disabled?: boolean;\n}\n\nexport type ContentMode = \"text\" | \"html\";\n\nexport default class ListItem extends LitElement {\n public static readonly ID = \"sd-list-item\";\n public static ensureDefined = (): void => {\n if (!customElements.get(ListItem.ID)) {\n customElements.define(ListItem.ID, ListItem);\n }\n };\n\n @property({ type: String })\n public caption: string;\n @property({ type: String })\n public description: string;\n @property({ type: Boolean })\n public selected: boolean;\n @property({ type: String })\n public icon: string;\n @property({ type: String })\n public iconBackgroundColor: string;\n @property({ type: String })\n public iconPlaceholder: string;\n @property({ type: Number })\n public level: number;\n @property()\n public contentMode: ContentMode = \"text\";\n @property({ type: Boolean, reflect: true, attribute: \"enable-line-clamp\" })\n public enableLineClamp: boolean;\n @property({\n converter: {\n fromAttribute: (value) => value == \"true\",\n toAttribute: (value) => value,\n },\n reflect: true,\n attribute: \"aria-disabled\",\n })\n public disabled: boolean;\n\n // aria attributes\n @property({ type: String, attribute: \"icon-attr-aria-label\" })\n public iconAttrAriaLabel: string;\n @property({ type: String, reflect: true })\n public role = \"option\";\n\n // title attributes\n @property({ type: String, attribute: \"caption-attr-title\" })\n public captionAttrTitle: string;\n @property({ type: String, attribute: \"description-attr-title\" })\n public descriptionAttrTitle: string;\n @property({ type: String, attribute: \"icon-attr-title\" })\n public iconAttrTitle: string;\n\n static get styles() {\n return [\n css`\n ${unsafeCSS(styles)}\n `,\n ];\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"container\">\n ${this.getLevelIndicators().map(\n (_, level) => html` <div class=\"level-indicator level-${level}\"></div> `,\n )}\n <div class=\"side-content\">\n <slot name=\"left-content\"></slot>\n ${this.renderIcon()}\n </div>\n <div class=\"labels\">\n ${this.renderLabel(\"caption\", this.caption, this.captionAttrTitle)}\n ${this.renderLabel(\"description\", this.description, this.descriptionAttrTitle)}\n </div>\n <div class=\"side-content\">\n <slot name=\"right-content\"></slot>\n </div>\n </div>\n `;\n }\n\n private renderIcon() {\n if (this.icon || this.iconPlaceholder) {\n return html`<div\n class=\"icon-wrapper\"\n @pointerdown=\"${this.handleIconClick}\"\n style=\"background-color:${ifDefined(this.iconBackgroundColor)};\"\n role=\"img\"\n aria-label=\"${ifDefined(this.iconAttrAriaLabel)}\"\n title=\"${ifDefined(this.iconAttrTitle)}\"\n >\n <div class=\"icon\" style=\"background-image:${placeholder(this.icon, this.iconPlaceholder)}\"></div>\n </div> `;\n }\n return nothing;\n }\n\n private renderLabel(className: string, value: string, title: string) {\n return value\n ? html`\n <div class=\"${className}\" title=\"${ifDefined(title)}\">\n ${this.contentMode === \"html\" ? unsafeHTML(value) : value}\n </div>\n `\n : nothing;\n }\n\n public updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n if (changedProperties.has(\"selected\")) {\n this.setAttribute(\"aria-selected\", String(this.selected));\n }\n }\n\n /**\n * Returns the width in pixel which is missing to show the caption and description without ellipsis.\n */\n public get missingWidthForTexts(): number {\n const originalLineClamp = this.enableLineClamp;\n this.removeAttribute(\"enable-line-clamp\"); // Need to remove immediately, otherwise the calculation may fail.\n\n let requiredWidth = 0;\n\n const captionElement = this.shadowRoot.querySelector(\".caption\");\n if (captionElement) {\n requiredWidth += captionElement.scrollWidth - captionElement.clientWidth;\n }\n\n const descriptionElement = this.shadowRoot.querySelector(\".description\");\n if (descriptionElement) {\n requiredWidth = Math.max(requiredWidth, descriptionElement.scrollWidth - descriptionElement.clientWidth);\n }\n if (requiredWidth > 0) {\n requiredWidth++; // Additional one pixel to ensure ellipsis is not needed anymore.\n }\n if (originalLineClamp) {\n this.setAttribute(\"enable-line-clamp\", \"\");\n }\n return requiredWidth;\n }\n\n private handleIconClick(event: PointerEvent): void {\n if (!this.disabled && !this.dispatchEvent(new PointerEvent(\"list-item-icon-click\", event))) {\n event.preventDefault();\n }\n }\n\n private getLevelIndicators(): number[] {\n if (!this.level) {\n return [];\n }\n // fill is needed because the ArrayConstructor\n // result an array with \"empty\" values in it\n // which are skipped when iterating\n return Array(Number(this.level)).fill(null);\n }\n}\n\nexport const generator = (data: ItemData, _index: number): ListItem => {\n const listItem = document.createElement(ListItem.ID) as ListItem;\n if (data) {\n listItem.caption = data.caption;\n listItem.description = data.description;\n listItem.icon = data.icon;\n listItem.iconBackgroundColor = data.iconBackgroundColor;\n listItem.iconPlaceholder = data.iconPlaceholder;\n listItem.level = data.level;\n listItem.disabled = data.disabled;\n if (data.contentMode) {\n listItem.contentMode = data.contentMode;\n }\n if (data.leftContentGenerator) {\n const leftContent = data.leftContentGenerator(data, listItem);\n if (leftContent) {\n leftContent.slot = \"left-content\";\n listItem.appendChild(leftContent);\n }\n }\n if (data.rightContentGenerator) {\n const rightContent = data.rightContentGenerator(data, listItem);\n if (rightContent) {\n rightContent.slot = \"right-content\";\n listItem.appendChild(rightContent);\n }\n }\n }\n return listItem;\n};\n\nListItem.ensureDefined();\n"],"names":["_ListItem","_a","LitElement","css","unsafeCSS","styles","html","_","level","ifDefined","placeholder","nothing","className","value","title","unsafeHTML","changedProperties","originalLineClamp","requiredWidth","captionElement","descriptionElement","event","__decorateClass","property","ListItem","generator","data","_index","listItem","leftContent","rightContent"],"mappings":";;;;;;;;;;;AA6BA,MAAqBA,KAArBC,IAAA,cAAsCC,EAAW;AAAA,EAAjD,cAAA;AAAA,UAAA,GAAA,SAAA,GAuBI,KAAO,cAA2B,QAiBlC,KAAO,OAAO;AAAA,EAAA;AAAA,EAUd,WAAW,SAAS;AAChB,WAAO;AAAA,MACHC;AAAA,kBACMC,EAAUC,CAAM,CAAC;AAAA;A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S,QAAQF,EAAK,OACtBE,EAAS,WAAWF,EAAK,UACrBA,EAAK,gBACLE,EAAS,cAAcF,EAAK,cAE5BA,EAAK,sBAAsB;AAC3B,YAAMG,IAAcH,EAAK,qBAAqBA,GAAME,CAAQ;AAC5D,MAAIC,MACAA,EAAY,OAAO,gBACnBD,EAAS,YAAYC,CAAW;AAAA,IAExC;AACA,QAAIH,EAAK,uBAAuB;AAC5B,YAAMI,IAAeJ,EAAK,sBAAsBA,GAAME,CAAQ;AAC9D,MAAIE,MACAA,EAAa,OAAO,iBACpBF,EAAS,YAAYE,CAAY;AAAA,IAEzC;AAAA,EACJ;AACA,SAAOF;AACX;AAEAJ,EAAS,cAAA;"}
1
+ {"version":3,"file":"list-item.mjs","sources":["../list-item.ts"],"sourcesContent":["import { LitElement, html, unsafeCSS, PropertyValues, css, nothing, TemplateResult } from \"lit\";\nimport { property } from \"lit/decorators/property.js\";\nimport { unsafeHTML } from \"lit/directives/unsafe-html.js\";\nimport { ifDefined } from \"lit/directives/if-defined.js\";\nimport { placeholderDirective as placeholder } from \"@cas-smartdesign/image-tools\";\n\ndeclare global {\n interface HTMLElementTagNameMap {\n [ListItem.ID]: ListItem;\n }\n}\n\nimport styles from \"./styles.scss?inline\";\n\nexport interface ItemData {\n caption?: string;\n description?: string;\n descriptionIcon?: string;\n leftContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n rightContentGenerator?: (data: ItemData, element: ListItem) => HTMLElement;\n icon?: string;\n iconBackgroundColor?: string;\n iconPlaceholder?: string;\n level?: number;\n contentMode?: ContentMode;\n disabled?: boolean;\n}\n\nexport type ContentMode = \"text\" | \"html\";\n\nexport default class ListItem extends LitElement {\n public static readonly ID = \"sd-list-item\";\n public static ensureDefined = (): void => {\n if (!customElements.get(ListItem.ID)) {\n customElements.define(ListItem.ID, ListItem);\n }\n };\n\n @property({ type: String })\n public caption: string;\n @property({ type: String })\n public description: string;\n @property({ type: String })\n descriptionIcon: string;\n @property({ type: Boolean })\n public selected: boolean;\n @property({ type: String })\n public icon: string;\n @property({ type: String })\n public iconBackgroundColor: string;\n @property({ type: String })\n public iconPlaceholder: string;\n @property({ type: Number })\n public level: number;\n @property()\n public contentMode: ContentMode = \"text\";\n @property({ type: Boolean, reflect: true, attribute: \"enable-line-clamp\" })\n public enableLineClamp: boolean;\n @property({\n converter: {\n fromAttribute: (value) => value == \"true\",\n toAttribute: (value) => value,\n },\n reflect: true,\n attribute: \"aria-disabled\",\n })\n public disabled: boolean;\n\n // aria attributes\n @property({ type: String, attribute: \"icon-attr-aria-label\" })\n public iconAttrAriaLabel: string;\n @property({ type: String, reflect: true })\n public role = \"option\";\n\n // title attributes\n @property({ type: String, attribute: \"caption-attr-title\" })\n public captionAttrTitle: string;\n @property({ type: String, attribute: \"description-attr-title\" })\n public descriptionAttrTitle: string;\n @property({ type: String, attribute: \"icon-attr-title\" })\n public iconAttrTitle: string;\n\n static get styles() {\n return [\n css`\n ${unsafeCSS(styles)}\n `,\n ];\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"container\">\n ${this.getLevelIndicators().map(\n (_, level) => html` <div class=\"level-indicator level-${level}\"></div> `,\n )}\n <div class=\"side-content\">\n <slot name=\"left-content\"></slot>\n ${this.renderIcon()}\n </div>\n <div class=\"labels\">\n ${this.renderLabel(\"caption\", this.caption, this.captionAttrTitle)}\n ${this.renderLabel(\n \"description\",\n this.description,\n this.descriptionAttrTitle,\n this.descriptionIcon,\n )}\n </div>\n <div class=\"side-content\">\n <slot name=\"right-content\"></slot>\n </div>\n </div>\n `;\n }\n\n private renderIcon() {\n if (this.icon || this.iconPlaceholder) {\n return html`<div\n class=\"icon-wrapper\"\n @pointerdown=\"${this.handleIconClick}\"\n style=\"background-color:${ifDefined(this.iconBackgroundColor)};\"\n role=\"img\"\n aria-label=\"${ifDefined(this.iconAttrAriaLabel)}\"\n title=\"${ifDefined(this.iconAttrTitle)}\"\n >\n <div class=\"icon\" style=\"background-image:${placeholder(this.icon, this.iconPlaceholder)}\"></div>\n </div> `;\n }\n return nothing;\n }\n\n private renderLabel(className: string, value: string, title: string, iconUrl?: string) {\n return value\n ? html`\n <div class=\"${className} ${iconUrl ? \"with-icon\" : \"\"}\" title=\"${ifDefined(title)}\">\n ${iconUrl\n ? html` <div class=\"${className}-icon\" style=\"background-image:url('${iconUrl}')\" aria-hidden=\"true\"></div> `\n : nothing}\n ${this.contentMode === \"html\" ? unsafeHTML(value) : value}\n </div>\n `\n : nothing;\n }\n\n public updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n if (changedProperties.has(\"selected\")) {\n this.setAttribute(\"aria-selected\", String(this.selected));\n }\n }\n\n /**\n * Returns the width in pixel which is missing to show the caption and description without ellipsis.\n */\n public get missingWidthForTexts(): number {\n const originalLineClamp = this.enableLineClamp;\n this.removeAttribute(\"enable-line-clamp\"); // Need to remove immediately, otherwise the calculation may fail.\n\n let requiredWidth = 0;\n\n const captionElement = this.shadowRoot.querySelector(\".caption\");\n if (captionElement) {\n requiredWidth += captionElement.scrollWidth - captionElement.clientWidth;\n }\n\n const descriptionElement = this.shadowRoot.querySelector(\".description\");\n if (descriptionElement) {\n requiredWidth = Math.max(requiredWidth, descriptionElement.scrollWidth - descriptionElement.clientWidth);\n }\n if (requiredWidth > 0) {\n requiredWidth++; // Additional one pixel to ensure ellipsis is not needed anymore.\n }\n if (originalLineClamp) {\n this.setAttribute(\"enable-line-clamp\", \"\");\n }\n return requiredWidth;\n }\n\n private handleIconClick(event: PointerEvent): void {\n if (!this.disabled && !this.dispatchEvent(new PointerEvent(\"list-item-icon-click\", event))) {\n event.preventDefault();\n }\n }\n\n private getLevelIndicators(): number[] {\n if (!this.level) {\n return [];\n }\n // fill is needed because the ArrayConstructor\n // result an array with \"empty\" values in it\n // which are skipped when iterating\n return Array(Number(this.level)).fill(null);\n }\n}\n\nexport const generator = (data: ItemData, _index: number): ListItem => {\n const listItem = document.createElement(ListItem.ID) as ListItem;\n if (data) {\n listItem.caption = data.caption;\n listItem.description = data.description;\n listItem.descriptionIcon = data.descriptionIcon;\n listItem.icon = data.icon;\n listItem.iconBackgroundColor = data.iconBackgroundColor;\n listItem.iconPlaceholder = data.iconPlaceholder;\n listItem.level = data.level;\n listItem.disabled = data.disabled;\n if (data.contentMode) {\n listItem.contentMode = data.contentMode;\n }\n if (data.leftContentGenerator) {\n const leftContent = data.leftContentGenerator(data, listItem);\n if (leftContent) {\n leftContent.slot = \"left-content\";\n listItem.appendChild(leftContent);\n }\n }\n if (data.rightContentGenerator) {\n const rightContent = data.rightContentGenerator(data, listItem);\n if (rightContent) {\n rightContent.slot = \"right-content\";\n listItem.appendChild(rightContent);\n }\n }\n }\n return listItem;\n};\n\nListItem.ensureDefined();\n"],"names":["_ListItem","_a","LitElement","css","unsafeCSS","styles","html","_","level","ifDefined","placeholder","nothing","className","value","title","iconUrl","unsafeHTML","changedProperties","originalLineClamp","requiredWidth","captionElement","descriptionElement","event","__decorateClass","property","ListItem","generator","data","_index","listItem","leftContent","rightContent"],"mappings":";;;;;;;;;;;AA8BA,MAAqBA,KAArBC,IAAA,cAAsCC,EAAW;AAAA,EAAjD,cAAA;AAAA,UAAA,GAAA,SAAA,GAyBI,KAAO,cAA2B,QAiBlC,KAAO,OAAO;AAAA,EAAA;AAAA,EAUd,WAAW,SAAS;AAChB,WAAO;AAAA,MACHC;AAAA,kBACMC,EAAUC,CAAM,CAAC;AAAA;AAAA,IAAA;AAAA,EAG/B;AAAA,EAEO,SAAyB;AAC5B,WAAOC;AAAA;AAAA,kBAEG,KAAK,qBAAqB;AAAA,MACxB,CAACC,GAAGC,MAAUF,uCAA0CE,CAAK;AAAA,IAAA,CAChE;AAAA;AAAA;AAAA,sBAGK,KAAK,YAAY;AAAA;AAAA;AAAA,sBAGjB,KAAK,YAAY,WAAW,KAAK,SAAS,KAAK,gBAAgB,CAAC;AAAA,sBAChE,KAAK;AAAA,MACH;AAAA,MACA,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,IAAA,CACR;A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YAAMG,IAAcH,EAAK,qBAAqBA,GAAME,CAAQ;AAC5D,MAAIC,MACAA,EAAY,OAAO,gBACnBD,EAAS,YAAYC,CAAW;AAAA,IAExC;AACA,QAAIH,EAAK,uBAAuB;AAC5B,YAAMI,IAAeJ,EAAK,sBAAsBA,GAAME,CAAQ;AAC9D,MAAIE,MACAA,EAAa,OAAO,iBACpBF,EAAS,YAAYE,CAAY;AAAA,IAEzC;AAAA,EACJ;AACA,SAAOF;AACX;AAEAJ,EAAS,cAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cas-smartdesign/list-item",
3
- "version": "7.4.1",
3
+ "version": "7.4.3",
4
4
  "description": "A list item element based on LitElement",
5
5
  "main": "dist/list-item-with-externals.js",
6
6
  "module": "dist/list-item.mjs",
package/readme.md CHANGED
@@ -12,6 +12,8 @@ The main entry point requires ES6 & support for Custom Elements v1
12
12
  - Defines the text of the caption component of the item
13
13
  - `description`: string
14
14
  - Defines the text of the description component of the item
15
+ - `descriptionIcon`: string
16
+ - Defines the icon of the description component of the item
15
17
  - `selected`: boolean
16
18
  - Defines whether if the item is in selected state
17
19
  - `icon`: string