@dile/iconlib 1.8.1 → 2.0.0

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.
@@ -0,0 +1,5 @@
1
+ import { DileIconBadge } from './src/DileIconBadge.js';
2
+
3
+ if (!customElements.get('dile-icon-badge')) {
4
+ customElements.define('dile-icon-badge', DileIconBadge);
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/iconlib",
3
- "version": "1.8.1",
3
+ "version": "2.0.0",
4
4
  "description": "Icon Component Library based on popular libraries",
5
5
  "keywords": [
6
6
  "UI",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "57a54e50de1a24d64dcf478fa6d39624e1f775eb"
28
+ "gitHead": "ceeab58670ba4c09593d0760a357ecac36214a44"
29
29
  }
@@ -1,4 +1,4 @@
1
- import { badgeStyles } from "./fontawesomeBadgeStyles.js";
1
+ import { badgeStyles } from "./badgeStyles.js";
2
2
  import '../dile-fontawesome-icon.js';
3
3
 
4
4
  export class DileFontawesomeBadge extends HTMLElement {
@@ -13,8 +13,9 @@ export class DileFontawesomeBadge extends HTMLElement {
13
13
  }
14
14
 
15
15
  render() {
16
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
16
17
  this.shadowRoot.innerHTML = `
17
- <div class="badge-container">
18
+ <div class="badge-container ${variantClass}">
18
19
  <div class="icon-wrapper">
19
20
  <dile-fontawesome-icon icon="${this.icon}"></dile-fontawesome-icon>
20
21
  </div>
@@ -34,8 +35,9 @@ export class DileFontawesomeBadge extends HTMLElement {
34
35
  this.icon = newValue;
35
36
  this.render();
36
37
  }
37
- if (name === 'variant' && newValue !== null) {
38
- this.variant = newValue;
38
+ if (name === 'variant') {
39
+ this.variant = newValue !== null ? newValue : null;
40
+ this.render();
39
41
  }
40
42
  if (name === 'rounded') {
41
43
  this.rounded = newValue !== null;
@@ -0,0 +1,69 @@
1
+ import { badgeStyles } from './badgeStyles.js';
2
+
3
+ export class DileIconBadge extends HTMLElement {
4
+ constructor() {
5
+ super();
6
+ this.attachShadow({ mode: 'open' });
7
+ this.shadowRoot.adoptedStyleSheets = [badgeStyles];
8
+ this.icon = 'lucide.dot';
9
+ this.variant = null;
10
+ this.render();
11
+ }
12
+
13
+ getTagName() {
14
+ if (!this.icon) return null;
15
+ const dotIndex = this.icon.indexOf('.');
16
+ if (dotIndex === -1) {
17
+ console.warn(`dile-icon-badge: icon="${this.icon}" no tiene el formato "familia.nombre", ej. "lucide.home".`);
18
+ return null;
19
+ }
20
+
21
+ const family = this.icon.slice(0, dotIndex);
22
+ const name = this.icon.slice(dotIndex + 1);
23
+ if (!name) return null;
24
+
25
+ return `dile-${family}-icon-${name}`;
26
+ }
27
+
28
+ render() {
29
+ const tag = this.getTagName();
30
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
31
+
32
+ if (this.variant) {
33
+ this.setAttribute('variant', this.variant);
34
+ } else {
35
+ this.removeAttribute('variant');
36
+ }
37
+
38
+ this.shadowRoot.innerHTML = `
39
+ <div class="badge-container ${variantClass}">
40
+ <div class="icon-wrapper">
41
+ ${tag ? `<${tag} class="badge-icon"></${tag}>` : ''}
42
+ </div>
43
+ <div class="text-wrapper">
44
+ <slot></slot>
45
+ </div>
46
+ </div>
47
+ `;
48
+ }
49
+
50
+ static get observedAttributes() {
51
+ return ['icon', 'variant'];
52
+ }
53
+
54
+ attributeChangedCallback(name, oldValue, newValue) {
55
+ if (name === 'icon' && newValue !== null) {
56
+ this.icon = newValue;
57
+ this.render();
58
+ }
59
+
60
+ if (name === 'variant' && newValue !== null) {
61
+ this.variant = newValue;
62
+ this.render();
63
+ }
64
+ }
65
+ }
66
+
67
+ if (!customElements.get('dile-icon-badge')) {
68
+ customElements.define('dile-icon-badge', DileIconBadge);
69
+ }
@@ -0,0 +1,20 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import './DileIconBadge.js';
3
+
4
+ describe('dile-icon-badge', () => {
5
+ afterEach(() => {
6
+ document.body.innerHTML = '';
7
+ });
8
+
9
+ it('renders a family-specific icon from the generic family.name value', async () => {
10
+ document.body.innerHTML = '<dile-icon-badge icon="lucide.house" variant="success">Ready</dile-icon-badge>';
11
+
12
+ const el = document.body.querySelector('dile-icon-badge');
13
+ await Promise.resolve();
14
+
15
+ expect(el).toBeTruthy();
16
+ expect(el.shadowRoot.querySelector('dile-lucide-icon-house')).toBeTruthy();
17
+ expect(el.textContent.trim()).toContain('Ready');
18
+ expect(el.shadowRoot.querySelector('.badge-container').classList.contains('variant-success')).toBe(true);
19
+ });
20
+ });
@@ -1,4 +1,4 @@
1
- import { badgeStyles } from "./lucideBadgeStyles.js";
1
+ import { badgeStyles } from "./badgeStyles.js";
2
2
  import '../dile-lucide-icon.js';
3
3
 
4
4
  export class DileLucideBadge extends HTMLElement {
@@ -13,8 +13,9 @@ export class DileLucideBadge extends HTMLElement {
13
13
  }
14
14
 
15
15
  render() {
16
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
16
17
  this.shadowRoot.innerHTML = `
17
- <div class="badge-container">
18
+ <div class="badge-container ${variantClass}">
18
19
  <div class="icon-wrapper">
19
20
  <dile-lucide-icon icon="${this.icon}"></dile-lucide-icon>
20
21
  </div>
@@ -34,8 +35,9 @@ export class DileLucideBadge extends HTMLElement {
34
35
  this.icon = newValue;
35
36
  this.render();
36
37
  }
37
- if (name === 'variant' && newValue !== null) {
38
- this.variant = newValue;
38
+ if (name === 'variant') {
39
+ this.variant = newValue !== null ? newValue : null;
40
+ this.render();
39
41
  }
40
42
  if (name === 'rounded') {
41
43
  this.rounded = newValue !== null;
@@ -1,4 +1,4 @@
1
- import { badgeStyles } from "./materialBadgeStyles.js";
1
+ import { badgeStyles } from "./badgeStyles.js";
2
2
  import '../dile-material-icon.js';
3
3
 
4
4
  export class DileMaterialBadge extends HTMLElement {
@@ -13,8 +13,9 @@ export class DileMaterialBadge extends HTMLElement {
13
13
  }
14
14
 
15
15
  render() {
16
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
16
17
  this.shadowRoot.innerHTML = `
17
- <div class="badge-container">
18
+ <div class="badge-container ${variantClass}">
18
19
  <div class="icon-wrapper">
19
20
  <dile-material-icon icon="${this.icon}"></dile-material-icon>
20
21
  </div>
@@ -34,8 +35,9 @@ export class DileMaterialBadge extends HTMLElement {
34
35
  this.icon = newValue;
35
36
  this.render();
36
37
  }
37
- if (name === 'variant' && newValue !== null) {
38
- this.variant = newValue;
38
+ if (name === 'variant') {
39
+ this.variant = newValue !== null ? newValue : null;
40
+ this.render();
39
41
  }
40
42
  if (name === 'rounded') {
41
43
  this.rounded = newValue !== null;
@@ -1,4 +1,4 @@
1
- import { badgeStyles } from "./phosphorBadgeStyles.js";
1
+ import { badgeStyles } from "./badgeStyles.js";
2
2
  import '../dile-phosphor-icon.js';
3
3
 
4
4
  export class DilePhosphorBadge extends HTMLElement {
@@ -13,8 +13,9 @@ export class DilePhosphorBadge extends HTMLElement {
13
13
  }
14
14
 
15
15
  render() {
16
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
16
17
  this.shadowRoot.innerHTML = `
17
- <div class="badge-container">
18
+ <div class="badge-container ${variantClass}">
18
19
  <div class="icon-wrapper">
19
20
  <dile-phosphor-icon icon="${this.icon}"></dile-phosphor-icon>
20
21
  </div>
@@ -34,8 +35,9 @@ export class DilePhosphorBadge extends HTMLElement {
34
35
  this.icon = newValue;
35
36
  this.render();
36
37
  }
37
- if (name === 'variant' && newValue !== null) {
38
- this.variant = newValue;
38
+ if (name === 'variant') {
39
+ this.variant = newValue !== null ? newValue : null;
40
+ this.render();
39
41
  }
40
42
  if (name === 'rounded') {
41
43
  this.rounded = newValue !== null;
@@ -1,4 +1,4 @@
1
- import { badgeStyles } from "./remixiconBadgeStyles.js";
1
+ import { badgeStyles } from "./badgeStyles.js";
2
2
  import '../dile-remixicon-icon.js';
3
3
 
4
4
  export class DileRemixiconBadge extends HTMLElement {
@@ -13,8 +13,9 @@ export class DileRemixiconBadge extends HTMLElement {
13
13
  }
14
14
 
15
15
  render() {
16
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
16
17
  this.shadowRoot.innerHTML = `
17
- <div class="badge-container">
18
+ <div class="badge-container ${variantClass}">
18
19
  <div class="icon-wrapper">
19
20
  <dile-remixicon-icon icon="${this.icon}"></dile-remixicon-icon>
20
21
  </div>
@@ -34,8 +35,9 @@ export class DileRemixiconBadge extends HTMLElement {
34
35
  this.icon = newValue;
35
36
  this.render();
36
37
  }
37
- if (name === 'variant' && newValue !== null) {
38
- this.variant = newValue;
38
+ if (name === 'variant') {
39
+ this.variant = newValue !== null ? newValue : null;
40
+ this.render();
39
41
  }
40
42
  if (name === 'rounded') {
41
43
  this.rounded = newValue !== null;
@@ -1,4 +1,4 @@
1
- import { badgeStyles } from "./tablerBadgeStyles.js";
1
+ import { badgeStyles } from "./badgeStyles.js";
2
2
  import '../dile-tabler-icon.js';
3
3
 
4
4
  export class DileTablerBadge extends HTMLElement {
@@ -13,8 +13,9 @@ export class DileTablerBadge extends HTMLElement {
13
13
  }
14
14
 
15
15
  render() {
16
+ const variantClass = this.variant ? `variant-${this.variant}` : '';
16
17
  this.shadowRoot.innerHTML = `
17
- <div class="badge-container">
18
+ <div class="badge-container ${variantClass}">
18
19
  <div class="icon-wrapper">
19
20
  <dile-tabler-icon icon="${this.icon}"></dile-tabler-icon>
20
21
  </div>
@@ -34,8 +35,9 @@ export class DileTablerBadge extends HTMLElement {
34
35
  this.icon = newValue;
35
36
  this.render();
36
37
  }
37
- if (name === 'variant' && newValue !== null) {
38
- this.variant = newValue;
38
+ if (name === 'variant') {
39
+ this.variant = newValue !== null ? newValue : null;
40
+ this.render();
39
41
  }
40
42
  if (name === 'rounded') {
41
43
  this.rounded = newValue !== null;
@@ -0,0 +1,81 @@
1
+ export const badgeStyles = new CSSStyleSheet();
2
+ badgeStyles.replaceSync(`
3
+ :host {
4
+ display: inline-flex;
5
+ --dile-icon-color: var(--dile-badge-on-color, var(--dile-on-primary-color, #303030));
6
+ --dile-icon-size: var(--dile-badge-icon-size, 18px);
7
+ }
8
+
9
+ .badge-container {
10
+ display: inline-flex;
11
+ align-items: center;
12
+ gap: var(--dile-badge-gap, 0.5rem);
13
+ padding: var(--dile-badge-padding, 0.375rem 0.75rem);
14
+ border-radius: var(--dile-badge-border-radius, 9999px);
15
+ background-color: var(--dile-badge-color, var(--dile-primary-color, #f3f3ae));
16
+ color: var(--dile-badge-on-color, var(--dile-on-primary-color, #303030));
17
+ font-size: var(--dile-badge-font-size, 0.8rem);
18
+ font-weight: var(--dile-badge-font-weight, 500);
19
+ border: var(--dile-badge-border-width, 0px) solid var(--dile-badge-border-color, transparent);
20
+ transition-duration: var(--dile-badge-transition-duration, 0.3s);
21
+ transition-timing-function: ease-in-out;
22
+ transition-property: background-color, color;
23
+ }
24
+
25
+ :host([variant="primary"]) .badge-container {
26
+ background-color: var(--dile-badge-primary, var(--dile-primary-color, #f3f3ae));
27
+ color: var(--dile-badge-on-primary, var(--dile-on-primary-color, #303030));
28
+ --dile-icon-color: var(--dile-badge-on-primary, var(--dile-on-primary-color, #303030));
29
+ }
30
+
31
+ :host([variant="secondary"]) .badge-container {
32
+ background-color: var(--dile-badge-secondary, var(--dile-secondary-color, #27a744));
33
+ color: var(--dile-badge-on-secondary, var(--dile-on-secondary-color, #ffffff));
34
+ --dile-icon-color: var(--dile-badge-on-secondary, var(--dile-on-secondary-color, #ffffff));
35
+ }
36
+
37
+ :host([variant="danger"]) .badge-container {
38
+ background-color: var(--dile-badge-danger, var(--dile-danger-color, #e34a1b));
39
+ color: var(--dile-badge-on-danger, var(--dile-on-danger-color, #ffffff));
40
+ --dile-icon-color: var(--dile-badge-on-danger, var(--dile-on-danger-color, #ffffff));
41
+ }
42
+
43
+ :host([variant="error"]) .badge-container {
44
+ background-color: var(--dile-badge-error, var(--dile-alert-error-color, #cf3535));
45
+ color: var(--dile-badge-on-error, var(--dile-on-alert-color, #ffffff));
46
+ --dile-icon-color: var(--dile-badge-on-error, var(--dile-on-alert-color, #ffffff));
47
+ }
48
+
49
+ :host([variant="success"]) .badge-container {
50
+ background-color: var(--dile-badge-success, var(--dile-alert-success-color, #00900f));
51
+ color: var(--dile-badge-on-success, var(--dile-on-alert-color, #ffffff));
52
+ --dile-icon-color: var(--dile-badge-on-success, var(--dile-on-alert-color, #ffffff));
53
+ }
54
+
55
+ :host([variant="warning"]) .badge-container {
56
+ background-color: var(--dile-badge-warning, var(--dile-alert-warning-color, #d7b740));
57
+ color: var(--dile-badge-on-warning, var(--dile-on-alert-color, #ffffff));
58
+ --dile-icon-color: var(--dile-badge-on-warning, var(--dile-on-alert-color, #ffffff));
59
+ }
60
+
61
+ :host([variant="soft"]) .badge-container {
62
+ background-color: var(--dile-badge-soft, #2a7a9f);
63
+ color: var(--dile-badge-on-soft, #ffffff);
64
+ --dile-icon-color: var(--dile-badge-on-soft, #ffffff);
65
+ }
66
+
67
+ .icon-wrapper {
68
+ display: flex;
69
+ align-items: center;
70
+ line-height: 1;
71
+ }
72
+
73
+ .text-wrapper {
74
+ display: flex;
75
+ align-items: center;
76
+ }
77
+
78
+ dile-iconlib {
79
+ display: inline-flex;
80
+ }
81
+ `);