@aquera/nile-elements 2.0.14 → 2.0.15

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
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "2.0.14",
6
+ "version": "2.0.15",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -63,11 +63,11 @@ export const styles = css`
63
63
  }
64
64
 
65
65
  .badge--orange {
66
- color: var(--nile-badge-color-font-orange, var(--ng-componentcolors-utility-orange-700));
66
+ color: var(--nile-badge-color-font-orange, var(--ng-componentcolors-utility-error-600));
67
67
  border-width: var(--nile-badge-color-border-width, var(--ng-border-width-1));
68
68
  border-style: solid;
69
- border-color: var(--nile-badge-color-border-color-orange, var(--ng-componentcolors-utility-orange-dark-200));
70
- background: var(--nile-badge-color-background-orange, var(--ng-componentcolors-utility-orange-dark-50));
69
+ border-color: var(--nile-badge-color-border-color-orange, var(--ng-componentcolors-utility-orange-300));
70
+ background: var(--nile-badge-color-background-orange, var(--ng-componentcolors-utility-orange-50));
71
71
  }
72
72
 
73
73
  .badge--purple {
@@ -120,7 +120,7 @@ export const styles = css`
120
120
  color: var(--nile-badge-color-font-warning, var(--ng-componentcolors-utility-warning-700));
121
121
  border-width: var(--nile-badge-color-border-width, var(--ng-border-width-1));
122
122
  border-style: solid;
123
- border-color: var(--nile-badge-color-border-color-warning, var(--ng-componentcolors-utility-warning-200));
123
+ border-color: var(--nile-badge-color-border-color-warning, var(--ng-componentcolors-utility-warning-300));
124
124
  background: var(--nile-badge-color-background-warning, var(--ng-componentcolors-utility-warning-50));
125
125
  }
126
126
 
@@ -153,7 +153,7 @@ export const styles = css`
153
153
  }
154
154
 
155
155
  .badge--orange.badge--pill-outline {
156
- border: var(--nile-badge-color-border-width-pill-outline, var(--ng-border-width-1)) solid var(--nile-badge-color-pill-outline-orange, var(--ng-componentcolors-utility-orange-dark-200));
156
+ border: var(--nile-badge-color-border-width-pill-outline, var(--ng-border-width-1)) solid var(--nile-badge-color-pill-outline-orange, var(--ng-componentcolors-utility-orange-300));
157
157
  }
158
158
 
159
159
  .badge--purple.badge--pill-outline {
@@ -181,7 +181,7 @@ export const styles = css`
181
181
  }
182
182
 
183
183
  .badge--warning.badge--pill-outline {
184
- border: var(--nile-badge-color-border-width-pill-outline, var(--ng-border-width-1)) solid var(--nile-badge-color-pill-outline-warning, var(--ng-componentcolors-utility-warning-200));
184
+ border: var(--nile-badge-color-border-width-pill-outline, var(--ng-border-width-1)) solid var(--nile-badge-color-pill-outline-warning, var(--ng-componentcolors-utility-warning-300));
185
185
  }
186
186
 
