@smart-react-components/ui 2.0.0-alpha-2 → 2.0.0-alpha-4

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 (85) hide show
  1. package/Alert/AlertCloseIcon/index.d.ts +2 -0
  2. package/Alert/AlertCloseIcon/index.js +7 -0
  3. package/Alert/AlertElement.d.ts +13 -0
  4. package/Alert/AlertElement.js +98 -0
  5. package/Alert/AlertIcon/AlertIconElement.d.ts +13 -0
  6. package/Alert/AlertIcon/AlertIconElement.js +55 -0
  7. package/Alert/AlertIcon/index.d.ts +11 -0
  8. package/Alert/AlertIcon/index.js +15 -0
  9. package/Alert/index.d.ts +14 -0
  10. package/Alert/index.js +57 -0
  11. package/Badge/BadgeElement.d.ts +20 -0
  12. package/Badge/BadgeElement.js +206 -0
  13. package/Badge/BadgeIcon/BadgeIconElement.d.ts +13 -0
  14. package/Badge/BadgeIcon/BadgeIconElement.js +82 -0
  15. package/Badge/BadgeIcon/index.d.ts +7 -0
  16. package/Badge/BadgeIcon/index.js +11 -0
  17. package/Badge/BadgeList/BadgeListElement.d.ts +7 -0
  18. package/Badge/BadgeList/BadgeListElement.js +20 -0
  19. package/Badge/BadgeList/index.d.ts +15 -0
  20. package/Badge/BadgeList/index.js +18 -0
  21. package/Badge/index.d.ts +19 -0
  22. package/Badge/index.js +59 -0
  23. package/Breadcrumb/BreadcrumbItem/BreadcrumbItemElement.d.ts +13 -0
  24. package/Breadcrumb/BreadcrumbItem/BreadcrumbItemElement.js +110 -0
  25. package/Breadcrumb/BreadcrumbItem/index.d.ts +21 -0
  26. package/Breadcrumb/BreadcrumbItem/index.js +17 -0
  27. package/Breadcrumb/BreadcrumbLink/index.d.ts +6 -0
  28. package/Breadcrumb/BreadcrumbLink/index.js +27 -0
  29. package/Breadcrumb/BreadcrumbList/BreadcrumbListElement.d.ts +10 -0
  30. package/Breadcrumb/BreadcrumbList/BreadcrumbListElement.js +22 -0
  31. package/Breadcrumb/BreadcrumbList/index.d.ts +16 -0
  32. package/Breadcrumb/BreadcrumbList/index.js +28 -0
  33. package/Breadcrumb/index.d.ts +3 -0
  34. package/Breadcrumb/index.js +12 -0
  35. package/Dropdown/DropdownArrowIcon/index.d.ts +2 -0
  36. package/Dropdown/DropdownArrowIcon/index.js +7 -0
  37. package/Dropdown/DropdownCategory/index.d.ts +7 -0
  38. package/Dropdown/DropdownCategory/index.js +9 -0
  39. package/Dropdown/DropdownItem/DropdownItemElement.d.ts +12 -0
  40. package/Dropdown/DropdownItem/DropdownItemElement.js +50 -0
  41. package/Dropdown/DropdownItem/index.d.ts +9 -0
  42. package/Dropdown/DropdownItem/index.js +31 -0
  43. package/Dropdown/DropdownList/DropdownListElement.d.ts +11 -0
  44. package/Dropdown/DropdownList/DropdownListElement.js +44 -0
  45. package/Dropdown/DropdownList/index.d.ts +13 -0
  46. package/Dropdown/DropdownList/index.js +9 -0
  47. package/Dropdown/index.d.ts +5 -0
  48. package/Dropdown/index.js +29 -0
  49. package/FixedBox/FixedBoxElement.d.ts +0 -3
  50. package/FixedBox/FixedBoxElement.js +0 -12
  51. package/FixedBox/index.d.ts +2 -1
  52. package/FixedBox/index.js +6 -156
  53. package/Popover/PopoverArrow.d.ts +4 -0
  54. package/Popover/PopoverArrow.js +41 -0
  55. package/Popover/PopoverElement.d.ts +14 -0
  56. package/Popover/PopoverElement.js +79 -0
  57. package/Popover/index.d.ts +26 -0
  58. package/Popover/index.js +63 -0
  59. package/Tooltip/TooltipElement.d.ts +12 -0
  60. package/Tooltip/TooltipElement.js +46 -0
  61. package/Tooltip/index.d.ts +26 -0
  62. package/Tooltip/index.js +38 -0
  63. package/hooks/useFixedBoxMethods.d.ts +21 -0
  64. package/hooks/useFixedBoxMethods.js +114 -0
  65. package/icons/ArrowDown.d.ts +6 -0
  66. package/icons/ArrowDown.js +12 -0
  67. package/icons/Close.d.ts +6 -0
  68. package/icons/Close.js +12 -0
  69. package/index.d.ts +14 -0
  70. package/index.js +28 -1
  71. package/package.json +7 -7
  72. package/types/index.d.ts +4 -0
  73. package/types/index.js +6 -1
  74. package/types/popover.d.ts +8 -0
  75. package/types/popover.js +2 -0
  76. package/util/css.d.ts +8 -0
  77. package/util/css.js +23 -0
  78. package/util/dom.d.ts +9 -0
  79. package/util/dom.js +47 -1
  80. package/util/fixed-box.d.ts +2 -6
  81. package/util/fixed-box.js +74 -44
  82. package/util/popover.d.ts +9 -0
  83. package/util/popover.js +213 -0
  84. package/util/props.d.ts +21 -0
  85. package/util/props.js +56 -0
