Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | 92x 216x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 698x 698x 698x 377x 377x 377x 698x 698x 698x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 176x 176x 176x 150x 150x 150x 150x 176x 160x 160x 160x 160x 160x 160x 160x 160x 160x 92x 391x 391x 391x 391x 176x 176x 391x 391x 162x 162x 162x 92x 92x 391x 183x 183x 183x 162x 162x 162x 153x 153x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 183x 183x 183x 162x 295x 162x 21x 21x 21x 21x 21x 21x 19x 92x 8x 8x 8x 8x 8x 8x 4x 4x 4x 4x 4x 4x 92x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 92x 92x 2x 92x 4x 4x 4x 4x 4x 4x 4x 92x 92x 1x 1x 1x 92x 12x 12x 12x 12x 3x 3x 1x 1x 1x 1x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 61x 61x 61x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x | import { property } from 'lit/decorators.js';
import { TemplateResult, html, css, PropertyValues } from 'lit';
import { Button } from '../display/Button';
import { CustomEventType } from '../interfaces';
import { styleMap } from 'lit-html/directives/style-map.js';
import { getClasses } from '../utils';
import { ResizeElement } from '../ResizeElement';
export enum ButtonType {
PRIMARY = 'primary',
SECONDARY = 'secondary',
DESTRUCTIVE = 'destructive'
}
export class DialogButton {
name?: string;
id?: string;
details?: any;
type?: string;
closes?: boolean;
}
export class Dialog extends ResizeElement {
static get widths(): { [size: string]: string } {
return {
small: '400px',
medium: '600px',
large: '655px',
xlarge: '800px'
};
}
static get styles() {
return css`
:host {
position: absolute;
z-index: 10000;
font-family: var(--font-family);
background: white;
}
.flex-grow {
flex-grow: 1;
}
.flex {
display: flex;
flex-direction: column;
width: 100%;
position: relative;
left: 0px;
top: 0px;
align-items: center;
height: 100vh;
}
.mobile .flex {
height: 100%;
position: fixed;
}
.mobile .grow-top {
flex-grow: 0;
}
.mobile .grow-bottom {
flex-grow: 0;
}
.grow-top {
flex-grow: 1;
}
.grow-bottom {
flex-grow: 3;
}
.bottom-padding {
padding: 3rem;
}
.dialog-mask {
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
opacity: 0;
position: fixed;
top: 0px;
left: 0px;
transition: opacity linear calc(var(--transition-speed) / 2ms);
pointer-events: none;
}
.mobile.dialog-mask .dialog-container {
border-radius: 0px;
}
.dialog-mask .dialog-container {
position: relative;
transition:
transform var(--transition-speed) ease-in-out,
opacity ease-in-out calc(var(--transition-speed) - 50ms);
border-radius: var(--curvature);
box-shadow: 0px 0px 2px 4px rgba(0, 0, 0, 0.06);
overflow: hidden;
transform: scale(0.9) translatey(2em);
background: white;
margin: auto;
display: flex;
flex-direction: column;
}
.dialog-body {
background: #fff;
overflow-y: auto;
overflow-x: hidden;
flex-grow: 1;
}
.dialog-mask.dialog-open {
opacity: 1;
pointer-events: auto;
}
.dialog-mask.dialog-open .dialog-container {
top: inherit;
}
.dialog-mask.dialog-animation-end .dialog-container {
transform: scale(1) translate(0, 0) !important;
}
.dialog-mask.dialog-ready .dialog-container {
transform: none;
}
.dialog-mask.dialog-loading .dialog-container {
margin-top: -10000px;
}
.header-text {
display: flex;
flex-direction: row;
align-items: center;
font-size: 20px;
padding: 12px 20px var(--dialog-header-padding-bottom, 12px);
color: var(--header-text);
background: var(--header-bg);
}
/* "flat" variant: header/footer share the body's white background
and lose their inner padding so the dialog reads as one
continuous surface. Use for content-focused dialogs that don't
need the tinted chrome. */
:host([variant='flat']) .header-text {
background: #fff;
color: var(--color-text);
padding-bottom: 0;
}
:host([variant='flat']) .dialog-footer {
background: #fff;
padding-top: 0;
}
.header-text .title {
flex-grow: 1;
}
.header-text .status {
font-size: 0.6em;
font-weight: bold;
}
.dialog-footer {
background: var(--dialog-footer-background, var(--color-primary-light));
padding: var(--dialog-footer-padding-top, 10px) 10px 10px;
display: flex;
flex-flow: row;
align-items: center;
}
temba-button {
margin-left: 10px;
--button-y: 0.4em;
--button-x: 1em;
}
.dialog-body temba-loading {
position: absolute;
right: 12px;
margin-top: -30px;
padding-bottom: 9px;
display: none;
}
#page-loader {
text-align: center;
display: block;
position: relative;
opacity: 0;
margin: auto;
margin-top: 30px;
width: 154px;
transition: opacity calc(var(--transition-speed) * 5ms) ease-in
calc(var(--transition-speed * 2));
visibility: hidden;
}
.dialog-mask.dialog-loading #page-loader {
opacity: 1;
visibility: visible;
}
#submit-loader {
flex-grow: 1;
text-align: right;
}
`;
}
@property({ type: Boolean })
open: boolean;
@property()
header: string;
@property()
body: string;
@property({ type: Boolean })
submitting: boolean;
@property({ type: Boolean })
destructive: boolean;
@property({ type: Boolean })
disabled: boolean;
@property({ type: Boolean })
loading: boolean;
@property({ type: Boolean })
hideOnClick: boolean;
@property({ type: String, reflect: true })
variant: string;
@property({ type: Boolean })
noFocus: boolean;
@property()
size = 'medium';
@property({ type: String })
primaryButtonName = 'Ok';
@property({ type: String })
cancelButtonName = 'Cancel';
@property({ type: String })
width = null;
@property()
submittingName = 'Saving';
@property()
animationEnd: boolean;
@property()
ready: boolean;
@property({ type: Array })
buttons: DialogButton[] = [];
@property({ attribute: false })
onButtonClicked: (button: Button) => void;
@property({ type: Number })
originX: number | null = null;
@property({ type: Number })
originY: number | null = null;
scrollOffset: any = 0;
public constructor() {
super();
}
private updateButtons() {
this.buttons = [];
if (this.cancelButtonName) {
this.buttons.push({
name: this.cancelButtonName,
type: ButtonType.SECONDARY,
closes: true
});
}
if (this.primaryButtonName) {
this.buttons.push({
name: this.primaryButtonName,
type: ButtonType.PRIMARY
});
}
}
public willUpdate(changes: PropertyValues) {
super.willUpdate(changes);
if (changes.has('cancelButtonName') || changes.has('primaryButtonName')) {
this.updateButtons();
}
if (changes.has('open') && this.open) {
if (this.originX == null && this.originY == null) {
// Default animation (no origin): set animationEnd before render
this.animationEnd = true;
}
}
}
public updated(changes: Map<string, any>) {
super.updated(changes);
if (changes.has('open')) {
const body = document.querySelector('body');
if (this.open) {
if (this.originX != null && this.originY != null) {
// Spring-from-origin animation: measure final position, then
// set initial transform at click point and transition to center
const ox = this.originX;
const oy = this.originY;
this.originX = null;
this.originY = null;
requestAnimationFrame(() => {
const container = this.shadowRoot?.querySelector(
'.dialog-container'
) as HTMLElement;
if (container) {
const rect = container.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
const dx = ox - cx;
const dy = oy - cy;
// Disable transition so we can set the start position instantly
container.style.transition = 'none';
container.style.transform = `translate(${dx}px, ${dy}px) scale(0.2)`;
// Force reflow to register the start position
container.getBoundingClientRect();
// Re-enable transition and trigger animation to final position
container.style.transition = '';
this.animationEnd = true;
window.setTimeout(() => {
this.ready = true;
this.animationEnd = false;
container.style.transform = '';
}, 400);
}
});
} else {
// Default animation (no origin): animationEnd already set in willUpdate
window.setTimeout(() => {
this.ready = true;
this.animationEnd = false;
}, 400);
}
this.scrollOffset = -document.documentElement.scrollTop;
body.style.position = 'fixed';
body.style.overflowY = 'scroll';
body.style.top = this.scrollOffset + 'px';
body.style.width = '100%';
body.style.overflowY = 'hidden';
} else {
body.style.position = '';
body.style.overflowY = '';
body.style.width = '';
body.style.marginRight = '';
body.style.paddingRight = '0px';
window.scrollTo(0, parseInt(this.scrollOffset || '0') * -1);
}
// make sure our buttons aren't in progress on show
if (this.open && !changes.get('open')) {
this.shadowRoot
.querySelectorAll('temba-button')
.forEach((button: Button) => {
if (button) button.submitting = false;
});
} else {
window.setTimeout(() => {
this.ready = false;
}, 400);
}
}
}
public focusFirstInput(): void {
window.setTimeout(() => {
let input = this.querySelector(
'temba-textinput, temba-completion, input[type="text"], textarea'
) as any;
if (input) {
input = input.textInputElement || input.inputElement || input;
if (!input.readOnly) {
input.focus();
input.click();
}
}
}, 100);
}
public handleClick(evt: MouseEvent) {
const button = evt.currentTarget as Button;
if (!button.disabled) {
let detail: DialogButton = {};
if (button.index >= 0 && button.index < this.buttons.length) {
detail = this.buttons[button.index];
}
this.fireCustomEvent(CustomEventType.ButtonClicked, { button, detail });
if (button.name === this.cancelButtonName || (detail && detail.closes)) {
this.open = false;
}
}
}
private getDocumentHeight(): number {
const body = document.body;
const html = document.documentElement;
return Math.max(
body.scrollHeight,
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
);
}
private clickCancel() {
const cancel = this.getCancelButton();
if (cancel) {
cancel.click();
}
}
public getCancelButton(): Button {
return this.shadowRoot.querySelector(
`temba-button[name='${this.cancelButtonName}']`
);
}
public getPrimaryButton(): Button {
return this.shadowRoot.querySelector(`temba-button[primary]`);
}
private handleKeyUp(event: KeyboardEvent) {
if (event.key === 'Escape') {
this.clickCancel();
}
}
private handleClickMask(event: MouseEvent) {
if (this.hideOnClick) {
const id = (event.target as HTMLElement).id;
if (id === 'dialog-mask' || id === 'dialog-bg') {
this.fireCustomEvent(CustomEventType.DialogHidden);
this.clickCancel();
}
}
}
public show(): void {
this.open = true;
}
public hide(): void {
this.open = false;
}
public render(): TemplateResult {
const dialogStyle = {
width: this.width
};
if (!this.width) {
dialogStyle['width'] = Dialog.widths[this.size];
}
if (this.isMobile()) {
dialogStyle['width'] = '100%';
dialogStyle['height'] = '100%';
delete dialogStyle['maxWidth'];
}
const header = this.header
? html`
<div class="dialog-header">
<div class="header-text">
<div class="title">${this.header}</div>
</div>
</div>
`
: null;
return html`
<div
id="dialog-mask"
@click=${this.handleClickMask}
class="dialog-mask ${getClasses({
'dialog-open': this.open,
'dialog-loading': this.loading,
'dialog-animation-end': this.animationEnd,
'dialog-ready': this.ready,
mobile: this.isMobile()
})}"
>
<div style="position: absolute; width: 100%;">
<temba-loading
id="page-loader"
units="6"
size="12"
color="#ccc"
></temba-loading>
</div>
<div class="flex">
<div class="grow-top" style="${
this.isMobile() ? 'flex-grow:0' : ''
}"></div>
<div
@keyup=${this.handleKeyUp}
style=${styleMap(dialogStyle)}
class="dialog-container"
>
${header}
<div class="dialog-body" @keypress=${this.handleKeyUp}>
${this.body ? this.body : html`<slot></slot>`}
<temba-loading units="6" size="8"></temba-loading>
</div>
<div class="dialog-footer">
<div class="flex-grow">
<slot name="gutter"></slot>
</div>
${this.buttons.map(
(button: DialogButton, index) => html`
<temba-button
name=${button.name}
?destructive=${button.type == 'primary' && this.destructive}
?primary=${button.type == 'primary' && !this.destructive}
?secondary=${button.type == 'secondary'}
?submitting=${this.submitting}
?disabled=${this.disabled && !button.closes}
index=${index}
@click=${this.handleClick}
></temba-button>
`
)}
</div>
</div>
<div class="grow-bottom"></div>
</div>
</div>
</div>
`;
}
}
|