187
187
  .badge--error.badge--pill-outline {
@@ -202,6 +202,27 @@ export const styles = css`
202
202
  padding: var(--nile-spacing-xxs, var(--ng-spacing-xxs)) var(--nile-spacing-md, var(--ng-spacing-md-alt));
203
203
  border-radius: var(--nile-radius-full, var(--ng-radius-full));
204
204
  }
205
+
206
+ /* Sizes — md is the base .badge rule above, so the default is unchanged. */
207
+ .badge.badge--sm {
208
+ padding: var(--nile-spacing-xxs, var(--ng-spacing-xxs)) var(--nile-spacing-md, var(--ng-spacing-md));
209
+ height: var(--nile-height-22px, var(--ng-height-22px));
210
+ }
211
+
212
+ .badge--sm .badge__content {
213
+ font-size: var(--nile-type-scale-2, var(--ng-font-size-text-xs));
214
+ line-height: var(--nile-type-scale-5, var(--ng-line-height-text-xs));
215
+ }
216
+
217
+ .badge.badge--lg {
218
+ padding: var(--nile-spacing-xs, var(--ng-spacing-xs)) var(--nile-spacing-lg, var(--ng-spacing-lg));
219
+ height: var(--nile-height-28px, var(--ng-height-28px));
220
+ }
221
+
222
+ .badge--lg .badge__content {
223
+ font-size: var(--nile-type-scale-3, var(--ng-font-size-text-sm));
224
+ line-height: var(--nile-type-scale-5, var(--ng-line-height-text-sm));
225
+ }
205
226
  `;
206
227
  export default [styles];
207
228
 
@@ -1,6 +1,7 @@
1
1
  import { expect, fixture, html, elementUpdated } from '@open-wc/testing';
2
2
  import './nile-badge';
3
3
  import NileBadge from './nile-badge';
4
+ import { styles } from './nile-badge.css';
4
5
 
5
6
  describe('NileBadge', () => {
6
7
  // === RENDERING ===
@@ -657,4 +658,90 @@ describe('NileBadge', () => {
657
658
  const el = await fixture<NileBadge>(html`<nile-badge>\u2713 Done</nile-badge>`);
658
659
  expect(el.textContent).to.contain('\u2713');
659
660
  });
661
+
662
+ // === SIZE TESTS ===
663
+ it('101. should have size default to md', async () => {
664
+ const el = await fixture<NileBadge>(html`<nile-badge></nile-badge>`);
665
+ expect(el.size).to.equal('md');
666
+ const span = el.shadowRoot!.querySelector('span');
667
+ expect(span!.classList.contains('badge--md')).to.be.true;
668
+ });
669
+
670
+ it('102. should reflect size attribute', async () => {
671
+ const el = await fixture<NileBadge>(html`<nile-badge size="lg"></nile-badge>`);
672
+ expect(el.getAttribute('size')).to.equal('lg');
673
+ });
674
+
675
+ for (const size of ['sm', 'md', 'lg'] as const) {
676
+ it(`103. should apply only the ${size} size class`, async () => {
677
+ const el = await fixture<NileBadge>(html`<nile-badge size=${size}>Label</nile-badge>`);
678
+ const span = el.shadowRoot!.querySelector('span')!;
679
+ for (const other of ['sm', 'md', 'lg']) {
680
+ expect(span.classList.contains(`badge--${other}`)).to.equal(other === size);
681
+ }
682
+ });
683
+ }
684
+
685
+ it('104. should update size class when size changes', async () => {
686
+ const el = await fixture<NileBadge>(html`<nile-badge>Label</nile-badge>`);
687
+ el.size = 'sm';
688
+ await elementUpdated(el);
689
+ const span = el.shadowRoot!.querySelector('span')!;
690
+ expect(span.classList.contains('badge--sm')).to.be.true;
691
+ expect(span.classList.contains('badge--md')).to.be.false;
692
+ });
693
+
694
+ describe('size dimensions (nxtgen tokens)', () => {
695
+ let tokens: HTMLStyleElement;
696
+
697
+ before(() => {
698
+ tokens = document.createElement('style');
699
+ tokens.textContent = `:root {
700
+ --ng-height-22px: 22px; --ng-height-24px: 24px; --ng-height-28px: 28px;
701
+ --ng-spacing-xxs: 2px; --ng-spacing-xs: 4px; --ng-spacing-md: 8px;
702
+ --ng-spacing-md-alt: 10px; --ng-spacing-lg: 12px;
703
+ }`;
704
+ document.head.appendChild(tokens);
705
+ });
706
+
707
+ after(() => tokens.remove());
708
+
709
+ it('105. should render 22px, 24px and 28px tall for sm, md and lg', async () => {
710
+ const heights: number[] = [];
711
+ for (const size of ['sm', 'md', 'lg']) {
712
+ const el = await fixture<NileBadge>(html`<nile-badge size=${size}>Label</nile-badge>`);
713
+ heights.push(el.shadowRoot!.querySelector('span')!.getBoundingClientRect().height);
714
+ }
715
+ expect(heights).to.deep.equal([22, 24, 28]);
716
+ });
717
+
718
+ it('106. should keep size padding when rounded', async () => {
719
+ const el = await fixture<NileBadge>(html`<nile-badge size="lg" rounded>Label</nile-badge>`);
720
+ const style = getComputedStyle(el.shadowRoot!.querySelector('span')!);
721
+ expect(style.paddingTop).to.equal('4px');
722
+ expect(style.paddingLeft).to.equal('12px');
723
+ });
724
+ });
725
+
726
+ describe('error / orange / warning colour tokens', () => {
727
+ const css = styles.cssText;
728
+ const rule = (selector: string) => css.slice(css.indexOf(`${selector} {`)).split('}')[0];
729
+ const ng = (token: string) => `var(--ng-componentcolors-utility-${token})`;
730
+
731
+ const cases: [string, string, string, string][] = [
732
+ ['error', 'error-50', 'error-200', 'error-700'],
733
+ ['orange', 'orange-50', 'orange-300', 'error-600'],
734
+ ['warning', 'warning-50', 'warning-300', 'warning-700'],
735
+ ];
736
+
737
+ cases.forEach(([variant, fill, border, text], i) => {
738
+ it(`${107 + i}. should map ${variant} to ${fill} / ${border} / ${text}`, () => {
739
+ const base = rule(`.badge--${variant}`);
740
+ expect(base).to.contain(`background-${variant}, ${ng(fill)})`);
741
+ expect(base).to.contain(`border-color-${variant}, ${ng(border)})`);
742
+ expect(base).to.contain(`font-${variant}, ${ng(text)})`);
743
+ expect(rule(`.badge--${variant}.badge--pill-outline`)).to.contain(`pill-outline-${variant}, ${ng(border)})`);
744
+ });
745
+ });
746
+ });
660
747
  });
@@ -84,6 +84,9 @@ export class NileBadge extends NileElement {
84
84
  | 'pill-outline'
85
85
  | 'badge-color'='badge-color';
86
86
 
87
+ /** The badge's size. `md` keeps the existing default dimensions. */
88
+ @property({ reflect: true }) size: 'sm' | 'md' | 'lg' = 'md';
89
+
87
90
  render() {
88
91
  return html`
89
92
  <span
@@ -111,6 +114,9 @@ export class NileBadge extends NileElement {
111
114
  this.rounded ||
112
115
  this.pilltype == 'pill-outline' ||
113
116
  this.pilltype == 'pill-color',
117
+ 'badge--sm': this.size === 'sm',
118
+ 'badge--md': this.size === 'md',
119
+ 'badge--lg': this.size === 'lg',
114
120
  })}
115
121
  >
116
122
  <slot part="content" class="badge__content"></slot>
@@ -496,7 +496,7 @@
496
496
  },
497
497
  {
498
498
  "name": "nile-badge",
499
- "description": "Events:\n\n * `nile-remove` {} - Emitted when the remove button is activated.\n\nSlots:\n\n * ` ` {} - The badge's content.\n\nAttributes:\n\n * `variant` {`\"primary\" | \"success\" | \"normal\" | \"warning\" | \"error\" | \"info\" | \"gray\" | \"brand\" | \"blue-light\" | \"blue\" | \"indigo\" | \"purple\" | \"pink\" | \"orange\" | \"blue-gray\" | \"gray-blue\"`} - The badge's theme variant.\n\n * `rounded` {`boolean`} - Draws a pill-style badge with rounded edges.\n\n * `pilltype` {`\"pill-color\" | \"pill-outline\" | \"badge-color\"`} - \n\nProperties:\n\n * `styles` - \n\n * `variant` {`\"primary\" | \"success\" | \"normal\" | \"warning\" | \"error\" | \"info\" | \"gray\" | \"brand\" | \"blue-light\" | \"blue\" | \"indigo\" | \"purple\" | \"pink\" | \"orange\" | \"blue-gray\" | \"gray-blue\"`} - The badge's theme variant.\n\n * `rounded` {`boolean`} - Draws a pill-style badge with rounded edges.\n\n * `pilltype` {`\"pill-color\" | \"pill-outline\" | \"badge-color\"`} - \n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
499
+ "description": "Events:\n\n * `nile-remove` {} - Emitted when the remove button is activated.\n\nSlots:\n\n * ` ` {} - The badge's content.\n\nAttributes:\n\n * `variant` {`\"primary\" | \"success\" | \"normal\" | \"warning\" | \"error\" | \"info\" | \"gray\" | \"brand\" | \"blue-light\" | \"blue\" | \"indigo\" | \"purple\" | \"pink\" | \"orange\" | \"blue-gray\" | \"gray-blue\"`} - The badge's theme variant.\n\n * `rounded` {`boolean`} - Draws a pill-style badge with rounded edges.\n\n * `pilltype` {`\"pill-color\" | \"pill-outline\" | \"badge-color\"`} - \n\n * `size` {`\"sm\" | \"md\" | \"lg\"`} - The badge's size. `md` keeps the existing default dimensions.\n\nProperties:\n\n * `styles` - \n\n * `variant` {`\"primary\" | \"success\" | \"normal\" | \"warning\" | \"error\" | \"info\" | \"gray\" | \"brand\" | \"blue-light\" | \"blue\" | \"indigo\" | \"purple\" | \"pink\" | \"orange\" | \"blue-gray\" | \"gray-blue\"`} - The badge's theme variant.\n\n * `rounded` {`boolean`} - Draws a pill-style badge with rounded edges.\n\n * `pilltype` {`\"pill-color\" | \"pill-outline\" | \"badge-color\"`} - \n\n * `size` {`\"sm\" | \"md\" | \"lg\"`} - The badge's size. `md` keeps the existing default dimensions.\n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
500
500
  "attributes": [
501
501
  {
502
502
  "name": "variant",
@@ -572,6 +572,21 @@
572
572
  }
573
573
  ]
574
574
  },
575
+ {
576
+ "name": "size",
577
+ "description": "`size` {`\"sm\" | \"md\" | \"lg\"`} - The badge's size. `md` keeps the existing default dimensions.\n\nProperty: size\n\nDefault: md",
578
+ "values": [
579
+ {
580
+ "name": "sm"
581
+ },
582
+ {
583
+ "name": "md"
584
+ },
585
+ {
586
+ "name": "lg"
587
+ }
588
+ ]
589
+ },
575
590
  {
576
591
  "name": "onnile-remove",
577
592
  "description": "`nile-remove` {} - Emitted when the remove button is activated."