@db-ux/react-core-components 4.4.2 → 4.5.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/components/accordion/accordion.js +3 -3
  3. package/dist/components/accordion-item/accordion-item.d.ts +1 -1
  4. package/dist/components/accordion-item/accordion-item.js +3 -2
  5. package/dist/components/badge/badge.d.ts +1 -1
  6. package/dist/components/badge/badge.js +3 -3
  7. package/dist/components/badge/model.d.ts +2 -2
  8. package/dist/components/brand/brand.d.ts +1 -1
  9. package/dist/components/brand/brand.js +2 -2
  10. package/dist/components/button/button.d.ts +1 -1
  11. package/dist/components/button/button.js +2 -2
  12. package/dist/components/button/model.d.ts +8 -10
  13. package/dist/components/card/card.js +2 -1
  14. package/dist/components/checkbox/checkbox.js +16 -7
  15. package/dist/components/custom-button/custom-button.d.ts +3 -0
  16. package/dist/components/custom-button/custom-button.js +12 -0
  17. package/dist/components/custom-button/index.d.ts +1 -0
  18. package/dist/components/custom-button/index.js +1 -0
  19. package/dist/components/custom-button/model.d.ts +6 -0
  20. package/dist/components/custom-button/model.js +1 -0
  21. package/dist/components/custom-select/custom-select.js +28 -19
  22. package/dist/components/custom-select-dropdown/custom-select-dropdown.js +2 -1
  23. package/dist/components/custom-select-form-field/custom-select-form-field.js +2 -1
  24. package/dist/components/custom-select-list/custom-select-list.js +2 -1
  25. package/dist/components/custom-select-list-item/custom-select-list-item.js +2 -1
  26. package/dist/components/divider/divider.js +2 -1
  27. package/dist/components/drawer/drawer.js +4 -4
  28. package/dist/components/header/header.js +3 -3
  29. package/dist/components/icon/icon.d.ts +1 -1
  30. package/dist/components/icon/icon.js +2 -1
  31. package/dist/components/infotext/infotext.d.ts +1 -1
  32. package/dist/components/infotext/infotext.js +2 -2
  33. package/dist/components/infotext/model.d.ts +2 -2
  34. package/dist/components/input/input.js +18 -9
  35. package/dist/components/link/link.d.ts +1 -1
  36. package/dist/components/link/link.js +2 -2
  37. package/dist/components/navigation/navigation.js +2 -1
  38. package/dist/components/navigation-item/navigation-item.d.ts +1 -1
  39. package/dist/components/navigation-item/navigation-item.js +3 -3
  40. package/dist/components/notification/model.d.ts +2 -2
  41. package/dist/components/notification/notification.d.ts +1 -1
  42. package/dist/components/notification/notification.js +3 -3
  43. package/dist/components/page/page.js +2 -1
  44. package/dist/components/popover/popover.js +4 -4
  45. package/dist/components/radio/radio.js +14 -4
  46. package/dist/components/section/section.js +2 -1
  47. package/dist/components/select/select.js +18 -9
  48. package/dist/components/stack/stack.js +2 -1
  49. package/dist/components/switch/model.d.ts +1 -1
  50. package/dist/components/switch/switch.d.ts +1 -1
  51. package/dist/components/switch/switch.js +26 -9
  52. package/dist/components/tab-item/tab-item.d.ts +1 -1
  53. package/dist/components/tab-item/tab-item.js +4 -4
  54. package/dist/components/tab-list/tab-list.js +2 -1
  55. package/dist/components/tab-panel/tab-panel.js +2 -1
  56. package/dist/components/tabs/tabs.js +4 -4
  57. package/dist/components/tag/model.d.ts +2 -6
  58. package/dist/components/tag/tag.d.ts +1 -1
  59. package/dist/components/tag/tag.js +2 -2
  60. package/dist/components/textarea/textarea.js +17 -8
  61. package/dist/components/tooltip/model.d.ts +3 -3
  62. package/dist/components/tooltip/tooltip.d.ts +1 -1
  63. package/dist/components/tooltip/tooltip.js +13 -7
  64. package/dist/index.d.ts +2 -0
  65. package/dist/index.js +2 -0
  66. package/dist/shared/model.d.ts +17 -3
  67. package/dist/utils/floating-components.js +65 -15
  68. package/dist/utils/index.js +6 -7
  69. package/package.json +4 -4
