@operato/popup 8.0.0-beta.0 → 8.0.0-beta.1
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/CHANGELOG.md +9 -0
- package/package.json +4 -4
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/preview.js +0 -52
- package/.storybook/server.mjs +0 -8
- package/src/index.ts +0 -7
- package/src/open-popup.ts +0 -166
- package/src/ox-floating-overlay.ts +0 -618
- package/src/ox-popup-list.ts +0 -577
- package/src/ox-popup-menu.ts +0 -247
- package/src/ox-popup-menuitem.ts +0 -187
- package/src/ox-popup.ts +0 -400
- package/src/ox-prompt.ts +0 -549
- package/src/position-converter.ts +0 -37
- package/stories/open-popup.stories.ts +0 -104
- package/stories/ox-popup-list-sortable.stories.ts +0 -215
- package/stories/ox-popup-list.stories.ts +0 -121
- package/stories/ox-popup-menu.stories.ts +0 -188
- package/stories/ox-popup.stories.ts +0 -79
- package/stories/ox-prompt-icon.stories.ts +0 -87
- package/stories/ox-prompt-normal.stories.ts +0 -80
- package/stories/ox-prompt.stories.ts +0 -82
- package/tsconfig.json +0 -25
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
package/src/ox-prompt.ts
DELETED
@@ -1,549 +0,0 @@
|
|
1
|
-
import '@material/web/button/filled-button.js'
|
2
|
-
import '@material/web/button/outlined-button.js'
|
3
|
-
import '@material/web/icon/icon.js'
|
4
|
-
import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
|
5
|
-
|
6
|
-
import { css, html, nothing, LitElement } from 'lit'
|
7
|
-
import { render } from 'lit-html'
|
8
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
9
|
-
import { ScrollbarStyles } from '@operato/styles'
|
10
|
-
|
11
|
-
const TYPES_ICON = {
|
12
|
-
success: 'verified',
|
13
|
-
error: 'error',
|
14
|
-
warning: 'warning',
|
15
|
-
info: 'info',
|
16
|
-
question: 'question_mark'
|
17
|
-
}
|
18
|
-
|
19
|
-
/**
|
20
|
-
* The `ox-prompt` custom element represents a modal popup that provides information or options for the user, such as confirmation or cancellation.
|
21
|
-
*/
|
22
|
-
@customElement('ox-prompt')
|
23
|
-
export class OxPrompt extends LitElement {
|
24
|
-
static styles = [
|
25
|
-
MDTypeScaleStyles,
|
26
|
-
ScrollbarStyles,
|
27
|
-
css`
|
28
|
-
:host {
|
29
|
-
position: absolute;
|
30
|
-
display: flex;
|
31
|
-
flex-direction: column;
|
32
|
-
gap: var(--ox-prompt-gap, var(--spacing-medium));
|
33
|
-
background-color: var(--ox-popup-list-background-color, var(--md-sys-color-surface));
|
34
|
-
z-index: 100;
|
35
|
-
padding: var(--ox-prompt-container-padding, var(--spacing-medium));
|
36
|
-
box-shadow: var(--ox-prompt-container-box-shadow, 2px 3px 10px 5px rgba(0, 0, 0, 0.15));
|
37
|
-
border-radius: var(--ox-prompt-container-border-radius, var(--md-sys-shape-corner-medium));
|
38
|
-
box-sizing: border-box;
|
39
|
-
min-width: 300;
|
40
|
-
line-height: initial;
|
41
|
-
text-align: initial;
|
42
|
-
}
|
43
|
-
|
44
|
-
:host([active]) {
|
45
|
-
display: block;
|
46
|
-
}
|
47
|
-
|
48
|
-
:host(*:focus) {
|
49
|
-
outline: none;
|
50
|
-
}
|
51
|
-
|
52
|
-
[titler] {
|
53
|
-
padding: var(--ox-prompt-title-padding, var(--spacing-medium));
|
54
|
-
padding-bottom: 0;
|
55
|
-
color: var(--ox-prompt-title-color, var(--md-sys-color-primary));
|
56
|
-
font-size: var(--md-sys-typescale-label-large-weight, var(--md-ref-typeface-weight-medium, 500));
|
57
|
-
font-weight: var(--md-sys-typescale-label-large-weight, var(--md-ref-typeface-weight-medium, 500));
|
58
|
-
}
|
59
|
-
|
60
|
-
[content] {
|
61
|
-
display: flex;
|
62
|
-
flex-direction: column;
|
63
|
-
gap: var(--ox-prompt-content-gap, var(--spacing-medium));
|
64
|
-
padding: var(--ox-prompt-content-padding, var(--spacing-medium));
|
65
|
-
color: var(--ox-prompt-body-color, var(--md-sys-color-on-surface));
|
66
|
-
word-break: keep-all;
|
67
|
-
white-space: pre-line;
|
68
|
-
|
69
|
-
md-icon {
|
70
|
-
align-self: center;
|
71
|
-
--md-icon-size: var(--icon-size-huge);
|
72
|
-
color: var(--ox-prompt-body-color-variant, var(--md-sys-color-primary));
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
[content].warning md-icon {
|
77
|
-
color: var(--status-warning-color, #ee8d03);
|
78
|
-
}
|
79
|
-
|
80
|
-
[content].error md-icon {
|
81
|
-
color: var(--md-sys-color-error, var(--md-sys-color-error));
|
82
|
-
}
|
83
|
-
|
84
|
-
[content].info md-icon {
|
85
|
-
color: var(--status-info-color, #398ace);
|
86
|
-
}
|
87
|
-
|
88
|
-
[content].success md-icon {
|
89
|
-
color: var(--status-success-color, #35a24a);
|
90
|
-
}
|
91
|
-
|
92
|
-
[buttons] {
|
93
|
-
display: flex;
|
94
|
-
border-top: 1px solid var(--md-sys-color-surface-variant);
|
95
|
-
gap: var(--ox-prompt-buttons-spacing, var(--spacing-large));
|
96
|
-
padding: var(--ox-prompt-buttons-padding, var(--spacing-medium));
|
97
|
-
padding-top: var(--spacing-large);
|
98
|
-
justify-content: center;
|
99
|
-
}
|
100
|
-
|
101
|
-
#confirm {
|
102
|
-
--md-filled-button-container-color: var(--md-sys-color-primary);
|
103
|
-
--md-filled-button-label-text-color: var(--md-sys-color-on-primary);
|
104
|
-
--md-filled-button-label-text-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
105
|
-
--md-filled-button-container-height: var(--form-element-height-medium);
|
106
|
-
--md-filled-button-container-shape: var(--md-sys-shape-corner-small);
|
107
|
-
--md-filled-button-leading-space: var(--spacing-large);
|
108
|
-
--md-filled-button-trailing-space: var(--spacing-large);
|
109
|
-
}
|
110
|
-
|
111
|
-
#cancel {
|
112
|
-
--md-outlined-button-container-color: var(--md-sys-color-surface-variant);
|
113
|
-
--md-outlined-button-label-text-color: var(--md-sys-color-on-surface-variant);
|
114
|
-
--md-outlined-button-label-text-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
115
|
-
--md-outlined-button-container-height: var(--form-element-height-medium);
|
116
|
-
--md-outlined-button-container-shape: var(--md-sys-shape-corner-small);
|
117
|
-
--md-outlined-button-leading-space: var(--spacing-large);
|
118
|
-
--md-outlined-button-trailing-space: var(--spacing-large);
|
119
|
-
}
|
120
|
-
`
|
121
|
-
]
|
122
|
-
|
123
|
-
/**
|
124
|
-
* Specifies the type of the popup. Possible values are 'success', 'error', 'warning', 'info', 'question'.
|
125
|
-
*/
|
126
|
-
@property({ type: String }) type?: 'success' | 'error' | 'warning' | 'info' | 'question'
|
127
|
-
|
128
|
-
/**
|
129
|
-
* Specifies the icon of the popup.
|
130
|
-
*/
|
131
|
-
@property({ type: String }) icon?: string
|
132
|
-
|
133
|
-
/**
|
134
|
-
* Specifies the title of the popup.
|
135
|
-
*/
|
136
|
-
@property({ type: String }) titler?: string = ''
|
137
|
-
|
138
|
-
/**
|
139
|
-
* Specifies the text content of the popup.
|
140
|
-
*/
|
141
|
-
@property({ type: String }) text?: string
|
142
|
-
|
143
|
-
/**
|
144
|
-
* Specifies the footer (additional information at the bottom) of the popup.
|
145
|
-
*/
|
146
|
-
@property({ type: String }) footer?: string
|
147
|
-
|
148
|
-
/**
|
149
|
-
* Determines whether the popup is displayed as a toast.
|
150
|
-
*/
|
151
|
-
@property({ type: Boolean }) toast?: boolean
|
152
|
-
|
153
|
-
/**
|
154
|
-
* Specifies settings for the confirmation button.
|
155
|
-
*/
|
156
|
-
@property({ type: Object }) confirmButton?: { text: string; color?: string }
|
157
|
-
|
158
|
-
/**
|
159
|
-
* Specifies settings for the cancel button.
|
160
|
-
*/
|
161
|
-
@property({ type: Object }) cancelButton?: { text: string; color?: string }
|
162
|
-
|
163
|
-
/**
|
164
|
-
* Prevents the popup from closing when it loses focus (blur event).
|
165
|
-
*/
|
166
|
-
@property({ type: Boolean, attribute: 'prevent-close-on-blur' }) preventCloseOnBlur: boolean = false
|
167
|
-
|
168
|
-
/**
|
169
|
-
* A callback function called when the popup is closed, providing the result of the user's interaction.
|
170
|
-
*/
|
171
|
-
@property({ type: Object }) callback?: (result: { value: boolean }) => void
|
172
|
-
|
173
|
-
@state() _parent?: Element
|
174
|
-
|
175
|
-
private resolveFn: ((value: boolean) => void) | null = null
|
176
|
-
|
177
|
-
render() {
|
178
|
-
return html`
|
179
|
-
${this.titler ? html` <div titler class="md-typescale-title-large">${this.titler}</div> ` : nothing}
|
180
|
-
<div content class="${this.type || 'info'} md-typescale-body-large">
|
181
|
-
${this.icon || this.type
|
182
|
-
? html` <md-icon icon>${this.icon || TYPES_ICON[this.type || 'info']}</md-icon> `
|
183
|
-
: nothing}
|
184
|
-
${this.text ? html` <div text>${this.text}</div> ` : nothing}
|
185
|
-
<slot> </slot>
|
186
|
-
${this.footer ? html` <div footer class="md-typescale-body-large">${this.footer}</div> ` : nothing}
|
187
|
-
</div>
|
188
|
-
<div buttons>
|
189
|
-
${this.confirmButton
|
190
|
-
? html`
|
191
|
-
<md-filled-button id="confirm" type="button" @click=${(e: Event) => this.onConfirm()}
|
192
|
-
>${this.confirmButton?.text}</md-filled-button
|
193
|
-
>
|
194
|
-
`
|
195
|
-
: nothing}
|
196
|
-
${this.cancelButton
|
197
|
-
? html`
|
198
|
-
<md-outlined-button id="cancel" type="button" @click=${(e: Event) => this.onCancel()}
|
199
|
-
>${this.cancelButton?.text}</md-outlined-button
|
200
|
-
>
|
201
|
-
`
|
202
|
-
: nothing}
|
203
|
-
</div>
|
204
|
-
`
|
205
|
-
}
|
206
|
-
|
207
|
-
resolve(result: boolean) {
|
208
|
-
if (this.resolveFn) {
|
209
|
-
this.resolveFn(result)
|
210
|
-
this.resolveFn = null
|
211
|
-
}
|
212
|
-
}
|
213
|
-
|
214
|
-
/**
|
215
|
-
* Function called when the confirm button is clicked.
|
216
|
-
*/
|
217
|
-
onConfirm() {
|
218
|
-
this.resolve(true)
|
219
|
-
this.close()
|
220
|
-
}
|
221
|
-
|
222
|
-
/**
|
223
|
-
* Function called when the cancel button is clicked.
|
224
|
-
*/
|
225
|
-
onCancel() {
|
226
|
-
this.resolve(false)
|
227
|
-
this.close()
|
228
|
-
}
|
229
|
-
|
230
|
-
protected _onfocusout: (e: FocusEvent) => void = function (this: OxPrompt, e: FocusEvent) {
|
231
|
-
const to = e.relatedTarget as HTMLElement
|
232
|
-
|
233
|
-
if (!this.contains(to)) {
|
234
|
-
/* 분명히 내 범위가 아닌 엘리먼트로 포커스가 옮겨졌다면, ox-prompt은 닫혀야 한다. */
|
235
|
-
// @ts-ignore for debug
|
236
|
-
if (this.preventCloseOnBlur || window.POPUP_DEBUG) {
|
237
|
-
return
|
238
|
-
}
|
239
|
-
|
240
|
-
this.resolve(false)
|
241
|
-
this.close()
|
242
|
-
}
|
243
|
-
}.bind(this)
|
244
|
-
|
245
|
-
protected _onkeydown: (e: KeyboardEvent) => void = function (this: OxPrompt, e: KeyboardEvent) {
|
246
|
-
e.stopPropagation()
|
247
|
-
|
248
|
-
switch (e.key) {
|
249
|
-
case 'Esc': // for IE/Edge
|
250
|
-
case 'Escape':
|
251
|
-
this.resolve(false)
|
252
|
-
this.close()
|
253
|
-
break
|
254
|
-
}
|
255
|
-
}.bind(this)
|
256
|
-
|
257
|
-
protected _onkeyup: (e: KeyboardEvent) => void = function (this: OxPrompt, e: KeyboardEvent) {
|
258
|
-
e.stopPropagation()
|
259
|
-
}.bind(this)
|
260
|
-
|
261
|
-
protected _onmouseup: (e: MouseEvent) => void = function (this: OxPrompt, e: MouseEvent) {
|
262
|
-
e.stopPropagation()
|
263
|
-
}.bind(this)
|
264
|
-
|
265
|
-
protected _onmousedown: (e: MouseEvent) => void = function (this: OxPrompt, e: MouseEvent) {
|
266
|
-
e.stopPropagation()
|
267
|
-
}.bind(this)
|
268
|
-
|
269
|
-
protected _oncontextmenu: (e: Event) => void = function (this: OxPrompt, e: Event) {
|
270
|
-
e.stopPropagation()
|
271
|
-
}.bind(this)
|
272
|
-
|
273
|
-
protected _onclick: (e: MouseEvent) => void = function (this: OxPrompt, e: MouseEvent) {
|
274
|
-
e.stopPropagation()
|
275
|
-
}.bind(this)
|
276
|
-
|
277
|
-
protected _onclose: (e: Event) => void = function (this: OxPrompt, e: Event) {
|
278
|
-
this.resolve(false)
|
279
|
-
this.close()
|
280
|
-
}.bind(this)
|
281
|
-
|
282
|
-
protected _oncollapse: (e: Event) => void = function (this: OxPrompt, e: Event) {
|
283
|
-
e.stopPropagation()
|
284
|
-
|
285
|
-
this.resolve(false)
|
286
|
-
this.close()
|
287
|
-
}.bind(this)
|
288
|
-
|
289
|
-
protected _onwindowblur: (e: Event) => void = function (this: OxPrompt, e: Event) {
|
290
|
-
// @ts-ignore for debug
|
291
|
-
if (this.preventCloseOnBlur || window.POPUP_DEBUG) {
|
292
|
-
return
|
293
|
-
}
|
294
|
-
|
295
|
-
this.resolve(false)
|
296
|
-
this.close()
|
297
|
-
}.bind(this)
|
298
|
-
|
299
|
-
connectedCallback() {
|
300
|
-
super.connectedCallback()
|
301
|
-
|
302
|
-
this.addEventListener('focusout', this._onfocusout)
|
303
|
-
this.addEventListener('keydown', this._onkeydown)
|
304
|
-
this.addEventListener('keyup', this._onkeyup)
|
305
|
-
this.addEventListener('click', this._onclick)
|
306
|
-
this.addEventListener('mouseup', this._onmouseup)
|
307
|
-
this.addEventListener('mousedown', this._onmousedown)
|
308
|
-
this.addEventListener('contextmenu', this._oncontextmenu)
|
309
|
-
this.addEventListener('ox-close', this._onclose)
|
310
|
-
this.addEventListener('ox-collapse', this._oncollapse)
|
311
|
-
|
312
|
-
this.setAttribute('tabindex', '0') // make this element focusable
|
313
|
-
this.guaranteeFocus()
|
314
|
-
}
|
315
|
-
|
316
|
-
/**
|
317
|
-
* Static method to open the `ox-prompt` popup.
|
318
|
-
* @param {object} options - An object containing popup options.
|
319
|
-
* @param {unknown} [options.template] - An optional content template to render inside the popup.
|
320
|
-
* @param {'success' | 'error' | 'warning' | 'info' | 'question'} [options.type] - The type of the popup, which can be one of: 'success', 'error', 'warning', 'info', 'question'.
|
321
|
-
* @param {string} [options.icon] - The icon to be displayed in the popup header.
|
322
|
-
* @param {string} [options.title] - The title to be displayed in the popup header.
|
323
|
-
* @param {string} [options.text] - The main text content of the popup.
|
324
|
-
* @param {string} [options.footer] - Additional information to be displayed at the bottom of the popup.
|
325
|
-
* @param {object} [options.confirmButton] - Configuration for the confirmation button in the popup.
|
326
|
-
* @param {string} options.confirmButton.text - The text to be displayed on the confirmation button.
|
327
|
-
* @param {string} [options.confirmButton.color] - The color of the confirmation button (CSS color).
|
328
|
-
* @param {object} [options.cancelButton] - Configuration for the cancel button in the popup.
|
329
|
-
* @param {string} options.cancelButton.text - The text to be displayed on the cancel button.
|
330
|
-
* @param {string} [options.cancelButton.color] - The color of the cancel button (CSS color).
|
331
|
-
* @param {number} [options.top] - The top position of the popup (in pixels).
|
332
|
-
* @param {number} [options.left] - The left position of the popup (in pixels).
|
333
|
-
* @param {number} [options.right] - The right position of the popup (in pixels).
|
334
|
-
* @param {number} [options.bottom] - The bottom position of the popup (in pixels).
|
335
|
-
* @param {string} [options.width] - The maximum width of the popup (CSS string).
|
336
|
-
* @param {string} [options.height] - The maximum height of the popup (CSS string).
|
337
|
-
* @param {Element | null} [options.parent] - The parent element to which the popup should be attached. If not provided, it will be attached to the document body.
|
338
|
-
* @param {boolean} [options.preventCloseOnBlur] - Prevents the popup from closing when it loses focus (blur event).
|
339
|
-
* @param {(result: { value: boolean }) => void} [options.callback] - A callback function that will be invoked when the user interacts with the popup, providing the result of the interaction.
|
340
|
-
* @returns {Promise<boolean>} A Promise that resolves based on user interaction with the popup.
|
341
|
-
*/
|
342
|
-
public static async open({
|
343
|
-
template,
|
344
|
-
type,
|
345
|
-
icon,
|
346
|
-
title,
|
347
|
-
text,
|
348
|
-
footer,
|
349
|
-
confirmButton,
|
350
|
-
cancelButton,
|
351
|
-
top,
|
352
|
-
left,
|
353
|
-
right,
|
354
|
-
bottom,
|
355
|
-
width,
|
356
|
-
height,
|
357
|
-
parent,
|
358
|
-
preventCloseOnBlur,
|
359
|
-
callback
|
360
|
-
}: {
|
361
|
-
template?: unknown
|
362
|
-
type?: 'success' | 'error' | 'warning' | 'info' | 'question'
|
363
|
-
icon?: string
|
364
|
-
title?: string
|
365
|
-
text?: string
|
366
|
-
footer?: string
|
367
|
-
confirmButton?: { text: string; color?: string }
|
368
|
-
cancelButton?: { text: string; color?: string }
|
369
|
-
top?: number
|
370
|
-
left?: number
|
371
|
-
right?: number
|
372
|
-
bottom?: number
|
373
|
-
width?: string
|
374
|
-
height?: string
|
375
|
-
parent?: Element | null
|
376
|
-
preventCloseOnBlur?: boolean
|
377
|
-
callback?: (result: { value: boolean }) => void
|
378
|
-
}): Promise<boolean> {
|
379
|
-
const owner = parent || document.body
|
380
|
-
const target = document.createElement('ox-prompt') as OxPrompt
|
381
|
-
|
382
|
-
target.type = type
|
383
|
-
target.icon = icon
|
384
|
-
target.text = text
|
385
|
-
target.titler = title
|
386
|
-
target.footer = footer
|
387
|
-
target.confirmButton = confirmButton
|
388
|
-
target.cancelButton = cancelButton
|
389
|
-
target.preventCloseOnBlur = !!preventCloseOnBlur
|
390
|
-
|
391
|
-
render(template, target)
|
392
|
-
|
393
|
-
target._parent = owner
|
394
|
-
owner.appendChild(target)
|
395
|
-
|
396
|
-
const result = await target.open({ top, left, right, bottom, width, height })
|
397
|
-
|
398
|
-
if (callback) {
|
399
|
-
await callback.call(null, { value: result })
|
400
|
-
}
|
401
|
-
|
402
|
-
return result
|
403
|
-
}
|
404
|
-
|
405
|
-
/**
|
406
|
-
* Opens the popup with specified position and dimensions.
|
407
|
-
* @param {object} options - An object specifying the position and dimensions of the popup.
|
408
|
-
* @param {number} [options.left] - The left position of the popup (in pixels). If not provided, the popup will be horizontally centered.
|
409
|
-
* @param {number} [options.top] - The top position of the popup (in pixels). If not provided, the popup will be vertically centered.
|
410
|
-
* @param {number} [options.right] - The right position of the popup (in pixels). Overrides 'left' if both 'left' and 'right' are provided.
|
411
|
-
* @param {number} [options.bottom] - The bottom position of the popup (in pixels). Overrides 'top' if both 'top' and 'bottom' are provided.
|
412
|
-
* @param {string} [options.width] - The maximum width of the popup (CSS string). If not provided, no width restriction is applied.
|
413
|
-
* @param {string} [options.height] - The maximum height of the popup (CSS string). If not provided, no height restriction is applied.
|
414
|
-
* @param {boolean} [options.silent=false] - Determines whether to focus the popup automatically (true) or not (false).
|
415
|
-
* @returns {Promise<boolean>} A Promise that resolves based on user interaction with the popup.
|
416
|
-
*/
|
417
|
-
open({
|
418
|
-
left,
|
419
|
-
top,
|
420
|
-
right,
|
421
|
-
bottom,
|
422
|
-
width,
|
423
|
-
height,
|
424
|
-
silent = false
|
425
|
-
}: {
|
426
|
-
left?: number
|
427
|
-
top?: number
|
428
|
-
right?: number
|
429
|
-
bottom?: number
|
430
|
-
width?: string
|
431
|
-
height?: string
|
432
|
-
silent?: boolean
|
433
|
-
}): Promise<boolean> {
|
434
|
-
if (width) {
|
435
|
-
this.style.maxWidth = width
|
436
|
-
this.style.overflowX = 'auto'
|
437
|
-
}
|
438
|
-
|
439
|
-
if (height) {
|
440
|
-
this.style.maxHeight = height
|
441
|
-
this.style.overflowY = 'auto'
|
442
|
-
}
|
443
|
-
|
444
|
-
if (left === undefined && top === undefined && right === undefined && bottom === undefined) {
|
445
|
-
this.style.left = '50%'
|
446
|
-
this.style.top = '50%'
|
447
|
-
this.style.transform = 'translateX(-50%) translateY(-50%)'
|
448
|
-
} else {
|
449
|
-
if (left !== undefined) this.style.left = `${left}px`
|
450
|
-
if (top !== undefined) this.style.top = `${top}px`
|
451
|
-
if (right !== undefined) this.style.right = `${right}px`
|
452
|
-
if (bottom !== undefined) this.style.bottom = `${bottom}px`
|
453
|
-
}
|
454
|
-
|
455
|
-
this.setAttribute('active', '')
|
456
|
-
|
457
|
-
// adjust popup position
|
458
|
-
requestAnimationFrame(() => {
|
459
|
-
const vh = document.body.clientHeight
|
460
|
-
const vw = document.body.clientWidth
|
461
|
-
|
462
|
-
var bounding = this.getBoundingClientRect()
|
463
|
-
|
464
|
-
var h = bounding.height
|
465
|
-
var w = bounding.width
|
466
|
-
var t = bounding.top
|
467
|
-
var l = bounding.left
|
468
|
-
|
469
|
-
// If the popup is too large, it will cause overflow scrolling.
|
470
|
-
if (vh < h) {
|
471
|
-
this.style.height = `${Math.min(Math.max(Math.floor((vh * 2) / 3), vh - (t + 20)), vh)}px`
|
472
|
-
this.style.overflow = 'auto'
|
473
|
-
h = vh
|
474
|
-
}
|
475
|
-
|
476
|
-
if (vw < w) {
|
477
|
-
this.style.width = `${Math.min(Math.max(Math.floor((vw * 2) / 3), vw - (l + 20)), vw)}px`
|
478
|
-
this.style.overflow = 'auto'
|
479
|
-
w = vw
|
480
|
-
}
|
481
|
-
|
482
|
-
// To prevent pop-ups from crossing screen boundaries, use the
|
483
|
-
const computedStyle = getComputedStyle(this)
|
484
|
-
|
485
|
-
if (t < 0) {
|
486
|
-
this.style.top = `calc(${computedStyle.top} + ${t}px)`
|
487
|
-
this.style.bottom = ''
|
488
|
-
} else if (vh <= t + h) {
|
489
|
-
this.style.top = `calc(${computedStyle.top} - ${t + h - vh}px)`
|
490
|
-
this.style.bottom = ''
|
491
|
-
}
|
492
|
-
|
493
|
-
if (l < 0) {
|
494
|
-
this.style.left = `calc(${computedStyle.left} + ${l}px)`
|
495
|
-
this.style.right = ''
|
496
|
-
} else if (vw < l + w) {
|
497
|
-
this.style.left = `calc(${computedStyle.left} - ${l + w - vw}px)`
|
498
|
-
this.style.right = ''
|
499
|
-
}
|
500
|
-
})
|
501
|
-
|
502
|
-
// auto focusing
|
503
|
-
!silent && this.guaranteeFocus()
|
504
|
-
|
505
|
-
/* When the window is out of focus, all pop-ups should disappear. */
|
506
|
-
window.addEventListener('blur', this._onwindowblur)
|
507
|
-
|
508
|
-
return new Promise(resolve => {
|
509
|
-
this.resolveFn = resolve
|
510
|
-
})
|
511
|
-
}
|
512
|
-
|
513
|
-
guaranteeFocus(target?: HTMLElement) {
|
514
|
-
const focusible = (target || this).querySelector(
|
515
|
-
':scope > button, :scope > [href], :scope > input, :scope > select, :scope > textarea, :scope > [tabindex]:not([tabindex="-1"])'
|
516
|
-
)
|
517
|
-
|
518
|
-
if (focusible) {
|
519
|
-
;(focusible as HTMLElement).focus()
|
520
|
-
} else {
|
521
|
-
this.focus()
|
522
|
-
}
|
523
|
-
}
|
524
|
-
|
525
|
-
/**
|
526
|
-
* Closes the popup.
|
527
|
-
*/
|
528
|
-
close() {
|
529
|
-
this.removeAttribute('active')
|
530
|
-
|
531
|
-
window.removeEventListener('blur', this._onwindowblur)
|
532
|
-
|
533
|
-
if (this._parent) {
|
534
|
-
/* this case is when the popup is opened by OxPrompt.open(...) */
|
535
|
-
this.removeEventListener('focusout', this._onfocusout)
|
536
|
-
this.removeEventListener('keydown', this._onkeydown)
|
537
|
-
this.removeEventListener('keyup', this._onkeyup)
|
538
|
-
this.removeEventListener('click', this._onclick)
|
539
|
-
this.removeEventListener('ox-close', this._onclose)
|
540
|
-
this.removeEventListener('ox-collapse', this._oncollapse)
|
541
|
-
this.removeEventListener('mouseup', this._onmouseup)
|
542
|
-
this.removeEventListener('mousedown', this._onmousedown)
|
543
|
-
this.removeEventListener('contextmenu', this._oncontextmenu)
|
544
|
-
|
545
|
-
this._parent.removeChild(this)
|
546
|
-
delete this._parent
|
547
|
-
}
|
548
|
-
}
|
549
|
-
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
interface PositionOptions {
|
2
|
-
left?: number
|
3
|
-
top?: number
|
4
|
-
right?: number
|
5
|
-
bottom?: number
|
6
|
-
relativeElement: HTMLElement
|
7
|
-
}
|
8
|
-
|
9
|
-
interface FixedPosition {
|
10
|
-
left?: number
|
11
|
-
top?: number
|
12
|
-
right?: number
|
13
|
-
bottom?: number
|
14
|
-
}
|
15
|
-
|
16
|
-
export function convertToFixedPosition({ left, top, right, bottom, relativeElement }: PositionOptions): FixedPosition {
|
17
|
-
// Get bounding rectangle of the relative element
|
18
|
-
const rect = relativeElement.getBoundingClientRect()
|
19
|
-
|
20
|
-
// Get the viewport dimensions
|
21
|
-
const viewportHeight = window.innerHeight
|
22
|
-
const viewportWidth = window.innerWidth
|
23
|
-
|
24
|
-
// Calculate fixed positions
|
25
|
-
const fixedLeft = left !== undefined ? rect.left + left : undefined
|
26
|
-
const fixedTop = top !== undefined ? rect.top + top : undefined
|
27
|
-
const fixedRight = right !== undefined ? viewportWidth - rect.right + right : undefined
|
28
|
-
const fixedBottom = bottom !== undefined ? viewportHeight - rect.bottom + bottom : undefined
|
29
|
-
|
30
|
-
// Return the new fixed position values
|
31
|
-
return {
|
32
|
-
left: fixedLeft,
|
33
|
-
top: fixedTop,
|
34
|
-
right: fixedRight,
|
35
|
-
bottom: fixedBottom
|
36
|
-
}
|
37
|
-
}
|
@@ -1,104 +0,0 @@
|
|
1
|
-
import '@material/web/all.js'
|
2
|
-
import { html, TemplateResult } from 'lit'
|
3
|
-
|
4
|
-
import { openPopup, PopupOptions } from '../src/open-popup'
|
5
|
-
import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
|
6
|
-
|
7
|
-
export default {
|
8
|
-
title: 'openPopup',
|
9
|
-
component: 'ox-popup',
|
10
|
-
argTypes: {
|
11
|
-
title: { constol: 'string' },
|
12
|
-
size: { control: 'select', options: ['large', 'medium', 'small'] },
|
13
|
-
hovering: { control: 'select', options: ['center', 'next', 'edge'] },
|
14
|
-
closable: { control: 'boolean' },
|
15
|
-
escapable: { control: 'boolean' },
|
16
|
-
backdrop: { control: 'boolean' },
|
17
|
-
help: { constol: 'string' }
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
interface Story<T> {
|
22
|
-
(args: T): TemplateResult
|
23
|
-
args?: Partial<T>
|
24
|
-
argTypes?: Record<string, unknown>
|
25
|
-
}
|
26
|
-
|
27
|
-
interface ArgTypes {
|
28
|
-
title: string
|
29
|
-
size: 'large' | 'medium' | 'small'
|
30
|
-
hovering: 'center' | 'next' | 'edge'
|
31
|
-
closable: boolean
|
32
|
-
escapable: boolean
|
33
|
-
backdrop: boolean
|
34
|
-
help: string
|
35
|
-
}
|
36
|
-
|
37
|
-
function popup(e: MouseEvent, options: PopupOptions) {
|
38
|
-
const noImage = new URL('/assets/images/no-image.png', import.meta.url).href
|
39
|
-
|
40
|
-
return openPopup(html`<img src=${noImage} />`, options)
|
41
|
-
}
|
42
|
-
|
43
|
-
const Template: Story<ArgTypes> = ({
|
44
|
-
title = '',
|
45
|
-
size = 'medium',
|
46
|
-
hovering = 'center',
|
47
|
-
closable,
|
48
|
-
escapable,
|
49
|
-
backdrop,
|
50
|
-
help
|
51
|
-
}: ArgTypes) => html`
|
52
|
-
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
|
53
|
-
|
54
|
-
<link href="/themes/light.css" rel="stylesheet" />
|
55
|
-
<link href="/themes/dark.css" rel="stylesheet" />
|
56
|
-
<link href="/themes/spacing.css" rel="stylesheet" />
|
57
|
-
|
58
|
-
<link
|
59
|
-
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
|
60
|
-
rel="stylesheet"
|
61
|
-
/>
|
62
|
-
<link
|
63
|
-
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
|
64
|
-
rel="stylesheet"
|
65
|
-
/>
|
66
|
-
<link
|
67
|
-
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
|
68
|
-
rel="stylesheet"
|
69
|
-
/>
|
70
|
-
|
71
|
-
<style>
|
72
|
-
${MDTypeScaleStyles.cssText}
|
73
|
-
</style>
|
74
|
-
|
75
|
-
<style>
|
76
|
-
#place {
|
77
|
-
width: 100%;
|
78
|
-
height: 500px;
|
79
|
-
text-align: center;
|
80
|
-
|
81
|
-
background-color: var(--md-sys-color-primary-container);
|
82
|
-
color: var(--md-sys-color-on-primary-container);
|
83
|
-
}
|
84
|
-
</style>
|
85
|
-
|
86
|
-
<div
|
87
|
-
id="place"
|
88
|
-
@click=${(e: MouseEvent) => popup(e, { title, size, hovering, closable, escapable, backdrop, help })}
|
89
|
-
class="md-typescale-display-medium"
|
90
|
-
>
|
91
|
-
Click this to popup image
|
92
|
-
</div>
|
93
|
-
`
|
94
|
-
|
95
|
-
export const Regular = Template.bind({})
|
96
|
-
Regular.args = {
|
97
|
-
title: 'Regular popup',
|
98
|
-
size: 'medium',
|
99
|
-
hovering: 'center',
|
100
|
-
closable: true,
|
101
|
-
escapable: true,
|
102
|
-
backdrop: true,
|
103
|
-
help: ''
|
104
|
-
}
|