@spectrum-web-components/overlay 0.15.0 → 0.15.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/active-overlay.d.ts +6 -0
- package/active-overlay.js +14 -0
- package/active-overlay.js.map +1 -0
- package/custom-elements.json +6 -6
- package/overlay-trigger.d.ts +6 -0
- package/overlay-trigger.js +14 -0
- package/overlay-trigger.js.map +1 -0
- package/package.json +6 -6
- package/src/ActiveOverlay.d.ts +77 -0
- package/src/ActiveOverlay.js +436 -0
- package/src/ActiveOverlay.js.map +1 -0
- package/src/OverlayTrigger.d.ts +66 -0
- package/src/OverlayTrigger.js +310 -0
- package/src/OverlayTrigger.js.map +1 -0
- package/src/VirtualTrigger.d.ts +7 -0
- package/src/VirtualTrigger.js +40 -0
- package/src/VirtualTrigger.js.map +1 -0
- package/src/active-overlay.css.d.ts +2 -0
- package/src/active-overlay.css.js +21 -0
- package/src/active-overlay.css.js.map +1 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +18 -0
- package/src/index.js.map +1 -0
- package/src/loader.d.ts +2 -0
- package/src/loader.js +16 -0
- package/src/loader.js.map +1 -0
- package/src/overlay-stack.d.ts +46 -0
- package/src/overlay-stack.js +449 -0
- package/src/overlay-stack.js.map +1 -0
- package/src/overlay-timer.d.ts +22 -0
- package/src/overlay-timer.js +89 -0
- package/src/overlay-timer.js.map +1 -0
- package/src/overlay-trigger.css.d.ts +2 -0
- package/src/overlay-trigger.css.js +17 -0
- package/src/overlay-trigger.css.js.map +1 -0
- package/src/overlay-types.d.ts +52 -0
- package/src/overlay-types.js +13 -0
- package/src/overlay-types.js.map +1 -0
- package/src/overlay.d.ts +59 -0
- package/src/overlay.js +119 -0
- package/src/overlay.js.map +1 -0
- package/stories/overlay-story-components.js +292 -0
- package/stories/overlay-story-components.js.map +1 -0
- package/stories/overlay.stories.js +805 -0
- package/stories/overlay.stories.js.map +1 -0
- package/sync/overlay-trigger.d.ts +1 -0
- package/sync/overlay-trigger.js +18 -0
- package/sync/overlay-trigger.js.map +1 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
4
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
6
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
9
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
10
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
11
|
+
governing permissions and limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
import { css, html, LitElement, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property, query, } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { Overlay } from '../';
|
|
16
|
+
import '@spectrum-web-components/button/sp-button.js';
|
|
17
|
+
import '@spectrum-web-components/popover/sp-popover.js';
|
|
18
|
+
import '@spectrum-web-components/radio/sp-radio.js';
|
|
19
|
+
import '@spectrum-web-components/radio/sp-radio-group.js';
|
|
20
|
+
import '@spectrum-web-components/overlay/overlay-trigger.js';
|
|
21
|
+
// Prevent infinite recursion in browser
|
|
22
|
+
const MAX_DEPTH = 7;
|
|
23
|
+
class OverlayTargetIcon extends LitElement {
|
|
24
|
+
static get styles() {
|
|
25
|
+
return css `
|
|
26
|
+
:host {
|
|
27
|
+
position: absolute;
|
|
28
|
+
display: block;
|
|
29
|
+
color: var(--spectrum-global-color-magenta-700);
|
|
30
|
+
width: 64px;
|
|
31
|
+
height: 64px;
|
|
32
|
+
top: 0;
|
|
33
|
+
left: 0;
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
render() {
|
|
38
|
+
return html `
|
|
39
|
+
<svg
|
|
40
|
+
aria-hidden="true"
|
|
41
|
+
focusable="false"
|
|
42
|
+
data-prefix="fas"
|
|
43
|
+
data-icon="bullseye"
|
|
44
|
+
class="svg-inline--fa fa-bullseye fa-w-16"
|
|
45
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
46
|
+
viewBox="0 0 496 512"
|
|
47
|
+
>
|
|
48
|
+
<path
|
|
49
|
+
fill="currentColor"
|
|
50
|
+
d="M248 8C111.03 8 0 119.03 0 256s111.03 248 248 248 248-111.03 248-248S384.97 8 248 8zm0 432c-101.69 0-184-82.29-184-184 0-101.69 82.29-184 184-184 101.69 0 184 82.29 184 184 0 101.69-82.29 184-184 184zm0-312c-70.69 0-128 57.31-128 128s57.31 128 128 128 128-57.31 128-128-57.31-128-128-128zm0 192c-35.29 0-64-28.71-64-64s28.71-64 64-64 64 28.71 64 64-28.71 64-64 64z"
|
|
51
|
+
></path>
|
|
52
|
+
</svg>
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
customElements.define('overlay-target-icon', OverlayTargetIcon);
|
|
57
|
+
class OverlayDrag extends LitElement {
|
|
58
|
+
constructor() {
|
|
59
|
+
super(...arguments);
|
|
60
|
+
this.top = 100;
|
|
61
|
+
this.left = 100;
|
|
62
|
+
}
|
|
63
|
+
static get styles() {
|
|
64
|
+
return css `
|
|
65
|
+
:host {
|
|
66
|
+
display: block;
|
|
67
|
+
width: 100%;
|
|
68
|
+
height: 100%;
|
|
69
|
+
position: relative;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
::slotted(*) {
|
|
73
|
+
display: block;
|
|
74
|
+
width: 100%;
|
|
75
|
+
height: 100%;
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
onSlotChange(event) {
|
|
80
|
+
const slot = event.target;
|
|
81
|
+
this.targetElement = undefined;
|
|
82
|
+
const nodes = slot.assignedNodes();
|
|
83
|
+
const slotElement = nodes.find((node) => node instanceof HTMLElement);
|
|
84
|
+
if (!slotElement)
|
|
85
|
+
return;
|
|
86
|
+
this.targetElement = slotElement.querySelector('[slot="trigger"]');
|
|
87
|
+
if (!this.targetElement)
|
|
88
|
+
return;
|
|
89
|
+
this.targetElement.addEventListener('mousedown', (event) => this.onMouseDown(event));
|
|
90
|
+
this.resetTargetPosition();
|
|
91
|
+
}
|
|
92
|
+
onMouseDown(event) {
|
|
93
|
+
const target = event.target;
|
|
94
|
+
const parent = target.parentElement;
|
|
95
|
+
if (!parent)
|
|
96
|
+
return;
|
|
97
|
+
const max = {
|
|
98
|
+
x: parent.offsetWidth - target.offsetWidth,
|
|
99
|
+
y: parent.offsetHeight - target.offsetHeight,
|
|
100
|
+
};
|
|
101
|
+
const dragStart = {
|
|
102
|
+
x: event.clientX,
|
|
103
|
+
y: event.clientY,
|
|
104
|
+
};
|
|
105
|
+
const originalPos = {
|
|
106
|
+
x: this.left,
|
|
107
|
+
y: this.top,
|
|
108
|
+
};
|
|
109
|
+
const onMouseMove = (event) => {
|
|
110
|
+
const dragDelta = {
|
|
111
|
+
x: event.clientX - dragStart.x,
|
|
112
|
+
y: event.clientY - dragStart.y,
|
|
113
|
+
};
|
|
114
|
+
const newPosition = {
|
|
115
|
+
x: dragDelta.x + originalPos.x,
|
|
116
|
+
y: dragDelta.y + originalPos.y,
|
|
117
|
+
};
|
|
118
|
+
this.left = Math.min(Math.max(newPosition.x, 0), max.x);
|
|
119
|
+
this.top = Math.min(Math.max(newPosition.y, 0), max.y);
|
|
120
|
+
Overlay.update();
|
|
121
|
+
};
|
|
122
|
+
const onMouseUp = () => {
|
|
123
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
124
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
125
|
+
};
|
|
126
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
127
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
128
|
+
}
|
|
129
|
+
resetTargetPosition() {
|
|
130
|
+
if (!this.targetElement)
|
|
131
|
+
return;
|
|
132
|
+
const target = this.targetElement;
|
|
133
|
+
const parent = target.parentElement;
|
|
134
|
+
if (!parent)
|
|
135
|
+
return;
|
|
136
|
+
this.left = (parent.offsetWidth - target.offsetWidth) / 2;
|
|
137
|
+
this.top = (parent.offsetHeight - target.offsetHeight) / 2;
|
|
138
|
+
}
|
|
139
|
+
updated() {
|
|
140
|
+
if (this.targetElement) {
|
|
141
|
+
this.targetElement.style.transform = `translate(${this.left}px, ${this.top}px)`;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
render() {
|
|
145
|
+
return html `
|
|
146
|
+
<slot @slotchange=${this.onSlotChange}></slot>
|
|
147
|
+
`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
__decorate([
|
|
151
|
+
property({ type: Number })
|
|
152
|
+
], OverlayDrag.prototype, "top", void 0);
|
|
153
|
+
__decorate([
|
|
154
|
+
property({ type: Number })
|
|
155
|
+
], OverlayDrag.prototype, "left", void 0);
|
|
156
|
+
customElements.define('overlay-drag', OverlayDrag);
|
|
157
|
+
class RecursivePopover extends LitElement {
|
|
158
|
+
constructor() {
|
|
159
|
+
super();
|
|
160
|
+
this.depth = 0;
|
|
161
|
+
this.isShiftTabbing = false;
|
|
162
|
+
this.placement = 'right';
|
|
163
|
+
this.depth = 0;
|
|
164
|
+
this.addEventListener('keydown', (event) => {
|
|
165
|
+
const { code } = event;
|
|
166
|
+
if (code === 'Enter') {
|
|
167
|
+
this.trigger.click();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
this.addEventListener('focusin', this.handleFocusin);
|
|
171
|
+
}
|
|
172
|
+
static get styles() {
|
|
173
|
+
return [
|
|
174
|
+
css `
|
|
175
|
+
:host {
|
|
176
|
+
display: block;
|
|
177
|
+
text-align: center;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
overlay-trigger {
|
|
181
|
+
display: inline-flex;
|
|
182
|
+
margin-top: 11px;
|
|
183
|
+
}
|
|
184
|
+
`,
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
handleFocusin() {
|
|
188
|
+
this.focus();
|
|
189
|
+
}
|
|
190
|
+
focus() {
|
|
191
|
+
if (this.shadowRoot.activeElement !== null) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const firstFocusable = this.shadowRoot.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
195
|
+
if (firstFocusable) {
|
|
196
|
+
if (firstFocusable.updateComplete) {
|
|
197
|
+
firstFocusable.updateComplete.then(() => firstFocusable.focus());
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
firstFocusable.focus();
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
super.focus();
|
|
205
|
+
}
|
|
206
|
+
onRadioChange(event) {
|
|
207
|
+
const target = event.target;
|
|
208
|
+
this.placement = target.selected;
|
|
209
|
+
}
|
|
210
|
+
captureEnter(event) {
|
|
211
|
+
const { code } = event;
|
|
212
|
+
if (code === 'Enter') {
|
|
213
|
+
event.stopPropagation();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
render() {
|
|
217
|
+
return html `
|
|
218
|
+
<sp-radio-group
|
|
219
|
+
horizontal
|
|
220
|
+
@change=${this.onRadioChange}
|
|
221
|
+
selected="${this.placement}"
|
|
222
|
+
name="group-example"
|
|
223
|
+
>
|
|
224
|
+
<sp-radio value="top">Top</sp-radio>
|
|
225
|
+
<sp-radio value="right">Right</sp-radio>
|
|
226
|
+
<sp-radio value="bottom">Bottom</sp-radio>
|
|
227
|
+
<sp-radio value="left">Left</sp-radio>
|
|
228
|
+
</sp-radio-group>
|
|
229
|
+
<overlay-trigger placement="${this.placement}" type="modal">
|
|
230
|
+
<sp-button
|
|
231
|
+
slot="trigger"
|
|
232
|
+
variant="accent"
|
|
233
|
+
@keydown=${this.captureEnter}
|
|
234
|
+
>
|
|
235
|
+
Open Popover
|
|
236
|
+
</sp-button>
|
|
237
|
+
<sp-popover
|
|
238
|
+
dialog
|
|
239
|
+
slot="click-content"
|
|
240
|
+
direction="${this.placement}"
|
|
241
|
+
tip
|
|
242
|
+
open
|
|
243
|
+
>
|
|
244
|
+
${this.depth < MAX_DEPTH
|
|
245
|
+
? html `
|
|
246
|
+
<recursive-popover
|
|
247
|
+
position="${this.placement}"
|
|
248
|
+
depth="${this.depth + 1}"
|
|
249
|
+
tabindex="0"
|
|
250
|
+
></recursive-popover>
|
|
251
|
+
`
|
|
252
|
+
: html `
|
|
253
|
+
<div>Maximum Depth</div>
|
|
254
|
+
`}
|
|
255
|
+
</sp-popover>
|
|
256
|
+
</overlay-trigger>
|
|
257
|
+
`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
__decorate([
|
|
261
|
+
property({ type: String })
|
|
262
|
+
], RecursivePopover.prototype, "placement", void 0);
|
|
263
|
+
__decorate([
|
|
264
|
+
property({ type: Number })
|
|
265
|
+
], RecursivePopover.prototype, "depth", void 0);
|
|
266
|
+
__decorate([
|
|
267
|
+
query('[slot="trigger"]')
|
|
268
|
+
], RecursivePopover.prototype, "trigger", void 0);
|
|
269
|
+
customElements.define('recursive-popover', RecursivePopover);
|
|
270
|
+
export class PopoverContent extends LitElement {
|
|
271
|
+
render() {
|
|
272
|
+
return html `
|
|
273
|
+
<overlay-trigger>
|
|
274
|
+
<sp-button slot="trigger">Open me</sp-button>
|
|
275
|
+
<sp-popover slot="click-content" direction="bottom" dialog>
|
|
276
|
+
<p>This is all the content.</p>
|
|
277
|
+
<p>This is all the content.</p>
|
|
278
|
+
<p>This is all the content.</p>
|
|
279
|
+
<p>This is all the content.</p>
|
|
280
|
+
</sp-popover>
|
|
281
|
+
</overlay-trigger>
|
|
282
|
+
`;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
__decorate([
|
|
286
|
+
query('[slot="trigger"]')
|
|
287
|
+
], PopoverContent.prototype, "button", void 0);
|
|
288
|
+
__decorate([
|
|
289
|
+
query('overlay-trigger')
|
|
290
|
+
], PopoverContent.prototype, "trigger", void 0);
|
|
291
|
+
customElements.define('popover-content', PopoverContent);
|
|
292
|
+
//# sourceMappingURL=overlay-story-components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-story-components.js","sourceRoot":"","sources":["overlay-story-components.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EACH,GAAG,EAEH,IAAI,EACJ,UAAU,GAEb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,QAAQ,EACR,KAAK,GACR,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EAAE,OAAO,EAA6B,MAAM,KAAK,CAAC;AAEzD,OAAO,8CAA8C,CAAC;AAEtD,OAAO,gDAAgD,CAAC;AACxD,OAAO,4CAA4C,CAAC;AACpD,OAAO,kDAAkD,CAAC;AAC1D,OAAO,qDAAqD,CAAC;AAE7D,wCAAwC;AACxC,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB,MAAM,iBAAkB,SAAQ,UAAU;IACtC,MAAM,KAAK,MAAM;QACb,OAAO,GAAG,CAAA;;;;;;;;;;SAUT,CAAC;IACN,CAAC;IAEM,MAAM;QACT,OAAO,IAAI,CAAA;;;;;;;;;;;;;;;SAeV,CAAC;IACN,CAAC;CACJ;AACD,cAAc,CAAC,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC;AAEhE,MAAM,WAAY,SAAQ,UAAU;IAApC;;QAEY,QAAG,GAAG,GAAG,CAAC;QAEV,SAAI,GAAG,GAAG,CAAC;IAyGvB,CAAC;IArGG,MAAM,KAAK,MAAM;QACb,OAAO,GAAG,CAAA;;;;;;;;;;;;;SAaT,CAAC;IACN,CAAC;IAEO,YAAY,CAAC,KAA0C;QAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAyB,CAAC;QAC7C,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;QAE/B,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACnC,MAAM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,cAAc,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;AAE7D,MAAM,OAAO,cAAe,SAAQ,UAAU;IAO1C,MAAM;QACF,OAAO,IAAI,CAAA;;;;;;;;;;SAUV,CAAC;IACN,CAAC;CACJ;AAlBG;IADC,KAAK,CAAC,kBAAkB,CAAC;8CACH;AAGvB;IADC,KAAK,CAAC,iBAAiB,CAAC;+CACO;AAiBpC,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n css,\n CSSResultGroup,\n html,\n LitElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport { Overlay, OverlayTrigger, Placement } from '../';\nimport { RadioGroup } from '@spectrum-web-components/radio';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { Button } from '@spectrum-web-components/button';\nimport '@spectrum-web-components/popover/sp-popover.js';\nimport '@spectrum-web-components/radio/sp-radio.js';\nimport '@spectrum-web-components/radio/sp-radio-group.js';\nimport '@spectrum-web-components/overlay/overlay-trigger.js';\n\n// Prevent infinite recursion in browser\nconst MAX_DEPTH = 7;\n\nclass OverlayTargetIcon extends LitElement {\n static get styles(): CSSResultGroup {\n return css`\n :host {\n position: absolute;\n display: block;\n color: var(--spectrum-global-color-magenta-700);\n width: 64px;\n height: 64px;\n top: 0;\n left: 0;\n }\n `;\n }\n\n public render(): TemplateResult {\n return html`\n <svg\n aria-hidden=\"true\"\n focusable=\"false\"\n data-prefix=\"fas\"\n data-icon=\"bullseye\"\n class=\"svg-inline--fa fa-bullseye fa-w-16\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 496 512\"\n >\n <path\n fill=\"currentColor\"\n d=\"M248 8C111.03 8 0 119.03 0 256s111.03 248 248 248 248-111.03 248-248S384.97 8 248 8zm0 432c-101.69 0-184-82.29-184-184 0-101.69 82.29-184 184-184 101.69 0 184 82.29 184 184 0 101.69-82.29 184-184 184zm0-312c-70.69 0-128 57.31-128 128s57.31 128 128 128 128-57.31 128-128-57.31-128-128-128zm0 192c-35.29 0-64-28.71-64-64s28.71-64 64-64 64 28.71 64 64-28.71 64-64 64z\"\n ></path>\n </svg>\n `;\n }\n}\ncustomElements.define('overlay-target-icon', OverlayTargetIcon);\n\nclass OverlayDrag extends LitElement {\n @property({ type: Number })\n private top = 100;\n @property({ type: Number })\n private left = 100;\n\n private targetElement: HTMLElement | undefined | null;\n\n static get styles(): CSSResultGroup {\n return css`\n :host {\n display: block;\n width: 100%;\n height: 100%;\n position: relative;\n }\n\n ::slotted(*) {\n display: block;\n width: 100%;\n height: 100%;\n }\n `;\n }\n\n private onSlotChange(event: Event & { target: HTMLSlotElement }): void {\n const slot = event.target as HTMLSlotElement;\n this.targetElement = undefined;\n\n const nodes = slot.assignedNodes();\n const slotElement = nodes.find(\n (node) => node instanceof HTMLElement\n ) as HTMLElement;\n if (!slotElement) return;\n\n this.targetElement = slotElement.querySelector(\n '[slot=\"trigger\"]'\n ) as HTMLElement;\n if (!this.targetElement) return;\n\n this.targetElement.addEventListener('mousedown', (event) =>\n this.onMouseDown(event)\n );\n\n this.resetTargetPosition();\n }\n\n private onMouseDown(event: MouseEvent): void {\n const target = event.target as HTMLElement;\n const parent = target.parentElement;\n if (!parent) return;\n\n const max = {\n x: parent.offsetWidth - target.offsetWidth,\n y: parent.offsetHeight - target.offsetHeight,\n };\n const dragStart = {\n x: event.clientX,\n y: event.clientY,\n };\n const originalPos = {\n x: this.left,\n y: this.top,\n };\n\n const onMouseMove = (event: MouseEvent): void => {\n const dragDelta = {\n x: event.clientX - dragStart.x,\n y: event.clientY - dragStart.y,\n };\n const newPosition = {\n x: dragDelta.x + originalPos.x,\n y: dragDelta.y + originalPos.y,\n };\n this.left = Math.min(Math.max(newPosition.x, 0), max.x);\n this.top = Math.min(Math.max(newPosition.y, 0), max.y);\n Overlay.update();\n };\n\n const onMouseUp = (): void => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', onMouseUp);\n };\n\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', onMouseUp);\n }\n\n public resetTargetPosition(): void {\n if (!this.targetElement) return;\n const target = this.targetElement as HTMLElement;\n const parent = target.parentElement;\n if (!parent) return;\n\n this.left = (parent.offsetWidth - target.offsetWidth) / 2;\n this.top = (parent.offsetHeight - target.offsetHeight) / 2;\n }\n\n public updated(): void {\n if (this.targetElement) {\n this.targetElement.style.transform = `translate(${this.left}px, ${this.top}px)`;\n }\n }\n\n public render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}></slot>\n `;\n }\n}\ncustomElements.define('overlay-drag', OverlayDrag);\n\nclass RecursivePopover extends LitElement {\n @property({ type: String })\n private placement: Placement;\n\n @property({ type: Number })\n private depth = 0;\n\n @query('[slot=\"trigger\"]')\n private trigger!: Button;\n\n protected isShiftTabbing = false;\n\n public shadowRoot!: ShadowRoot;\n\n public static get styles(): CSSResultGroup {\n return [\n css`\n :host {\n display: block;\n text-align: center;\n }\n\n overlay-trigger {\n display: inline-flex;\n margin-top: 11px;\n }\n `,\n ];\n }\n\n public constructor() {\n super();\n this.placement = 'right';\n this.depth = 0;\n this.addEventListener('keydown', (event: KeyboardEvent) => {\n const { code } = event;\n if (code === 'Enter') {\n this.trigger.click();\n }\n });\n this.addEventListener('focusin', this.handleFocusin);\n }\n\n private handleFocusin(): void {\n this.focus();\n }\n\n public focus(): void {\n if (this.shadowRoot.activeElement !== null) {\n return;\n }\n const firstFocusable = this.shadowRoot.querySelector(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n ) as LitElement;\n if (firstFocusable) {\n if (firstFocusable.updateComplete) {\n firstFocusable.updateComplete.then(() =>\n firstFocusable.focus()\n );\n } else {\n firstFocusable.focus();\n }\n return;\n }\n super.focus();\n }\n\n public onRadioChange(event: Event): void {\n const target = event.target as RadioGroup;\n this.placement = target.selected as Placement;\n }\n\n private captureEnter(event: KeyboardEvent): void {\n const { code } = event;\n if (code === 'Enter') {\n event.stopPropagation();\n }\n }\n\n public render(): TemplateResult {\n return html`\n <sp-radio-group\n horizontal\n @change=${this.onRadioChange}\n selected=\"${this.placement}\"\n name=\"group-example\"\n >\n <sp-radio value=\"top\">Top</sp-radio>\n <sp-radio value=\"right\">Right</sp-radio>\n <sp-radio value=\"bottom\">Bottom</sp-radio>\n <sp-radio value=\"left\">Left</sp-radio>\n </sp-radio-group>\n <overlay-trigger placement=\"${this.placement}\" type=\"modal\">\n <sp-button\n slot=\"trigger\"\n variant=\"accent\"\n @keydown=${this.captureEnter}\n >\n Open Popover\n </sp-button>\n <sp-popover\n dialog\n slot=\"click-content\"\n direction=\"${this.placement}\"\n tip\n open\n >\n ${this.depth < MAX_DEPTH\n ? html`\n <recursive-popover\n position=\"${this.placement}\"\n depth=\"${this.depth + 1}\"\n tabindex=\"0\"\n ></recursive-popover>\n `\n : html`\n <div>Maximum Depth</div>\n `}\n </sp-popover>\n </overlay-trigger>\n `;\n }\n}\ncustomElements.define('recursive-popover', RecursivePopover);\n\nexport class PopoverContent extends LitElement {\n @query('[slot=\"trigger\"]')\n public button!: Button;\n\n @query('overlay-trigger')\n public trigger!: OverlayTrigger;\n\n render(): TemplateResult {\n return html`\n <overlay-trigger>\n <sp-button slot=\"trigger\">Open me</sp-button>\n <sp-popover slot=\"click-content\" direction=\"bottom\" dialog>\n <p>This is all the content.</p>\n <p>This is all the content.</p>\n <p>This is all the content.</p>\n <p>This is all the content.</p>\n </sp-popover>\n </overlay-trigger>\n `;\n }\n}\n\ncustomElements.define('popover-content', PopoverContent);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'popover-content': PopoverContent;\n }\n}\n"]}
|