@@ -228,10 +228,54 @@ export const getFloatingProps = (element, parent, placement) => {
228
228
  innerHeight
229
229
  };
230
230
  };
231
+ const MAX_ANCESTOR_DEPTH = 10;
232
+ const ancestorCache = new WeakMap();
233
+ const getAncestorHasCorrectedPlacement = (element) => {
234
+ if (ancestorCache.has(element)) {
235
+ return ancestorCache.get(element);
236
+ }
237
+ let current = element.parentElement;
238
+ let anchor = 0;
239
+ while (current && anchor < MAX_ANCESTOR_DEPTH) {
240
+ if (current.dataset['correctedPlacement']) {
241
+ ancestorCache.set(element, current);
242
+ return current;
243
+ }
244
+ current = current.parentElement;
245
+ anchor += 1;
246
+ }
247
+ ancestorCache.set(element, null);
248
+ return null;
249
+ };
231
250
  export const handleFixedPopover = (element, parent, placement) => {
232
- var _a;
233
- const distance = (_a = getComputedStyle(element).getPropertyValue('--db-popover-distance')) !== null && _a !== void 0 ? _a : '0px';
234
- const { top, height, width, childHeight, childWidth, right, left, bottom, correctedPlacement, innerWidth, innerHeight } = getFloatingProps(element, parent, placement);
251
+ var _a, _b;
252
+ const parentComputedStyles = getComputedStyle(parent);
253
+ const parentHasFloatingPosition = ['absolute', 'fixed'].includes(parentComputedStyles.position);
254
+ const ancestorWithCorrectedPlacement = getAncestorHasCorrectedPlacement(element);
255
+ const noFloatingAncestor = !ancestorWithCorrectedPlacement && !parentHasFloatingPosition;
256
+ const distance = (_b = (_a = getComputedStyle(element)) === null || _a === void 0 ? void 0 : _a.getPropertyValue('--db-popover-distance')) !== null && _b !== void 0 ? _b : '0px';
257
+ let { top, height, width, childHeight, childWidth, right, left, bottom, correctedPlacement, innerWidth, innerHeight } = getFloatingProps(element, parent, placement);
258
+ if (ancestorWithCorrectedPlacement) {
259
+ const ancestorRect = ancestorWithCorrectedPlacement.getBoundingClientRect();
260
+ left = Math.abs(left - ancestorRect.left);
261
+ right = (width + Math.abs(right - ancestorRect.right)) * 1.5; // We add a transform -50% later
262
+ top = Math.abs(top - ancestorRect.top);
263
+ bottom = (height + Math.abs(bottom - ancestorRect.bottom)) * 1.5; // We add a transform -50% later
264
+ }
265
+ if (parentHasFloatingPosition) {
266
+ /*
267
+ * If we have a floating element inside an element with position:absolute/fixed
268
+ * we need to calculate with relative values
269
+ * */
270
+ left = 0;
271
+ right = width;
272
+ top = 0;
273
+ bottom = height;
274
+ if (['auto', 'inherit', '0'].includes(parentComputedStyles.zIndex)) {
275
+ // We need the default zIndex for floating elements on the parent
276
+ parent.style.zIndex = '1';
277
+ }
278
+ }
235
279
  // Tooltip arrow position
236
280
  if (childWidth > width && (correctedPlacement.startsWith('bottom') || correctedPlacement.startsWith('top'))) {
237
281
  const diff = width / 2 / childWidth * 100;
@@ -241,6 +285,9 @@ export const handleFixedPopover = (element, parent, placement) => {
241
285
  else if (correctedPlacement.endsWith('end')) {
242
286
  element.style.setProperty('--db-tooltip-arrow-inline-start', `${100 - diff}%`);
243
287
  }
288
+ else {
289
+ element.style.setProperty('--db-tooltip-arrow-inline-start', `50%`);
290
+ }
244
291
  }
245
292
  if (childHeight > height && (correctedPlacement.startsWith('left') || correctedPlacement.startsWith('bottom'))) {
246
293
  const diff = height / 2 / childHeight * 100;
@@ -250,6 +297,9 @@ export const handleFixedPopover = (element, parent, placement) => {
250
297
  else if (correctedPlacement.endsWith('end')) {
251
298
  element.style.setProperty('--db-tooltip-arrow-block-start', `${100 - diff}%`);
252
299
  }
300
+ else {
301
+ element.style.setProperty('--db-tooltip-arrow-block-start', `50%`);
302
+ }
253
303
  }
254
304
  // Popover position
255
305
  if (correctedPlacement === 'right' || correctedPlacement === 'left') {
@@ -259,11 +309,11 @@ export const handleFixedPopover = (element, parent, placement) => {
259
309
  else if (correctedPlacement === 'right-start' || correctedPlacement === 'left-start') {
260
310
  const end = top + childHeight;
261
311
  element.style.insetBlockStart = `${top}px`;
262
- element.style.insetBlockEnd = `${end > innerHeight ? innerHeight : end}px`;
312
+ element.style.insetBlockEnd = `${!parentHasFloatingPosition && end > innerHeight ? innerHeight : end}px`;
263
313
  }
264
314
  else if (correctedPlacement === 'right-end' || correctedPlacement === 'left-end') {
265
315
  const start = bottom - childHeight;
266
- element.style.insetBlockStart = `${start < 0 ? 0 : start}px`;
316
+ element.style.insetBlockStart = `${!parentHasFloatingPosition && start < 0 ? 0 : start}px`;
267
317
  element.style.insetBlockEnd = `${bottom}px`;
268
318
  }
269
319
  else if (correctedPlacement === 'top' || correctedPlacement === 'bottom') {
@@ -273,32 +323,32 @@ export const handleFixedPopover = (element, parent, placement) => {
273
323
  else if (correctedPlacement === 'top-start' || correctedPlacement === 'bottom-start') {
274
324
  const end = left + childWidth;
275
325
  element.style.insetInlineStart = `${left}px`;
276
- element.style.insetInlineEnd = `${end > innerWidth ? innerWidth : end}px`;
326
+ element.style.insetInlineEnd = `${!parentHasFloatingPosition && end > innerWidth ? innerWidth : end}px`;
277
327
  }
278
328
  else if (correctedPlacement === 'top-end' || correctedPlacement === 'bottom-end') {
279
- const start = left - childWidth;
280
- element.style.insetInlineStart = `${right - childWidth}px`;
281
- element.style.insetInlineEnd = `${start < 0 ? 0 : start}px`;
329
+ const start = right - childWidth;
330
+ element.style.insetInlineStart = `${!parentHasFloatingPosition && start < 0 ? 0 : start}px`;
331
+ element.style.insetInlineEnd = `${right}px`;
282
332
  }
283
333
  if (correctedPlacement === null || correctedPlacement === void 0 ? void 0 : correctedPlacement.startsWith('right')) {
284
334
  const end = right + childWidth;
285
335
  element.style.insetInlineStart = `calc(${right}px + ${distance})`;
286
- element.style.insetInlineEnd = `calc(${end > innerWidth ? innerWidth : end}px + ${distance})`;
336
+ element.style.insetInlineEnd = `calc(${noFloatingAncestor && end > innerWidth ? innerWidth : end}px + ${distance})`;
287
337
  }
288
338
  else if (correctedPlacement === null || correctedPlacement === void 0 ? void 0 : correctedPlacement.startsWith('left')) {
289
339
  const start = left - childWidth;
290
- element.style.insetInlineStart = `calc(${start < 0 ? 0 : start}px - ${distance})`;
340
+ element.style.insetInlineStart = `calc(${noFloatingAncestor && start < 0 ? 0 : start}px - ${distance})`;
291
341
  element.style.insetInlineEnd = `calc(${right}px - ${distance})`;
292
342
  }
293
343
  else if (correctedPlacement === null || correctedPlacement === void 0 ? void 0 : correctedPlacement.startsWith('top')) {
294
344
  const start = top - childHeight;
295
- element.style.insetBlockStart = `calc(${start < 0 ? 0 : start}px - ${distance})`;
296
- element.style.insetBlockEnd = `calc(${bottom}px - ${distance})`;
345
+ element.style.insetBlockStart = `calc(${noFloatingAncestor && start < 0 ? 0 : start}px - ${distance})`;
346
+ element.style.insetBlockEnd = `calc(${parentHasFloatingPosition ? start : bottom}px - ${distance})`;
297
347
  }
298
348
  else if (correctedPlacement === null || correctedPlacement === void 0 ? void 0 : correctedPlacement.startsWith('bottom')) {
299
349
  const end = bottom + childHeight;
300
- element.style.insetBlockStart = `calc(${bottom}px + ${distance})`;
301
- element.style.insetBlockEnd = `calc(${end > innerHeight ? innerHeight : end}px + ${distance})`;
350
+ element.style.insetBlockStart = `calc(${parentHasFloatingPosition ? end : bottom}px + ${distance})`;
351
+ element.style.insetBlockEnd = `calc(${noFloatingAncestor && end > innerHeight ? innerHeight : end}px + ${distance})`;
302
352
  }
303
353
  element.style.position = 'fixed';
304
354
  element.dataset['correctedPlacement'] = correctedPlacement;
@@ -70,15 +70,15 @@ export const getBooleanAsString = (originBool) => {
70
70
  if (originBool === undefined || originBool === null)
71
71
  return;
72
72
  if (typeof originBool === 'string') {
73
- return String(Boolean(originBool));
73
+ return String(originBool === 'true');
74
74
  }
75
75
  return String(originBool);
76
76
  };
77
77
  export const getBoolean = (originBool, propertyName) => {
78
78
  if (originBool === undefined || originBool === null)
79
79
  return;
80
- if (typeof originBool === 'string' && propertyName) {
81
- return Boolean(propertyName === originBool || originBool);
80
+ if (typeof originBool === 'string') {
81
+ return Boolean(propertyName === originBool || originBool === 'true');
82
82
  }
83
83
  return Boolean(originBool);
84
84
  };
@@ -119,20 +119,19 @@ export const getStep = (step) => {
119
119
  export const getInputValue = (value, inputType) => {
120
120
  return inputType && ['number', 'range'].includes(inputType) ? getNumber(value) : value;
121
121
  };
122
+ const toBool = (value) => typeof value === 'string' ? value === 'true' : value;
122
123
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
124
  export const getHideProp = (show) => {
124
125
  if (show === undefined || show === null) {
125
126
  return undefined;
126
127
  }
127
- return getBooleanAsString(!Boolean(show));
128
+ return getBooleanAsString(!toBool(show));
128
129
  };
129
130
  export const stringPropVisible = (givenString, showString) => {
130
131
  if (showString === undefined) {
131
132
  return !!givenString;
132
133
  }
133
- else {
134
- return Boolean(showString) && Boolean(givenString);
135
- }
134
+ return toBool(showString) && Boolean(givenString);
136
135
  };
137
136
  export const getSearchInput = (element) => element.querySelector(`input[type="search"]`);
138
137
  export const getOptionKey = (option, prefix) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@db-ux/react-core-components",
3
- "version": "4.4.2",
3
+ "version": "4.5.0",
4
4
  "description": "React components for @db-ux/core-components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@playwright/experimental-ct-react": "1.58.2",
34
- "@types/react": "19.2.13",
34
+ "@types/react": "19.2.14",
35
35
  "react": "19.2.4",
36
36
  "react-dom": "19.2.4"
37
37
  },
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "sideEffects": false,
43
43
  "dependencies": {
44
- "@db-ux/core-components": "4.4.2",
45
- "@db-ux/core-foundations": "4.4.2"
44
+ "@db-ux/core-components": "4.5.0",
45
+ "@db-ux/core-foundations": "4.5.0"
46
46
  }
47
47
  }