@aquera/nile-elements 1.8.7 → 1.8.8

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.
Files changed (30) hide show
  1. package/README.md +3 -0
  2. package/dist/index.js +33 -4
  3. package/dist/nile-side-bar/nile-side-bar.cjs.js +1 -1
  4. package/dist/nile-side-bar/nile-side-bar.cjs.js.map +1 -1
  5. package/dist/nile-side-bar/nile-side-bar.css.cjs.js +1 -1
  6. package/dist/nile-side-bar/nile-side-bar.css.cjs.js.map +1 -1
  7. package/dist/nile-side-bar/nile-side-bar.css.esm.js +31 -2
  8. package/dist/nile-side-bar/nile-side-bar.esm.js +2 -2
  9. package/dist/nile-side-bar-expand/nile-side-bar-expand.cjs.js +1 -1
  10. package/dist/nile-side-bar-expand/nile-side-bar-expand.cjs.js.map +1 -1
  11. package/dist/nile-side-bar-expand/nile-side-bar-expand.esm.js +2 -2
  12. package/dist/src/nile-side-bar/nile-side-bar.css.js +29 -0
  13. package/dist/src/nile-side-bar/nile-side-bar.css.js.map +1 -1
  14. package/dist/src/nile-side-bar/nile-side-bar.d.ts +16 -0
  15. package/dist/src/nile-side-bar/nile-side-bar.js +30 -0
  16. package/dist/src/nile-side-bar/nile-side-bar.js.map +1 -1
  17. package/dist/src/nile-side-bar/nile-side-bar.test.d.ts +2 -0
  18. package/dist/src/nile-side-bar/nile-side-bar.test.js +96 -0
  19. package/dist/src/nile-side-bar/nile-side-bar.test.js.map +1 -0
  20. package/dist/src/nile-side-bar-expand/nile-side-bar-expand.js +4 -6
  21. package/dist/src/nile-side-bar-expand/nile-side-bar-expand.js.map +1 -1
  22. package/dist/src/version.js +1 -1
  23. package/dist/src/version.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/src/nile-side-bar/nile-side-bar.css.ts +29 -0
  27. package/src/nile-side-bar/nile-side-bar.test.ts +109 -0
  28. package/src/nile-side-bar/nile-side-bar.ts +29 -0
  29. package/src/nile-side-bar-expand/nile-side-bar-expand.ts +7 -8
  30. package/vscode-html-custom-data.json +10 -1
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": "1.8.7",
6
+ "version": "1.8.8",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -45,6 +45,35 @@ export const styles = css`
45
45
  transform: translateX(calc(var(--sidebar-width) - var(--sidebar-collapsed-width)));
46
46
  }
47
47
 
48
+ /*
49
+ * Overlay mode: lift the sidebar out of normal flow so expanding it floats
50
+ * on top of adjacent content instead of pushing siblings. Anchors to the
51
+ * nearest positioned ancestor; set --sidebar-overlay-position: fixed to pin
52
+ * it to the viewport instead.
53
+ */
54
+ :host([overlay]) {
55
+ position: var(--sidebar-overlay-position, absolute);
56
+ top: 0;
57
+ bottom: 0;
58
+ height: 100%;
59
+ }
60
+
61
+ :host([overlay][position='left']) {
62
+ left: 0;
63
+ }
64
+
65
+ :host([overlay][position='right']) {
66
+ right: 0;
67
+ }
68
+
69
+ /* Elevate while expanded so it reads as floating above the page. */
70
+ :host([overlay]:not([collapsed])) {
71
+ box-shadow: var(
72
+ --sidebar-overlay-shadow,
73
+ 0px 8px 24px 0px rgba(119, 125, 130, 0.25)
74
+ );
75
+ }
76
+
48
77
  :host {
49
78
  scrollbar-width: thin;
50
79
  scrollbar-color: #64748b transparent;
@@ -0,0 +1,109 @@
1
+ import { expect, fixture, html, oneEvent } from '@open-wc/testing';
2
+ import './nile-side-bar';
3
+ import '../nile-side-bar-expand/nile-side-bar-expand';
4
+ import type { NileSideBar } from './nile-side-bar';
5
+
6
+ describe('NileSideBar — collapse/expand API', () => {
7
+ it('1. defaults to expanded (not collapsed) and not overlay', async () => {
8
+ const el = await fixture<NileSideBar>(html`<nile-side-bar></nile-side-bar>`);
9
+ expect(el.collapsed).to.be.false;
10
+ expect(el.overlay).to.be.false;
11
+ expect(el.hasAttribute('overlay')).to.be.false;
12
+ });
13
+
14
+ it('2. collapse() sets collapsed state + reflects attribute', async () => {
15
+ const el = await fixture<NileSideBar>(html`<nile-side-bar></nile-side-bar>`);
16
+ el.collapse();
17
+ await el.updateComplete;
18
+ expect(el.collapsed).to.be.true;
19
+ expect(el.hasAttribute('collapsed')).to.be.true;
20
+ });
21
+
22
+ it('3. expand() clears collapsed state', async () => {
23
+ const el = await fixture<NileSideBar>(html`<nile-side-bar collapsed></nile-side-bar>`);
24
+ expect(el.collapsed).to.be.true;
25
+ el.expand();
26
+ await el.updateComplete;
27
+ expect(el.collapsed).to.be.false;
28
+ expect(el.hasAttribute('collapsed')).to.be.false;
29
+ });
30
+
31
+ it('4. toggle() flips state', async () => {
32
+ const el = await fixture<NileSideBar>(html`<nile-side-bar></nile-side-bar>`);
33
+ el.toggle();
34
+ await el.updateComplete;
35
+ expect(el.collapsed).to.be.true;
36
+ el.toggle();
37
+ await el.updateComplete;
38
+ expect(el.collapsed).to.be.false;
39
+ });
40
+
41
+ it('5. toggle(force) sets an explicit state', async () => {
42
+ const el = await fixture<NileSideBar>(html`<nile-side-bar></nile-side-bar>`);
43
+ el.toggle(false); // already expanded -> no-op
44
+ await el.updateComplete;
45
+ expect(el.collapsed).to.be.false;
46
+ el.toggle(true);
47
+ await el.updateComplete;
48
+ expect(el.collapsed).to.be.true;
49
+ });
50
+
51
+ it('6. emits nile-toggle with new collapsed state', async () => {
52
+ const el = await fixture<NileSideBar>(html`<nile-side-bar></nile-side-bar>`);
53
+ setTimeout(() => el.collapse());
54
+ const ev = await oneEvent(el, 'nile-toggle');
55
+ expect(ev.detail.collapsed).to.be.true;
56
+ });
57
+
58
+ it('7. does NOT emit nile-toggle when state is unchanged', async () => {
59
+ const el = await fixture<NileSideBar>(html`<nile-side-bar></nile-side-bar>`);
60
+ let fired = false;
61
+ el.addEventListener('nile-toggle', () => { fired = true; });
62
+ el.expand(); // already expanded
63
+ await el.updateComplete;
64
+ expect(fired).to.be.false;
65
+ });
66
+
67
+ it('8. built-in expand button toggles the sidebar (normal mode)', async () => {
68
+ const el = await fixture<NileSideBar>(html`
69
+ <nile-side-bar>
70
+ <nile-side-bar-expand slot="expand"></nile-side-bar-expand>
71
+ </nile-side-bar>
72
+ `);
73
+ await el.updateComplete;
74
+ const expandEl = el.querySelector('nile-side-bar-expand') as HTMLElement & { collapsed: boolean };
75
+ const btn = expandEl.shadowRoot!.querySelector('.expand-btn') as HTMLElement;
76
+
77
+ let detail: any;
78
+ el.addEventListener('nile-toggle', (e: Event) => { detail = (e as CustomEvent).detail; });
79
+
80
+ btn.click();
81
+ await el.updateComplete;
82
+ expect(el.collapsed).to.be.true;
83
+ expect(detail.collapsed).to.be.true;
84
+ expect(expandEl.collapsed).to.be.true; // arrow icon state stays in sync
85
+
86
+ btn.click();
87
+ await el.updateComplete;
88
+ expect(el.collapsed).to.be.false;
89
+ expect(expandEl.collapsed).to.be.false;
90
+ });
91
+
92
+ it('9. overlay attribute is opt-in and reflects', async () => {
93
+ const el = await fixture<NileSideBar>(html`<nile-side-bar overlay></nile-side-bar>`);
94
+ expect(el.overlay).to.be.true;
95
+ el.overlay = false;
96
+ await el.updateComplete;
97
+ expect(el.hasAttribute('overlay')).to.be.false;
98
+ });
99
+
100
+ it('10. methods work the same with overlay enabled', async () => {
101
+ const el = await fixture<NileSideBar>(html`<nile-side-bar overlay></nile-side-bar>`);
102
+ el.collapse();
103
+ await el.updateComplete;
104
+ expect(el.collapsed).to.be.true;
105
+ el.expand();
106
+ await el.updateComplete;
107
+ expect(el.collapsed).to.be.false;
108
+ });
109
+ });
@@ -18,6 +18,17 @@ import NileElement from '../internal/nile-element';
18
18
  * @attr position - Position of the sidebar ("left" | "right"). Defaults to "left".
19
19
  * @attr width - Expanded width of the sidebar (px).
20
20
  * @attr collapsed-width - Collapsed width of the sidebar (px).
21
+ * @attr overlay - When set, the sidebar is taken out of normal flow and floats
22
+ * on top of adjacent content, so expanding it overlays the page instead of
23
+ * pushing siblings sideways.
24
+ *
25
+ * @event nile-toggle - Fired after the collapsed state changes (via the built-in
26
+ * expand button or the public expand()/collapse()/toggle() methods).
27
+ * `event.detail.collapsed` is the new state.
28
+ *
29
+ * @method expand() - Expand the sidebar.
30
+ * @method collapse() - Collapse the sidebar.
31
+ * @method toggle(force?) - Toggle, or force a specific collapsed state.
21
32
  */
22
33
  @customElement('nile-side-bar')
23
34
  export class NileSideBar extends NileElement {
@@ -25,6 +36,8 @@ export class NileSideBar extends NileElement {
25
36
 
26
37
  @property({ type: Boolean, reflect: true, attribute: true })collapsed: boolean = false;
27
38
 
39
+ @property({ type: Boolean, reflect: true, attribute: true })overlay: boolean = false;
40
+
28
41
  @property({ type: Boolean, reflect: true, attribute: true })fullHeight: boolean = false;
29
42
 
30
43
  @property({ type: Number, attribute: true })width: number | null = null;
@@ -62,6 +75,22 @@ export class NileSideBar extends NileElement {
62
75
  this.style.setProperty('--sidebar-collapsed-width', `${this.collapsedWidth}px`);
63
76
  }
64
77
  }
78
+ public expand(): void {
79
+ this.setCollapsed(false);
80
+ }
81
+ public collapse(): void {
82
+ this.setCollapsed(true);
83
+ }
84
+
85
+ public toggle(force?: boolean): void {
86
+ this.setCollapsed(force ?? !this.collapsed);
87
+ }
88
+
89
+ private setCollapsed(value: boolean): void {
90
+ if (this.collapsed === value) return;
91
+ this.collapsed = value;
92
+ this.emit('nile-toggle', { collapsed: value });
93
+ }
65
94
 
66
95
  public render(): TemplateResult {
67
96
  return html`
