@4sh/ui-kit 0.1.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/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +229 -0
- package/fesm2022/4sh-ui-kit-forms.mjs +501 -0
- package/fesm2022/4sh-ui-kit-forms.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-motion.mjs +155 -0
- package/fesm2022/4sh-ui-kit-motion.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-overlay.mjs +61 -0
- package/fesm2022/4sh-ui-kit-overlay.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-theming.mjs +120 -0
- package/fesm2022/4sh-ui-kit-theming.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-types.mjs +12 -0
- package/fesm2022/4sh-ui-kit-types.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-accordion.mjs +244 -0
- package/fesm2022/4sh-ui-kit-ui-accordion.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-alert.mjs +160 -0
- package/fesm2022/4sh-ui-kit-ui-alert.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-autocomplete.mjs +926 -0
- package/fesm2022/4sh-ui-kit-ui-autocomplete.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-avatar-group.mjs +34 -0
- package/fesm2022/4sh-ui-kit-ui-avatar-group.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-avatar.mjs +122 -0
- package/fesm2022/4sh-ui-kit-ui-avatar.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-badge.mjs +95 -0
- package/fesm2022/4sh-ui-kit-ui-badge.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-breadcrumb.mjs +190 -0
- package/fesm2022/4sh-ui-kit-ui-breadcrumb.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-button-split.mjs +151 -0
- package/fesm2022/4sh-ui-kit-ui-button-split.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-button.mjs +222 -0
- package/fesm2022/4sh-ui-kit-ui-button.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-card.mjs +164 -0
- package/fesm2022/4sh-ui-kit-ui-card.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-checkbox.mjs +118 -0
- package/fesm2022/4sh-ui-kit-ui-checkbox.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-chip.mjs +205 -0
- package/fesm2022/4sh-ui-kit-ui-chip.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-context-menu.mjs +219 -0
- package/fesm2022/4sh-ui-kit-ui-context-menu.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-datepicker.mjs +1508 -0
- package/fesm2022/4sh-ui-kit-ui-datepicker.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-drawer.mjs +300 -0
- package/fesm2022/4sh-ui-kit-ui-drawer.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-empty-state.mjs +148 -0
- package/fesm2022/4sh-ui-kit-ui-empty-state.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-field.mjs +102 -0
- package/fesm2022/4sh-ui-kit-ui-field.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-file-upload.mjs +568 -0
- package/fesm2022/4sh-ui-kit-ui-file-upload.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-helper.mjs +85 -0
- package/fesm2022/4sh-ui-kit-ui-helper.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-icon.mjs +98 -0
- package/fesm2022/4sh-ui-kit-ui-icon.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-image.mjs +201 -0
- package/fesm2022/4sh-ui-kit-ui-image.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-group.mjs +119 -0
- package/fesm2022/4sh-ui-kit-ui-input-group.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-mask.mjs +125 -0
- package/fesm2022/4sh-ui-kit-ui-input-mask.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-number.mjs +234 -0
- package/fesm2022/4sh-ui-kit-ui-input-number.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-otp.mjs +288 -0
- package/fesm2022/4sh-ui-kit-ui-input-otp.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input-tags.mjs +679 -0
- package/fesm2022/4sh-ui-kit-ui-input-tags.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-input.mjs +121 -0
- package/fesm2022/4sh-ui-kit-ui-input.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-label.mjs +61 -0
- package/fesm2022/4sh-ui-kit-ui-label.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-link.mjs +147 -0
- package/fesm2022/4sh-ui-kit-ui-link.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-menu.mjs +484 -0
- package/fesm2022/4sh-ui-kit-ui-menu.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-modal.mjs +555 -0
- package/fesm2022/4sh-ui-kit-ui-modal.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-nudger.mjs +168 -0
- package/fesm2022/4sh-ui-kit-ui-nudger.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-paginator.mjs +245 -0
- package/fesm2022/4sh-ui-kit-ui-paginator.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-popover.mjs +296 -0
- package/fesm2022/4sh-ui-kit-ui-popover.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-progress-bar.mjs +124 -0
- package/fesm2022/4sh-ui-kit-ui-progress-bar.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-radio.mjs +92 -0
- package/fesm2022/4sh-ui-kit-ui-radio.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-rating.mjs +185 -0
- package/fesm2022/4sh-ui-kit-ui-rating.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-read-only.mjs +146 -0
- package/fesm2022/4sh-ui-kit-ui-read-only.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-segment-control.mjs +386 -0
- package/fesm2022/4sh-ui-kit-ui-segment-control.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-select.mjs +868 -0
- package/fesm2022/4sh-ui-kit-ui-select.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-separator.mjs +77 -0
- package/fesm2022/4sh-ui-kit-ui-separator.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-sidebar.mjs +577 -0
- package/fesm2022/4sh-ui-kit-ui-sidebar.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-skeleton.mjs +81 -0
- package/fesm2022/4sh-ui-kit-ui-skeleton.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-slider.mjs +340 -0
- package/fesm2022/4sh-ui-kit-ui-slider.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-spinner.mjs +132 -0
- package/fesm2022/4sh-ui-kit-ui-spinner.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-stepper.mjs +389 -0
- package/fesm2022/4sh-ui-kit-ui-stepper.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-table.mjs +1406 -0
- package/fesm2022/4sh-ui-kit-ui-table.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-tabs.mjs +503 -0
- package/fesm2022/4sh-ui-kit-ui-tabs.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-tag.mjs +84 -0
- package/fesm2022/4sh-ui-kit-ui-tag.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-textarea.mjs +119 -0
- package/fesm2022/4sh-ui-kit-ui-textarea.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-toast.mjs +424 -0
- package/fesm2022/4sh-ui-kit-ui-toast.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-toggle.mjs +120 -0
- package/fesm2022/4sh-ui-kit-ui-toggle.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit-ui-tooltip.mjs +445 -0
- package/fesm2022/4sh-ui-kit-ui-tooltip.mjs.map +1 -0
- package/fesm2022/4sh-ui-kit.mjs +16 -0
- package/fesm2022/4sh-ui-kit.mjs.map +1 -0
- package/package.json +287 -0
- package/styles/base/_base.scss +19 -0
- package/styles/base/_motion.scss +144 -0
- package/styles/base/_typography.scss +99 -0
- package/styles/generated/_tokens-breakpoint.scss +8 -0
- package/styles/generated/_tokens-metrics.scss +37 -0
- package/styles/generated/_tokens-primitives.scss +284 -0
- package/styles/generated/_tokens-responsive.scss +99 -0
- package/styles/generated/_tokens-semantics.scss +1274 -0
- package/styles/generated/_tokens-styles.scss +35 -0
- package/styles/generated/_tokens-transitions.scss +11 -0
- package/styles/generated/_tokens-typography.scss +14 -0
- package/styles/generated/_tokens.scss +10 -0
- package/styles/index.scss +25 -0
- package/styles/settings/_ui-config.scss +67 -0
- package/styles/utils/_functions.scss +67 -0
- package/styles/utils/_helpers.scss +129 -0
- package/styles/utils/_mixins.scss +186 -0
- package/styles/utils/_motion.scss +47 -0
- package/styles/utils/_overlay.scss +26 -0
- package/styles/utils.scss +15 -0
- package/styles.css +1 -0
- package/types/4sh-ui-kit-forms.d.ts +259 -0
- package/types/4sh-ui-kit-motion.d.ts +111 -0
- package/types/4sh-ui-kit-overlay.d.ts +31 -0
- package/types/4sh-ui-kit-theming.d.ts +54 -0
- package/types/4sh-ui-kit-types.d.ts +13 -0
- package/types/4sh-ui-kit-ui-accordion.d.ts +140 -0
- package/types/4sh-ui-kit-ui-alert.d.ts +89 -0
- package/types/4sh-ui-kit-ui-autocomplete.d.ts +411 -0
- package/types/4sh-ui-kit-ui-avatar-group.d.ts +17 -0
- package/types/4sh-ui-kit-ui-avatar.d.ts +55 -0
- package/types/4sh-ui-kit-ui-badge.d.ts +38 -0
- package/types/4sh-ui-kit-ui-breadcrumb.d.ts +131 -0
- package/types/4sh-ui-kit-ui-button-split.d.ts +102 -0
- package/types/4sh-ui-kit-ui-button.d.ts +91 -0
- package/types/4sh-ui-kit-ui-card.d.ts +102 -0
- package/types/4sh-ui-kit-ui-checkbox.d.ts +54 -0
- package/types/4sh-ui-kit-ui-chip.d.ts +114 -0
- package/types/4sh-ui-kit-ui-context-menu.d.ts +105 -0
- package/types/4sh-ui-kit-ui-datepicker.d.ts +539 -0
- package/types/4sh-ui-kit-ui-drawer.d.ts +147 -0
- package/types/4sh-ui-kit-ui-empty-state.d.ts +93 -0
- package/types/4sh-ui-kit-ui-field.d.ts +53 -0
- package/types/4sh-ui-kit-ui-file-upload.d.ts +268 -0
- package/types/4sh-ui-kit-ui-helper.d.ts +46 -0
- package/types/4sh-ui-kit-ui-icon.d.ts +69 -0
- package/types/4sh-ui-kit-ui-image.d.ts +88 -0
- package/types/4sh-ui-kit-ui-input-group.d.ts +54 -0
- package/types/4sh-ui-kit-ui-input-mask.d.ts +63 -0
- package/types/4sh-ui-kit-ui-input-number.d.ts +96 -0
- package/types/4sh-ui-kit-ui-input-otp.d.ts +130 -0
- package/types/4sh-ui-kit-ui-input-tags.d.ts +350 -0
- package/types/4sh-ui-kit-ui-input.d.ts +78 -0
- package/types/4sh-ui-kit-ui-label.d.ts +36 -0
- package/types/4sh-ui-kit-ui-link.d.ts +72 -0
- package/types/4sh-ui-kit-ui-menu.d.ts +235 -0
- package/types/4sh-ui-kit-ui-modal.d.ts +241 -0
- package/types/4sh-ui-kit-ui-nudger.d.ts +79 -0
- package/types/4sh-ui-kit-ui-paginator.d.ts +150 -0
- package/types/4sh-ui-kit-ui-popover.d.ts +125 -0
- package/types/4sh-ui-kit-ui-progress-bar.d.ts +82 -0
- package/types/4sh-ui-kit-ui-radio.d.ts +44 -0
- package/types/4sh-ui-kit-ui-rating.d.ts +90 -0
- package/types/4sh-ui-kit-ui-read-only.d.ts +70 -0
- package/types/4sh-ui-kit-ui-segment-control.d.ts +184 -0
- package/types/4sh-ui-kit-ui-select.d.ts +392 -0
- package/types/4sh-ui-kit-ui-separator.d.ts +43 -0
- package/types/4sh-ui-kit-ui-sidebar.d.ts +358 -0
- package/types/4sh-ui-kit-ui-skeleton.d.ts +52 -0
- package/types/4sh-ui-kit-ui-slider.d.ts +127 -0
- package/types/4sh-ui-kit-ui-spinner.d.ts +67 -0
- package/types/4sh-ui-kit-ui-stepper.d.ts +220 -0
- package/types/4sh-ui-kit-ui-table.d.ts +570 -0
- package/types/4sh-ui-kit-ui-tabs.d.ts +225 -0
- package/types/4sh-ui-kit-ui-tag.d.ts +46 -0
- package/types/4sh-ui-kit-ui-textarea.d.ts +61 -0
- package/types/4sh-ui-kit-ui-toast.d.ts +247 -0
- package/types/4sh-ui-kit-ui-toggle.d.ts +67 -0
- package/types/4sh-ui-kit-ui-tooltip.d.ts +167 -0
- package/types/4sh-ui-kit.d.ts +4 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, output, viewChild, computed, forwardRef, Component } from '@angular/core';
|
|
3
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
4
|
+
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
5
|
+
import { BaseFieldControl } from '@4sh/ui-kit/forms';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ui-toggle — headless switch built on a real native `<input type="checkbox" role="switch">`.
|
|
9
|
+
*
|
|
10
|
+
* The native input stays in the DOM (invisible, covering the track) so keyboard,
|
|
11
|
+
* screen readers, label click and form semantics come for free. `role="switch"`
|
|
12
|
+
* + `aria-checked` make assistive tech announce it as on/off. Interactive states
|
|
13
|
+
* (hover/focus/disabled/checked) are pure CSS driven by `form.*` design tokens.
|
|
14
|
+
*
|
|
15
|
+
* Works standalone, with `[(ngModel)]` or reactive forms (ControlValueAccessor).
|
|
16
|
+
* By default the model value is boolean; `trueValue`/`falseValue` let the model
|
|
17
|
+
* carry any pair of values (e.g. 'on'/'off', 1/0).
|
|
18
|
+
*/
|
|
19
|
+
class UiToggle extends BaseFieldControl {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
/** Label displayed next to the switch (clicking it toggles the switch). */
|
|
23
|
+
this.label = input(/* @ts-ignore */
|
|
24
|
+
...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ []));
|
|
25
|
+
/** Side of the switch the label sits on (both sides are clickable). */
|
|
26
|
+
this.labelPosition = input('after', /* @ts-ignore */
|
|
27
|
+
...(ngDevMode ? [{ debugName: "labelPosition" }] : /* istanbul ignore next */ []));
|
|
28
|
+
/** Size. */
|
|
29
|
+
this.size = input('default', /* @ts-ignore */
|
|
30
|
+
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
31
|
+
/** Model value emitted when on. */
|
|
32
|
+
this.trueValue = input(true, /* @ts-ignore */
|
|
33
|
+
...(ngDevMode ? [{ debugName: "trueValue" }] : /* istanbul ignore next */ []));
|
|
34
|
+
/** Model value emitted when off. */
|
|
35
|
+
this.falseValue = input(false, /* @ts-ignore */
|
|
36
|
+
...(ngDevMode ? [{ debugName: "falseValue" }] : /* istanbul ignore next */ []));
|
|
37
|
+
/**
|
|
38
|
+
* Custom handle (thumb) template. Receives a `{ checked }` context, so the
|
|
39
|
+
* rendered content can react to the on/off state (e.g. a check / times icon).
|
|
40
|
+
*/
|
|
41
|
+
this.handle = input(/* @ts-ignore */
|
|
42
|
+
...(ngDevMode ? [undefined, { debugName: "handle" }] : /* istanbul ignore next */ []));
|
|
43
|
+
/** Emitted on user toggle with the new model value (never when disabled/readonly). */
|
|
44
|
+
this.toggleChange = output();
|
|
45
|
+
/** Emitted when the native input receives focus. */
|
|
46
|
+
this.toggleFocus = output();
|
|
47
|
+
/** Emitted when the native input loses focus. */
|
|
48
|
+
this.toggleBlur = output();
|
|
49
|
+
/** @ignore */
|
|
50
|
+
this.inputEl = viewChild.required('inputEl', /* @ts-ignore */
|
|
51
|
+
...(ngDevMode ? [{ debugName: "inputEl" }] : /* istanbul ignore next */ []));
|
|
52
|
+
/** @ignore */
|
|
53
|
+
this.checked = computed(() => this.modelValue() === this.trueValue(), /* @ts-ignore */
|
|
54
|
+
...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
|
|
55
|
+
/** @ignore A visible label is provided. */
|
|
56
|
+
this.hasLabel = computed(() => !!this.label(), /* @ts-ignore */
|
|
57
|
+
...(ngDevMode ? [{ debugName: "hasLabel" }] : /* istanbul ignore next */ []));
|
|
58
|
+
/** @ignore Context handed to the custom handle template. */
|
|
59
|
+
this.handleContext = computed(() => ({ checked: this.checked() }), /* @ts-ignore */
|
|
60
|
+
...(ngDevMode ? [{ debugName: "handleContext" }] : /* istanbul ignore next */ []));
|
|
61
|
+
/** @ignore */
|
|
62
|
+
this.classes = computed(() => {
|
|
63
|
+
const c = ['ui-toggle'];
|
|
64
|
+
if (this.size() !== 'default')
|
|
65
|
+
c.push(`_${this.size()}`);
|
|
66
|
+
if (this.checked())
|
|
67
|
+
c.push('_checked');
|
|
68
|
+
if (this.isDisabled())
|
|
69
|
+
c.push('_disabled');
|
|
70
|
+
if (this.readonly())
|
|
71
|
+
c.push('_readonly');
|
|
72
|
+
if (this.isInvalid())
|
|
73
|
+
c.push('_invalid');
|
|
74
|
+
return c.join(' ');
|
|
75
|
+
}, /* @ts-ignore */
|
|
76
|
+
...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
|
|
77
|
+
}
|
|
78
|
+
/** @ignore */
|
|
79
|
+
uidPrefix() {
|
|
80
|
+
return 'ui-toggle';
|
|
81
|
+
}
|
|
82
|
+
/** Focus the native input programmatically. */
|
|
83
|
+
focus(options) {
|
|
84
|
+
this.inputEl().nativeElement.focus(options);
|
|
85
|
+
}
|
|
86
|
+
/** @ignore Native change: single source of truth for user toggles. */
|
|
87
|
+
onNativeChange() {
|
|
88
|
+
const inputEl = this.inputEl().nativeElement;
|
|
89
|
+
if (this.readonly()) {
|
|
90
|
+
inputEl.checked = this.checked(); // revert the native toggle
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const value = inputEl.checked ? this.trueValue() : this.falseValue();
|
|
94
|
+
this.modelValue.set(value);
|
|
95
|
+
this.emitChange(value);
|
|
96
|
+
this.toggleChange.emit(value);
|
|
97
|
+
}
|
|
98
|
+
/** @ignore */
|
|
99
|
+
onBlur(event) {
|
|
100
|
+
this.emitTouch();
|
|
101
|
+
this.toggleBlur.emit(event);
|
|
102
|
+
}
|
|
103
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiToggle, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
|
104
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: UiToggle, isStandalone: true, selector: "ui-toggle", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, labelPosition: { classPropertyName: "labelPosition", publicName: "labelPosition", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, trueValue: { classPropertyName: "trueValue", publicName: "trueValue", isSignal: true, isRequired: false, transformFunction: null }, falseValue: { classPropertyName: "falseValue", publicName: "falseValue", isSignal: true, isRequired: false, transformFunction: null }, handle: { classPropertyName: "handle", publicName: "handle", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { toggleChange: "toggleChange", toggleFocus: "toggleFocus", toggleBlur: "toggleBlur" }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiToggle), multi: true }], viewQueries: [{ propertyName: "inputEl", first: true, predicate: ["inputEl"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "<label [class]=\"classes()\">\n @if (hasLabel() && labelPosition() === 'before') {\n <ng-container [ngTemplateOutlet]=\"labelTpl\" />\n }\n\n <span class=\"ui-toggle-control\">\n <input\n #inputEl\n type=\"checkbox\"\n role=\"switch\"\n class=\"ui-toggle-input\"\n [id]=\"resolvedId()\"\n [checked]=\"checked()\"\n [disabled]=\"isDisabled()\"\n [required]=\"required()\"\n [attr.name]=\"name() || null\"\n [attr.tabindex]=\"tabindex()\"\n [attr.aria-checked]=\"checked()\"\n [attr.aria-label]=\"label() ? null : ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-invalid]=\"isInvalid() ? 'true' : null\"\n (change)=\"onNativeChange()\"\n (focus)=\"toggleFocus.emit($event)\"\n (blur)=\"onBlur($event)\"\n />\n <span class=\"ui-toggle-track\" aria-hidden=\"true\">\n <span class=\"ui-toggle-thumb\">\n @if (handle(); as tpl) {\n <ng-container [ngTemplateOutlet]=\"tpl\" [ngTemplateOutletContext]=\"handleContext()\" />\n }\n </span>\n </span>\n </span>\n\n @if (hasLabel() && labelPosition() === 'after') {\n <ng-container [ngTemplateOutlet]=\"labelTpl\" />\n }\n</label>\n\n<ng-template #labelTpl>\n <span class=\"ui-toggle-label\">\n <span class=\"ui-toggle-text\">{{ label() }}</span>\n @if (required()) {\n <span class=\"ui-toggle-required\" aria-hidden=\"true\">*</span>\n }\n </span>\n</ng-template>\n", styles: [".ui-toggle{display:inline-flex;align-items:center;gap:var(--units-sm);cursor:pointer}.ui-toggle-control{position:relative;display:inline-flex;flex-shrink:0}.ui-toggle-input{position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;opacity:0;cursor:inherit}.ui-toggle-track{display:flex;align-items:center;box-sizing:border-box;border:var(--stroke-sm) solid transparent;border-radius:var(--radius-full);background-color:var(--form-low-content-default);transition:background-color var(--transition-default) var(--transition-easeinout),border-color var(--transition-default) var(--transition-easeinout),box-shadow var(--transition-default) var(--transition-easeinout)}.ui-toggle-thumb{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;box-sizing:border-box;border-radius:var(--radius-full);background-color:var(--form-high-surface-default);color:var(--form-low-content-default);line-height:0;overflow:hidden;transition:transform var(--transition-default) var(--transition-easeinout),background-color var(--transition-default) var(--transition-easeinout)}.ui-toggle .ui-toggle-track{width:2.75rem;height:1.5rem;padding:.0625rem}.ui-toggle .ui-toggle-thumb{width:1.25rem;height:1.25rem}.ui-toggle._checked .ui-toggle-thumb{transform:translate(1.25rem)}.ui-toggle._small .ui-toggle-track{width:2.25rem;height:1.25rem;padding:.0625rem}.ui-toggle._small .ui-toggle-thumb{width:1rem;height:1rem}.ui-toggle._small._checked .ui-toggle-thumb{transform:translate(1rem)}.ui-toggle:hover:not(._disabled):not(._readonly) .ui-toggle-track{background-color:var(--form-low-content-hover)}.ui-toggle._checked:hover:not(._disabled):not(._readonly) .ui-toggle-track{background-color:var(--form-high-content-hover)}.ui-toggle._checked .ui-toggle-track{background-color:var(--form-high-content-checked)}.ui-toggle:has(.ui-toggle-input:focus-visible) .ui-toggle-track{box-shadow:0 0 0 var(--units-2xs) rgb(from var(--form-high-stroke-focused) r g b/50%)}.ui-toggle._invalid .ui-toggle-track{border-color:var(--form-error-stroke-default)}.ui-toggle._invalid:has(.ui-toggle-input:focus-visible) .ui-toggle-track{box-shadow:0 0 0 var(--units-2xs) rgb(from var(--form-error-stroke-focused) r g b/50%)}.ui-toggle-label{display:inline-flex;align-items:center;gap:var(--units-2xs);font-family:var(--fontfamily-base);font-size:var(--size-typography-text-default);color:var(--ui-label-color, var(--form-high-content-default));cursor:inherit;-webkit-user-select:none;user-select:none;transition:color var(--transition-default) var(--transition-easeinout)}.ui-toggle._small .ui-toggle-label{font-size:var(--size-typography-text-md)}.ui-toggle-required{color:var(--informative-errorlow-content-default)}.ui-toggle._disabled{cursor:not-allowed}.ui-toggle._disabled .ui-toggle-track{background-color:var(--form-low-content-disabled)}.ui-toggle._disabled .ui-toggle-thumb{background-color:var(--form-high-surface-disabled)}.ui-toggle._disabled .ui-toggle-label{color:var(--form-high-content-disabled)}.ui-toggle._disabled._checked .ui-toggle-track{background-color:var(--form-high-content-disabled)}.ui-toggle._readonly{cursor:default}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
|
|
105
|
+
}
|
|
106
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiToggle, decorators: [{
|
|
107
|
+
type: Component,
|
|
108
|
+
args: [{ selector: 'ui-toggle', imports: [NgTemplateOutlet], providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiToggle), multi: true }], template: "<label [class]=\"classes()\">\n @if (hasLabel() && labelPosition() === 'before') {\n <ng-container [ngTemplateOutlet]=\"labelTpl\" />\n }\n\n <span class=\"ui-toggle-control\">\n <input\n #inputEl\n type=\"checkbox\"\n role=\"switch\"\n class=\"ui-toggle-input\"\n [id]=\"resolvedId()\"\n [checked]=\"checked()\"\n [disabled]=\"isDisabled()\"\n [required]=\"required()\"\n [attr.name]=\"name() || null\"\n [attr.tabindex]=\"tabindex()\"\n [attr.aria-checked]=\"checked()\"\n [attr.aria-label]=\"label() ? null : ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-invalid]=\"isInvalid() ? 'true' : null\"\n (change)=\"onNativeChange()\"\n (focus)=\"toggleFocus.emit($event)\"\n (blur)=\"onBlur($event)\"\n />\n <span class=\"ui-toggle-track\" aria-hidden=\"true\">\n <span class=\"ui-toggle-thumb\">\n @if (handle(); as tpl) {\n <ng-container [ngTemplateOutlet]=\"tpl\" [ngTemplateOutletContext]=\"handleContext()\" />\n }\n </span>\n </span>\n </span>\n\n @if (hasLabel() && labelPosition() === 'after') {\n <ng-container [ngTemplateOutlet]=\"labelTpl\" />\n }\n</label>\n\n<ng-template #labelTpl>\n <span class=\"ui-toggle-label\">\n <span class=\"ui-toggle-text\">{{ label() }}</span>\n @if (required()) {\n <span class=\"ui-toggle-required\" aria-hidden=\"true\">*</span>\n }\n </span>\n</ng-template>\n", styles: [".ui-toggle{display:inline-flex;align-items:center;gap:var(--units-sm);cursor:pointer}.ui-toggle-control{position:relative;display:inline-flex;flex-shrink:0}.ui-toggle-input{position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;opacity:0;cursor:inherit}.ui-toggle-track{display:flex;align-items:center;box-sizing:border-box;border:var(--stroke-sm) solid transparent;border-radius:var(--radius-full);background-color:var(--form-low-content-default);transition:background-color var(--transition-default) var(--transition-easeinout),border-color var(--transition-default) var(--transition-easeinout),box-shadow var(--transition-default) var(--transition-easeinout)}.ui-toggle-thumb{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;box-sizing:border-box;border-radius:var(--radius-full);background-color:var(--form-high-surface-default);color:var(--form-low-content-default);line-height:0;overflow:hidden;transition:transform var(--transition-default) var(--transition-easeinout),background-color var(--transition-default) var(--transition-easeinout)}.ui-toggle .ui-toggle-track{width:2.75rem;height:1.5rem;padding:.0625rem}.ui-toggle .ui-toggle-thumb{width:1.25rem;height:1.25rem}.ui-toggle._checked .ui-toggle-thumb{transform:translate(1.25rem)}.ui-toggle._small .ui-toggle-track{width:2.25rem;height:1.25rem;padding:.0625rem}.ui-toggle._small .ui-toggle-thumb{width:1rem;height:1rem}.ui-toggle._small._checked .ui-toggle-thumb{transform:translate(1rem)}.ui-toggle:hover:not(._disabled):not(._readonly) .ui-toggle-track{background-color:var(--form-low-content-hover)}.ui-toggle._checked:hover:not(._disabled):not(._readonly) .ui-toggle-track{background-color:var(--form-high-content-hover)}.ui-toggle._checked .ui-toggle-track{background-color:var(--form-high-content-checked)}.ui-toggle:has(.ui-toggle-input:focus-visible) .ui-toggle-track{box-shadow:0 0 0 var(--units-2xs) rgb(from var(--form-high-stroke-focused) r g b/50%)}.ui-toggle._invalid .ui-toggle-track{border-color:var(--form-error-stroke-default)}.ui-toggle._invalid:has(.ui-toggle-input:focus-visible) .ui-toggle-track{box-shadow:0 0 0 var(--units-2xs) rgb(from var(--form-error-stroke-focused) r g b/50%)}.ui-toggle-label{display:inline-flex;align-items:center;gap:var(--units-2xs);font-family:var(--fontfamily-base);font-size:var(--size-typography-text-default);color:var(--ui-label-color, var(--form-high-content-default));cursor:inherit;-webkit-user-select:none;user-select:none;transition:color var(--transition-default) var(--transition-easeinout)}.ui-toggle._small .ui-toggle-label{font-size:var(--size-typography-text-md)}.ui-toggle-required{color:var(--informative-errorlow-content-default)}.ui-toggle._disabled{cursor:not-allowed}.ui-toggle._disabled .ui-toggle-track{background-color:var(--form-low-content-disabled)}.ui-toggle._disabled .ui-toggle-thumb{background-color:var(--form-high-surface-disabled)}.ui-toggle._disabled .ui-toggle-label{color:var(--form-high-content-disabled)}.ui-toggle._disabled._checked .ui-toggle-track{background-color:var(--form-high-content-disabled)}.ui-toggle._readonly{cursor:default}\n"] }]
|
|
109
|
+
}], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], labelPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelPosition", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], trueValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "trueValue", required: false }] }], falseValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "falseValue", required: false }] }], handle: [{ type: i0.Input, args: [{ isSignal: true, alias: "handle", required: false }] }], toggleChange: [{ type: i0.Output, args: ["toggleChange"] }], toggleFocus: [{ type: i0.Output, args: ["toggleFocus"] }], toggleBlur: [{ type: i0.Output, args: ["toggleBlur"] }], inputEl: [{ type: i0.ViewChild, args: ['inputEl', { isSignal: true }] }] } });
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
* Public API Surface of ui-kit/ui-toggle
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Generated bundle index. Do not edit.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
export { UiToggle };
|
|
120
|
+
//# sourceMappingURL=4sh-ui-kit-ui-toggle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"4sh-ui-kit-ui-toggle.mjs","sources":["../../../projects/ui-kit/ui-toggle/src/lib/ui-toggle.ts","../../../projects/ui-kit/ui-toggle/src/lib/ui-toggle.html","../../../projects/ui-kit/ui-toggle/src/public-api.ts","../../../projects/ui-kit/ui-toggle/src/4sh-ui-kit-ui-toggle.ts"],"sourcesContent":["import {\n Component,\n computed,\n ElementRef,\n forwardRef,\n input,\n output,\n TemplateRef,\n viewChild,\n} from '@angular/core';\nimport { NgTemplateOutlet } from '@angular/common';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { BaseFieldControl } from '@4sh/ui-kit/forms';\n\nexport type ToggleSize = 'default' | 'small';\nexport type ToggleLabelPosition = 'before' | 'after';\nexport interface ToggleHandleContext {\n checked: boolean;\n}\n\n/**\n * ui-toggle — headless switch built on a real native `<input type=\"checkbox\" role=\"switch\">`.\n *\n * The native input stays in the DOM (invisible, covering the track) so keyboard,\n * screen readers, label click and form semantics come for free. `role=\"switch\"`\n * + `aria-checked` make assistive tech announce it as on/off. Interactive states\n * (hover/focus/disabled/checked) are pure CSS driven by `form.*` design tokens.\n *\n * Works standalone, with `[(ngModel)]` or reactive forms (ControlValueAccessor).\n * By default the model value is boolean; `trueValue`/`falseValue` let the model\n * carry any pair of values (e.g. 'on'/'off', 1/0).\n */\n@Component({\n selector: 'ui-toggle',\n imports: [NgTemplateOutlet],\n templateUrl: './ui-toggle.html',\n styleUrl: './ui-toggle.scss',\n providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiToggle), multi: true }],\n})\nexport class UiToggle<T = boolean> extends BaseFieldControl<T> {\n /** Label displayed next to the switch (clicking it toggles the switch). */\n label = input<string>();\n /** Side of the switch the label sits on (both sides are clickable). */\n labelPosition = input<ToggleLabelPosition>('after');\n /** Size. */\n size = input<ToggleSize>('default');\n /** Model value emitted when on. */\n trueValue = input<T>(true as T);\n /** Model value emitted when off. */\n falseValue = input<T>(false as T);\n /**\n * Custom handle (thumb) template. Receives a `{ checked }` context, so the\n * rendered content can react to the on/off state (e.g. a check / times icon).\n */\n handle = input<TemplateRef<ToggleHandleContext>>();\n\n /** Emitted on user toggle with the new model value (never when disabled/readonly). */\n toggleChange = output<T>();\n /** Emitted when the native input receives focus. */\n toggleFocus = output<FocusEvent>();\n /** Emitted when the native input loses focus. */\n toggleBlur = output<FocusEvent>();\n\n /** @ignore */\n private readonly inputEl = viewChild.required<ElementRef<HTMLInputElement>>('inputEl');\n\n /** @ignore */\n protected readonly checked = computed(() => this.modelValue() === this.trueValue());\n /** @ignore A visible label is provided. */\n protected readonly hasLabel = computed(() => !!this.label());\n /** @ignore Context handed to the custom handle template. */\n protected readonly handleContext = computed<ToggleHandleContext>(() => ({ checked: this.checked() }));\n\n /** @ignore */\n protected readonly classes = computed(() => {\n const c = ['ui-toggle'];\n if (this.size() !== 'default') c.push(`_${this.size()}`);\n if (this.checked()) c.push('_checked');\n if (this.isDisabled()) c.push('_disabled');\n if (this.readonly()) c.push('_readonly');\n if (this.isInvalid()) c.push('_invalid');\n return c.join(' ');\n });\n\n /** @ignore */\n protected override uidPrefix(): string {\n return 'ui-toggle';\n }\n\n /** Focus the native input programmatically. */\n focus(options?: FocusOptions): void {\n this.inputEl().nativeElement.focus(options);\n }\n\n /** @ignore Native change: single source of truth for user toggles. */\n protected onNativeChange(): void {\n const inputEl = this.inputEl().nativeElement;\n if (this.readonly()) {\n inputEl.checked = this.checked(); // revert the native toggle\n return;\n }\n const value = inputEl.checked ? this.trueValue() : this.falseValue();\n this.modelValue.set(value);\n this.emitChange(value);\n this.toggleChange.emit(value);\n }\n\n /** @ignore */\n protected onBlur(event: FocusEvent): void {\n this.emitTouch();\n this.toggleBlur.emit(event);\n }\n}\n","<label [class]=\"classes()\">\n @if (hasLabel() && labelPosition() === 'before') {\n <ng-container [ngTemplateOutlet]=\"labelTpl\" />\n }\n\n <span class=\"ui-toggle-control\">\n <input\n #inputEl\n type=\"checkbox\"\n role=\"switch\"\n class=\"ui-toggle-input\"\n [id]=\"resolvedId()\"\n [checked]=\"checked()\"\n [disabled]=\"isDisabled()\"\n [required]=\"required()\"\n [attr.name]=\"name() || null\"\n [attr.tabindex]=\"tabindex()\"\n [attr.aria-checked]=\"checked()\"\n [attr.aria-label]=\"label() ? null : ariaLabel() || null\"\n [attr.aria-labelledby]=\"ariaLabelledBy() || null\"\n [attr.aria-invalid]=\"isInvalid() ? 'true' : null\"\n (change)=\"onNativeChange()\"\n (focus)=\"toggleFocus.emit($event)\"\n (blur)=\"onBlur($event)\"\n />\n <span class=\"ui-toggle-track\" aria-hidden=\"true\">\n <span class=\"ui-toggle-thumb\">\n @if (handle(); as tpl) {\n <ng-container [ngTemplateOutlet]=\"tpl\" [ngTemplateOutletContext]=\"handleContext()\" />\n }\n </span>\n </span>\n </span>\n\n @if (hasLabel() && labelPosition() === 'after') {\n <ng-container [ngTemplateOutlet]=\"labelTpl\" />\n }\n</label>\n\n<ng-template #labelTpl>\n <span class=\"ui-toggle-label\">\n <span class=\"ui-toggle-text\">{{ label() }}</span>\n @if (required()) {\n <span class=\"ui-toggle-required\" aria-hidden=\"true\">*</span>\n }\n </span>\n</ng-template>\n","/*\n * Public API Surface of ui-kit/ui-toggle\n */\n\nexport * from './lib/ui-toggle';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { input, computed, ViewEncapsulation, Component, booleanAttribute, numberAttribute, output, inject, ElementRef, ViewContainerRef, Injector, Renderer2, PLATFORM_ID, TemplateRef, afterNextRender, effect, untracked, DestroyRef, Directive } from '@angular/core';
|
|
3
|
+
import { NgTemplateOutlet, isPlatformBrowser } from '@angular/common';
|
|
4
|
+
import { Overlay } from '@angular/cdk/overlay';
|
|
5
|
+
import { ComponentPortal } from '@angular/cdk/portal';
|
|
6
|
+
import { closeOnNavigation } from '@4sh/ui-kit/overlay';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal visual panel of the tooltip (the "bubble" + arrow).
|
|
10
|
+
*
|
|
11
|
+
* Rendered inside a CDK overlay by the {@link UiTooltip} directive — never used
|
|
12
|
+
* directly in templates. Styling is co-located in `ui-tooltip.scss` and fully
|
|
13
|
+
* token-driven; every value is overridable through the `--ui-tooltip-*` CSS hooks.
|
|
14
|
+
*/
|
|
15
|
+
class UiTooltipPanel {
|
|
16
|
+
constructor() {
|
|
17
|
+
/** Plain-text (or HTML when `escape=false`) content. Ignored if `template` is set. */
|
|
18
|
+
this.text = input(/* @ts-ignore */
|
|
19
|
+
...(ngDevMode ? [undefined, { debugName: "text" }] : /* istanbul ignore next */ []));
|
|
20
|
+
/** Rich content rendered through `ngTemplateOutlet`. Takes precedence over `text`. */
|
|
21
|
+
this.template = input(/* @ts-ignore */
|
|
22
|
+
...(ngDevMode ? [undefined, { debugName: "template" }] : /* istanbul ignore next */ []));
|
|
23
|
+
/** Context object forwarded to `template`. */
|
|
24
|
+
this.templateContext = input(/* @ts-ignore */
|
|
25
|
+
...(ngDevMode ? [undefined, { debugName: "templateContext" }] : /* istanbul ignore next */ []));
|
|
26
|
+
/** When true (default) content is text; when false, `text` is bound as sanitized HTML. */
|
|
27
|
+
this.escape = input(true, /* @ts-ignore */
|
|
28
|
+
...(ngDevMode ? [{ debugName: "escape" }] : /* istanbul ignore next */ []));
|
|
29
|
+
/** Extra class(es) applied to the tooltip root for one-off customization. */
|
|
30
|
+
this.styleClass = input(/* @ts-ignore */
|
|
31
|
+
...(ngDevMode ? [undefined, { debugName: "styleClass" }] : /* istanbul ignore next */ []));
|
|
32
|
+
/** Side the tooltip sits on — sets the arrow orientation. */
|
|
33
|
+
this.position = input('top', /* @ts-ignore */
|
|
34
|
+
...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
|
|
35
|
+
/** DOM id, wired to the trigger via `aria-describedby`. */
|
|
36
|
+
this.tooltipId = input(/* @ts-ignore */
|
|
37
|
+
...(ngDevMode ? [undefined, { debugName: "tooltipId" }] : /* istanbul ignore next */ []));
|
|
38
|
+
/** Whether the panel is in its shown (opaque) state — drives the fade transition. */
|
|
39
|
+
this.visible = input(false, /* @ts-ignore */
|
|
40
|
+
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
|
|
41
|
+
/** When true the panel accepts pointer events (autoHide disabled). */
|
|
42
|
+
this.interactive = input(false, /* @ts-ignore */
|
|
43
|
+
...(ngDevMode ? [{ debugName: "interactive" }] : /* istanbul ignore next */ []));
|
|
44
|
+
/** @ignore */
|
|
45
|
+
this.classes = computed(() => {
|
|
46
|
+
const c = ['ui-tooltip', `_${this.position()}`];
|
|
47
|
+
if (this.visible())
|
|
48
|
+
c.push('_visible');
|
|
49
|
+
if (this.interactive())
|
|
50
|
+
c.push('_interactive');
|
|
51
|
+
const sc = this.styleClass();
|
|
52
|
+
if (sc)
|
|
53
|
+
c.push(sc);
|
|
54
|
+
return c.join(' ');
|
|
55
|
+
}, /* @ts-ignore */
|
|
56
|
+
...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
|
|
57
|
+
}
|
|
58
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiTooltipPanel, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
59
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: UiTooltipPanel, isStandalone: true, selector: "ui-tooltip", inputs: { text: { classPropertyName: "text", publicName: "text", isSignal: true, isRequired: false, transformFunction: null }, template: { classPropertyName: "template", publicName: "template", isSignal: true, isRequired: false, transformFunction: null }, templateContext: { classPropertyName: "templateContext", publicName: "templateContext", isSignal: true, isRequired: false, transformFunction: null }, escape: { classPropertyName: "escape", publicName: "escape", isSignal: true, isRequired: false, transformFunction: null }, styleClass: { classPropertyName: "styleClass", publicName: "styleClass", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, tooltipId: { classPropertyName: "tooltipId", publicName: "tooltipId", isSignal: true, isRequired: false, transformFunction: null }, visible: { classPropertyName: "visible", publicName: "visible", isSignal: true, isRequired: false, transformFunction: null }, interactive: { classPropertyName: "interactive", publicName: "interactive", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<div [class]=\"classes()\" role=\"tooltip\" [id]=\"tooltipId()\">\n <span class=\"ui-tooltip-arrow\" aria-hidden=\"true\"></span>\n <div class=\"ui-tooltip-text\">\n @if (template()) {\n <ng-container *ngTemplateOutlet=\"template()!; context: templateContext()\" />\n } @else if (escape()) {\n {{ text() }}\n } @else {\n <span [innerHTML]=\"text()\"></span>\n }\n </div>\n</div>\n", styles: [".ui-tooltip{position:relative;display:inline-block;box-sizing:border-box;max-width:16rem;padding:var(--units-sm) var(--units-default);border:var(--stroke-sm) solid var(--informative-defaulthigh-stroke-default);border-radius:var(--radius-default);background-color:var(--informative-defaulthigh-surface-default);color:var(--informative-defaulthigh-content-default);box-shadow:var(--shadow-default-md);font-family:var(--fontfamily-base);font-weight:var(--weight-regular);font-size:var(--size-typography-text-md);line-height:1.4;overflow-wrap:break-word;--ui-motion-duration: var(--transition-fast);--ui-motion-easing: var(--transition-easeout);opacity:0;transition:opacity var(--ui-motion-duration, var(--transition-default)) var(--ui-motion-easing, var(--transition-easeinout)) var(--ui-motion-delay, 0ms),translate var(--ui-motion-duration, var(--transition-default)) var(--ui-motion-easing, var(--transition-easeinout)) var(--ui-motion-delay, 0ms)}.ui-tooltip._top{translate:0 4px}.ui-tooltip._bottom{translate:0 -4px}.ui-tooltip._left{translate:4px 0}.ui-tooltip._right{translate:-4px 0}.ui-tooltip._visible{opacity:1;translate:0 0}.ui-tooltip._interactive{pointer-events:auto}@media(prefers-reduced-motion:reduce){.ui-tooltip{transition-duration:.01ms;translate:none}}:root[data-motion=off] .ui-tooltip{transition-duration:.01ms;translate:none}.ui-tooltip-text{display:block}.ui-tooltip-arrow{position:absolute;width:.5rem;height:.5rem;background-color:var(--informative-defaulthigh-surface-default);border:var(--stroke-sm) solid var(--informative-defaulthigh-stroke-default);rotate:45deg}.ui-tooltip._top .ui-tooltip-arrow{bottom:-.25rem;left:50%;margin-left:-.25rem;border-top:0;border-left:0}.ui-tooltip._bottom .ui-tooltip-arrow{top:-.25rem;left:50%;margin-left:-.25rem;border-right:0;border-bottom:0}.ui-tooltip._left .ui-tooltip-arrow{right:-.25rem;top:50%;margin-top:-.25rem;border-bottom:0;border-left:0}.ui-tooltip._right .ui-tooltip-arrow{left:-.25rem;top:50%;margin-top:-.25rem;border-top:0;border-right:0}\n"], dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
|
|
60
|
+
}
|
|
61
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiTooltipPanel, decorators: [{
|
|
62
|
+
type: Component,
|
|
63
|
+
args: [{ selector: 'ui-tooltip', imports: [NgTemplateOutlet], encapsulation: ViewEncapsulation.Emulated, template: "<div [class]=\"classes()\" role=\"tooltip\" [id]=\"tooltipId()\">\n <span class=\"ui-tooltip-arrow\" aria-hidden=\"true\"></span>\n <div class=\"ui-tooltip-text\">\n @if (template()) {\n <ng-container *ngTemplateOutlet=\"template()!; context: templateContext()\" />\n } @else if (escape()) {\n {{ text() }}\n } @else {\n <span [innerHTML]=\"text()\"></span>\n }\n </div>\n</div>\n", styles: [".ui-tooltip{position:relative;display:inline-block;box-sizing:border-box;max-width:16rem;padding:var(--units-sm) var(--units-default);border:var(--stroke-sm) solid var(--informative-defaulthigh-stroke-default);border-radius:var(--radius-default);background-color:var(--informative-defaulthigh-surface-default);color:var(--informative-defaulthigh-content-default);box-shadow:var(--shadow-default-md);font-family:var(--fontfamily-base);font-weight:var(--weight-regular);font-size:var(--size-typography-text-md);line-height:1.4;overflow-wrap:break-word;--ui-motion-duration: var(--transition-fast);--ui-motion-easing: var(--transition-easeout);opacity:0;transition:opacity var(--ui-motion-duration, var(--transition-default)) var(--ui-motion-easing, var(--transition-easeinout)) var(--ui-motion-delay, 0ms),translate var(--ui-motion-duration, var(--transition-default)) var(--ui-motion-easing, var(--transition-easeinout)) var(--ui-motion-delay, 0ms)}.ui-tooltip._top{translate:0 4px}.ui-tooltip._bottom{translate:0 -4px}.ui-tooltip._left{translate:4px 0}.ui-tooltip._right{translate:-4px 0}.ui-tooltip._visible{opacity:1;translate:0 0}.ui-tooltip._interactive{pointer-events:auto}@media(prefers-reduced-motion:reduce){.ui-tooltip{transition-duration:.01ms;translate:none}}:root[data-motion=off] .ui-tooltip{transition-duration:.01ms;translate:none}.ui-tooltip-text{display:block}.ui-tooltip-arrow{position:absolute;width:.5rem;height:.5rem;background-color:var(--informative-defaulthigh-surface-default);border:var(--stroke-sm) solid var(--informative-defaulthigh-stroke-default);rotate:45deg}.ui-tooltip._top .ui-tooltip-arrow{bottom:-.25rem;left:50%;margin-left:-.25rem;border-top:0;border-left:0}.ui-tooltip._bottom .ui-tooltip-arrow{top:-.25rem;left:50%;margin-left:-.25rem;border-right:0;border-bottom:0}.ui-tooltip._left .ui-tooltip-arrow{right:-.25rem;top:50%;margin-top:-.25rem;border-bottom:0;border-left:0}.ui-tooltip._right .ui-tooltip-arrow{left:-.25rem;top:50%;margin-top:-.25rem;border-top:0;border-right:0}\n"] }]
|
|
64
|
+
}], propDecorators: { text: [{ type: i0.Input, args: [{ isSignal: true, alias: "text", required: false }] }], template: [{ type: i0.Input, args: [{ isSignal: true, alias: "template", required: false }] }], templateContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "templateContext", required: false }] }], escape: [{ type: i0.Input, args: [{ isSignal: true, alias: "escape", required: false }] }], styleClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "styleClass", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], tooltipId: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipId", required: false }] }], visible: [{ type: i0.Input, args: [{ isSignal: true, alias: "visible", required: false }] }], interactive: [{ type: i0.Input, args: [{ isSignal: true, alias: "interactive", required: false }] }] } });
|
|
65
|
+
|
|
66
|
+
/** Gap (px) left between the trigger and the tooltip for the arrow — mirrors `$tooltip-arrow-size` in the SCSS. */
|
|
67
|
+
const ARROW_GAP = 8;
|
|
68
|
+
/** Process-wide counter for unique tooltip ids (aria-describedby wiring). */
|
|
69
|
+
let nextId = 0;
|
|
70
|
+
/**
|
|
71
|
+
* Attribute directive that attaches an advisory tooltip to its host element.
|
|
72
|
+
*
|
|
73
|
+
* Headless behavior (Angular CDK Overlay) + a co-located, fully token-driven panel
|
|
74
|
+
* ({@link UiTooltipPanel}). Inspired by the PrimeNG `pTooltip` API, adapted to the
|
|
75
|
+
* signals idiom of this design system.
|
|
76
|
+
*
|
|
77
|
+
* Positioning, viewport flipping and scroll re-alignment are delegated to the CDK
|
|
78
|
+
* `FlexibleConnectedPositionStrategy` (no manual geometry).
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```html
|
|
82
|
+
* <button uiTooltip="Save the document" tooltipPosition="bottom">Save</button>
|
|
83
|
+
* <button [uiTooltip]="tpl" [tooltipContext]="{ $implicit: user }">Profile</button>
|
|
84
|
+
* <ng-template #tpl let-u>{{ u.name }}</ng-template>
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
class UiTooltip {
|
|
88
|
+
constructor() {
|
|
89
|
+
/** Content: plain text, HTML (with `escape=false`) or a `TemplateRef` for rich content. */
|
|
90
|
+
this.content = input(undefined, { ...(ngDevMode ? { debugName: "content" } : /* istanbul ignore next */ {}), alias: 'uiTooltip' });
|
|
91
|
+
/** Preferred side of the trigger. CDK flips it automatically when space is lacking. */
|
|
92
|
+
this.tooltipPosition = input('top', /* @ts-ignore */
|
|
93
|
+
...(ngDevMode ? [{ debugName: "tooltipPosition" }] : /* istanbul ignore next */ []));
|
|
94
|
+
/** Auto-flip to another side when the preferred one lacks space (default). `false` locks the side. */
|
|
95
|
+
this.fitContent = input(true, { ...(ngDevMode ? { debugName: "fitContent" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
96
|
+
/** Interaction(s) that reveal the tooltip. `both` (default) also covers keyboard focus (a11y). */
|
|
97
|
+
this.tooltipEvent = input('both', /* @ts-ignore */
|
|
98
|
+
...(ngDevMode ? [{ debugName: "tooltipEvent" }] : /* istanbul ignore next */ []));
|
|
99
|
+
/** Disables the tooltip entirely. */
|
|
100
|
+
this.tooltipDisabled = input(false, { ...(ngDevMode ? { debugName: "tooltipDisabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
101
|
+
/** Delay before showing, in ms. */
|
|
102
|
+
this.showDelay = input(150, { ...(ngDevMode ? { debugName: "showDelay" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
103
|
+
/** Delay before hiding, in ms. */
|
|
104
|
+
this.hideDelay = input(0, { ...(ngDevMode ? { debugName: "hideDelay" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
105
|
+
/** `true` (default): content rendered as text. `false`: `content` bound as sanitized HTML. */
|
|
106
|
+
this.escape = input(true, { ...(ngDevMode ? { debugName: "escape" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
107
|
+
/** Extra class(es) applied to the tooltip panel. */
|
|
108
|
+
this.tooltipStyleClass = input(/* @ts-ignore */
|
|
109
|
+
...(ngDevMode ? [undefined, { debugName: "tooltipStyleClass" }] : /* istanbul ignore next */ []));
|
|
110
|
+
/** Auto-hide when the pointer leaves the trigger (default). `false` keeps it open while hovered. */
|
|
111
|
+
this.autoHide = input(true, { ...(ngDevMode ? { debugName: "autoHide" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
112
|
+
/** Hide when the Escape key is pressed (default, WCAG dismissible). */
|
|
113
|
+
this.hideOnEscape = input(true, { ...(ngDevMode ? { debugName: "hideOnEscape" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
114
|
+
/** Auto-hide after N ms even while active. `0` (default) disables it. */
|
|
115
|
+
this.life = input(0, { ...(ngDevMode ? { debugName: "life" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
116
|
+
/** Only show when the trigger text is truncated (ellipsis active). */
|
|
117
|
+
this.showOnEllipsis = input(false, { ...(ngDevMode ? { debugName: "showOnEllipsis" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
118
|
+
/** Additional vertical offset (px) from the computed position. */
|
|
119
|
+
this.positionTop = input(0, { ...(ngDevMode ? { debugName: "positionTop" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
120
|
+
/** Additional horizontal offset (px) from the computed position. */
|
|
121
|
+
this.positionLeft = input(0, { ...(ngDevMode ? { debugName: "positionLeft" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
122
|
+
/** Context object forwarded to a `TemplateRef` content. */
|
|
123
|
+
this.tooltipContext = input(/* @ts-ignore */
|
|
124
|
+
...(ngDevMode ? [undefined, { debugName: "tooltipContext" }] : /* istanbul ignore next */ []));
|
|
125
|
+
/** Emitted right after the tooltip becomes visible. */
|
|
126
|
+
this.tooltipShow = output();
|
|
127
|
+
/** Emitted right after the tooltip is hidden. */
|
|
128
|
+
this.tooltipHide = output();
|
|
129
|
+
/** @ignore */
|
|
130
|
+
this.el = inject(ElementRef);
|
|
131
|
+
/** @ignore */
|
|
132
|
+
this.overlay = inject(Overlay);
|
|
133
|
+
/** @ignore */
|
|
134
|
+
this.vcr = inject(ViewContainerRef);
|
|
135
|
+
/** @ignore */
|
|
136
|
+
this.injector = inject(Injector);
|
|
137
|
+
/** @ignore */
|
|
138
|
+
this.renderer = inject(Renderer2);
|
|
139
|
+
/** @ignore */
|
|
140
|
+
this.isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
141
|
+
/** @ignore */
|
|
142
|
+
this.overlayRef = null;
|
|
143
|
+
/** @ignore */
|
|
144
|
+
this.positionStrategy = null;
|
|
145
|
+
/** @ignore */
|
|
146
|
+
this.panelRef = null;
|
|
147
|
+
/** @ignore */
|
|
148
|
+
this.tooltipId = `ui-tooltip-${nextId++}`;
|
|
149
|
+
/** @ignore Deferred timers. */
|
|
150
|
+
this.showTimer = null;
|
|
151
|
+
this.hideTimer = null;
|
|
152
|
+
this.lifeTimer = null;
|
|
153
|
+
/** @ignore Teardown handles for host / document listeners. */
|
|
154
|
+
this.disposers = [];
|
|
155
|
+
/** @ignore Content is a template (vs a string). */
|
|
156
|
+
this.hasTemplate = computed(() => this.content() instanceof TemplateRef, /* @ts-ignore */
|
|
157
|
+
...(ngDevMode ? [{ debugName: "hasTemplate" }] : /* istanbul ignore next */ []));
|
|
158
|
+
// A navigation removes the trigger without ever firing `mouseleave`:
|
|
159
|
+
// drop the tooltip (and any pending show) instead of leaving it stuck.
|
|
160
|
+
closeOnNavigation(() => this.remove());
|
|
161
|
+
// Inputs are only resolved after construction → bind once the view exists (browser only).
|
|
162
|
+
if (this.isBrowser) {
|
|
163
|
+
afterNextRender(() => this.bindTriggerEvents());
|
|
164
|
+
}
|
|
165
|
+
// Keep an open tooltip in sync with live content / option changes.
|
|
166
|
+
effect(() => {
|
|
167
|
+
// Track the visible inputs so the effect re-runs on any change.
|
|
168
|
+
const content = this.content();
|
|
169
|
+
this.escape();
|
|
170
|
+
this.tooltipStyleClass();
|
|
171
|
+
this.tooltipContext();
|
|
172
|
+
untracked(() => {
|
|
173
|
+
if (!this.panelRef)
|
|
174
|
+
return;
|
|
175
|
+
this.applyContent();
|
|
176
|
+
if (!content)
|
|
177
|
+
this.hide();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
// Hide as soon as the tooltip is disabled.
|
|
181
|
+
effect(() => {
|
|
182
|
+
if (this.tooltipDisabled())
|
|
183
|
+
untracked(() => this.hide());
|
|
184
|
+
});
|
|
185
|
+
inject(DestroyRef).onDestroy(() => this.destroy());
|
|
186
|
+
}
|
|
187
|
+
/** Programmatically show the tooltip (respects `showDelay`). */
|
|
188
|
+
show() {
|
|
189
|
+
this.activate();
|
|
190
|
+
}
|
|
191
|
+
/** Programmatically hide the tooltip (respects `hideDelay`). */
|
|
192
|
+
hide() {
|
|
193
|
+
this.deactivate();
|
|
194
|
+
}
|
|
195
|
+
// --- Trigger events --------------------------------------------------
|
|
196
|
+
/** @ignore */
|
|
197
|
+
bindTriggerEvents() {
|
|
198
|
+
const host = this.el.nativeElement;
|
|
199
|
+
const evt = this.tooltipEvent();
|
|
200
|
+
if (evt === 'hover' || evt === 'both') {
|
|
201
|
+
this.disposers.push(this.renderer.listen(host, 'mouseenter', () => this.activate()), this.renderer.listen(host, 'mouseleave', () => this.deactivate()), this.renderer.listen(host, 'click', () => this.deactivate()), this.renderer.listen(host, 'touchstart', () => this.activate()));
|
|
202
|
+
}
|
|
203
|
+
if (evt === 'focus' || evt === 'both') {
|
|
204
|
+
// focusin/focusout bubble → also works when the host wraps the focusable element.
|
|
205
|
+
this.disposers.push(this.renderer.listen(host, 'focusin', () => this.activate()), this.renderer.listen(host, 'focusout', () => this.deactivate()));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// --- Activation lifecycle -------------------------------------------
|
|
209
|
+
/** @ignore */
|
|
210
|
+
activate() {
|
|
211
|
+
if (this.tooltipDisabled() || !this.hasContent())
|
|
212
|
+
return;
|
|
213
|
+
if (this.showOnEllipsis() && !this.hasEllipsis())
|
|
214
|
+
return;
|
|
215
|
+
this.clearHideTimer();
|
|
216
|
+
if (this.overlayRef?.hasAttached())
|
|
217
|
+
return;
|
|
218
|
+
const delay = this.showDelay();
|
|
219
|
+
this.clearShowTimer();
|
|
220
|
+
if (delay > 0) {
|
|
221
|
+
this.showTimer = setTimeout(() => this.render(), delay);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
this.render();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** @ignore */
|
|
228
|
+
deactivate() {
|
|
229
|
+
this.clearShowTimer();
|
|
230
|
+
const delay = this.hideDelay();
|
|
231
|
+
if (delay > 0) {
|
|
232
|
+
this.clearHideTimer();
|
|
233
|
+
this.hideTimer = setTimeout(() => this.remove(), delay);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
this.remove();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// --- Overlay rendering ----------------------------------------------
|
|
240
|
+
/** @ignore */
|
|
241
|
+
render() {
|
|
242
|
+
if (!this.hasContent() || this.tooltipDisabled())
|
|
243
|
+
return;
|
|
244
|
+
const overlayRef = this.getOverlayRef();
|
|
245
|
+
if (!overlayRef.hasAttached()) {
|
|
246
|
+
this.panelRef = overlayRef.attach(new ComponentPortal(UiTooltipPanel, this.vcr, this.injector));
|
|
247
|
+
this.panelRef.setInput('tooltipId', this.tooltipId);
|
|
248
|
+
this.applyContent();
|
|
249
|
+
this.renderer.setAttribute(this.el.nativeElement, 'aria-describedby', this.tooltipId);
|
|
250
|
+
// Let hover pass through unless the tooltip is interactive (autoHide=false).
|
|
251
|
+
overlayRef.overlayElement.style.pointerEvents = this.autoHide() ? 'none' : 'auto';
|
|
252
|
+
if (!this.autoHide())
|
|
253
|
+
this.bindPanelHover(overlayRef);
|
|
254
|
+
}
|
|
255
|
+
// Trigger the fade-in on the next frame so the transition runs.
|
|
256
|
+
requestAnimationFrame(() => this.panelRef?.setInput('visible', true));
|
|
257
|
+
this.armLifeTimer();
|
|
258
|
+
if (this.hideOnEscape())
|
|
259
|
+
this.bindEscape();
|
|
260
|
+
this.tooltipShow.emit();
|
|
261
|
+
}
|
|
262
|
+
/** @ignore */
|
|
263
|
+
remove() {
|
|
264
|
+
this.clearLifeTimer();
|
|
265
|
+
this.clearShowTimer();
|
|
266
|
+
if (!this.overlayRef?.hasAttached())
|
|
267
|
+
return;
|
|
268
|
+
this.overlayRef.detach();
|
|
269
|
+
this.panelRef = null;
|
|
270
|
+
this.renderer.removeAttribute(this.el.nativeElement, 'aria-describedby');
|
|
271
|
+
this.tooltipHide.emit();
|
|
272
|
+
}
|
|
273
|
+
/** @ignore Built once, reused across shows; positions refreshed each time. */
|
|
274
|
+
getOverlayRef() {
|
|
275
|
+
if (this.overlayRef) {
|
|
276
|
+
this.positionStrategy?.withPositions(this.positionsFor(this.tooltipPosition()));
|
|
277
|
+
return this.overlayRef;
|
|
278
|
+
}
|
|
279
|
+
this.positionStrategy = this.overlay
|
|
280
|
+
.position()
|
|
281
|
+
.flexibleConnectedTo(this.el)
|
|
282
|
+
.withFlexibleDimensions(false)
|
|
283
|
+
.withPush(false)
|
|
284
|
+
.withViewportMargin(ARROW_GAP)
|
|
285
|
+
.withPositions(this.positionsFor(this.tooltipPosition()));
|
|
286
|
+
// Single subscription for the whole lifecycle → arrow follows the effective side.
|
|
287
|
+
this.positionStrategy.positionChanges.subscribe((change) => {
|
|
288
|
+
this.panelRef?.setInput('position', this.sideOf(change.connectionPair));
|
|
289
|
+
});
|
|
290
|
+
this.overlayRef = this.overlay.create({
|
|
291
|
+
positionStrategy: this.positionStrategy,
|
|
292
|
+
scrollStrategy: this.overlay.scrollStrategies.reposition(),
|
|
293
|
+
panelClass: 'ui-tooltip-overlay',
|
|
294
|
+
hasBackdrop: false,
|
|
295
|
+
});
|
|
296
|
+
return this.overlayRef;
|
|
297
|
+
}
|
|
298
|
+
/** @ignore Ordered positions (preferred first, then fallbacks) for CDK auto-flip. */
|
|
299
|
+
positionsFor(pos) {
|
|
300
|
+
const ox = this.positionLeft();
|
|
301
|
+
const oy = this.positionTop();
|
|
302
|
+
const top = {
|
|
303
|
+
originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom',
|
|
304
|
+
offsetX: ox, offsetY: -ARROW_GAP + oy,
|
|
305
|
+
};
|
|
306
|
+
const bottom = {
|
|
307
|
+
originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top',
|
|
308
|
+
offsetX: ox, offsetY: ARROW_GAP + oy,
|
|
309
|
+
};
|
|
310
|
+
const left = {
|
|
311
|
+
originX: 'start', originY: 'center', overlayX: 'end', overlayY: 'center',
|
|
312
|
+
offsetX: -ARROW_GAP + ox, offsetY: oy,
|
|
313
|
+
};
|
|
314
|
+
const right = {
|
|
315
|
+
originX: 'end', originY: 'center', overlayX: 'start', overlayY: 'center',
|
|
316
|
+
offsetX: ARROW_GAP + ox, offsetY: oy,
|
|
317
|
+
};
|
|
318
|
+
const primary = { top, bottom, left, right };
|
|
319
|
+
// fitContent=false → keep only the preferred side (no auto-flip).
|
|
320
|
+
if (!this.fitContent())
|
|
321
|
+
return [primary[pos]];
|
|
322
|
+
const order = {
|
|
323
|
+
top: [top, bottom, right, left],
|
|
324
|
+
bottom: [bottom, top, right, left],
|
|
325
|
+
left: [left, right, top, bottom],
|
|
326
|
+
right: [right, left, top, bottom],
|
|
327
|
+
};
|
|
328
|
+
return order[pos];
|
|
329
|
+
}
|
|
330
|
+
/** @ignore Map the active CDK connection pair back to the visual side (for the arrow). */
|
|
331
|
+
sideOf(pair) {
|
|
332
|
+
if (pair.overlayY === 'bottom')
|
|
333
|
+
return 'top';
|
|
334
|
+
if (pair.overlayY === 'top')
|
|
335
|
+
return 'bottom';
|
|
336
|
+
if (pair.overlayX === 'end')
|
|
337
|
+
return 'left';
|
|
338
|
+
return 'right';
|
|
339
|
+
}
|
|
340
|
+
// --- Content ---------------------------------------------------------
|
|
341
|
+
/** @ignore */
|
|
342
|
+
applyContent() {
|
|
343
|
+
if (!this.panelRef)
|
|
344
|
+
return;
|
|
345
|
+
const content = this.content();
|
|
346
|
+
if (this.hasTemplate()) {
|
|
347
|
+
this.panelRef.setInput('template', content);
|
|
348
|
+
this.panelRef.setInput('templateContext', this.tooltipContext());
|
|
349
|
+
this.panelRef.setInput('text', undefined);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
this.panelRef.setInput('text', content);
|
|
353
|
+
this.panelRef.setInput('template', undefined);
|
|
354
|
+
}
|
|
355
|
+
this.panelRef.setInput('escape', this.escape());
|
|
356
|
+
this.panelRef.setInput('styleClass', this.tooltipStyleClass());
|
|
357
|
+
this.panelRef.setInput('interactive', !this.autoHide());
|
|
358
|
+
}
|
|
359
|
+
/** @ignore */
|
|
360
|
+
hasContent() {
|
|
361
|
+
const c = this.content();
|
|
362
|
+
return this.hasTemplate() || !!(typeof c === 'string' && c.length);
|
|
363
|
+
}
|
|
364
|
+
/** @ignore Whether the trigger text is visually truncated. */
|
|
365
|
+
hasEllipsis() {
|
|
366
|
+
const el = this.el.nativeElement;
|
|
367
|
+
return el.offsetWidth < el.scrollWidth || el.offsetHeight < el.scrollHeight;
|
|
368
|
+
}
|
|
369
|
+
// --- Interactive / dismiss listeners --------------------------------
|
|
370
|
+
/** @ignore Keep the tooltip open while the pointer is over it (autoHide=false). */
|
|
371
|
+
bindPanelHover(overlayRef) {
|
|
372
|
+
const panel = overlayRef.overlayElement;
|
|
373
|
+
const enter = this.renderer.listen(panel, 'mouseenter', () => this.clearHideTimer());
|
|
374
|
+
const leave = this.renderer.listen(panel, 'mouseleave', () => this.deactivate());
|
|
375
|
+
this.disposers.push(enter, leave);
|
|
376
|
+
}
|
|
377
|
+
/** @ignore */
|
|
378
|
+
bindEscape() {
|
|
379
|
+
const off = this.renderer.listen('document', 'keydown.escape', () => {
|
|
380
|
+
this.deactivate();
|
|
381
|
+
off();
|
|
382
|
+
});
|
|
383
|
+
this.disposers.push(off);
|
|
384
|
+
}
|
|
385
|
+
// --- Timers ----------------------------------------------------------
|
|
386
|
+
/** @ignore */
|
|
387
|
+
armLifeTimer() {
|
|
388
|
+
this.clearLifeTimer();
|
|
389
|
+
const life = this.life();
|
|
390
|
+
if (life > 0)
|
|
391
|
+
this.lifeTimer = setTimeout(() => this.remove(), life);
|
|
392
|
+
}
|
|
393
|
+
/** @ignore */
|
|
394
|
+
clearShowTimer() {
|
|
395
|
+
if (this.showTimer) {
|
|
396
|
+
clearTimeout(this.showTimer);
|
|
397
|
+
this.showTimer = null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/** @ignore */
|
|
401
|
+
clearHideTimer() {
|
|
402
|
+
if (this.hideTimer) {
|
|
403
|
+
clearTimeout(this.hideTimer);
|
|
404
|
+
this.hideTimer = null;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/** @ignore */
|
|
408
|
+
clearLifeTimer() {
|
|
409
|
+
if (this.lifeTimer) {
|
|
410
|
+
clearTimeout(this.lifeTimer);
|
|
411
|
+
this.lifeTimer = null;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/** @ignore */
|
|
415
|
+
destroy() {
|
|
416
|
+
this.clearShowTimer();
|
|
417
|
+
this.clearHideTimer();
|
|
418
|
+
this.clearLifeTimer();
|
|
419
|
+
this.disposers.forEach((off) => off());
|
|
420
|
+
this.disposers.length = 0;
|
|
421
|
+
this.overlayRef?.dispose();
|
|
422
|
+
this.overlayRef = null;
|
|
423
|
+
this.panelRef = null;
|
|
424
|
+
}
|
|
425
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiTooltip, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
426
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.8", type: UiTooltip, isStandalone: true, selector: "[uiTooltip]", inputs: { content: { classPropertyName: "content", publicName: "uiTooltip", isSignal: true, isRequired: false, transformFunction: null }, tooltipPosition: { classPropertyName: "tooltipPosition", publicName: "tooltipPosition", isSignal: true, isRequired: false, transformFunction: null }, fitContent: { classPropertyName: "fitContent", publicName: "fitContent", isSignal: true, isRequired: false, transformFunction: null }, tooltipEvent: { classPropertyName: "tooltipEvent", publicName: "tooltipEvent", isSignal: true, isRequired: false, transformFunction: null }, tooltipDisabled: { classPropertyName: "tooltipDisabled", publicName: "tooltipDisabled", isSignal: true, isRequired: false, transformFunction: null }, showDelay: { classPropertyName: "showDelay", publicName: "showDelay", isSignal: true, isRequired: false, transformFunction: null }, hideDelay: { classPropertyName: "hideDelay", publicName: "hideDelay", isSignal: true, isRequired: false, transformFunction: null }, escape: { classPropertyName: "escape", publicName: "escape", isSignal: true, isRequired: false, transformFunction: null }, tooltipStyleClass: { classPropertyName: "tooltipStyleClass", publicName: "tooltipStyleClass", isSignal: true, isRequired: false, transformFunction: null }, autoHide: { classPropertyName: "autoHide", publicName: "autoHide", isSignal: true, isRequired: false, transformFunction: null }, hideOnEscape: { classPropertyName: "hideOnEscape", publicName: "hideOnEscape", isSignal: true, isRequired: false, transformFunction: null }, life: { classPropertyName: "life", publicName: "life", isSignal: true, isRequired: false, transformFunction: null }, showOnEllipsis: { classPropertyName: "showOnEllipsis", publicName: "showOnEllipsis", isSignal: true, isRequired: false, transformFunction: null }, positionTop: { classPropertyName: "positionTop", publicName: "positionTop", isSignal: true, isRequired: false, transformFunction: null }, positionLeft: { classPropertyName: "positionLeft", publicName: "positionLeft", isSignal: true, isRequired: false, transformFunction: null }, tooltipContext: { classPropertyName: "tooltipContext", publicName: "tooltipContext", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { tooltipShow: "tooltipShow", tooltipHide: "tooltipHide" }, exportAs: ["uiTooltip"], ngImport: i0 }); }
|
|
427
|
+
}
|
|
428
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: UiTooltip, decorators: [{
|
|
429
|
+
type: Directive,
|
|
430
|
+
args: [{
|
|
431
|
+
selector: '[uiTooltip]',
|
|
432
|
+
exportAs: 'uiTooltip',
|
|
433
|
+
}]
|
|
434
|
+
}], ctorParameters: () => [], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "uiTooltip", required: false }] }], tooltipPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipPosition", required: false }] }], fitContent: [{ type: i0.Input, args: [{ isSignal: true, alias: "fitContent", required: false }] }], tooltipEvent: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipEvent", required: false }] }], tooltipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipDisabled", required: false }] }], showDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "showDelay", required: false }] }], hideDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideDelay", required: false }] }], escape: [{ type: i0.Input, args: [{ isSignal: true, alias: "escape", required: false }] }], tooltipStyleClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipStyleClass", required: false }] }], autoHide: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoHide", required: false }] }], hideOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideOnEscape", required: false }] }], life: [{ type: i0.Input, args: [{ isSignal: true, alias: "life", required: false }] }], showOnEllipsis: [{ type: i0.Input, args: [{ isSignal: true, alias: "showOnEllipsis", required: false }] }], positionTop: [{ type: i0.Input, args: [{ isSignal: true, alias: "positionTop", required: false }] }], positionLeft: [{ type: i0.Input, args: [{ isSignal: true, alias: "positionLeft", required: false }] }], tooltipContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipContext", required: false }] }], tooltipShow: [{ type: i0.Output, args: ["tooltipShow"] }], tooltipHide: [{ type: i0.Output, args: ["tooltipHide"] }] } });
|
|
435
|
+
|
|
436
|
+
/*
|
|
437
|
+
* Public API Surface of ui-kit/ui-tooltip
|
|
438
|
+
*/
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Generated bundle index. Do not edit.
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
export { UiTooltip, UiTooltipPanel };
|
|
445
|
+
//# sourceMappingURL=4sh-ui-kit-ui-tooltip.mjs.map
|