@orfium/ictinus 4.86.0 → 4.87.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 (29) hide show
  1. package/dist/components/ButtonBase/ButtonBase.style.d.ts +1 -1
  2. package/dist/components/ButtonBase/ButtonBase.style.js +5 -2
  3. package/dist/components/ButtonBase/config.d.ts +3 -3
  4. package/dist/components/Chart/BarChart/BarChart.js +3 -1
  5. package/dist/components/Chart/BarChart/utils.d.ts +1 -1
  6. package/dist/components/DatePicker/DatePicker.js +3 -5
  7. package/dist/components/DatePicker/DatePicker.style.js +1 -1
  8. package/dist/components/Filter/Filter.js +8 -12
  9. package/dist/components/Filter/Filter.style.js +2 -2
  10. package/dist/components/Menu/Menu.js +3 -7
  11. package/dist/components/Notification/NotificationsContainer/NotificationsContainer.style.js +4 -2
  12. package/dist/components/Overlay/Overlay.js +22 -12
  13. package/dist/components/Overlay/Overlay.style.js +8 -8
  14. package/dist/components/Select/Select.d.ts +2 -2
  15. package/dist/components/Select/Select.js +21 -11
  16. package/dist/components/utils/PositionInScreen/PositionInScreen.d.ts +2 -0
  17. package/dist/components/utils/PositionInScreen/PositionInScreen.js +140 -22
  18. package/dist/components/utils/PositionInScreen/PositionInScreen.style.d.ts +0 -4
  19. package/dist/components/utils/PositionInScreen/PositionInScreen.style.js +4 -23
  20. package/dist/components/utils/PositionInScreen/hooks.d.ts +6 -0
  21. package/dist/components/utils/PositionInScreen/hooks.js +106 -49
  22. package/dist/hooks/useOverlayStack.d.ts +4 -0
  23. package/dist/hooks/useOverlayStack.js +52 -0
  24. package/dist/hooks/useTypeColorToColorMatch.js +1 -1
  25. package/dist/test/utils.d.ts +1 -1
  26. package/dist/theme/palette.d.ts +10 -10
  27. package/dist/theme/palette.js +3 -0
  28. package/dist/theme/utils.js +18 -10
  29. package/package.json +2 -2
@@ -6,6 +6,7 @@ var _head = _interopRequireDefault(require("lodash/head"));
6
6
  var _react = require("react");
