@nectary/components 1.3.3 → 1.4.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/date-picker/index.js +0 -3
- package/help-tooltip/index.js +1 -1
- package/package.json +1 -2
- package/tooltip/index.js +42 -25
- package/tooltip/tooltip-state.d.ts +1 -0
- package/tooltip/tooltip-state.js +6 -0
- package/tooltip/types.d.ts +7 -0
- package/tooltip/utils.d.ts +4 -1
- package/tooltip/utils.js +7 -1
package/date-picker/index.js
CHANGED
|
@@ -283,9 +283,6 @@ defineCustomElement('sinch-date-picker', class extends NectaryElement {
|
|
|
283
283
|
if (this.range) {
|
|
284
284
|
if (this.#date1 !== null && this.#date2 === null) {
|
|
285
285
|
const date2 = isoToDate(dateIso);
|
|
286
|
-
if (areDatesEqual(this.#date1, date2)) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
286
|
const dateTuple = sortDates([this.#date1, date2]);
|
|
290
287
|
const value = packCsv(dateTuple.map(dateToIso));
|
|
291
288
|
this.#date1 = dateTuple[0];
|
package/help-tooltip/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../tooltip';
|
|
2
2
|
import '../icon';
|
|
3
3
|
import { defineCustomElement, getAttribute, getBooleanAttribute, getCssVar, getIntegerAttribute, getReactEventHandler, NectaryElement, updateAttribute, updateBooleanAttribute, updateIntegerAttribute } from '../utils';
|
|
4
|
-
const templateHTML = '<style>:host{display:contents}#icon{--sinch-size-icon:18px;--sinch-icon-font-variation-settings:var(--sinch-help-tooltip-icon-font-variation-settings)}</style><sinch-tooltip><sinch-icon id="icon"></sinch-icon></sinch-tooltip>';
|
|
4
|
+
const templateHTML = '<style>:host{display:contents}#icon{--sinch-size-icon:18px;--sinch-icon-font-variation-settings:var(--sinch-help-tooltip-icon-font-variation-settings)}</style><sinch-tooltip type="fast"><sinch-icon id="icon"></sinch-icon></sinch-tooltip>';
|
|
5
5
|
const template = document.createElement('template');
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
defineCustomElement('sinch-help-tooltip', class extends NectaryElement {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nectary/components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"**/*/*.css",
|
|
6
6
|
"**/*/*.json",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
23
23
|
"@babel/preset-env": "^7.20.2",
|
|
24
24
|
"@babel/preset-typescript": "^7.18.6",
|
|
25
|
-
"@types/node": "^18.11.18",
|
|
26
25
|
"@types/react": "^18.0.27",
|
|
27
26
|
"babel-plugin-html-inline-minifier": "workspace:^0.0.0",
|
|
28
27
|
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
|
package/tooltip/index.js
CHANGED
|
@@ -3,9 +3,10 @@ import '../pop';
|
|
|
3
3
|
import { defineCustomElement, getBooleanAttribute, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute, NectaryElement, setClass, rectOverlap, getReactEventHandler, shouldReduceMotion } from '../utils';
|
|
4
4
|
const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;color:var(--sinch-color-text-default);background-color:var(--sinch-color-snow-600);border-radius:var(--sinch-shape-radius-xs);pointer-events:none;opacity:0}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#text{word-break:break-word;pointer-events:none}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-color-snow-600);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([inverted]:not([inverted=false])) #content{background-color:var(--sinch-color-stormy-500);color:var(--sinch-color-text-inverted)}:host([inverted]:not([inverted=false])) #tip{fill:var(--sinch-color-stormy-500)}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
|
|
5
5
|
import { TooltipState } from './tooltip-state';
|
|
6
|
-
import { assertOrientation, getPopOrientation, orientationValues } from './utils';
|
|
6
|
+
import { assertOrientation, assertType, getPopOrientation, orientationValues, typeValues } from './utils';
|
|
7
7
|
const TIP_SIZE = 8;
|
|
8
|
-
const
|
|
8
|
+
const SHOW_DELAY_SLOW = 1000;
|
|
9
|
+
const SHOW_DELAY_FAST = 250;
|
|
9
10
|
const HIDE_DELAY = 0;
|
|
10
11
|
const ANIMATION_DURATION = 100;
|
|
11
12
|
const template = document.createElement('template');
|
|
@@ -34,7 +35,7 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
|
|
|
34
35
|
this.#$target = shadowRoot.querySelector('#target');
|
|
35
36
|
this.#shouldReduceMotion = shouldReduceMotion();
|
|
36
37
|
this.#tooltipState = new TooltipState({
|
|
37
|
-
showDelay:
|
|
38
|
+
showDelay: SHOW_DELAY_SLOW,
|
|
38
39
|
hideDelay: this.#shouldReduceMotion ? HIDE_DELAY + ANIMATION_DURATION : HIDE_DELAY,
|
|
39
40
|
hideAnimationDuration: this.#shouldReduceMotion ? 0 : ANIMATION_DURATION,
|
|
40
41
|
onShowStart: this.#onStateShowStart,
|
|
@@ -61,7 +62,38 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
|
|
|
61
62
|
this.#tooltipState.destroy();
|
|
62
63
|
}
|
|
63
64
|
static get observedAttributes() {
|
|
64
|
-
return ['text', 'orientation'];
|
|
65
|
+
return ['text', 'orientation', 'type'];
|
|
66
|
+
}
|
|
67
|
+
attributeChangedCallback(name, _, newVal) {
|
|
68
|
+
switch (name) {
|
|
69
|
+
case 'text':
|
|
70
|
+
{
|
|
71
|
+
this.#updateText();
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case 'orientation':
|
|
75
|
+
{
|
|
76
|
+
if ('production' !== 'production') {
|
|
77
|
+
assertOrientation(newVal);
|
|
78
|
+
}
|
|
79
|
+
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
80
|
+
if (this.#isOpen()) {
|
|
81
|
+
this.#resetTipOrientation();
|
|
82
|
+
this.#updateTipOrientation();
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'type':
|
|
87
|
+
{
|
|
88
|
+
if ('production' !== 'production') {
|
|
89
|
+
assertType(newVal);
|
|
90
|
+
}
|
|
91
|
+
this.#tooltipState.updateOptions({
|
|
92
|
+
showDelay: newVal === 'fast' ? SHOW_DELAY_FAST : SHOW_DELAY_SLOW
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
65
97
|
}
|
|
66
98
|
get text() {
|
|
67
99
|
return getAttribute(this, 'text', '');
|
|
@@ -81,33 +113,18 @@ defineCustomElement('sinch-tooltip', class extends NectaryElement {
|
|
|
81
113
|
set orientation(value) {
|
|
82
114
|
updateLiteralAttribute(this, orientationValues, 'orientation', value);
|
|
83
115
|
}
|
|
116
|
+
get type() {
|
|
117
|
+
return getLiteralAttribute(this, typeValues, 'type', 'slow');
|
|
118
|
+
}
|
|
119
|
+
set type(value) {
|
|
120
|
+
updateLiteralAttribute(this, typeValues, 'type', value);
|
|
121
|
+
}
|
|
84
122
|
get footprintRect() {
|
|
85
123
|
return this.#$pop.footprintRect;
|
|
86
124
|
}
|
|
87
125
|
get tooltipRect() {
|
|
88
126
|
return this.#$pop.popoverRect;
|
|
89
127
|
}
|
|
90
|
-
attributeChangedCallback(name, _, newVal) {
|
|
91
|
-
switch (name) {
|
|
92
|
-
case 'text':
|
|
93
|
-
{
|
|
94
|
-
this.#updateText();
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
case 'orientation':
|
|
98
|
-
{
|
|
99
|
-
if ('production' !== 'production') {
|
|
100
|
-
assertOrientation(newVal);
|
|
101
|
-
}
|
|
102
|
-
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
103
|
-
if (this.#isOpen()) {
|
|
104
|
-
this.#resetTipOrientation();
|
|
105
|
-
this.#updateTipOrientation();
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
128
|
#onMouseDown = () => {
|
|
112
129
|
this.#tooltipState.destroy();
|
|
113
130
|
};
|
package/tooltip/tooltip-state.js
CHANGED
package/tooltip/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TRect, TSinchElementReact } from '../types';
|
|
2
2
|
export type TSinchTooltipOrientation = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
3
|
+
export type TSinchTooltipType = 'slow' | 'fast';
|
|
3
4
|
export type TSinchTooltipElement = HTMLElement & {
|
|
4
5
|
/** Text */
|
|
5
6
|
text: string;
|
|
@@ -9,6 +10,8 @@ export type TSinchTooltipElement = HTMLElement & {
|
|
|
9
10
|
inverted: boolean;
|
|
10
11
|
/** Orientation, where it *points to* from origin */
|
|
11
12
|
orientation: TSinchTooltipOrientation;
|
|
13
|
+
/** Type */
|
|
14
|
+
type: TSinchTooltipType;
|
|
12
15
|
readonly footprintRect: TRect;
|
|
13
16
|
readonly tooltipRect: TRect;
|
|
14
17
|
/** Show event */
|
|
@@ -23,6 +26,8 @@ export type TSinchTooltipElement = HTMLElement & {
|
|
|
23
26
|
setAttribute(name: 'inverted', value: ''): void;
|
|
24
27
|
/** Orientation, where it *points to* from origin */
|
|
25
28
|
setAttribute(name: 'orientation', value: TSinchTooltipOrientation): void;
|
|
29
|
+
/** Type */
|
|
30
|
+
setAttribute(name: 'type', value: TSinchTooltipType): void;
|
|
26
31
|
};
|
|
27
32
|
export type TSinchTooltipReact = TSinchElementReact<TSinchTooltipElement> & {
|
|
28
33
|
/** Text */
|
|
@@ -33,6 +38,8 @@ export type TSinchTooltipReact = TSinchElementReact<TSinchTooltipElement> & {
|
|
|
33
38
|
inverted?: boolean;
|
|
34
39
|
/** Orientation, where it *points to* from origin */
|
|
35
40
|
orientation?: TSinchTooltipOrientation;
|
|
41
|
+
/** Type */
|
|
42
|
+
type?: TSinchTooltipType;
|
|
36
43
|
/** Show event handler */
|
|
37
44
|
'on-show'?: (e: CustomEvent<void>) => void;
|
|
38
45
|
/** Hide event handler */
|
package/tooltip/utils.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { TSinchTooltipOrientation } from './types';
|
|
1
|
+
import type { TSinchTooltipOrientation, TSinchTooltipType } from './types';
|
|
2
2
|
import type { TSinchPopOrientation } from '../pop/types';
|
|
3
|
+
export declare const typeValues: readonly TSinchTooltipType[];
|
|
3
4
|
export declare const orientationValues: readonly TSinchTooltipOrientation[];
|
|
4
5
|
export declare const getPopOrientation: (orientation: TSinchTooltipOrientation) => TSinchPopOrientation;
|
|
5
6
|
type TAssertOrientation = (value: string | null) => asserts value is TSinchTooltipOrientation;
|
|
6
7
|
export declare const assertOrientation: TAssertOrientation;
|
|
8
|
+
type TAssertType = (value: string | null) => asserts value is TSinchTooltipType;
|
|
9
|
+
export declare const assertType: TAssertType;
|
|
7
10
|
export {};
|
package/tooltip/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const typeValues = ['fast', 'slow'];
|
|
1
2
|
export const orientationValues = ['top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right'];
|
|
2
3
|
export const getPopOrientation = orientation => {
|
|
3
4
|
if (orientation === 'top') {
|
|
@@ -15,7 +16,12 @@ export const getPopOrientation = orientation => {
|
|
|
15
16
|
return orientation;
|
|
16
17
|
};
|
|
17
18
|
export const assertOrientation = value => {
|
|
18
|
-
if (value
|
|
19
|
+
if (value !== null && !orientationValues.includes(value)) {
|
|
19
20
|
throw new Error(`sinch-tooltip: invalid orientation attribute: ${value}`);
|
|
20
21
|
}
|
|
22
|
+
};
|
|
23
|
+
export const assertType = value => {
|
|
24
|
+
if (value !== null && !typeValues.includes(value)) {
|
|
25
|
+
throw new Error(`sinch-tooltip: invalid type attribute: ${value}`);
|
|
26
|
+
}
|
|
21
27
|
};
|