@db-ux/react-core-components 1.0.0-test-13b991d
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 +76 -0
- package/dist/components/accordion/accordion.d.ts +3 -0
- package/dist/components/accordion/accordion.js +92 -0
- package/dist/components/accordion/index.d.ts +1 -0
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/accordion/model.d.ts +41 -0
- package/dist/components/accordion/model.js +2 -0
- package/dist/components/accordion-item/accordion-item.d.ts +8 -0
- package/dist/components/accordion-item/accordion-item.js +34 -0
- package/dist/components/accordion-item/index.d.ts +1 -0
- package/dist/components/accordion-item/index.js +1 -0
- package/dist/components/accordion-item/model.d.ts +24 -0
- package/dist/components/accordion-item/model.js +1 -0
- package/dist/components/badge/badge.d.ts +3 -0
- package/dist/components/badge/badge.js +32 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/badge/model.d.ts +16 -0
- package/dist/components/badge/model.js +1 -0
- package/dist/components/brand/brand.d.ts +3 -0
- package/dist/components/brand/brand.js +13 -0
- package/dist/components/brand/index.d.ts +1 -0
- package/dist/components/brand/index.js +1 -0
- package/dist/components/brand/model.d.ts +10 -0
- package/dist/components/brand/model.js +1 -0
- package/dist/components/button/button.d.ts +3 -0
- package/dist/components/button/button.js +16 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/button/model.d.ts +52 -0
- package/dist/components/button/model.js +3 -0
- package/dist/components/card/card.d.ts +3 -0
- package/dist/components/card/card.js +16 -0
- package/dist/components/card/index.d.ts +1 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/card/model.d.ts +18 -0
- package/dist/components/card/model.js +2 -0
- package/dist/components/checkbox/checkbox.d.ts +3 -0
- package/dist/components/checkbox/checkbox.js +112 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/checkbox/model.d.ts +10 -0
- package/dist/components/checkbox/model.js +1 -0
- package/dist/components/divider/divider.d.ts +3 -0
- package/dist/components/divider/divider.js +11 -0
- package/dist/components/divider/index.d.ts +1 -0
- package/dist/components/divider/index.js +1 -0
- package/dist/components/divider/model.d.ts +18 -0
- package/dist/components/divider/model.js +2 -0
- package/dist/components/drawer/drawer.d.ts +3 -0
- package/dist/components/drawer/drawer.js +70 -0
- package/dist/components/drawer/index.d.ts +1 -0
- package/dist/components/drawer/index.js +1 -0
- package/dist/components/drawer/model.d.ts +41 -0
- package/dist/components/drawer/model.js +3 -0
- package/dist/components/header/header.d.ts +3 -0
- package/dist/components/header/header.js +68 -0
- package/dist/components/header/index.d.ts +1 -0
- package/dist/components/header/index.js +1 -0
- package/dist/components/header/model.d.ts +44 -0
- package/dist/components/header/model.js +1 -0
- package/dist/components/icon/icon.d.ts +3 -0
- package/dist/components/icon/icon.js +11 -0
- package/dist/components/icon/index.d.ts +1 -0
- package/dist/components/icon/index.js +1 -0
- package/dist/components/icon/model.d.ts +12 -0
- package/dist/components/icon/model.js +2 -0
- package/dist/components/infotext/index.d.ts +1 -0
- package/dist/components/infotext/index.js +1 -0
- package/dist/components/infotext/infotext.d.ts +3 -0
- package/dist/components/infotext/infotext.js +12 -0
- package/dist/components/infotext/model.d.ts +5 -0
- package/dist/components/infotext/model.js +1 -0
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/input.d.ts +3 -0
- package/dist/components/input/input.js +119 -0
- package/dist/components/input/model.d.ts +39 -0
- package/dist/components/input/model.js +5 -0
- package/dist/components/link/index.d.ts +1 -0
- package/dist/components/link/index.js +1 -0
- package/dist/components/link/link.d.ts +3 -0
- package/dist/components/link/link.js +17 -0
- package/dist/components/link/model.d.ts +24 -0
- package/dist/components/link/model.js +3 -0
- package/dist/components/navigation/index.d.ts +1 -0
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/model.d.ts +5 -0
- package/dist/components/navigation/model.js +1 -0
- package/dist/components/navigation/navigation.d.ts +3 -0
- package/dist/components/navigation/navigation.js +17 -0
- package/dist/components/navigation-item/index.d.ts +1 -0
- package/dist/components/navigation-item/index.js +1 -0
- package/dist/components/navigation-item/model.d.ts +34 -0
- package/dist/components/navigation-item/model.js +1 -0
- package/dist/components/navigation-item/navigation-item.d.ts +3 -0
- package/dist/components/navigation-item/navigation-item.js +68 -0
- package/dist/components/notification/index.d.ts +1 -0
- package/dist/components/notification/index.js +1 -0
- package/dist/components/notification/model.d.ts +57 -0
- package/dist/components/notification/model.js +3 -0
- package/dist/components/notification/notification.d.ts +3 -0
- package/dist/components/notification/notification.js +25 -0
- package/dist/components/page/index.d.ts +1 -0
- package/dist/components/page/index.js +1 -0
- package/dist/components/page/model.d.ts +32 -0
- package/dist/components/page/model.js +2 -0
- package/dist/components/page/page.d.ts +3 -0
- package/dist/components/page/page.js +47 -0
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/popover/model.d.ts +18 -0
- package/dist/components/popover/model.js +1 -0
- package/dist/components/popover/popover.d.ts +3 -0
- package/dist/components/popover/popover.js +74 -0
- package/dist/components/radio/index.d.ts +1 -0
- package/dist/components/radio/index.js +1 -0
- package/dist/components/radio/model.d.ts +7 -0
- package/dist/components/radio/model.js +1 -0
- package/dist/components/radio/radio.d.ts +3 -0
- package/dist/components/radio/radio.js +54 -0
- package/dist/components/section/index.d.ts +1 -0
- package/dist/components/section/index.js +1 -0
- package/dist/components/section/model.d.ts +5 -0
- package/dist/components/section/model.js +1 -0
- package/dist/components/section/section.d.ts +3 -0
- package/dist/components/section/section.js +16 -0
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/select/model.d.ts +43 -0
- package/dist/components/select/model.js +1 -0
- package/dist/components/select/select.d.ts +3 -0
- package/dist/components/select/select.js +132 -0
- package/dist/components/stack/index.d.ts +1 -0
- package/dist/components/stack/index.js +1 -0
- package/dist/components/stack/model.d.ts +34 -0
- package/dist/components/stack/model.js +4 -0
- package/dist/components/stack/stack.d.ts +3 -0
- package/dist/components/stack/stack.js +11 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/switch/model.d.ts +12 -0
- package/dist/components/switch/model.js +1 -0
- package/dist/components/switch/switch.d.ts +3 -0
- package/dist/components/switch/switch.js +47 -0
- package/dist/components/tab-item/index.d.ts +1 -0
- package/dist/components/tab-item/index.js +1 -0
- package/dist/components/tab-item/model.d.ts +24 -0
- package/dist/components/tab-item/model.js +1 -0
- package/dist/components/tab-item/tab-item.d.ts +3 -0
- package/dist/components/tab-item/tab-item.js +37 -0
- package/dist/components/tab-list/index.d.ts +1 -0
- package/dist/components/tab-list/index.js +1 -0
- package/dist/components/tab-list/model.d.ts +5 -0
- package/dist/components/tab-list/model.js +1 -0
- package/dist/components/tab-list/tab-list.d.ts +3 -0
- package/dist/components/tab-list/tab-list.js +17 -0
- package/dist/components/tab-panel/index.d.ts +1 -0
- package/dist/components/tab-panel/index.js +1 -0
- package/dist/components/tab-panel/model.d.ts +10 -0
- package/dist/components/tab-panel/model.js +1 -0
- package/dist/components/tab-panel/tab-panel.d.ts +3 -0
- package/dist/components/tab-panel/tab-panel.js +14 -0
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tabs/model.d.ts +47 -0
- package/dist/components/tabs/model.js +2 -0
- package/dist/components/tabs/tabs.d.ts +3 -0
- package/dist/components/tabs/tabs.js +138 -0
- package/dist/components/tag/index.d.ts +1 -0
- package/dist/components/tag/index.js +1 -0
- package/dist/components/tag/model.d.ts +45 -0
- package/dist/components/tag/model.js +1 -0
- package/dist/components/tag/tag.d.ts +3 -0
- package/dist/components/tag/tag.js +46 -0
- package/dist/components/textarea/index.d.ts +1 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/textarea/model.d.ts +30 -0
- package/dist/components/textarea/model.js +2 -0
- package/dist/components/textarea/textarea.d.ts +3 -0
- package/dist/components/textarea/textarea.js +105 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tooltip/model.d.ts +7 -0
- package/dist/components/tooltip/model.js +1 -0
- package/dist/components/tooltip/tooltip.d.ts +3 -0
- package/dist/components/tooltip/tooltip.js +43 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +36 -0
- package/dist/shared/constants.d.ts +83 -0
- package/dist/shared/constants.js +87 -0
- package/dist/shared/model.d.ts +446 -0
- package/dist/shared/model.js +20 -0
- package/dist/utils/form-components.d.ts +2 -0
- package/dist/utils/form-components.js +10 -0
- package/dist/utils/index.d.ts +61 -0
- package/dist/utils/index.js +166 -0
- package/dist/utils/navigation.d.ts +32 -0
- package/dist/utils/navigation.js +136 -0
- package/package.json +43 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
export const uuid = () => {
|
|
2
|
+
var _a, _b;
|
|
3
|
+
if (typeof window !== 'undefined') {
|
|
4
|
+
if ((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) {
|
|
5
|
+
return window.crypto.randomUUID();
|
|
6
|
+
}
|
|
7
|
+
else if ((_b = window.crypto) === null || _b === void 0 ? void 0 : _b.getRandomValues) {
|
|
8
|
+
return window.crypto.getRandomValues(new Uint32Array(3)).join('-');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return Math.random().toString().substring(2);
|
|
12
|
+
};
|
|
13
|
+
export const addAttributeToChildren = (element, attribute) => {
|
|
14
|
+
const children = element.children;
|
|
15
|
+
Object.values(children).forEach((child) => {
|
|
16
|
+
child.setAttribute(attribute.key, attribute.value);
|
|
17
|
+
if (child.children.length > 0) {
|
|
18
|
+
addAttributeToChildren(child, attribute);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
export const cls = (...args) => {
|
|
23
|
+
let result = '';
|
|
24
|
+
for (const arg of args) {
|
|
25
|
+
if (arg) {
|
|
26
|
+
if (typeof arg === 'string') {
|
|
27
|
+
result += `${arg} `;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
for (const key in arg) {
|
|
31
|
+
if (arg[key]) {
|
|
32
|
+
result += `${key} `;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result.trim();
|
|
39
|
+
};
|
|
40
|
+
const reactHtmlAttributes = ['suppressHydrationWarning', 'suppressContentEditableWarning', 'translate', 'title', 'tabIndex', 'style', 'spellCheck', 'nonce', 'lang', 'hidden', 'draggable', 'dir', 'contextMenu', 'contentEditable', 'autoFocus', 'accessKey', 'is', 'inputMode', 'unselectable', 'security', 'results', 'vocab', 'typeof', 'rev', 'resource', 'rel', 'property', 'inlist', 'datatype', 'content', 'about', 'role', 'radioGroup', 'color'];
|
|
41
|
+
export const filterPassingProps = (props, propsPassingFilter) => Object.keys(props).filter(key => (key.startsWith('data-') || key.startsWith('aria-') || key.startsWith('default') || key.startsWith('auto') || key.startsWith('item') || key.startsWith('on') || reactHtmlAttributes.includes(key)) && !propsPassingFilter.includes(key)).reduce((obj, key) => {
|
|
42
|
+
return Object.assign(Object.assign({}, obj), { [key]: props[key] });
|
|
43
|
+
}, {});
|
|
44
|
+
export const getRootProps = (props, rooProps) => {
|
|
45
|
+
return Object.keys(props).filter(key => rooProps.includes(key)).reduce((obj, key) => {
|
|
46
|
+
return Object.assign(Object.assign({}, obj), { [key]: props[key] });
|
|
47
|
+
}, {});
|
|
48
|
+
};
|
|
49
|
+
export const visibleInVX = (el) => {
|
|
50
|
+
const { left, right } = el.getBoundingClientRect();
|
|
51
|
+
const { innerWidth } = window;
|
|
52
|
+
return left >= 0 && right <= innerWidth;
|
|
53
|
+
};
|
|
54
|
+
export const visibleInVY = (el) => {
|
|
55
|
+
const { top, bottom } = el.getBoundingClientRect();
|
|
56
|
+
const { innerHeight } = window;
|
|
57
|
+
return top >= 0 && bottom <= innerHeight;
|
|
58
|
+
};
|
|
59
|
+
export const isInView = (el) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const { top, bottom, left, right } = el.getBoundingClientRect();
|
|
62
|
+
const { innerHeight, innerWidth } = window;
|
|
63
|
+
let outTop = top < 0;
|
|
64
|
+
let outBottom = bottom > innerHeight;
|
|
65
|
+
let outLeft = left < 0;
|
|
66
|
+
let outRight = right > innerWidth;
|
|
67
|
+
// We need to check if it was already outside
|
|
68
|
+
const outsideY = el.hasAttribute('data-outside-vy');
|
|
69
|
+
const outsideX = el.hasAttribute('data-outside-vx');
|
|
70
|
+
const parentRect = (_a = el === null || el === void 0 ? void 0 : el.parentElement) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
71
|
+
if (parentRect) {
|
|
72
|
+
if (outsideY) {
|
|
73
|
+
const position = el.getAttribute('data-outside-vy');
|
|
74
|
+
if (position === 'top') {
|
|
75
|
+
outTop = parentRect.top - (bottom - parentRect.bottom) < 0;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
outBottom = parentRect.bottom + (parentRect.top - top) > innerHeight;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (outsideX) {
|
|
82
|
+
const position = el.getAttribute('data-outside-vx');
|
|
83
|
+
if (position === 'left') {
|
|
84
|
+
outLeft = parentRect.left - (right - parentRect.right) < 0;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
outRight = parentRect.right + (parentRect.left - left) > innerWidth;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
outTop,
|
|
93
|
+
outBottom,
|
|
94
|
+
outLeft,
|
|
95
|
+
outRight
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export const handleDataOutside = (el) => {
|
|
99
|
+
const { outTop, outBottom, outLeft, outRight } = isInView(el);
|
|
100
|
+
let dataOutsidePair = {};
|
|
101
|
+
if (outTop || outBottom) {
|
|
102
|
+
dataOutsidePair = {
|
|
103
|
+
vy: outTop ? 'top' : 'bottom'
|
|
104
|
+
};
|
|
105
|
+
el.setAttribute('data-outside-vy', dataOutsidePair.vy);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
el.removeAttribute('data-outside-vy');
|
|
109
|
+
}
|
|
110
|
+
if (outLeft || outRight) {
|
|
111
|
+
dataOutsidePair = Object.assign(Object.assign({}, dataOutsidePair), { vx: outRight ? 'right' : 'left' });
|
|
112
|
+
el.setAttribute('data-outside-vx', dataOutsidePair.vx);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
el.removeAttribute('data-outside-vx');
|
|
116
|
+
}
|
|
117
|
+
return dataOutsidePair;
|
|
118
|
+
};
|
|
119
|
+
export const isArrayOfStrings = (value) => Array.isArray(value) && value.every(item => typeof item === 'string');
|
|
120
|
+
const appleOs = ['Mac', 'iPhone', 'iPad', 'iPod'];
|
|
121
|
+
export const hasVoiceOver = () => typeof window !== 'undefined' && appleOs.some(os => window.navigator.userAgent.includes(os));
|
|
122
|
+
export const delay = (fn, ms) => new Promise(() => setTimeout(fn, ms));
|
|
123
|
+
/**
|
|
124
|
+
* Some frameworks like stencil would not add "true" as value for a prop
|
|
125
|
+
* if it is used in a framework like angular e.g.: [disabled]="myDisabledProp"
|
|
126
|
+
* @param originBool Some boolean to convert to string
|
|
127
|
+
*/
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
export const getBooleanAsString = (originBool) => {
|
|
130
|
+
if (originBool) {
|
|
131
|
+
return String(originBool);
|
|
132
|
+
}
|
|
133
|
+
return originBool;
|
|
134
|
+
};
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
+
export const getHideProp = (show) => {
|
|
137
|
+
if (show === undefined || show === null) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
return getBooleanAsString(!show);
|
|
141
|
+
};
|
|
142
|
+
export const stringPropVisible = (givenString, showString) => {
|
|
143
|
+
if (showString === undefined) {
|
|
144
|
+
return !!givenString;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return showString && givenString;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
export default {
|
|
151
|
+
getRootProps,
|
|
152
|
+
filterPassingProps,
|
|
153
|
+
cls,
|
|
154
|
+
addAttributeToChildren,
|
|
155
|
+
uuid,
|
|
156
|
+
visibleInVX,
|
|
157
|
+
visibleInVY,
|
|
158
|
+
isInView,
|
|
159
|
+
handleDataOutside,
|
|
160
|
+
isArrayOfStrings,
|
|
161
|
+
hasVoiceOver,
|
|
162
|
+
delay,
|
|
163
|
+
getBooleanAsString,
|
|
164
|
+
getHideProp,
|
|
165
|
+
stringPropVisible
|
|
166
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type TriangleData = {
|
|
2
|
+
itemRect: DOMRect;
|
|
3
|
+
parentElementWidth: number;
|
|
4
|
+
subNavigationHeight: number;
|
|
5
|
+
padding: number;
|
|
6
|
+
outsideVX: 'left' | 'right' | undefined;
|
|
7
|
+
outsideVY: 'top' | 'bottom' | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare const isEventTargetNavigationItem: (event: unknown) => boolean;
|
|
10
|
+
export declare class NavigationItemSafeTriangle {
|
|
11
|
+
private readonly element;
|
|
12
|
+
private readonly subNavigation;
|
|
13
|
+
private readonly parentSubNavigation;
|
|
14
|
+
private triangleData?;
|
|
15
|
+
private initialized;
|
|
16
|
+
private mouseX;
|
|
17
|
+
private mouseY;
|
|
18
|
+
constructor(element: HTMLElement | null, subNavigation: Element | null);
|
|
19
|
+
private init;
|
|
20
|
+
enableFollow(): void;
|
|
21
|
+
disableFollow(): void;
|
|
22
|
+
private getTriangleTipX;
|
|
23
|
+
private getTriangleTipY;
|
|
24
|
+
private hasMouseEnteredSubNavigation;
|
|
25
|
+
private getTriangleCoordinates;
|
|
26
|
+
followByMouseEvent(event: MouseEvent): void;
|
|
27
|
+
}
|
|
28
|
+
declare const _default: {
|
|
29
|
+
isEventTargetNavigationItem: (event: unknown) => boolean;
|
|
30
|
+
NavigationItemSafeTriangle: typeof NavigationItemSafeTriangle;
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { handleDataOutside } from './index';
|
|
2
|
+
export const isEventTargetNavigationItem = (event) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const { target } = event;
|
|
5
|
+
return Boolean(!((_a = target === null || target === void 0 ? void 0 : target.classList) === null || _a === void 0 ? void 0 : _a.contains('db-navigation-item-expand-button')) && ((_b = target === null || target === void 0 ? void 0 : target.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('db-navigation-item')));
|
|
6
|
+
};
|
|
7
|
+
export class NavigationItemSafeTriangle {
|
|
8
|
+
constructor(element, subNavigation) {
|
|
9
|
+
var _a;
|
|
10
|
+
this.parentSubNavigation = null;
|
|
11
|
+
this.initialized = false;
|
|
12
|
+
this.mouseX = 0;
|
|
13
|
+
this.mouseY = 0;
|
|
14
|
+
this.element = element;
|
|
15
|
+
this.subNavigation = subNavigation;
|
|
16
|
+
if (!this.element || !this.subNavigation) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.parentSubNavigation = (_a = this.element) === null || _a === void 0 ? void 0 : _a.closest('.db-sub-navigation');
|
|
20
|
+
/*
|
|
21
|
+
* only initiate if:
|
|
22
|
+
* 1. item is not at root navigation level
|
|
23
|
+
* 2. item is not in the mobile navigation / within db-drawer
|
|
24
|
+
*/
|
|
25
|
+
if (this.parentSubNavigation && !this.element.closest('.db-drawer')) {
|
|
26
|
+
this.init();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
init() {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
const parentElementWidth = (_b = (_a = this.parentSubNavigation) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) !== null && _b !== void 0 ? _b : 0;
|
|
32
|
+
// the triangle has the width of the sub-navigation, current nav-item can be wider.
|
|
33
|
+
// so the width of the triangle must be adapted to a possibly wider nav-item.
|
|
34
|
+
(_c = this.element) === null || _c === void 0 ? void 0 : _c.style.setProperty('--db-navigation-item-inline-size', `${parentElementWidth}px`);
|
|
35
|
+
this.initialized = true;
|
|
36
|
+
}
|
|
37
|
+
enableFollow() {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (!this.initialized || this.triangleData || !this.element || !this.subNavigation) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const dataOutsidePair = handleDataOutside(this.subNavigation);
|
|
43
|
+
const itemRect = this.element.getBoundingClientRect();
|
|
44
|
+
const parentElementWidth = (_b = (_a = this.parentSubNavigation) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) !== null && _b !== void 0 ? _b : 0;
|
|
45
|
+
this.triangleData = {
|
|
46
|
+
itemRect,
|
|
47
|
+
parentElementWidth,
|
|
48
|
+
subNavigationHeight: this.subNavigation.getBoundingClientRect().height,
|
|
49
|
+
padding: (parentElementWidth - itemRect.width) / 2,
|
|
50
|
+
outsideVX: dataOutsidePair.vx,
|
|
51
|
+
outsideVY: dataOutsidePair.vy
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
disableFollow() {
|
|
55
|
+
this.triangleData = undefined;
|
|
56
|
+
}
|
|
57
|
+
getTriangleTipX() {
|
|
58
|
+
if (!this.triangleData)
|
|
59
|
+
return 0;
|
|
60
|
+
if (this.triangleData.outsideVX === 'right') {
|
|
61
|
+
// vertical flipped triangle needs an inverted x pos
|
|
62
|
+
return this.triangleData.itemRect.width - this.mouseX;
|
|
63
|
+
}
|
|
64
|
+
// triangle stops shrinking from 75% x pos
|
|
65
|
+
return Math.min(this.mouseX, this.triangleData.itemRect.width * 0.75);
|
|
66
|
+
}
|
|
67
|
+
getTriangleTipY() {
|
|
68
|
+
if (!this.triangleData)
|
|
69
|
+
return 0;
|
|
70
|
+
// padding must be added to the y pos of the tip so that the y pos matches the cursor
|
|
71
|
+
const mouseYLimited = Math.max(Math.min(this.mouseY, this.triangleData.itemRect.height), 0) + this.triangleData.padding;
|
|
72
|
+
if (this.triangleData.outsideVY === 'bottom') {
|
|
73
|
+
// add offset to tip y pos to match corrected sub-navigation y pos
|
|
74
|
+
return mouseYLimited + (this.triangleData.subNavigationHeight - this.triangleData.padding * 2 - this.triangleData.itemRect.height);
|
|
75
|
+
}
|
|
76
|
+
return mouseYLimited;
|
|
77
|
+
}
|
|
78
|
+
hasMouseEnteredSubNavigation() {
|
|
79
|
+
if (!this.triangleData) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const isSubNavigationOnLeftSide = this.triangleData.outsideVX === 'right';
|
|
83
|
+
if (isSubNavigationOnLeftSide && this.mouseX < -1 * this.triangleData.padding) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (!isSubNavigationOnLeftSide && this.mouseX > this.triangleData.parentElementWidth - this.triangleData.padding) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
getTriangleCoordinates(variant) {
|
|
92
|
+
if (!this.triangleData) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (variant === 'fill-gap') {
|
|
96
|
+
const itemHeight = `${this.triangleData.itemRect.height + 2 * this.triangleData.padding}px`;
|
|
97
|
+
const xStart = `${this.triangleData.parentElementWidth - this.triangleData.padding}px`;
|
|
98
|
+
return {
|
|
99
|
+
lb: `${xStart} ${itemHeight}`,
|
|
100
|
+
lt: `${xStart} 0`,
|
|
101
|
+
rt: '100% 0',
|
|
102
|
+
rb: `100% ${itemHeight}`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const tipX = this.getTriangleTipX();
|
|
106
|
+
const tipY = this.getTriangleTipY();
|
|
107
|
+
const lb = `${tipX}px ${tipY}px`;
|
|
108
|
+
const lt = `${tipX}px ${tipY}px`;
|
|
109
|
+
return {
|
|
110
|
+
lb,
|
|
111
|
+
lt,
|
|
112
|
+
rt: '100% 0',
|
|
113
|
+
rb: '100% 100%'
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
followByMouseEvent(event) {
|
|
117
|
+
if (!this.initialized || !this.triangleData || !this.element || !this.subNavigation) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.mouseX = event.clientX - this.triangleData.itemRect.left;
|
|
121
|
+
this.mouseY = event.clientY - this.triangleData.itemRect.top;
|
|
122
|
+
const isOverSubNavigation = this.hasMouseEnteredSubNavigation();
|
|
123
|
+
const coordinates = this.getTriangleCoordinates(isOverSubNavigation ? 'fill-gap' : 'safe-triangle');
|
|
124
|
+
if (!coordinates) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.element.style.setProperty('--db-navigation-item-clip-path', `polygon(${coordinates.lb}, ${coordinates.lt}, ${coordinates.rt}, ${coordinates.rb})`);
|
|
128
|
+
if (isOverSubNavigation) {
|
|
129
|
+
this.triangleData = undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export default {
|
|
134
|
+
isEventTargetNavigationItem,
|
|
135
|
+
NavigationItemSafeTriangle
|
|
136
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@db-ux/react-core-components",
|
|
3
|
+
"version": "1.0.0-test-13b991d",
|
|
4
|
+
"description": "React components for @db-ux/core-components",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/db-ux-design-system/core-web.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "npm-run-all tsc",
|
|
18
|
+
"mv:dist": "cpr dist ../../build-outputs/react/dist -o",
|
|
19
|
+
"mv:package.json": "cpr package.json ../../build-outputs/react/package.json -o",
|
|
20
|
+
"mv:readme": "cpr README.md ../../build-outputs/react/README.md -o",
|
|
21
|
+
"open:report": "npx playwright show-report",
|
|
22
|
+
"postbuild": "npm-run-all -p mv:*",
|
|
23
|
+
"regenerate:screenshots": "playwright test -c playwright.config.ts --update-snapshots",
|
|
24
|
+
"test:components": "playwright test -c playwright.config.ts",
|
|
25
|
+
"test:windows": "playwright test -c playwright.screen-reader.win.ts",
|
|
26
|
+
"tsc": "tsc -p . --sourceMap false"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@playwright/experimental-ct-react": "1.50.1",
|
|
30
|
+
"@types/react": "^18.3.13",
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"react-dom": "^18.3.1"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@db-ux/core-components": "1.0.0-test-13b991d",
|
|
41
|
+
"@db-ux/core-foundations": "1.0.0-test-13b991d"
|
|
42
|
+
}
|
|
43
|
+
}
|