7
7
  var _utils = require("./utils");
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
9
10
  var useHeights = function useHeights(parentRef, itemRef) {
10
11
  var _useState = (0, _react.useState)(0),
11
12
  parentHeight = _useState[0],
@@ -50,73 +51,129 @@ var useHeights = function useHeights(parentRef, itemRef) {
50
51
  };
51
52
  var usePositionInScreen = exports.usePositionInScreen = function usePositionInScreen(parentRef, itemRef, offsetX, offsetY, visible) {
52
53
  var _useState3 = (0, _react.useState)({
53
- x: -1,
54
- y: -1
54
+ x: 0,
55
+ y: 0
55
56
  }),
56
57
  position = _useState3[0],
57
58
  setPosition = _useState3[1];
58
- var _useHeights = useHeights(parentRef, itemRef),
59
- parentHeight = _useHeights.parentHeight,
60
- childHeight = _useHeights.childHeight;
61
- (0, _react.useLayoutEffect)(function () {
62
- // x,y are cordinates in screen
63
- // width is wrapper elements dimensions
64
- var _ref = parentRef ? parentRef == null ? void 0 : parentRef.getBoundingClientRect() : {
65
- x: 0,
66
- y: 0,
67
- width: 0
68
- },
69
- parentX = _ref.x,
70
- parentY = _ref.y,
71
- parentWidth = _ref.width;
59
+ var _useState4 = (0, _react.useState)(0),
60
+ triggerWidth = _useState4[0],
61
+ setTriggerWidth = _useState4[1];
62
+ var _useState5 = (0, _react.useState)(0),
63
+ maxHeight = _useState5[0],
64
+ setMaxHeight = _useState5[1];
65
+ var _useState6 = (0, _react.useState)(0),
66
+ maxWidth = _useState6[0],
67
+ setMaxWidth = _useState6[1];
68
+ var _useState7 = (0, _react.useState)(false),
69
+ isPositioned = _useState7[0],
70
+ setIsPositioned = _useState7[1];
71
+ var _useState8 = (0, _react.useState)('bottom'),
72
+ placement = _useState8[0],
73
+ setPlacement = _useState8[1];
74
+ var animationFrameRef = (0, _react.useRef)(0);
75
+ var calculatePosition = (0, _react.useCallback)(function () {
76
+ var _itemRef$children$, _childRect$width, _childRect$height;
77
+ // Define a small buffer for screen edge detection
78
+ var SCREEN_EDGE_BUFFER = 8;
72
79
 
73
- // width is the element's that's going to be positioned dimensions
74
- var _ref2 = itemRef && itemRef.children[0] ? itemRef.children[0].getBoundingClientRect() : {
75
- width: 0
76
- },
77
- width = _ref2.width;
80
+ // Get parent element dimensions and position
81
+ var parentRect = parentRef == null ? void 0 : parentRef.getBoundingClientRect();
82
+ if (!parentRect) return;
78
83
 
79
- // If the item-to-be-positioned is out of screen height
80
- var itemYOutOfScreenHeight = parentY + parentHeight + childHeight > window.innerHeight;
84
+ // Get viewport-relative coordinates (without scroll offset)
85
+ var parentX = parentRect.left;
86
+ var parentY = parentRect.top;
87
+ var parentWidth = parentRect.width;
88
+ var parentHeight = parentRect.height;
81
89
 
82
- // The element that we are positioning is absolutely positioned inside the relative
83
- // container. So x,y are zero means the element will be positioned exactly on top
84
- // of the parent element.
85
- var x = 0;
86
- var y = 0;
87
- if (itemYOutOfScreenHeight) {
88
- // We place the element height+offsetY (px) above the parent
89
- y = y - childHeight - offsetY;
90
- if (parentY + y < 0) {
91
- // Rare case where client height is super small. We don't exactly support this.
92
- // So we render it as if it was inside the screen height
93
- y = parentHeight + offsetY;
94
- }
90
+ // Get positioned element dimensions
91
+ var childRect = itemRef == null || (_itemRef$children$ = itemRef.children[0]) == null ? void 0 : _itemRef$children$.getBoundingClientRect();
92
+ var childWidth = (_childRect$width = childRect == null ? void 0 : childRect.width) != null ? _childRect$width : 0;
93
+ var childHeight = (_childRect$height = childRect == null ? void 0 : childRect.height) != null ? _childRect$height : 0;
94
+
95
+ // Calculate positions (viewport-relative, without scroll)
96
+ var x = parentX + offsetX;
97
+ var y;
98
+ var currentPlacement = 'bottom';
99
+
100
+ // Check if element would overflow screen bounds (with buffer) when placed below
101
+ var spaceBelow = window.innerHeight - (parentRect.bottom + offsetY) - SCREEN_EDGE_BUFFER;
102
+ var spaceAbove = parentRect.top - offsetY - SCREEN_EDGE_BUFFER;
103
+
104
+ // First try to place it below, if there's not enough space, try above
105
+ if (childHeight <= spaceBelow) {
106
+ // Place below - enough space
107
+ y = parentY + parentHeight + offsetY;
108
+ currentPlacement = 'bottom';
109
+ } else if (childHeight <= spaceAbove) {
110
+ // Place above - enough space above
111
+ y = parentY - childHeight - offsetY;
112
+ currentPlacement = 'top';
95
113
  } else {
96
- // We place the element offsetY (px) under the parent
97
- y = parentHeight + offsetY;
114
+ // Not enough space either way, place where there's more space and allow scrolling
115
+ if (spaceBelow >= spaceAbove) {
116
+ y = parentY + parentHeight + offsetY;
117
+ currentPlacement = 'bottom';
118
+ } else {
119
+ y = parentY - childHeight - offsetY;
120
+ currentPlacement = 'top';
121
+ }
98
122
  }
99
123
 
100
- // If the item-to-be-positioned is out of screen width
101
- var itemXOutOfScreenWidth = parentX + width > window.innerWidth;
124
+ // Check if element would overflow screen bounds horizontally (with buffer)
125
+ var itemXOutOfScreenWidth = x + childWidth > window.innerWidth - SCREEN_EDGE_BUFFER;
102
126
  if (itemXOutOfScreenWidth) {
103
- // We place the element parentWidth-width-offsetX (px) at the left of the parent
104
- x = x + parentWidth - width - offsetX;
127
+ // Align to right edge of parent if would overflow right
128
+ x = parentX + parentWidth - childWidth - offsetX;
129
+ // Ensure we don't position outside the left edge
130
+ if (x < SCREEN_EDGE_BUFFER) {
131
+ x = SCREEN_EDGE_BUFFER;
132
+ }
133
+ }
134
+
135
+ // Calculate maxHeight - space available from y position to bottom/top of screen based on placement
136
+ var availableHeight;
137
+ if (currentPlacement === 'top') {
138
+ availableHeight = parentY - SCREEN_EDGE_BUFFER;
105
139
  } else {
106
- // We place the element offset (px) at the right of the parent
107
- x = offsetX;
140
+ availableHeight = window.innerHeight - (parentY + parentHeight + offsetY) - SCREEN_EDGE_BUFFER;
108
141
  }
142
+
143
+ // Calculate maxWidth - space available from x position to right edge of screen
144
+ var availableRightSpace = window.innerWidth - x - SCREEN_EDGE_BUFFER;
109
145
  setPosition({
110
146
  x: x,
111
147
  y: y
112
148
  });
113
- }, [parentRef, itemRef, visible, offsetY, offsetX, parentHeight, childHeight]);
114
- return position;
149
+ setMaxHeight(availableHeight);
150
+ setMaxWidth(availableRightSpace);
151
+ setIsPositioned(true);
152
+ setPlacement(currentPlacement);
153
+ setTriggerWidth(parentWidth);
154
+ }, [parentRef, itemRef, offsetY, offsetX]);
155
+ (0, _react.useLayoutEffect)(function () {
156
+ if (!visible) return;
157
+ animationFrameRef.current = requestAnimationFrame(function () {
158
+ calculatePosition();
159
+ });
160
+ return function () {
161
+ cancelAnimationFrame(animationFrameRef.current);
162
+ };
163
+ }, [calculatePosition, visible]);
164
+ return _extends({}, position, {
165
+ maxHeight: maxHeight,
166
+ maxWidth: maxWidth,
167
+ isPositioned: isPositioned,
168
+ calculatePosition: calculatePosition,
169
+ placement: placement,
170
+ triggerWidth: triggerWidth
171
+ });
115
172
  };
116
173
  var useWrapperWidth = exports.useWrapperWidth = function useWrapperWidth(hasWrapperWidth, wrapperRef) {
117
- var _useState4 = (0, _react.useState)(),
118
- width = _useState4[0],
119
- setWidth = _useState4[1];
174
+ var _useState9 = (0, _react.useState)(),
175
+ width = _useState9[0],
176
+ setWidth = _useState9[1];
120
177
  (0, _react.useLayoutEffect)(function () {
121
178
  if (hasWrapperWidth) {
122
179
  var _wrapperRef$getBoundi;
@@ -0,0 +1,4 @@
1
+ import { RefObject, DOMAttributes } from 'react';
2
+ export declare function useOverlayStack(visible: boolean, ref: RefObject<Element | null>, onClose?: () => void): {
3
+ overlayProps: DOMAttributes<Element>;
4
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.useOverlayStack = useOverlayStack;
5
+ var _react = require("react");
6
+ var visibleOverlays = [];
7
+ function useOverlayStack(visible, ref, onClose) {
8
+ (0, _react.useEffect)(function () {
9
+ if (visible && !visibleOverlays.includes(ref)) {
10
+ visibleOverlays.push(ref);
11
+ }
12
+ return function () {
13
+ var index = visibleOverlays.indexOf(ref);
14
+ if (index >= 0) {
15
+ visibleOverlays.splice(index, 1);
16
+ }
17
+ };
18
+ }, [ref, visible]);
19
+ var onHide = (0, _react.useCallback)(function () {
20
+ if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {
21
+ onClose();
22
+ }
23
+ }, [onClose, ref]);
24
+ (0, _react.useEffect)(function () {
25
+ if (!visible) return;
26
+ var handleClickOutside = function handleClickOutside(e) {
27
+ if (ref.current && !ref.current.contains(e.target)) {
28
+ if (visibleOverlays[visibleOverlays.length - 1] === ref) {
29
+ e.stopPropagation();
30
+ e.preventDefault();
31
+ }
32
+ onHide();
33
+ }
34
+ };
35
+ document.addEventListener('mousedown', handleClickOutside);
36
+ return function () {
37
+ document.removeEventListener('mousedown', handleClickOutside);
38
+ };
39
+ }, [visible, onHide, ref]);
40
+ var onKeyDown = function onKeyDown(e) {
41
+ if (e.key === 'Escape' && !e.nativeEvent.isComposing) {
42
+ e.stopPropagation();
43
+ e.preventDefault();
44
+ onHide();
45
+ }
46
+ };
47
+ return {
48
+ overlayProps: {
49
+ onKeyDown: onKeyDown
50
+ }
51
+ };
52
+ }
@@ -68,7 +68,7 @@ var TypeColorToColorMatchProvider = exports.TypeColorToColorMatchProvider = func
68
68
  var calculateColorBetweenColorAndType = React.useCallback(function (color, type) {
69
69
  var calculatedColor = color ? (0, _themeFunctions.calculateActualColorFromComponentProp)(color) : undefined;
70
70
  return calculatedColor ? calculatedColor : typesShadesColor[type];
71
- }, [types, theme, typesShadesColor]);
71
+ }, [typesShadesColor]);
72
72
  return (0, _react2.jsx)(TypeColorToColorMatchContext.Provider, {
73
73
  value: {
74
74
  typesShadesColor: typesShadesColor,
@@ -1,6 +1,6 @@
1
1
  import { renderHook } from '@testing-library/react-hooks';
2
2
  import React from 'react';
3
3
  export declare const selectDropdownOption: (dropdownInput: HTMLInputElement, option: string) => Promise<void>;
4
- declare const renderWithThemeProvider: (children: React.ReactElement) => import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement>;
4
+ declare const renderWithThemeProvider: (children: React.ReactElement) => import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>;
5
5
  export * from '@testing-library/react';
6
6
  export { renderHook, renderWithThemeProvider as render };
@@ -28,9 +28,9 @@ export declare const MAX_SHADE = 950;
28
28
  * Each color has again the above variations (shades)
29
29
  **/
30
30
  export declare const mainTypes: readonly ["primary", "secondary", "success", "error", "warning", "info", "light", "link"];
31
- export declare type flatPalette = Record<typeof flatColors[number], generatedColorShades>;
32
- export declare type palePalette = Record<typeof paleColors[number], string>;
33
- export declare type generatedColorShades = Record<typeof colorShades[number], string>;
31
+ export declare type flatPalette = Record<(typeof flatColors)[number], generatedColorShades>;
32
+ export declare type palePalette = Record<(typeof paleColors)[number], string>;
33
+ export declare type generatedColorShades = Record<(typeof colorShades)[number], string>;
34
34
  /**
35
35
  * Palette is end output of what is produced and exported to the client projects
36
36
  **/
@@ -44,14 +44,14 @@ export declare type Palette = {
44
44
  pale: palePalette;
45
45
  white: string;
46
46
  black: string;
47
- } & Record<typeof mainTypes[number], generatedColorShades>;
47
+ } & Record<(typeof mainTypes)[number], generatedColorShades>;
48
48
  export declare type formFieldStyles = 'filled' | 'outlined' | 'elevated';
49
49
  export declare type GetColor = {
50
- (color: typeof flatColors[number], variant: typeof colorShades[number]): string;
51
- (color: typeof flatColors[number], variant: typeof colorShades[number], scope: 'flat'): string;
52
- (color: TextColorTypes, variant: typeof colorShades[number], scope: 'text'): string;
53
- (color: typeof mainTypes[number], variant: typeof colorShades[number], scope: 'normal'): string;
54
- (color: typeof paleColors[number], variant: null, scope: 'pale'): string;
50
+ (color: (typeof flatColors)[number], variant: (typeof colorShades)[number]): string;
51
+ (color: (typeof flatColors)[number], variant: (typeof colorShades)[number], scope: 'flat'): string;
52
+ (color: TextColorTypes, variant: (typeof colorShades)[number], scope: 'text'): string;
53
+ (color: (typeof mainTypes)[number], variant: (typeof colorShades)[number], scope: 'normal'): string;
54
+ (color: (typeof paleColors)[number], variant: null, scope: 'pale'): string;
55
55
  };
56
56
  export declare const getColor: (palette: Palette) => GetColor;
57
57
  /**
@@ -59,7 +59,7 @@ export declare const getColor: (palette: Palette) => GetColor;
59
59
  * swatches are calculated based on accessibility by getAAColor function and splited to those two colors
60
60
  **/
61
61
  export declare type GetAAColorFromSwatches = {
62
- (color: typeof flatColors[number], variant: typeof colorShades[number]): string;
62
+ (color: (typeof flatColors)[number], variant: (typeof colorShades)[number]): string;
63
63
  };
64
64
  export declare const getAAColorFromSwatches: (palette: Palette) => GetAAColorFromSwatches;
65
65
  export declare type GetAAColor = {
@@ -50,11 +50,14 @@ var getColor = exports.getColor = function getColor(palette) {
50
50
  var endColor;
51
51
  if (variant === null) {
52
52
  var _palette$scope;
53
+ //@ts-ignore
53
54
  endColor = palette == null || (_palette$scope = palette[scope]) == null ? void 0 : _palette$scope[color];
54
55
  } else if (scope === 'normal') {
56
+ //@ts-ignore
55
57
  endColor = palette[color][variant];
56
58
  } else {
57
59
  var _palette$scope2;
60
+ //@ts-ignore
58
61
  endColor = palette == null || (_palette$scope2 = palette[scope]) == null || (_palette$scope2 = _palette$scope2[color]) == null ? void 0 : _palette$scope2[variant];
59
62
  }
60
63
  (0, _helpers.errorHandler)(_utils.getColorErrors, endColor);
@@ -39,6 +39,7 @@ var colorShadesCreator = exports.colorShadesCreator = function colorShadesCreato
39
39
  return [].concat(tints(weight).reverse(), [base], shades(weight));
40
40
  };
41
41
  return all().reduce(function (acc, _, index) {
42
+ //@ts-ignore
42
43
  acc["" + (index + 1) * 50] = _;
43
44
  return acc;
44
45
  }, {});
@@ -57,16 +58,23 @@ var colorShadesCreator = exports.colorShadesCreator = function colorShadesCreato
57
58
  * a complete palette.
58
59
  */
59
60
  var iterateObject = exports.iterateObject = function iterateObject(obj, func) {
60
- return Object.keys(obj).reduce(function (acc, value) {
61
- if (typeof obj[value] !== 'object') {
62
- acc[value] = func(obj[value], value);
63
- } else if (EXCLUDED.includes(value)) {
64
- acc[value] = obj[value];
65
- } else {
66
- acc[value] = iterateObject(obj[value], func);
67
- }
68
- return acc;
69
- }, {});
61
+ return (
62
+ //@ts-ignore
63
+ Object.keys(obj).reduce(function (acc, value) {
64
+ //@ts-ignore
65
+ if (typeof obj[value] !== 'object') {
66
+ //@ts-ignore
67
+ acc[value] = func(obj[value], value);
68
+ } else if (EXCLUDED.includes(value)) {
69
+ //@ts-ignore
70
+ acc[value] = obj[value];
71
+ } else {
72
+ //@ts-ignore
73
+ acc[value] = iterateObject(obj[value], func);
74
+ }
75
+ return acc;
76
+ }, {})
77
+ );
70
78
  };
71
79
  var enhancePaletteWithShades = exports.enhancePaletteWithShades = function enhancePaletteWithShades(obj) {
72
80
  return iterateObject(obj, function (value, name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orfium/ictinus",
3
- "version": "4.86.0",
3
+ "version": "4.87.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "@storybook/react": "^6.5.16",
35
35
  "@svgr/webpack": "^8.1.0",
36
36
  "@testing-library/jest-dom": "^5.12.0",
37
- "@testing-library/react": "^11.2.6",
37
+ "@testing-library/react": "14.3.1",
38
38
  "@testing-library/react-hooks": "^5.1.2",
39
39
  "@testing-library/user-event": "^13.1.8",
40
40
  "@types/events": "^3.0.0",