@neovici/cosmoz-dropdown 1.3.0 → 1.5.2

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.3.0",
3
+ "version": "1.5.2",
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,27 +24,36 @@ 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`
31
34
  <style>
32
35
  .anchor {
33
36
  pointer-events: none;
37
+ padding: var(--cosmoz-dropdown-anchor-spacing);
34
38
  }
35
39
  button {
36
40
  border: none;
37
41
  cursor: pointer;
42
+ position: relative;
38
43
  pointer-events: auto;
39
44
  outline: none;
40
- background: var(--cosmoz-dropdown-button-bg-color, #101010);
41
- 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));
42
47
  border-radius: var(--cosmoz-dropdown-button-radius, 50%);
43
48
  width: var(--cosmoz-dropdown-button-width, var(--cosmoz-dropdown-button-size, 40px));
44
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));
54
+ }
55
+ ::slotted(svg) {
56
+ pointer-events: none;
45
57
  }
46
58
  </style>
47
59
  <div class="anchor" part="anchor">
@@ -49,15 +61,51 @@ const preventDefault = e => e.preventDefault(),
49
61
  <slot name="button">...</slot>
50
62
  </button>
51
63
  </div>
52
- ${ active
53
- ? html` <cosmoz-dropdown-content part="dropdown" .anchor=${ anchor } .placement=${ placement }>
54
- <slot></slot>
55
- </cosmoz-dropdown-content>`
56
- : [] }
64
+ ${ active && html`
65
+ <cosmoz-dropdown-content id="dropdown" part="dropdown" .anchor=${ anchor } .placement=${ placement } .render=${ render }>
66
+ <slot></slot>
67
+ </cosmoz-dropdown-content>` || [] }
57
68
  `;
58
- };
69
+ },
70
+ List = () => html`
71
+ <style>
72
+ :host { display: contents; }
73
+ ::slotted(:not(slot)) {
74
+ display: block;
75
+ --paper-button_-_display: block;
76
+ box-sizing: border-box;
77
+ padding: 10px 24px;
78
+ background: transparent;
79
+ color: var(--cosmoz-dropdown-menu-color, #101010);
80
+ transition: background 0.25s, color 0.25s;
81
+ border: none;
82
+ cursor: pointer;
83
+ font-size: 14px;
84
+ line-height: 20px;
85
+ text-align: left;
86
+ margin: 0;
87
+ width: 100%;
88
+ }
89
+ ::slotted(:not(slot):hover) {
90
+ background: var(--cosmoz-dropdown-menu-hover-color, var(--cosmoz-selection-color, rgba(58, 145, 226, 0.1)));
91
+ }
92
+
93
+ ::slotted(:not(slot)[disabled]) {
94
+ opacity: 0.5;
95
+ pointer-events: none;
96
+ }
97
+ </style>
98
+ <slot></slot>
99
+ `,
100
+ Menu = host => html`
101
+ <cosmoz-dropdown .placement=${ host.placement }>
102
+ <slot name="button" slot="button"></slot>
103
+ <cosmoz-dropdown-list><slot></slot></cosmoz-dropdown-list>
104
+ </cosmoz-dropdown>`;
59
105
 
60
- customElements.define('cosmoz-dropdown', component(Dropdown));
61
106
  customElements.define('cosmoz-dropdown-content', component(Content));
107
+ customElements.define('cosmoz-dropdown', component(Dropdown));
108
+ customElements.define('cosmoz-dropdown-list', component(List));
109
+ customElements.define('cosmoz-dropdown-menu', component(Menu));
62
110
 
63
111
  export { Dropdown, Content };