@@ -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';
@@ -0,0 +1,21 @@
1
+ import { ContentElement } from '@smart-react-components/core/types';
2
+ import { StyledComponent } from 'styled-components';
3
+ import { OrderPosition } from '../types';
4
+ /**
5
+ * Extracts icon elements out of children.
6
+ *
7
+ * @params children - children prop given to the component.
8
+ * @params Content - The component that wraps all children except for icons.
9
+ * @params props - props given to the icon component.
10
+ */
11
+ export declare const extractIconsOutOfChildren: (children: ContentElement, Content: StyledComponent<'div', any>, props: object) => {
12
+ children: JSX.Element;
13
+ hasIconLeft: boolean;
14
+ hasIconRight: boolean;
15
+ };
16
+ /**
17
+ * Returns reverse value of the order position.
18
+ * If value is left, returns right.
19
+ * If value is right, returns left.
20
+ */
21
+ export declare const getReverseOrderPosition: (value: OrderPosition) => number;
package/util/props.js ADDED
@@ -0,0 +1,56 @@
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
+ exports.getReverseOrderPosition = exports.extractIconsOutOfChildren = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const types_1 = require("../types");
9
+ /**
10
+ * Extracts icon elements out of children.
11
+ *
12
+ * @params children - children prop given to the component.
13
+ * @params Content - The component that wraps all children except for icons.
14
+ * @params props - props given to the icon component.
15
+ */
16
+ const extractIconsOutOfChildren = (children, Content, props) => {
17
+ var _a, _b, _c;
18
+ if (!Array.isArray(children)) {
19
+ return {
20
+ children: react_1.default.createElement(Content, null, children),
21
+ hasIconLeft: false,
22
+ hasIconRight: false,
23
+ };
24
+ }
25
+ let iconLeft = null;
26
+ let iconRight = null;
27
+ const content = [];
28
+ for (let idx = 0; idx < children.length; idx++) {
29
+ const item = children[idx];
30
+ if (idx === 0 && ((_a = item.type) === null || _a === void 0 ? void 0 : _a.displayName) === 'SRCIcon') {
31
+ iconLeft = react_1.default.cloneElement(item, Object.assign(Object.assign({}, props), { iconPosition: types_1.OrderPosition.LEFT }));
32
+ continue;
33
+ }
34
+ if (idx === children.length - 1 && ((_b = item.type) === null || _b === void 0 ? void 0 : _b.displayName) === 'SRCIcon') {
35
+ iconRight = react_1.default.cloneElement(item, Object.assign(Object.assign({}, props), { iconPosition: types_1.OrderPosition.RIGHT }));
36
+ continue;
37
+ }
38
+ content.push(react_1.default.cloneElement(item, { key: (_c = item.key) !== null && _c !== void 0 ? _c : idx }));
39
+ }
40
+ return {
41
+ children: (react_1.default.createElement(react_1.default.Fragment, null,
42
+ iconLeft && iconLeft,
43
+ react_1.default.createElement(Content, null, content),
44
+ iconRight && iconRight)),
45
+ hasIconLeft: !!iconLeft,
46
+ hasIconRight: !!iconRight,
47
+ };
48
+ };
49
+ exports.extractIconsOutOfChildren = extractIconsOutOfChildren;
50
+ /**
51
+ * Returns reverse value of the order position.
52
+ * If value is left, returns right.
53
+ * If value is right, returns left.
54
+ */
55
+ const getReverseOrderPosition = (value) => value ^ (types_1.OrderPosition.LEFT | types_1.OrderPosition.RIGHT);
56
+ exports.getReverseOrderPosition = getReverseOrderPosition;