@neovici/cosmoz-dropdown 1.2.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.2.0",
3
+ "version": "1.5.0",
4
4
  "description": "A simple dropdown web component",
5
5
  "keywords": [
6
6
  "lit-html",
@@ -1,41 +1,56 @@
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;
16
+ padding: var(--cosmoz-dropdown-spacing, 0px);
17
+ z-index: var(--cosmoz-dropdown-z-index, 2);
18
+ }
19
+ .content {
14
20
  background: var(--cosmoz-dropdown-bg-color, #fff);
15
21
  box-shadow: var(--cosmoz-dropdown-box-shadow, 0px 3px 4px 2px rgba(0, 0, 0, 0.1));
16
22
  }
23
+ ::slotted(*) {
24
+ display: block;
25
+ }
17
26
  </style>
18
- <slot></slot>`;
27
+ <div class="content" part="content"><slot></slot>${ render?.() || nothing }</div>`;
19
28
  },
20
29
  Dropdown = host => {
21
- const { placement } = host,
30
+ const { placement, render } = host,
22
31
  anchor = useCallback(() => host.shadowRoot.querySelector('.anchor'), []),
23
32
  { active, onToggle } = useHostFocus(host);
24
33
  return html`
25
34
  <style>
26
35
  .anchor {
27
36
  pointer-events: none;
37
+ padding: var(--cosmoz-dropdown-anchor-spacing);
28
38
  }
29
39
  button {
30
40
  border: none;
31
41
  cursor: pointer;
42
+ position: relative;
32
43
  pointer-events: auto;
33
44
  outline: none;
34
- background: var(--cosmoz-dropdown-button-bg-color, #101010);
35
- 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));
36
47
  border-radius: var(--cosmoz-dropdown-button-radius, 50%);
37
48
  width: var(--cosmoz-dropdown-button-width, var(--cosmoz-dropdown-button-size, 40px));
38
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));
39
54
  }
40
55
  </style>
41
56
  <div class="anchor" part="anchor">
@@ -43,15 +58,50 @@ const preventDefault = e => e.preventDefault(),
43
58
  <slot name="button">...</slot>
44
59
  </button>
45
60
  </div>
46
- ${ active
47
- ? html` <cosmoz-dropdown-content part="dropdown" .anchor=${ anchor } .placement=${ placement }>
48
- <slot></slot>
49
- </cosmoz-dropdown-content>`
50
- : [] }
61
+ ${ active && html`
62
+ <cosmoz-dropdown-content id="dropdown" part="dropdown" .anchor=${ anchor } .placement=${ placement } .render=${ render }>
63
+ <slot></slot>
64
+ </cosmoz-dropdown-content>` || [] }
51
65
  `;
52
- };
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>`;
53
101
 
54
- customElements.define('cosmoz-dropdown', component(Dropdown));
55
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));
56
106
 
57
107
  export { Dropdown, Content };