@smart-react-components/ui 2.0.0-alpha-1 → 2.0.0-alpha-3
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/Alert/AlertCloseIcon/index.d.ts +2 -0
- package/Alert/AlertCloseIcon/index.js +7 -0
- package/Alert/AlertElement.d.ts +13 -0
- package/Alert/AlertElement.js +98 -0
- package/Alert/AlertIcon/AlertIconElement.d.ts +13 -0
- package/Alert/AlertIcon/AlertIconElement.js +55 -0
- package/Alert/AlertIcon/index.d.ts +11 -0
- package/Alert/AlertIcon/index.js +15 -0
- package/Alert/index.d.ts +14 -0
- package/Alert/index.js +57 -0
- package/Badge/BadgeElement.d.ts +20 -0
- package/Badge/BadgeElement.js +206 -0
- package/Badge/BadgeIcon/BadgeIconElement.d.ts +13 -0
- package/Badge/BadgeIcon/BadgeIconElement.js +82 -0
- package/Badge/BadgeIcon/index.d.ts +7 -0
- package/Badge/BadgeIcon/index.js +11 -0
- package/Badge/BadgeList/BadgeListElement.d.ts +7 -0
- package/Badge/BadgeList/BadgeListElement.js +20 -0
- package/Badge/BadgeList/index.d.ts +15 -0
- package/Badge/BadgeList/index.js +18 -0
- package/Badge/index.d.ts +19 -0
- package/Badge/index.js +59 -0
- package/Breadcrumb/BreadcrumbItem/BreadcrumbItemElement.d.ts +13 -0
- package/Breadcrumb/BreadcrumbItem/BreadcrumbItemElement.js +110 -0
- package/Breadcrumb/BreadcrumbItem/index.d.ts +21 -0
- package/Breadcrumb/BreadcrumbItem/index.js +17 -0
- package/Breadcrumb/BreadcrumbLink/index.d.ts +6 -0
- package/Breadcrumb/BreadcrumbLink/index.js +29 -0
- package/Breadcrumb/BreadcrumbList/BreadcrumbListElement.d.ts +10 -0
- package/Breadcrumb/BreadcrumbList/BreadcrumbListElement.js +22 -0
- package/Breadcrumb/BreadcrumbList/index.d.ts +16 -0
- package/Breadcrumb/BreadcrumbList/index.js +28 -0
- package/Breadcrumb/index.d.ts +3 -0
- package/Breadcrumb/index.js +12 -0
- package/Dropdown/DropdownArrowIcon/index.d.ts +2 -0
- package/Dropdown/DropdownArrowIcon/index.js +7 -0
- package/Dropdown/DropdownCategory/index.d.ts +7 -0
- package/Dropdown/DropdownCategory/index.js +9 -0
- package/Dropdown/DropdownItem/DropdownItemElement.d.ts +12 -0
- package/Dropdown/DropdownItem/DropdownItemElement.js +50 -0
- package/Dropdown/DropdownItem/index.d.ts +9 -0
- package/Dropdown/DropdownItem/index.js +31 -0
- package/Dropdown/DropdownList/DropdownListElement.d.ts +11 -0
- package/Dropdown/DropdownList/DropdownListElement.js +44 -0
- package/Dropdown/DropdownList/index.d.ts +13 -0
- package/Dropdown/DropdownList/index.js +9 -0
- package/Dropdown/index.d.ts +5 -0
- package/Dropdown/index.js +29 -0
- package/FixedBox/FixedBoxElement.d.ts +7 -0
- package/FixedBox/FixedBoxElement.js +28 -0
- package/FixedBox/OverlayElement.d.ts +6 -0
- package/FixedBox/OverlayElement.js +81 -0
- package/FixedBox/index.d.ts +29 -0
- package/FixedBox/index.js +37 -0
- package/Loading/LoadingElement.d.ts +7 -0
- package/Loading/LoadingElement.js +54 -0
- package/Loading/index.d.ts +8 -0
- package/Loading/index.js +15 -0
- package/Overlay/OverlayElement.d.ts +9 -0
- package/Overlay/OverlayElement.js +36 -0
- package/Overlay/index.d.ts +14 -0
- package/Overlay/index.js +150 -0
- package/Popover/PopoverArrow.d.ts +4 -0
- package/Popover/PopoverArrow.js +41 -0
- package/Popover/PopoverElement.d.ts +14 -0
- package/Popover/PopoverElement.js +79 -0
- package/Popover/index.d.ts +26 -0
- package/Popover/index.js +63 -0
- package/ProgressBar/ProgressBarElement.d.ts +16 -0
- package/ProgressBar/ProgressBarElement.js +86 -0
- package/ProgressBar/index.d.ts +20 -0
- package/ProgressBar/index.js +89 -0
- package/Tooltip/TooltipElement.d.ts +12 -0
- package/Tooltip/TooltipElement.js +46 -0
- package/Tooltip/index.d.ts +26 -0
- package/Tooltip/index.js +38 -0
- package/hooks/useFixedBoxMethods.d.ts +21 -0
- package/hooks/useFixedBoxMethods.js +114 -0
- package/icons/ArrowDown.d.ts +6 -0
- package/icons/ArrowDown.js +12 -0
- package/icons/Close.d.ts +6 -0
- package/icons/Close.js +12 -0
- package/index.d.ts +18 -0
- package/index.js +36 -1
- package/package.json +8 -7
- package/types/index.d.ts +15 -0
- package/types/index.js +21 -0
- package/types/popover.d.ts +8 -0
- package/types/popover.js +2 -0
- package/util/css.d.ts +8 -0
- package/util/css.js +23 -0
- package/util/dom.d.ts +24 -0
- package/util/dom.js +84 -0
- package/util/fixed-box.d.ts +5 -0
- package/util/fixed-box.js +106 -0
- package/util/popover.d.ts +9 -0
- package/util/popover.js +213 -0
- package/util/props.d.ts +21 -0
- package/util/props.js +56 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Svg_1 = __importDefault(require("@smart-react-components/core/Element/Svg"));
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
exports.default = (0, styled_components_1.default)(Svg_1.default).attrs({
|
|
10
|
+
children: react_1.default.createElement("path", { d: "M7.41 7.84L12 12.42l4.59-4.58L18 9.25l-6 6-6-6z" }),
|
|
11
|
+
viewBox: '5 4 14 14',
|
|
12
|
+
}) ``;
|
package/icons/Close.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StyledProps } from '@smart-react-components/core/styled-props';
|
|
2
|
+
declare const _default: import("styled-components").StyledComponent<"svg", any, StyledProps & {
|
|
3
|
+
children: JSX.Element;
|
|
4
|
+
viewBox: "2 2 14 14";
|
|
5
|
+
}, "children" | "viewBox">;
|
|
6
|
+
export default _default;
|
package/icons/Close.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Svg_1 = __importDefault(require("@smart-react-components/core/Element/Svg"));
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
exports.default = (0, styled_components_1.default)(Svg_1.default).attrs({
|
|
10
|
+
children: react_1.default.createElement("path", { d: "M14.53 4.53l-1.06-1.06L9 7.94 4.53 3.47 3.47 4.53 7.94 9l-4.47 4.47 1.06 1.06L9 10.06l4.47 4.47 1.06-1.06L10.06 9z" }),
|
|
11
|
+
viewBox: '2 2 14 14',
|
|
12
|
+
}) ``;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
+
export { default as Alert } from './Alert';
|
|
2
|
+
export { default as AlertCloseIcon } from './Alert/AlertCloseIcon';
|
|
3
|
+
export { default as AlertIcon } from './Alert/AlertIcon';
|
|
4
|
+
export { default as Badge } from './Badge';
|
|
5
|
+
export { default as BadgeIcon } from './Badge/BadgeIcon';
|
|
6
|
+
export { default as BadgeList } from './Badge/BadgeList';
|
|
7
|
+
export * from './Breadcrumb';
|
|
8
|
+
export { default as Dropdown } from './Dropdown';
|
|
9
|
+
export { default as DropdownArrowIcon } from './Dropdown/DropdownArrowIcon';
|
|
10
|
+
export { default as DropdownCategory } from './Dropdown/DropdownCategory';
|
|
11
|
+
export { default as DropdownItem } from './Dropdown/DropdownItem';
|
|
12
|
+
export { default as DropdownList } from './Dropdown/DropdownList';
|
|
13
|
+
export { default as FixedBox } from './FixedBox';
|
|
1
14
|
export * from './Grid';
|
|
15
|
+
export { default as Loading } from './Loading';
|
|
16
|
+
export { default as Overlay } from './Overlay';
|
|
17
|
+
export { default as Popover } from './Popover';
|
|
18
|
+
export { default as ProgressBar } from './ProgressBar';
|
|
19
|
+
export { default as Tooltip } from './Tooltip';
|
|
2
20
|
export { default as WaveEffect } from './WaveEffect';
|
package/index.js
CHANGED
|
@@ -17,7 +17,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.WaveEffect = void 0;
|
|
20
|
+
exports.WaveEffect = exports.Tooltip = exports.ProgressBar = exports.Popover = exports.Overlay = exports.Loading = exports.FixedBox = exports.DropdownList = exports.DropdownItem = exports.DropdownCategory = exports.DropdownArrowIcon = exports.Dropdown = exports.BadgeList = exports.BadgeIcon = exports.Badge = exports.AlertIcon = exports.AlertCloseIcon = exports.Alert = void 0;
|
|
21
|
+
var Alert_1 = require("./Alert");
|
|
22
|
+
Object.defineProperty(exports, "Alert", { enumerable: true, get: function () { return __importDefault(Alert_1).default; } });
|
|
23
|
+
var AlertCloseIcon_1 = require("./Alert/AlertCloseIcon");
|
|
24
|
+
Object.defineProperty(exports, "AlertCloseIcon", { enumerable: true, get: function () { return __importDefault(AlertCloseIcon_1).default; } });
|
|
25
|
+
var AlertIcon_1 = require("./Alert/AlertIcon");
|
|
26
|
+
Object.defineProperty(exports, "AlertIcon", { enumerable: true, get: function () { return __importDefault(AlertIcon_1).default; } });
|
|
27
|
+
var Badge_1 = require("./Badge");
|
|
28
|
+
Object.defineProperty(exports, "Badge", { enumerable: true, get: function () { return __importDefault(Badge_1).default; } });
|
|
29
|
+
var BadgeIcon_1 = require("./Badge/BadgeIcon");
|
|
30
|
+
Object.defineProperty(exports, "BadgeIcon", { enumerable: true, get: function () { return __importDefault(BadgeIcon_1).default; } });
|
|
31
|
+
var BadgeList_1 = require("./Badge/BadgeList");
|
|
32
|
+
Object.defineProperty(exports, "BadgeList", { enumerable: true, get: function () { return __importDefault(BadgeList_1).default; } });
|
|
33
|
+
__exportStar(require("./Breadcrumb"), exports);
|
|
34
|
+
var Dropdown_1 = require("./Dropdown");
|
|
35
|
+
Object.defineProperty(exports, "Dropdown", { enumerable: true, get: function () { return __importDefault(Dropdown_1).default; } });
|
|
36
|
+
var DropdownArrowIcon_1 = require("./Dropdown/DropdownArrowIcon");
|
|
37
|
+
Object.defineProperty(exports, "DropdownArrowIcon", { enumerable: true, get: function () { return __importDefault(DropdownArrowIcon_1).default; } });
|
|
38
|
+
var DropdownCategory_1 = require("./Dropdown/DropdownCategory");
|
|
39
|
+
Object.defineProperty(exports, "DropdownCategory", { enumerable: true, get: function () { return __importDefault(DropdownCategory_1).default; } });
|
|
40
|
+
var DropdownItem_1 = require("./Dropdown/DropdownItem");
|
|
41
|
+
Object.defineProperty(exports, "DropdownItem", { enumerable: true, get: function () { return __importDefault(DropdownItem_1).default; } });
|
|
42
|
+
var DropdownList_1 = require("./Dropdown/DropdownList");
|
|
43
|
+
Object.defineProperty(exports, "DropdownList", { enumerable: true, get: function () { return __importDefault(DropdownList_1).default; } });
|
|
44
|
+
var FixedBox_1 = require("./FixedBox");
|
|
45
|
+
Object.defineProperty(exports, "FixedBox", { enumerable: true, get: function () { return __importDefault(FixedBox_1).default; } });
|
|
21
46
|
__exportStar(require("./Grid"), exports);
|
|
47
|
+
var Loading_1 = require("./Loading");
|
|
48
|
+
Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return __importDefault(Loading_1).default; } });
|
|
49
|
+
var Overlay_1 = require("./Overlay");
|
|
50
|
+
Object.defineProperty(exports, "Overlay", { enumerable: true, get: function () { return __importDefault(Overlay_1).default; } });
|
|
51
|
+
var Popover_1 = require("./Popover");
|
|
52
|
+
Object.defineProperty(exports, "Popover", { enumerable: true, get: function () { return __importDefault(Popover_1).default; } });
|
|
53
|
+
var ProgressBar_1 = require("./ProgressBar");
|
|
54
|
+
Object.defineProperty(exports, "ProgressBar", { enumerable: true, get: function () { return __importDefault(ProgressBar_1).default; } });
|
|
55
|
+
var Tooltip_1 = require("./Tooltip");
|
|
56
|
+
Object.defineProperty(exports, "Tooltip", { enumerable: true, get: function () { return __importDefault(Tooltip_1).default; } });
|
|
22
57
|
var WaveEffect_1 = require("./WaveEffect");
|
|
23
58
|
Object.defineProperty(exports, "WaveEffect", { enumerable: true, get: function () { return __importDefault(WaveEffect_1).default; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart-react-components/ui",
|
|
3
|
-
"version": "2.0.0-alpha-
|
|
3
|
+
"version": "2.0.0-alpha-3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"description": "SRC UI includes React and Styled components.",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"test": "jest"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@smart-react-components/core": "2.0.0-alpha-
|
|
68
|
-
"@smart-react-components/router": "2.0.0-alpha-
|
|
69
|
-
"@smart-react-components/transition": "2.0.0-alpha-
|
|
67
|
+
"@smart-react-components/core": "2.0.0-alpha-10",
|
|
68
|
+
"@smart-react-components/router": "2.0.0-alpha-5",
|
|
69
|
+
"@smart-react-components/transition": "2.0.0-alpha-6",
|
|
70
70
|
"@testing-library/react": "13.4.0",
|
|
71
71
|
"@types/jest": "29.0.1",
|
|
72
72
|
"@types/react": "18.0.19",
|
|
@@ -83,10 +83,11 @@
|
|
|
83
83
|
"typescript": "4.8.3"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@smart-react-components/core": "^2.0.0-alpha-
|
|
87
|
-
"@smart-react-components/router": "^2.0.0-alpha-
|
|
88
|
-
"@smart-react-components/transition": "^2.0.0-alpha-
|
|
86
|
+
"@smart-react-components/core": "^2.0.0-alpha-10",
|
|
87
|
+
"@smart-react-components/router": "^2.0.0-alpha-5",
|
|
88
|
+
"@smart-react-components/transition": "^2.0.0-alpha-6",
|
|
89
89
|
"react": "^18.2.0",
|
|
90
|
+
"react-dom": "^18.2.0",
|
|
90
91
|
"styled-components": "^5.3.5"
|
|
91
92
|
}
|
|
92
93
|
}
|
package/types/index.d.ts
ADDED
package/types/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TriggerInteraction = exports.Position = exports.OrderPosition = void 0;
|
|
4
|
+
var OrderPosition;
|
|
5
|
+
(function (OrderPosition) {
|
|
6
|
+
OrderPosition[OrderPosition["LEFT"] = 1] = "LEFT";
|
|
7
|
+
OrderPosition[OrderPosition["RIGHT"] = 2] = "RIGHT";
|
|
8
|
+
})(OrderPosition = exports.OrderPosition || (exports.OrderPosition = {}));
|
|
9
|
+
var Position;
|
|
10
|
+
(function (Position) {
|
|
11
|
+
Position[Position["LEFT"] = 1] = "LEFT";
|
|
12
|
+
Position[Position["RIGHT"] = 2] = "RIGHT";
|
|
13
|
+
Position[Position["TOP"] = 4] = "TOP";
|
|
14
|
+
Position[Position["BOTTOM"] = 8] = "BOTTOM";
|
|
15
|
+
})(Position = exports.Position || (exports.Position = {}));
|
|
16
|
+
var TriggerInteraction;
|
|
17
|
+
(function (TriggerInteraction) {
|
|
18
|
+
TriggerInteraction[TriggerInteraction["NONE"] = 0] = "NONE";
|
|
19
|
+
TriggerInteraction[TriggerInteraction["CLICK"] = 1] = "CLICK";
|
|
20
|
+
TriggerInteraction[TriggerInteraction["HOVER"] = 2] = "HOVER";
|
|
21
|
+
})(TriggerInteraction = exports.TriggerInteraction || (exports.TriggerInteraction = {}));
|
package/types/popover.js
ADDED
package/util/css.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Value } from '@smart-react-components/core/types';
|
|
2
|
+
/**
|
|
3
|
+
* Takes a CSS number as JavaScript string or number.
|
|
4
|
+
* Splits the given input in two as value and unit parts.
|
|
5
|
+
* Provides a callback with value of the input.
|
|
6
|
+
* Returns the returned value from the callback along with unit of the input.
|
|
7
|
+
*/
|
|
8
|
+
export declare const toCSSValue: (input: Value) => (callback: any) => string;
|
package/util/css.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCSSValue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Takes a CSS number as JavaScript string or number.
|
|
6
|
+
* Splits the given input in two as value and unit parts.
|
|
7
|
+
* Provides a callback with value of the input.
|
|
8
|
+
* Returns the returned value from the callback along with unit of the input.
|
|
9
|
+
*/
|
|
10
|
+
const toCSSValue = (input) => {
|
|
11
|
+
let value;
|
|
12
|
+
let unit;
|
|
13
|
+
if (typeof input === 'number') {
|
|
14
|
+
value = input;
|
|
15
|
+
unit = 'px';
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
value = Number(input.replace(/[A-z|%]+/, ''));
|
|
19
|
+
unit = input.replace(/[\d|.]+/, '');
|
|
20
|
+
}
|
|
21
|
+
return callback => `${callback(value)}${unit}`;
|
|
22
|
+
};
|
|
23
|
+
exports.toCSSValue = toCSSValue;
|
package/util/dom.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const mouseWheel: string[];
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the left, top, width and height of the element shown on the screen.
|
|
4
|
+
*/
|
|
5
|
+
export declare const calculateShownPart: (el: HTMLElement | null) => {
|
|
6
|
+
left: number;
|
|
7
|
+
top: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Checks if an element can be rendered in the React portal.
|
|
13
|
+
*/
|
|
14
|
+
export declare const canBeRenderedInPortal: () => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Gets scroll parent of the given element.
|
|
17
|
+
*
|
|
18
|
+
* @param el
|
|
19
|
+
*/
|
|
20
|
+
export declare const getScrollParent: (el: HTMLElement) => HTMLElement;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if target is a clickable element.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isTargetClickable: (target: HTMLElement, container: HTMLElement) => boolean;
|
package/util/dom.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTargetClickable = exports.getScrollParent = exports.canBeRenderedInPortal = exports.calculateShownPart = exports.mouseWheel = void 0;
|
|
4
|
+
const dom_1 = require("@smart-react-components/core/util/dom");
|
|
5
|
+
exports.mouseWheel = ['wheel', 'mousewheel', 'DOMMouseScroll'];
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the left, top, width and height of the element shown on the screen.
|
|
8
|
+
*/
|
|
9
|
+
const calculateShownPart = (el) => {
|
|
10
|
+
if (!el) {
|
|
11
|
+
return {
|
|
12
|
+
left: 0,
|
|
13
|
+
top: 0,
|
|
14
|
+
width: window.innerWidth,
|
|
15
|
+
height: window.innerHeight,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const parent = (0, exports.calculateShownPart)((0, exports.getScrollParent)(el));
|
|
19
|
+
let { left, top, width, height } = el.getBoundingClientRect();
|
|
20
|
+
// left & width
|
|
21
|
+
if (left < 0) {
|
|
22
|
+
width += left;
|
|
23
|
+
left = 0;
|
|
24
|
+
}
|
|
25
|
+
if (width > 0 && left < parent.left) {
|
|
26
|
+
width -= parent.left - left;
|
|
27
|
+
left = parent.left;
|
|
28
|
+
}
|
|
29
|
+
if (width > 0 && width + left > parent.width + parent.left) {
|
|
30
|
+
width -= (width + left) - (parent.width + parent.left);
|
|
31
|
+
}
|
|
32
|
+
// top & height
|
|
33
|
+
if (top < 0) {
|
|
34
|
+
height += top;
|
|
35
|
+
top = 0;
|
|
36
|
+
}
|
|
37
|
+
if (height > 0 && top < parent.top) {
|
|
38
|
+
height -= parent.top - top;
|
|
39
|
+
top = parent.top;
|
|
40
|
+
}
|
|
41
|
+
if (height > 0 && height + top > parent.height + parent.top) {
|
|
42
|
+
height -= (height + top) - (parent.height + parent.top);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
left,
|
|
46
|
+
top,
|
|
47
|
+
width,
|
|
48
|
+
height,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.calculateShownPart = calculateShownPart;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if an element can be rendered in the React portal.
|
|
54
|
+
*/
|
|
55
|
+
const canBeRenderedInPortal = () => !dom_1.isServer && process.env.NODE_ENV !== 'test';
|
|
56
|
+
exports.canBeRenderedInPortal = canBeRenderedInPortal;
|
|
57
|
+
/**
|
|
58
|
+
* Gets scroll parent of the given element.
|
|
59
|
+
*
|
|
60
|
+
* @param el
|
|
61
|
+
*/
|
|
62
|
+
const getScrollParent = (el) => {
|
|
63
|
+
for (let parent = el; (parent = parent.parentElement);) {
|
|
64
|
+
const style = window.getComputedStyle(parent, null);
|
|
65
|
+
if (/(auto|scroll|hidden)/.test(style.overflow + style.overflowX + style.overflowY)) {
|
|
66
|
+
return parent;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
exports.getScrollParent = getScrollParent;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if target is a clickable element.
|
|
74
|
+
*/
|
|
75
|
+
const isTargetClickable = (target, container) => {
|
|
76
|
+
while (container.contains(target)) {
|
|
77
|
+
if (target.hasAttribute('data-src-not-clickable')) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
target = target.parentNode;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
exports.isTargetClickable = isTargetClickable;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculated fixed box position and size.
|
|
4
|
+
*/
|
|
5
|
+
export declare const calculatePosition: (triggerEl: HTMLElement, boxEl: HTMLDivElement | null, position: Position, maxWidth: number | undefined, minWidth: number | undefined, space: number) => void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculatePosition = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const dom_1 = require("./dom");
|
|
6
|
+
/**
|
|
7
|
+
* Calculated fixed box position and size.
|
|
8
|
+
*/
|
|
9
|
+
const calculatePosition = (triggerEl, boxEl, position, maxWidth, minWidth, space) => {
|
|
10
|
+
if (!boxEl) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const windowWidth = window.innerWidth;
|
|
14
|
+
const windowHeight = window.innerHeight;
|
|
15
|
+
const triggerRect = Object.assign(Object.assign({}, triggerEl.getBoundingClientRect()), (0, dom_1.calculateShownPart)(triggerEl));
|
|
16
|
+
if (triggerRect.width <= 0 || triggerRect.height <= 0) {
|
|
17
|
+
boxEl.setAttribute('style', 'pointer-events: none; visibility: hidden;');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
boxEl.removeAttribute('style');
|
|
21
|
+
let width = boxEl.offsetWidth;
|
|
22
|
+
if (minWidth && minWidth > width) {
|
|
23
|
+
width = minWidth;
|
|
24
|
+
}
|
|
25
|
+
if (maxWidth && maxWidth < width) {
|
|
26
|
+
width = maxWidth;
|
|
27
|
+
}
|
|
28
|
+
boxEl.style.width = `${width}px`;
|
|
29
|
+
boxEl.setAttribute('style', position & (types_1.Position.LEFT | types_1.Position.RIGHT)
|
|
30
|
+
? calculatePositionBasedOnXAxis(triggerRect, boxEl, position, space, windowWidth, windowHeight)
|
|
31
|
+
: calculatePositionBasedOnYAxis(triggerRect, boxEl, position, space, windowWidth, windowHeight));
|
|
32
|
+
};
|
|
33
|
+
exports.calculatePosition = calculatePosition;
|
|
34
|
+
/**
|
|
35
|
+
* Calculates fixed box position and sized based on X axis position.
|
|
36
|
+
*/
|
|
37
|
+
const calculatePositionBasedOnXAxis = (triggerRect, boxEl, position, space, windowWidth, windowHeight) => {
|
|
38
|
+
// left & width
|
|
39
|
+
let left;
|
|
40
|
+
const width = boxEl.offsetWidth;
|
|
41
|
+
const diffLeft = triggerRect.left - (space + width);
|
|
42
|
+
const diffRight = windowWidth - (triggerRect.left + triggerRect.width + space + width);
|
|
43
|
+
if ((position === types_1.Position.LEFT && (diffLeft >= 0 || diffLeft >= diffRight))
|
|
44
|
+
|| (position === types_1.Position.RIGHT && diffRight < 0 && diffLeft > diffRight)) {
|
|
45
|
+
left = diffLeft;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
left = triggerRect.left + triggerRect.width + space;
|
|
49
|
+
}
|
|
50
|
+
// top & height
|
|
51
|
+
let top;
|
|
52
|
+
let height = boxEl.offsetHeight;
|
|
53
|
+
const triggerHeight = triggerRect.height + triggerRect.top <= windowHeight ? triggerRect.height : (windowHeight - triggerRect.top);
|
|
54
|
+
const diffBottom = windowHeight - (triggerRect.top + height);
|
|
55
|
+
const diffTop = (triggerRect.top + triggerHeight) - height;
|
|
56
|
+
if (diffBottom >= 0 || diffBottom >= diffTop) {
|
|
57
|
+
height = diffBottom > 0 ? height : windowHeight - (triggerRect.top + height);
|
|
58
|
+
top = triggerRect.top;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
height = height + Math.min(diffTop, 0);
|
|
62
|
+
top = (height > triggerHeight) ? ((triggerRect.top + triggerHeight) - height) : triggerRect.top;
|
|
63
|
+
}
|
|
64
|
+
return `
|
|
65
|
+
left: ${left}px;
|
|
66
|
+
top: ${top}px;
|
|
67
|
+
width: ${width}px;
|
|
68
|
+
height: ${height}px;
|
|
69
|
+
`;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Calculates fixed box position and sized based on Y axis position.
|
|
73
|
+
*/
|
|
74
|
+
const calculatePositionBasedOnYAxis = (triggerRect, boxEl, position, space, windowWidth, windowHeight) => {
|
|
75
|
+
// left & width
|
|
76
|
+
let left;
|
|
77
|
+
const width = boxEl.offsetWidth;
|
|
78
|
+
const diffLeft = windowWidth - (triggerRect.left + width);
|
|
79
|
+
const diffRight = triggerRect.left - width;
|
|
80
|
+
if (diffLeft >= 0 || diffLeft >= diffRight) {
|
|
81
|
+
left = triggerRect.left;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
left = triggerRect.left + triggerRect.width - width;
|
|
85
|
+
}
|
|
86
|
+
// top & height
|
|
87
|
+
let top;
|
|
88
|
+
let height = boxEl.offsetHeight;
|
|
89
|
+
const diffBottom = windowHeight - (triggerRect.top + triggerRect.height + height + space);
|
|
90
|
+
const diffTop = (triggerRect.top + triggerRect.height) - (height + 1);
|
|
91
|
+
if ((position === types_1.Position.BOTTOM && (diffBottom >= 0 || diffBottom >= diffTop))
|
|
92
|
+
|| (position === types_1.Position.TOP && diffTop < 0 && diffBottom > diffTop)) {
|
|
93
|
+
height = diffBottom > 0 ? height : (windowHeight - (triggerRect.top + triggerRect.height + space));
|
|
94
|
+
top = triggerRect.top + triggerRect.height + space;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
height = diffTop > 0 ? height : triggerRect.top;
|
|
98
|
+
top = (triggerRect.top + triggerRect.height) - (height + 1);
|
|
99
|
+
}
|
|
100
|
+
return `
|
|
101
|
+
left: ${left}px;
|
|
102
|
+
top: ${top}px;
|
|
103
|
+
width: ${width}px;
|
|
104
|
+
height: ${height}px;
|
|
105
|
+
`;
|
|
106
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Position } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the box and arrow position.
|
|
4
|
+
*/
|
|
5
|
+
export declare const calculatePosition: (triggerEl: HTMLElement, boxEl: HTMLDivElement | null, headerEl: HTMLHeadingElement | null, arrowEl: SVGSVGElement, position: Position, space: number) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Generates CSS transition classes.
|
|
8
|
+
*/
|
|
9
|
+
export declare const generateCSSTransitionClasses: (key: string, duration: number) => string;
|
package/util/popover.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCSSTransitionClasses = exports.calculatePosition = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const dom_1 = require("./dom");
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the box and arrow position based on X axis.
|
|
8
|
+
*/
|
|
9
|
+
const calculatePositionBasedOnXAxis = (triggerRect, boxRect, headerRect, pos, space, windowWidth, windowHeight) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const [arrowWidth, arrowHeight] = getArrowSize(pos);
|
|
12
|
+
let left;
|
|
13
|
+
let arrowLeft;
|
|
14
|
+
let overflow;
|
|
15
|
+
if (pos === types_1.Position.RIGHT) {
|
|
16
|
+
left = triggerRect.left + triggerRect.width + space + arrowWidth;
|
|
17
|
+
overflow = Math.abs(Math.min(windowWidth - (left + boxRect.width), 0));
|
|
18
|
+
arrowLeft = (arrowWidth - 2) * -1;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
left = triggerRect.left - (boxRect.width + arrowWidth + space);
|
|
22
|
+
overflow = Math.abs(Math.min(left, 0));
|
|
23
|
+
arrowLeft = boxRect.width - 2;
|
|
24
|
+
}
|
|
25
|
+
const top = headerRect
|
|
26
|
+
? (triggerRect.top + (triggerRect.height / 2) - (headerRect.height + (arrowHeight / 2)))
|
|
27
|
+
: (triggerRect.top + (triggerRect.height / 2) - (boxRect.height / 2));
|
|
28
|
+
const arrowTop = (_a = headerRect === null || headerRect === void 0 ? void 0 : headerRect.height) !== null && _a !== void 0 ? _a : ((boxRect.height - arrowHeight) / 2);
|
|
29
|
+
const isArrowInHeader = headerRect && arrowTop + (arrowHeight * 2) < headerRect.height;
|
|
30
|
+
if (top < 0) {
|
|
31
|
+
overflow += Math.abs(top);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
overflow += Math.abs(Math.min(windowHeight - (top + boxRect.height), 0));
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
arrowStyle: `
|
|
38
|
+
left: ${arrowLeft}px;
|
|
39
|
+
top: ${arrowTop}px;
|
|
40
|
+
`,
|
|
41
|
+
isArrowInHeader,
|
|
42
|
+
overflow,
|
|
43
|
+
pos,
|
|
44
|
+
style: `
|
|
45
|
+
left: ${left}px;
|
|
46
|
+
top: ${top}px;
|
|
47
|
+
`,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Calculates the box and arrow position based on Y axis.
|
|
52
|
+
*/
|
|
53
|
+
const calculatePositionBasedOnYAxis = (triggerRect, boxRect, headerRect, pos, space, windowWidth, windowHeight) => {
|
|
54
|
+
const [arrowWidth, arrowHeight] = getArrowSize(pos);
|
|
55
|
+
let arrowTop;
|
|
56
|
+
let top;
|
|
57
|
+
let overflow;
|
|
58
|
+
if (pos === types_1.Position.TOP) {
|
|
59
|
+
top = triggerRect.top - (boxRect.height + arrowHeight + space);
|
|
60
|
+
overflow = Math.abs(Math.min(top, 0));
|
|
61
|
+
arrowTop = boxRect.height - 1;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
top = triggerRect.top + triggerRect.height + space + arrowHeight;
|
|
65
|
+
overflow = Math.abs(Math.min(windowHeight - (top + boxRect.height), 0));
|
|
66
|
+
arrowTop = (arrowHeight - 1) * -1;
|
|
67
|
+
}
|
|
68
|
+
const left = (triggerRect.left) + (triggerRect.width / 2) - (boxRect.width / 2);
|
|
69
|
+
const arrowLeft = (boxRect.width / 2) - (arrowWidth / 2);
|
|
70
|
+
if (left < 0) {
|
|
71
|
+
overflow += Math.abs(left);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
overflow += Math.abs(Math.min(windowWidth - (left + boxRect.width), 0));
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
arrowStyle: `
|
|
78
|
+
left: ${arrowLeft}px;
|
|
79
|
+
top: ${arrowTop}px;
|
|
80
|
+
`,
|
|
81
|
+
isArrowInHeader: headerRect && pos === types_1.Position.BOTTOM,
|
|
82
|
+
overflow,
|
|
83
|
+
pos,
|
|
84
|
+
style: `
|
|
85
|
+
left: ${left}px;
|
|
86
|
+
top: ${top}px;
|
|
87
|
+
`,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Calculates the box and arrow position.
|
|
92
|
+
*/
|
|
93
|
+
const calculatePosition = (triggerEl, boxEl, headerEl, arrowEl, position, space) => {
|
|
94
|
+
if (!boxEl) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const windowWidth = window.innerWidth;
|
|
98
|
+
const windowHeight = window.innerHeight;
|
|
99
|
+
const triggerRect = Object.assign(Object.assign({}, triggerEl.getBoundingClientRect()), (0, dom_1.calculateShownPart)(triggerEl));
|
|
100
|
+
if (triggerRect.width <= 0 || triggerRect.height <= 0) {
|
|
101
|
+
boxEl.setAttribute('style', 'pointer-events: none; visibility: hidden;');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
boxEl.removeAttribute('style');
|
|
105
|
+
const boxRect = boxEl.getBoundingClientRect();
|
|
106
|
+
const headerRect = headerEl === null || headerEl === void 0 ? void 0 : headerEl.getBoundingClientRect();
|
|
107
|
+
let result;
|
|
108
|
+
for (let i = 0, p; i < 4; i++) {
|
|
109
|
+
switch (i) {
|
|
110
|
+
case 0:
|
|
111
|
+
p = position;
|
|
112
|
+
break;
|
|
113
|
+
case 1:
|
|
114
|
+
case 3:
|
|
115
|
+
if (p & (types_1.Position.LEFT | types_1.Position.TOP)) {
|
|
116
|
+
p <<= 1;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
p >>= 1;
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case 2:
|
|
123
|
+
if (p & (types_1.Position.LEFT | types_1.Position.RIGHT)) {
|
|
124
|
+
p = types_1.Position.TOP;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
p = types_1.Position.LEFT;
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
const r = p & (types_1.Position.LEFT | types_1.Position.RIGHT)
|
|
132
|
+
? calculatePositionBasedOnXAxis(triggerRect, boxRect, headerRect, p, space, windowWidth, windowHeight)
|
|
133
|
+
: calculatePositionBasedOnYAxis(triggerRect, boxRect, headerRect, p, space, windowWidth, windowHeight);
|
|
134
|
+
if (!result || r.overflow < result.overflow) {
|
|
135
|
+
result = r;
|
|
136
|
+
}
|
|
137
|
+
if (result.overflow === 0) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
boxEl.setAttribute('style', result.style);
|
|
142
|
+
boxEl.setAttribute('data-src-position', String(result.pos));
|
|
143
|
+
arrowEl.setAttribute('style', result.arrowStyle);
|
|
144
|
+
arrowEl.setAttribute('viewBox', getArrowViewBox(result.pos));
|
|
145
|
+
arrowEl.setAttribute('data-src-position', String(result.pos));
|
|
146
|
+
arrowEl.setAttribute('data-arrow-header', String(result.isArrowInHeader));
|
|
147
|
+
};
|
|
148
|
+
exports.calculatePosition = calculatePosition;
|
|
149
|
+
/**
|
|
150
|
+
* Generates CSS transition classes.
|
|
151
|
+
*/
|
|
152
|
+
const generateCSSTransitionClasses = (key, duration) => `
|
|
153
|
+
&.src-${key}-show-active,
|
|
154
|
+
&.src-${key}-hide-active {
|
|
155
|
+
transition: ${duration}ms 0s ease-in-out;
|
|
156
|
+
transition-property: transform, opacity;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
&.src-${key}-show {
|
|
160
|
+
opacity: 0;
|
|
161
|
+
|
|
162
|
+
&[data-src-position="${types_1.Position.LEFT}"] { transform: translateX(-30px); }
|
|
163
|
+
&[data-src-position="${types_1.Position.RIGHT}"] { transform: translateX(30px); }
|
|
164
|
+
&[data-src-position="${types_1.Position.TOP}"] { transform: translateY(-30px); }
|
|
165
|
+
&[data-src-position="${types_1.Position.BOTTOM}"] { transform: translateY(-30px); }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&.src-${key}-show-active {
|
|
169
|
+
opacity: 1;
|
|
170
|
+
|
|
171
|
+
&[data-src-position="${types_1.Position.LEFT}"],
|
|
172
|
+
&[data-src-position="${types_1.Position.RIGHT}"] {
|
|
173
|
+
transform: translateX(0);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&[data-src-position="${types_1.Position.TOP}"],
|
|
177
|
+
&[data-src-position="${types_1.Position.BOTTOM}"] {
|
|
178
|
+
transform: translateY(0);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
&.src-${key}-hide {
|
|
183
|
+
opacity: 1;
|
|
184
|
+
|
|
185
|
+
&[data-src-position="${types_1.Position.LEFT}"],
|
|
186
|
+
&[data-src-position="${types_1.Position.RIGHT}"] {
|
|
187
|
+
transform: translateX(0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&[data-src-position="${types_1.Position.TOP}"],
|
|
191
|
+
&[data-src-position="${types_1.Position.BOTTOM}"] {
|
|
192
|
+
transform: translateY(0);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
&.src-${key}-hide-active {
|
|
197
|
+
opacity: 0;
|
|
198
|
+
|
|
199
|
+
&[data-src-position="${types_1.Position.LEFT}"] { transform: translateX(-30px); }
|
|
200
|
+
&[data-src-position="${types_1.Position.RIGHT}"] { transform: translateX(30px); }
|
|
201
|
+
&[data-src-position="${types_1.Position.TOP}"] { transform: translateY(-30px); }
|
|
202
|
+
&[data-src-position="${types_1.Position.BOTTOM}"] { transform: translateY(-30px); }
|
|
203
|
+
}
|
|
204
|
+
`;
|
|
205
|
+
exports.generateCSSTransitionClasses = generateCSSTransitionClasses;
|
|
206
|
+
/**
|
|
207
|
+
* Returns width and height attributes depending on position
|
|
208
|
+
*/
|
|
209
|
+
const getArrowSize = (position) => position & (types_1.Position.LEFT | types_1.Position.RIGHT) ? [10, 15] : [15, 10];
|
|
210
|
+
/**
|
|
211
|
+
* Returns viewBox attribute depending on position
|
|
212
|
+
*/
|
|
213
|
+
const getArrowViewBox = (position) => position & (types_1.Position.LEFT | types_1.Position.RIGHT) ? '0 0 252.8 378.5' : '0 0 377.3 251.9';
|