@@ -30,17 +30,16 @@ export class NileSideBarExpand extends NileElement {
30
30
  }
31
31
 
32
32
  private toggleSidebar() {
33
- const sidebar = this.closest('nile-side-bar');
33
+ const sidebar = this.closest('nile-side-bar') as
34
+ | (HTMLElement & { toggle?: (force?: boolean) => void })
35
+ | null;
34
36
  if (!sidebar) return;
35
-
36
- const isCollapsed = sidebar.hasAttribute('collapsed');
37
- if (isCollapsed) {
38
- sidebar.removeAttribute('collapsed');
39
- this.collapsed = false;
37
+ if (typeof sidebar.toggle === 'function') {
38
+ sidebar.toggle();
40
39
  } else {
41
- sidebar.setAttribute('collapsed', '');
42
- this.collapsed = true;
40
+ sidebar.toggleAttribute('collapsed', !sidebar.hasAttribute('collapsed'));
43
41
  }
42
+ this.collapsed = sidebar.hasAttribute('collapsed');
44
43
  }
45
44
 
46
45
  public render(): TemplateResult {
@@ -6340,7 +6340,7 @@
6340
6340
  },
6341
6341
  {
6342
6342
  "name": "nile-side-bar",
6343
- "description": "Nile side-bar component.\n\nAttributes:\n\n * `collapsed` {`boolean`} - \n\n * `fullHeight` {`boolean`} - \n\n * `collapsedWidth` {`number | null`} - \n\n * `position` {`\"left\" | \"right\"`} - Position of the sidebar (\"left\" | \"right\"). Defaults to \"left\".\n\n * `width` {`number | null`} - Expanded width of the sidebar (px).\n\n * `collapsed-width` - Collapsed width of the sidebar (px).\n\nProperties:\n\n * `collapsed` {`boolean`} - \n\n * `fullHeight` {`boolean`} - \n\n * `collapsedWidth` {`number | null`} - \n\n * `position` {`\"left\" | \"right\"`} - Position of the sidebar (\"left\" | \"right\"). Defaults to \"left\".\n\n * `width` {`number | null`} - Expanded width of the sidebar (px).\n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
6343
+ "description": "Nile side-bar component.\n\nEvents:\n\n * `nile-toggle` {} - Fired after the collapsed state changes (via the built-in\nexpand button or the public expand()/collapse()/toggle() methods).\n`event.detail.collapsed` is the new state.\n\nAttributes:\n\n * `collapsed` {`boolean`} - \n\n * `fullHeight` {`boolean`} - \n\n * `collapsedWidth` {`number | null`} - \n\n * `position` {`\"left\" | \"right\"`} - Position of the sidebar (\"left\" | \"right\"). Defaults to \"left\".\n\n * `width` {`number | null`} - Expanded width of the sidebar (px).\n\n * `overlay` {`boolean`} - When set, the sidebar is taken out of normal flow and floats\non top of adjacent content, so expanding it overlays the page instead of\npushing siblings sideways.\n\n * `collapsed-width` - Collapsed width of the sidebar (px).\n\nProperties:\n\n * `collapsed` {`boolean`} - \n\n * `fullHeight` {`boolean`} - \n\n * `collapsedWidth` {`number | null`} - \n\n * `position` {`\"left\" | \"right\"`} - Position of the sidebar (\"left\" | \"right\"). Defaults to \"left\".\n\n * `width` {`number | null`} - Expanded width of the sidebar (px).\n\n * `overlay` {`boolean`} - When set, the sidebar is taken out of normal flow and floats\non top of adjacent content, so expanding it overlays the page instead of\npushing siblings sideways.\n\n * `BUBBLES` {`boolean`} - \n\n * `COMPOSED` {`boolean`} - \n\n * `CANCELABLE` {`boolean`} - ",
6344
6344
  "attributes": [
6345
6345
  {
6346
6346
  "name": "collapsed",
@@ -6374,9 +6374,18 @@
6374
6374
  "description": "`width` {`number | null`} - Expanded width of the sidebar (px).\n\nProperty: width\n\nDefault: null",
6375
6375
  "values": []
6376
6376
  },
6377
+ {
6378
+ "name": "overlay",
6379
+ "description": "`overlay` {`boolean`} - When set, the sidebar is taken out of normal flow and floats\non top of adjacent content, so expanding it overlays the page instead of\npushing siblings sideways.\n\nProperty: overlay\n\nDefault: false",
6380
+ "valueSet": "v"
6381
+ },
6377
6382
  {
6378
6383
  "name": "collapsed-width",
6379
6384
  "description": "`collapsed-width` - Collapsed width of the sidebar (px).\n\n"
6385
+ },
6386
+ {
6387
+ "name": "onnile-toggle",
6388
+ "description": "`nile-toggle` {} - Fired after the collapsed state changes (via the built-in\nexpand button or the public expand()/collapse()/toggle() methods).\n`event.detail.collapsed` is the new state."
6380
6389
  }
6381
6390
  ]
6382
6391
  },