cps-ui-kit 0.27.0 → 0.28.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/README.md +1 -0
- package/esm2020/lib/directives/cps-tooltip.directive.mjs +201 -0
- package/esm2020/public-api.mjs +2 -1
- package/fesm2015/cps-ui-kit.mjs +201 -1
- package/fesm2015/cps-ui-kit.mjs.map +1 -1
- package/fesm2020/cps-ui-kit.mjs +199 -1
- package/fesm2020/cps-ui-kit.mjs.map +1 -1
- package/lib/directives/cps-tooltip.directive.d.ts +35 -0
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
- package/styles/cps-tooltip-style.scss +13 -0
- package/styles/styles.scss +2 -1
- /package/styles/{_variables.scss → variables.scss} +0 -0
package/fesm2020/cps-ui-kit.mjs
CHANGED
|
@@ -3348,6 +3348,204 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
3348
3348
|
type: Output
|
|
3349
3349
|
}] } });
|
|
3350
3350
|
|
|
3351
|
+
class CpsTooltipDirective {
|
|
3352
|
+
// eslint-disable-next-line no-useless-constructor
|
|
3353
|
+
constructor(_elementRef) {
|
|
3354
|
+
this._elementRef = _elementRef;
|
|
3355
|
+
this.tooltipOpenDelay = 300;
|
|
3356
|
+
this.tooltipCloseDelay = 300;
|
|
3357
|
+
this.tooltipOpenOn = 'hover';
|
|
3358
|
+
this.tooltipPosition = 'top';
|
|
3359
|
+
this.tooltipPersistent = false;
|
|
3360
|
+
this.tooltipDisabled = false;
|
|
3361
|
+
this.tooltipMaxWidth = '100%';
|
|
3362
|
+
this.tooltipContentClass = 'cps-tooltip-content';
|
|
3363
|
+
this._createTooltip = () => {
|
|
3364
|
+
if (this._popup)
|
|
3365
|
+
this._destroyTooltip();
|
|
3366
|
+
if (this.tooltipDisabled)
|
|
3367
|
+
return;
|
|
3368
|
+
this._popup = document.createElement('div');
|
|
3369
|
+
this._constructElement(this._popup);
|
|
3370
|
+
if (this.tooltipPersistent)
|
|
3371
|
+
this._popup.addEventListener('click', this._destroyTooltip);
|
|
3372
|
+
window.addEventListener('scroll', this._destroyTooltip, true);
|
|
3373
|
+
};
|
|
3374
|
+
this._destroyTooltip = () => {
|
|
3375
|
+
window.removeEventListener('scroll', this._destroyTooltip, true);
|
|
3376
|
+
this._popup?.removeEventListener('click', this._destroyTooltip);
|
|
3377
|
+
this._popup?.remove();
|
|
3378
|
+
this._popup = undefined;
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
ngOnDestroy() {
|
|
3382
|
+
this._destroyTooltip();
|
|
3383
|
+
}
|
|
3384
|
+
_constructElement(popup) {
|
|
3385
|
+
const popupContent = document.createElement('div');
|
|
3386
|
+
popupContent.innerHTML = this.tooltip || 'Add your text to this tooltip';
|
|
3387
|
+
popupContent.classList.add(this.tooltipContentClass);
|
|
3388
|
+
popup.appendChild(popupContent);
|
|
3389
|
+
popup.classList.add('cps-tooltip');
|
|
3390
|
+
popup.style.maxWidth = convertSize(this.tooltipMaxWidth);
|
|
3391
|
+
document.body.appendChild(popup);
|
|
3392
|
+
const coords = this._getCoords();
|
|
3393
|
+
if (!coords) {
|
|
3394
|
+
this._destroyTooltip();
|
|
3395
|
+
throw new Error('Not enough space on the screen for the tooltip!');
|
|
3396
|
+
}
|
|
3397
|
+
popup.style.left = coords.left.toString() + 'px';
|
|
3398
|
+
popup.style.top = coords.top.toString() + 'px';
|
|
3399
|
+
}
|
|
3400
|
+
_getCoords() {
|
|
3401
|
+
function isInsideScreen(coords) {
|
|
3402
|
+
return (coords.top >= 0 &&
|
|
3403
|
+
coords.left >= 0 &&
|
|
3404
|
+
coords.left + popupRect.width <= window.innerWidth &&
|
|
3405
|
+
coords.top + popupRect.height <= window.innerHeight);
|
|
3406
|
+
}
|
|
3407
|
+
let positions = ['top', 'bottom', 'left', 'right'];
|
|
3408
|
+
positions = positions.filter((item) => item !== this.tooltipPosition);
|
|
3409
|
+
positions.unshift(this.tooltipPosition);
|
|
3410
|
+
const targetEl = this._elementRef.nativeElement;
|
|
3411
|
+
const targetElRect = targetEl.getBoundingClientRect();
|
|
3412
|
+
const popupRect = this._popup.getBoundingClientRect();
|
|
3413
|
+
for (const pos of positions) {
|
|
3414
|
+
const coords = this._getCoordsForPosition(pos, targetEl, targetElRect, popupRect);
|
|
3415
|
+
if (isInsideScreen(coords)) {
|
|
3416
|
+
return coords;
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
return undefined;
|
|
3420
|
+
}
|
|
3421
|
+
_getCoordsForPosition(position, targetEl, targetElRect, popupRect) {
|
|
3422
|
+
switch (position) {
|
|
3423
|
+
case 'bottom':
|
|
3424
|
+
return {
|
|
3425
|
+
left: targetElRect.left +
|
|
3426
|
+
window.scrollX +
|
|
3427
|
+
(targetEl.offsetWidth - popupRect.width) / 2,
|
|
3428
|
+
top: targetElRect.bottom + window.scrollY + 8
|
|
3429
|
+
};
|
|
3430
|
+
case 'left':
|
|
3431
|
+
return {
|
|
3432
|
+
left: targetElRect.left - window.scrollX - popupRect.width - 8,
|
|
3433
|
+
top: targetElRect.top +
|
|
3434
|
+
window.scrollY +
|
|
3435
|
+
(targetEl.offsetHeight - popupRect.height) / 2
|
|
3436
|
+
};
|
|
3437
|
+
case 'right':
|
|
3438
|
+
return {
|
|
3439
|
+
left: targetElRect.right + window.scrollX + 8,
|
|
3440
|
+
top: targetElRect.top +
|
|
3441
|
+
window.scrollY +
|
|
3442
|
+
(targetEl.offsetHeight - popupRect.height) / 2
|
|
3443
|
+
};
|
|
3444
|
+
default:
|
|
3445
|
+
return {
|
|
3446
|
+
left: targetElRect.left +
|
|
3447
|
+
window.scrollX +
|
|
3448
|
+
(targetEl.offsetWidth - popupRect.width) / 2,
|
|
3449
|
+
top: targetElRect.top + window.scrollY - popupRect.height - 8
|
|
3450
|
+
};
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
onMouseEnter() {
|
|
3454
|
+
if (this.tooltipOpenOn === 'hover') {
|
|
3455
|
+
clearTimeout(this._hideTimeout);
|
|
3456
|
+
this._showTimeout = setTimeout(this._createTooltip, this.tooltipOpenDelay);
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
onMouseLeave() {
|
|
3460
|
+
clearTimeout(this._showTimeout);
|
|
3461
|
+
if (!this.tooltipPersistent) {
|
|
3462
|
+
this._hideTimeout = setTimeout(this._destroyTooltip, this.tooltipCloseDelay);
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3465
|
+
onFocus() {
|
|
3466
|
+
if (this.tooltipOpenOn === 'focus') {
|
|
3467
|
+
clearTimeout(this._hideTimeout);
|
|
3468
|
+
this._showTimeout = setTimeout(this._createTooltip, this.tooltipOpenDelay);
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
onBlur() {
|
|
3472
|
+
clearTimeout(this._showTimeout);
|
|
3473
|
+
if (!this.tooltipPersistent && this.tooltipOpenOn === 'focus') {
|
|
3474
|
+
this._hideTimeout = setTimeout(this._destroyTooltip, this.tooltipCloseDelay);
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
onClick() {
|
|
3478
|
+
if (this.tooltipOpenOn === 'click') {
|
|
3479
|
+
clearTimeout(this._hideTimeout);
|
|
3480
|
+
this._showTimeout = setTimeout(this._createTooltip, 0);
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
onPageResize() {
|
|
3484
|
+
if (this._popup)
|
|
3485
|
+
this._destroyTooltip();
|
|
3486
|
+
}
|
|
3487
|
+
onDocumentClick(target) {
|
|
3488
|
+
if (this.tooltipPersistent && this._popup) {
|
|
3489
|
+
if (!target?.isConnected) {
|
|
3490
|
+
return;
|
|
3491
|
+
}
|
|
3492
|
+
const clickedInside = this._elementRef?.nativeElement?.contains(target);
|
|
3493
|
+
if (!clickedInside) {
|
|
3494
|
+
this._destroyTooltip();
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
CpsTooltipDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CpsTooltipDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
3500
|
+
CpsTooltipDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: CpsTooltipDirective, isStandalone: true, selector: "[cpsTooltip]", inputs: { tooltip: ["cpsTooltip", "tooltip"], tooltipOpenDelay: "tooltipOpenDelay", tooltipCloseDelay: "tooltipCloseDelay", tooltipOpenOn: "tooltipOpenOn", tooltipPosition: "tooltipPosition", tooltipPersistent: "tooltipPersistent", tooltipDisabled: "tooltipDisabled", tooltipMaxWidth: "tooltipMaxWidth", tooltipContentClass: "tooltipContentClass" }, host: { listeners: { "mouseenter": "onMouseEnter()", "mouseleave": "onMouseLeave()", "focus": "onFocus()", "blur": "onBlur()", "click": "onClick()", "window:resize": "onPageResize()", "document:click": "onDocumentClick($event.target)" } }, ngImport: i0 });
|
|
3501
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CpsTooltipDirective, decorators: [{
|
|
3502
|
+
type: Directive,
|
|
3503
|
+
args: [{
|
|
3504
|
+
selector: '[cpsTooltip]',
|
|
3505
|
+
standalone: true
|
|
3506
|
+
}]
|
|
3507
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { tooltip: [{
|
|
3508
|
+
type: Input,
|
|
3509
|
+
args: ['cpsTooltip']
|
|
3510
|
+
}], tooltipOpenDelay: [{
|
|
3511
|
+
type: Input
|
|
3512
|
+
}], tooltipCloseDelay: [{
|
|
3513
|
+
type: Input
|
|
3514
|
+
}], tooltipOpenOn: [{
|
|
3515
|
+
type: Input
|
|
3516
|
+
}], tooltipPosition: [{
|
|
3517
|
+
type: Input
|
|
3518
|
+
}], tooltipPersistent: [{
|
|
3519
|
+
type: Input
|
|
3520
|
+
}], tooltipDisabled: [{
|
|
3521
|
+
type: Input
|
|
3522
|
+
}], tooltipMaxWidth: [{
|
|
3523
|
+
type: Input
|
|
3524
|
+
}], tooltipContentClass: [{
|
|
3525
|
+
type: Input
|
|
3526
|
+
}], onMouseEnter: [{
|
|
3527
|
+
type: HostListener,
|
|
3528
|
+
args: ['mouseenter']
|
|
3529
|
+
}], onMouseLeave: [{
|
|
3530
|
+
type: HostListener,
|
|
3531
|
+
args: ['mouseleave']
|
|
3532
|
+
}], onFocus: [{
|
|
3533
|
+
type: HostListener,
|
|
3534
|
+
args: ['focus']
|
|
3535
|
+
}], onBlur: [{
|
|
3536
|
+
type: HostListener,
|
|
3537
|
+
args: ['blur']
|
|
3538
|
+
}], onClick: [{
|
|
3539
|
+
type: HostListener,
|
|
3540
|
+
args: ['click']
|
|
3541
|
+
}], onPageResize: [{
|
|
3542
|
+
type: HostListener,
|
|
3543
|
+
args: ['window:resize']
|
|
3544
|
+
}], onDocumentClick: [{
|
|
3545
|
+
type: HostListener,
|
|
3546
|
+
args: ['document:click', ['$event.target']]
|
|
3547
|
+
}] } });
|
|
3548
|
+
|
|
3351
3549
|
class CpsButtonToggleComponent {
|
|
3352
3550
|
set value(value) {
|
|
3353
3551
|
this._value = value;
|
|
@@ -3462,5 +3660,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
3462
3660
|
* Generated bundle index. Do not edit.
|
|
3463
3661
|
*/
|
|
3464
3662
|
|
|
3465
|
-
export { CpsAutocompleteComponent, CpsButtonComponent, CpsButtonToggleComponent, CpsCheckboxComponent, CpsChipComponent, CpsDatepickerComponent, CpsExpansionPanelComponent, CpsIconComponent, CpsInputComponent, CpsLoaderComponent, CpsProgressCircularComponent, CpsProgressLinearComponent, CpsRadioComponent, CpsSelectComponent, CpsTableColumnSortableDirective, CpsTableComponent, CpsTagComponent, CpsTextareaComponent, CpsTreeAutocompleteComponent, CpsTreeSelectComponent, getCSSColor, getCpsColors, getTextColor, iconNames, tableFactory };
|
|
3663
|
+
export { CpsAutocompleteComponent, CpsButtonComponent, CpsButtonToggleComponent, CpsCheckboxComponent, CpsChipComponent, CpsDatepickerComponent, CpsExpansionPanelComponent, CpsIconComponent, CpsInputComponent, CpsLoaderComponent, CpsProgressCircularComponent, CpsProgressLinearComponent, CpsRadioComponent, CpsSelectComponent, CpsTableColumnSortableDirective, CpsTableComponent, CpsTagComponent, CpsTextareaComponent, CpsTooltipDirective, CpsTreeAutocompleteComponent, CpsTreeSelectComponent, getCSSColor, getCpsColors, getTextColor, iconNames, tableFactory };
|
|
3466
3664
|
//# sourceMappingURL=cps-ui-kit.mjs.map
|