@neovici/cosmoz-dropdown 1.4.0 → 1.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-dropdown",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "A simple dropdown web component",
5
5
  "keywords": [
6
6
  "lit-html",
@@ -1,17 +1,20 @@
1
- import { html, component, useCallback } from 'haunted';
1
+ import { component, useCallback } from 'haunted';
2
+ import { html, nothing } from 'lit-html';
2
3
  import { usePosition } from './use-position';
3
4
  import { useHostFocus } from './use-focus';
4
5
 
5
6
  const preventDefault = e => e.preventDefault(),
6
7
  Content = host => {
7
- usePosition({ anchor: host.anchor, host, placement: host.placement });
8
+ const { anchor, placement, render } = host;
9
+ usePosition({ anchor, placement, host });
8
10
  return html` <style>
9
11
  :host {
10
12
  position: fixed;
11
13
  left: -9999999999px;
12
14
  min-width: 72px;
13
15
  box-sizing: border-box;
14
- padding: var(--cosmoz-dropdown-spacing, 0px)
16
+ padding: var(--cosmoz-dropdown-spacing, 0px);
17
+ z-index: var(--cosmoz-dropdown-z-index, 2);
15
18
  }
16
19
  .content {
17
20
  background: var(--cosmoz-dropdown-bg-color, #fff);
@@ -21,10 +24,10 @@ const preventDefault = e => e.preventDefault(),
21
24
  display: block;
22
25
  }
23
26
  </style>
24
- <div class="content"><slot></slot></div>`;
27
+ <div class="content" part="content"><slot></slot>${ render?.() || nothing }</div>`;
25
28
  },
26
29
  Dropdown = host => {
27
- const { placement } = host,
30
+ const { placement, render } = host,
28
31
  anchor = useCallback(() => host.shadowRoot.querySelector('.anchor'), []),
29
32
  { active, onToggle } = useHostFocus(host);
30
33
  return html`
@@ -36,13 +39,18 @@ const preventDefault = e => e.preventDefault(),
36
39
  button {
37
40
  border: none;
38
41
  cursor: pointer;
42
+ position: relative;
39
43
  pointer-events: auto;
40
44
  outline: none;
41
- background: var(--cosmoz-dropdown-button-bg-color, #101010);
42
- color: var(--cosmoz-dropdown-button-color, #fff);
45
+ background: var(--cosmoz-dropdown-button-bg-color, var(--cosmoz-button-bg-color, #101010));
46
+ color: var(--cosmoz-dropdown-button-color, var(--cosmoz-button-color, #fff));
43
47
  border-radius: var(--cosmoz-dropdown-button-radius, 50%);
44
48
  width: var(--cosmoz-dropdown-button-width, var(--cosmoz-dropdown-button-size, 40px));
45
49
  height: var(--cosmoz-dropdown-button-height, var(--cosmoz-dropdown-button-size, 40px));
50
+ padding: var(--cosmoz-dropdown-button-padding);
51
+ }
52
+ button:hover {
53
+ background: var(--cosmoz-dropdown-button-hover-bg-color, var(--cosmoz-button-hover-bg-color, #3A3F44));
46
54
  }
47
55
  </style>
48
56
  <div class="anchor" part="anchor">
@@ -50,15 +58,50 @@ const preventDefault = e => e.preventDefault(),
50
58
  <slot name="button">...</slot>
51
59
  </button>
52
60
  </div>
53
- ${ active
54
- ? html` <cosmoz-dropdown-content part="dropdown" .anchor=${ anchor } .placement=${ placement }>
55
- <slot></slot>
56
- </cosmoz-dropdown-content>`
57
- : [] }
61
+ ${ active && html`
62
+ <cosmoz-dropdown-content id="dropdown" part="dropdown" .anchor=${ anchor } .placement=${ placement } .render=${ render }>
63
+ <slot></slot>
64
+ </cosmoz-dropdown-content>` || [] }
58
65
  `;
59
- };
66
+ },
67
+ List = () => html`
68
+ <style>
69
+ :host { display: contents; }
70
+ ::slotted(:not(slot)) {
71
+ display: block;
72
+ --paper-button_-_display: block;
73
+ padding: 10px 24px;
74
+ background: transparent;
75
+ color: var(--cosmoz-dropdown-menu-color, #101010);
76
+ transition: background 0.25s, color 0.25s;
77
+ border: none;
78
+ cursor: pointer;
79
+ font-size: 14px;
80
+ line-height: 20px;
81
+ text-align: left;
82
+ margin: 0;
83
+ width: 100%;
84
+ }
85
+ ::slotted(:not(slot):hover) {
86
+ background: var(--cosmoz-dropdown-menu-hover-color, var(--cosmoz-selection-color, rgba(58, 145, 226, 0.1)));
87
+ }
88
+
89
+ ::slotted(:not(slot)[disabled]) {
90
+ opacity: 0.5;
91
+ pointer-events: none;
92
+ }
93
+ </style>
94
+ <slot></slot>
95
+ `,
96
+ Menu = host => html`
97
+ <cosmoz-dropdown .placement=${ host.placement }>
98
+ <slot name="button" slot="button"></slot>
99
+ <cosmoz-dropdown-list><slot></slot></cosmoz-dropdown-list>
100
+ </cosmoz-dropdown>`;
60
101
 
61
- customElements.define('cosmoz-dropdown', component(Dropdown));
62
102
  customElements.define('cosmoz-dropdown-content', component(Content));
103
+ customElements.define('cosmoz-dropdown', component(Dropdown));
104
+ customElements.define('cosmoz-dropdown-list', component(List));
105
+ customElements.define('cosmoz-dropdown-menu', component(Menu));
63
106
 
64
107
  export { Dropdown, Content };