@neovici/cosmoz-dropdown 1.4.0 → 1.5.3
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 +1 -1
- package/src/cosmoz-dropdown.js +62 -15
package/package.json
CHANGED
package/src/cosmoz-dropdown.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
|
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,29 +39,73 @@ 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));
|
|
54
|
+
}
|
|
55
|
+
::slotted(svg) {
|
|
56
|
+
pointer-events: none;
|
|
46
57
|
}
|
|
47
58
|
</style>
|
|
48
59
|
<div class="anchor" part="anchor">
|
|
49
|
-
<button @click=${ onToggle } @mousedown=${ preventDefault } part="button">
|
|
60
|
+
<button @click=${ onToggle } @mousedown=${ preventDefault } part="button" id="dropdownButton">
|
|
50
61
|
<slot name="button">...</slot>
|
|
51
62
|
</button>
|
|
52
63
|
</div>
|
|
53
|
-
${ active
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
: [] }
|
|
64
|
+
${ active && html`
|
|
65
|
+
<cosmoz-dropdown-content id="dropdown" part="dropdown" .anchor=${ anchor } .placement=${ placement } .render=${ render }>
|
|
66
|
+
<slot></slot>
|
|
67
|
+
</cosmoz-dropdown-content>` || [] }
|
|
58
68
|
`;
|
|
59
|
-
}
|
|
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>`;
|
|
60
105
|
|
|
61
|
-
customElements.define('cosmoz-dropdown', component(Dropdown));
|
|
62
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));
|
|
63
110
|
|
|
64
111
|
export { Dropdown, Content };
|