@smart-react-components/ui 2.0.0-alpha-1 → 2.0.0-alpha-2
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/FixedBox/FixedBoxElement.d.ts +10 -0
- package/FixedBox/FixedBoxElement.js +40 -0
- package/FixedBox/OverlayElement.d.ts +6 -0
- package/FixedBox/OverlayElement.js +81 -0
- package/FixedBox/index.d.ts +28 -0
- package/FixedBox/index.js +187 -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/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/index.d.ts +4 -0
- package/index.js +9 -1
- package/package.json +8 -7
- package/types/index.d.ts +11 -0
- package/types/index.js +16 -0
- package/util/dom.d.ts +15 -0
- package/util/dom.js +38 -0
- package/util/fixed-box.d.ts +9 -0
- package/util/fixed-box.js +76 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StyledProps } from '@smart-react-components/core/styled-props';
|
|
2
|
+
import { Breakpoint } from '@smart-react-components/core/types/grid';
|
|
3
|
+
interface Props extends StyledProps {
|
|
4
|
+
breakpoint: Breakpoint | null;
|
|
5
|
+
}
|
|
6
|
+
export declare const FixedBoxReplicaElement: import("styled-components").StyledComponent<"div", any, {
|
|
7
|
+
className: "src-replica";
|
|
8
|
+
}, "className">;
|
|
9
|
+
declare const _default: import("styled-components").StyledComponent<"div", any, StyledProps & Props, never>;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
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.FixedBoxReplicaElement = void 0;
|
|
7
|
+
const Div_1 = __importDefault(require("@smart-react-components/core/Element/Div"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
exports.FixedBoxReplicaElement = styled_components_1.default.div.attrs({
|
|
10
|
+
className: 'src-replica',
|
|
11
|
+
}) `
|
|
12
|
+
left: -999px;
|
|
13
|
+
opacity: 0;
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
position: fixed;
|
|
16
|
+
top: -999px;
|
|
17
|
+
visibility: hidden;
|
|
18
|
+
z-index: -999;
|
|
19
|
+
`;
|
|
20
|
+
exports.default = (0, styled_components_1.default)(Div_1.default)(({ theme, breakpoint, width }) => `
|
|
21
|
+
overflow: auto;
|
|
22
|
+
position: fixed;
|
|
23
|
+
z-index: ${theme.$.zIndex.fixedBox};
|
|
24
|
+
|
|
25
|
+
${breakpoint
|
|
26
|
+
? `
|
|
27
|
+
@media(max-width: ${theme.$.length.breakpoint[breakpoint] - 1}px) {
|
|
28
|
+
height: auto !important;
|
|
29
|
+
max-height: 100% !important;
|
|
30
|
+
position: static;
|
|
31
|
+
|
|
32
|
+
${!width
|
|
33
|
+
? `
|
|
34
|
+
width: 100% !important;
|
|
35
|
+
`
|
|
36
|
+
: ''}
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
: ''}
|
|
40
|
+
`);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Props as OverlayElementProps } from '../Overlay/OverlayElement';
|
|
2
|
+
interface Props extends OverlayElementProps {
|
|
3
|
+
duration: number;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: import("styled-components").StyledComponent<"div", any, import("@smart-react-components/core").StyledProps & OverlayElementProps & Props, never>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,81 @@
|
|
|
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 styled_components_1 = __importDefault(require("styled-components"));
|
|
7
|
+
const OverlayElement_1 = __importDefault(require("../Overlay/OverlayElement"));
|
|
8
|
+
const overlayAnimation = duration => `
|
|
9
|
+
will-change: opacity;
|
|
10
|
+
|
|
11
|
+
&.src-fixed-box-show {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&.src-fixed-box-show-active {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&.src-fixed-box-hide {
|
|
20
|
+
opacity: 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.src-fixed-box-hide-active {
|
|
24
|
+
opacity: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&.src-fixed-box-show-active,
|
|
28
|
+
&.src-fixed-box-hide-active {
|
|
29
|
+
transition: opacity ${duration}ms 0s ease-in-out;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const fixedBoxAnimation = duration => `
|
|
33
|
+
> * {
|
|
34
|
+
will-change: opacity, transform;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&.src-fixed-box-show > * {
|
|
38
|
+
opacity: 0;
|
|
39
|
+
transform: translateY(60px);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&.src-fixed-box-show-active > * {
|
|
43
|
+
opacity: 1;
|
|
44
|
+
transform: translateY(0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.src-fixed-box-hide > * {
|
|
48
|
+
opacity: 1;
|
|
49
|
+
transform: translateY(0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&.src-fixed-box-hide-active > * {
|
|
53
|
+
opacity: 0;
|
|
54
|
+
transform: translateY(60px);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&.src-fixed-box-show-active,
|
|
58
|
+
&.src-fixed-box-hide-active {
|
|
59
|
+
> * {
|
|
60
|
+
transition: ${duration}ms 0s ease-in-out;
|
|
61
|
+
transition-property: opacity, transform;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
exports.default = (0, styled_components_1.default)(OverlayElement_1.default)(({ theme, breakpoint, duration }) => `
|
|
66
|
+
${breakpoint
|
|
67
|
+
? `
|
|
68
|
+
@media(max-width: ${theme.$.length.breakpoint.medium - 1}px) {
|
|
69
|
+
align-items: center;
|
|
70
|
+
|
|
71
|
+
${overlayAnimation(duration)}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@media(min-width: ${theme.$.length.breakpoint.medium}px) {
|
|
75
|
+
${fixedBoxAnimation(duration)}
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
: `
|
|
79
|
+
${fixedBoxAnimation(duration)}
|
|
80
|
+
`}
|
|
81
|
+
`);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SetState } from '@smart-react-components/core/types';
|
|
2
|
+
import { Breakpoint } from '@smart-react-components/core/types/grid';
|
|
3
|
+
import { TransitionAfterCallback, TransitionBeforeCallback } from '@smart-react-components/transition/types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Position, TriggerInteraction } from '../types';
|
|
6
|
+
export { Position, TriggerInteraction } from '../types';
|
|
7
|
+
export interface Props {
|
|
8
|
+
afterHide?: TransitionAfterCallback;
|
|
9
|
+
afterShow?: TransitionAfterCallback;
|
|
10
|
+
beforeHide?: TransitionBeforeCallback;
|
|
11
|
+
beforeShow?: TransitionBeforeCallback;
|
|
12
|
+
breakpoint?: Breakpoint;
|
|
13
|
+
children: [JSX.Element, JSX.Element];
|
|
14
|
+
hasHideAnimation?: boolean;
|
|
15
|
+
hasShowAnimation?: boolean;
|
|
16
|
+
isDismissible?: boolean;
|
|
17
|
+
maxWidth?: number;
|
|
18
|
+
minWidth?: number;
|
|
19
|
+
position?: Position;
|
|
20
|
+
setStatus?: SetState<boolean>;
|
|
21
|
+
space?: number;
|
|
22
|
+
status?: boolean;
|
|
23
|
+
transitionClassName?: string;
|
|
24
|
+
transitionDuration?: number;
|
|
25
|
+
triggerInteraction?: TriggerInteraction;
|
|
26
|
+
}
|
|
27
|
+
declare const FixedBox: React.FC<Props>;
|
|
28
|
+
export default FixedBox;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.TriggerInteraction = exports.Position = void 0;
|
|
39
|
+
const dom_1 = require("@smart-react-components/core/util/dom");
|
|
40
|
+
const CSSTransition_1 = __importDefault(require("@smart-react-components/transition/CSSTransition"));
|
|
41
|
+
const react_1 = __importDefault(require("react"));
|
|
42
|
+
const react_dom_1 = require("react-dom");
|
|
43
|
+
const styled_components_1 = require("styled-components");
|
|
44
|
+
const Overlay_1 = __importDefault(require("../Overlay"));
|
|
45
|
+
const types_1 = require("../types");
|
|
46
|
+
const dom_2 = require("../util/dom");
|
|
47
|
+
const fixed_box_1 = require("../util/fixed-box");
|
|
48
|
+
const FixedBoxElement_1 = __importStar(require("./FixedBoxElement"));
|
|
49
|
+
const OverlayElement_1 = __importDefault(require("./OverlayElement"));
|
|
50
|
+
var types_2 = require("../types");
|
|
51
|
+
Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return types_2.Position; } });
|
|
52
|
+
Object.defineProperty(exports, "TriggerInteraction", { enumerable: true, get: function () { return types_2.TriggerInteraction; } });
|
|
53
|
+
const FixedBox = ({ afterHide, afterShow, beforeHide, beforeShow, breakpoint = 'medium', children, hasHideAnimation = true, hasShowAnimation = true, isDismissible = true, maxWidth, minWidth, position = types_1.Position.BOTTOM, setStatus, space = 0, status, transitionClassName, transitionDuration, triggerInteraction = types_1.TriggerInteraction.CLICK, }) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const theme = react_1.default.useContext(styled_components_1.ThemeContext);
|
|
56
|
+
const triggerEl = react_1.default.useRef(null);
|
|
57
|
+
const boxEl = react_1.default.useRef(null);
|
|
58
|
+
const boxReplicaEl = react_1.default.useRef(null);
|
|
59
|
+
const leaveTimeout = react_1.default.useRef(null);
|
|
60
|
+
const [localStatus, setLocalStatus] = react_1.default.useState(() => false);
|
|
61
|
+
const getTriggerEl = () => { var _a; return ((_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl).current; };
|
|
62
|
+
const getStatus = () => status !== null && status !== void 0 ? status : localStatus;
|
|
63
|
+
const getSetStatus = () => setStatus !== null && setStatus !== void 0 ? setStatus : setLocalStatus;
|
|
64
|
+
const handleTriggerClick = (e) => {
|
|
65
|
+
const triggerEl = getTriggerEl();
|
|
66
|
+
if ((0, dom_2.isTargetClickable)(e.target, triggerEl)) {
|
|
67
|
+
getSetStatus()(!getStatus());
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const handleTriggerMouseEnter = e => {
|
|
71
|
+
if (e.target === getTriggerEl()) {
|
|
72
|
+
getSetStatus()(true);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const handleWindowClick = (e) => {
|
|
76
|
+
const target = e.target;
|
|
77
|
+
const triggerEl = getTriggerEl();
|
|
78
|
+
if (!triggerEl.contains(target) && !boxEl.current.contains(target)) {
|
|
79
|
+
getSetStatus()(false);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const handleWindowMouseMove = (e) => {
|
|
83
|
+
const target = e.target;
|
|
84
|
+
const triggerEl = getTriggerEl();
|
|
85
|
+
if (!triggerEl.contains(target) && !boxEl.current.contains(target)) {
|
|
86
|
+
if (!leaveTimeout.current) {
|
|
87
|
+
leaveTimeout.current = setTimeout(() => {
|
|
88
|
+
clearTimeout(leaveTimeout.current);
|
|
89
|
+
leaveTimeout.current = null;
|
|
90
|
+
getSetStatus()(false);
|
|
91
|
+
}, 250);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (leaveTimeout.current) {
|
|
95
|
+
clearTimeout(leaveTimeout.current);
|
|
96
|
+
leaveTimeout.current = null;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const handlePosition = () => {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
if (!boxEl.current) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (boxReplicaEl.current) {
|
|
105
|
+
boxReplicaEl.current.innerHTML = boxEl.current.innerHTML;
|
|
106
|
+
}
|
|
107
|
+
const triggerRect = getTriggerEl().getBoundingClientRect();
|
|
108
|
+
const boxReplicaRect = (_b = (_a = boxReplicaEl.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) !== null && _b !== void 0 ? _b : boxEl.current.getBoundingClientRect();
|
|
109
|
+
let width = boxReplicaRect.width;
|
|
110
|
+
if (minWidth && minWidth > width) {
|
|
111
|
+
width = minWidth;
|
|
112
|
+
}
|
|
113
|
+
if (maxWidth && maxWidth < width) {
|
|
114
|
+
width = maxWidth;
|
|
115
|
+
}
|
|
116
|
+
const windowWidth = window.innerWidth;
|
|
117
|
+
const windowHeight = window.innerHeight;
|
|
118
|
+
const style = position & (types_1.Position.TOP | types_1.Position.BOTTOM)
|
|
119
|
+
? (0, fixed_box_1.calculateYAxisBasedPosition)(triggerRect, boxReplicaRect, position, width, space, windowWidth, windowHeight)
|
|
120
|
+
: (0, fixed_box_1.calculateXAxisBasedPosition)(triggerRect, boxReplicaRect, position, width, space, windowWidth, windowHeight);
|
|
121
|
+
boxEl.current.setAttribute('style', style);
|
|
122
|
+
};
|
|
123
|
+
const handleBeforeShow = el => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
yield (beforeShow === null || beforeShow === void 0 ? void 0 : beforeShow(el));
|
|
125
|
+
handlePosition();
|
|
126
|
+
resolve();
|
|
127
|
+
}));
|
|
128
|
+
react_1.default.useEffect(() => {
|
|
129
|
+
if (getStatus()) {
|
|
130
|
+
handlePosition();
|
|
131
|
+
}
|
|
132
|
+
}, []);
|
|
133
|
+
react_1.default.useEffect(() => {
|
|
134
|
+
const triggerEl = getTriggerEl();
|
|
135
|
+
const debounceWindowMouseMove = (0, dom_1.debounce)(handleWindowMouseMove);
|
|
136
|
+
const debouncePosition = (0, dom_1.debounce)(handlePosition);
|
|
137
|
+
if (triggerInteraction & types_1.TriggerInteraction.CLICK) {
|
|
138
|
+
(0, dom_1.addEventListener)(triggerEl, ['click'], handleTriggerClick);
|
|
139
|
+
if (getStatus() && isDismissible) {
|
|
140
|
+
(0, dom_1.addEventListener)(window, ['click'], handleWindowClick);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!dom_1.isMobile && triggerInteraction & types_1.TriggerInteraction.HOVER) {
|
|
144
|
+
if (!getStatus()) {
|
|
145
|
+
(0, dom_1.addEventListener)(triggerEl, ['mouseenter'], handleTriggerMouseEnter);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
(0, dom_1.addEventListener)(window, ['mousemove'], debounceWindowMouseMove);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (getStatus()) {
|
|
152
|
+
(0, dom_1.addEventListener)(window, ['resize', 'scroll'], debouncePosition);
|
|
153
|
+
}
|
|
154
|
+
(0, dom_1.addEventListener)(triggerEl, ['src.fixedBox.setPosition'], handlePosition);
|
|
155
|
+
return () => {
|
|
156
|
+
if (triggerInteraction & types_1.TriggerInteraction.CLICK) {
|
|
157
|
+
(0, dom_1.removeEventListener)(triggerEl, ['click'], handleTriggerClick);
|
|
158
|
+
if (getStatus() && isDismissible) {
|
|
159
|
+
(0, dom_1.removeEventListener)(window, ['click'], handleWindowClick);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!dom_1.isMobile && triggerInteraction & types_1.TriggerInteraction.HOVER) {
|
|
163
|
+
if (!getStatus()) {
|
|
164
|
+
(0, dom_1.removeEventListener)(triggerEl, ['mouseenter'], handleTriggerMouseEnter);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
(0, dom_1.removeEventListener)(window, ['mousemove'], debounceWindowMouseMove);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (getStatus()) {
|
|
171
|
+
(0, dom_1.removeEventListener)(window, ['resize', 'scroll'], debouncePosition);
|
|
172
|
+
}
|
|
173
|
+
(0, dom_1.removeEventListener)(triggerEl, ['src.fixedBox.setPosition'], handlePosition);
|
|
174
|
+
};
|
|
175
|
+
}, [status, setStatus, localStatus, setLocalStatus, triggerInteraction]);
|
|
176
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
177
|
+
react_1.default.cloneElement(children[0], { ref: (_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl }),
|
|
178
|
+
react_1.default.createElement(CSSTransition_1.default, { afterHide: afterHide, afterShow: afterShow, beforeHide: beforeHide, beforeShow: handleBeforeShow, className: transitionClassName !== null && transitionClassName !== void 0 ? transitionClassName : 'src-fixed-box', duration: transitionDuration !== null && transitionDuration !== void 0 ? transitionDuration : theme.$.transition.fixedBoxDuration, hasHideAnimation: hasHideAnimation, hasShowAnimation: hasShowAnimation, status: getStatus() },
|
|
179
|
+
react_1.default.createElement(Overlay_1.default, { breakpoint: breakpoint, elementProps: {
|
|
180
|
+
as: OverlayElement_1.default,
|
|
181
|
+
duration: transitionDuration !== null && transitionDuration !== void 0 ? transitionDuration : theme.$.transition.fixedBoxDuration,
|
|
182
|
+
isDisplayedWhenBreakpointNull: false,
|
|
183
|
+
} },
|
|
184
|
+
react_1.default.createElement(FixedBoxElement_1.default, { breakpoint: breakpoint, ref: boxEl }, children[1]))),
|
|
185
|
+
(0, dom_2.canBeRenderedInPortal)() && (0, react_dom_1.createPortal)(react_1.default.createElement(FixedBoxElement_1.FixedBoxReplicaElement, { ref: boxReplicaEl }), document.body)));
|
|
186
|
+
};
|
|
187
|
+
exports.default = FixedBox;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StyledProps } from '@smart-react-components/core/styled-props';
|
|
2
|
+
import { ResponsiveProp, SizeProp } from '@smart-react-components/core/types';
|
|
3
|
+
interface Props extends StyledProps, ResponsiveProp<'loadingSize', SizeProp> {
|
|
4
|
+
loadingColor: string;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: import("styled-components").StyledComponent<"svg", any, StyledProps & Props, never>;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 Circle_1 = __importDefault(require("@smart-react-components/core/Element/Circle"));
|
|
7
|
+
const Svg_1 = __importDefault(require("@smart-react-components/core/Element/Svg"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
10
|
+
exports.default = (0, styled_components_1.default)(Svg_1.default).attrs(({ loadingColor }) => ({
|
|
11
|
+
children: react_1.default.createElement(Circle_1.default, { cx: "22", cy: "22", r: "20", stroke: loadingColor, strokeWidth: 4 }),
|
|
12
|
+
getLoadingSize: (v, t) => `
|
|
13
|
+
height: ${t.$.size.loading[v]};
|
|
14
|
+
width: ${t.$.size.loading[v]};
|
|
15
|
+
`,
|
|
16
|
+
viewBox: '0 0 44 44',
|
|
17
|
+
})) `
|
|
18
|
+
animation: src-loading-animation 2000ms linear infinite;
|
|
19
|
+
|
|
20
|
+
circle {
|
|
21
|
+
animation: src-loading-circle-animation 2000ms linear infinite;
|
|
22
|
+
fill: none;
|
|
23
|
+
stroke-dasharray: 1,150;
|
|
24
|
+
stroke-dashoffset: 0;
|
|
25
|
+
stroke-linecap: round;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@keyframes src-loading-animation {
|
|
29
|
+
from {
|
|
30
|
+
transform: rotate(0deg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
to {
|
|
34
|
+
transform: rotate(360deg);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@keyframes src-loading-circle-animation {
|
|
39
|
+
0% {
|
|
40
|
+
stroke-dasharray: 1,150;
|
|
41
|
+
stroke-dashoffset: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
50% {
|
|
45
|
+
stroke-dasharray: 90,150;
|
|
46
|
+
stroke-dashoffset: -35;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
100% {
|
|
50
|
+
stroke-dasharray: 90,150;
|
|
51
|
+
stroke-dashoffset: -124;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IntrinsicStyledMarginProps } from '@smart-react-components/core/element-props/intrinsic-styled-margin-props';
|
|
2
|
+
import { SizeProps } from '@smart-react-components/core/types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export interface Props extends IntrinsicStyledMarginProps, SizeProps {
|
|
5
|
+
color?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const Loading: React.FC<Props>;
|
|
8
|
+
export default Loading;
|
package/Loading/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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 element_props_1 = __importDefault(require("@smart-react-components/core/element-props"));
|
|
7
|
+
const intrinsic_styled_margin_props_1 = __importDefault(require("@smart-react-components/core/element-props/intrinsic-styled-margin-props"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const LoadingElement_1 = __importDefault(require("./LoadingElement"));
|
|
10
|
+
const Loading = props => (react_1.default.createElement(LoadingElement_1.default, Object.assign({ loadingColor: props.color, loadingSize: props.size, loadingSizeSm: props.sizeSm, loadingSizeMd: props.sizeMd, loadingSizeLg: props.sizeLg, loadingSizeXl: props.sizeXl }, (0, element_props_1.default)(props, [intrinsic_styled_margin_props_1.default]))));
|
|
11
|
+
Loading.defaultProps = {
|
|
12
|
+
color: '$color.blue',
|
|
13
|
+
size: 'medium',
|
|
14
|
+
};
|
|
15
|
+
exports.default = Loading;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StyledProps } from '@smart-react-components/core/styled-props';
|
|
2
|
+
import { Breakpoint } from '@smart-react-components/core/types/grid';
|
|
3
|
+
export interface Props extends StyledProps {
|
|
4
|
+
breakpoint: Breakpoint | null;
|
|
5
|
+
hasBackground: boolean;
|
|
6
|
+
isDisplayedWhenBreakpointNull: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: import("styled-components").StyledComponent<"div", any, StyledProps & Props, never>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 Div_1 = __importDefault(require("@smart-react-components/core/Element/Div"));
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const overlayCSS = ({ theme, hasBackground }) => `
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
display: flex;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
height: 100%;
|
|
13
|
+
left: 0;
|
|
14
|
+
padding: ${theme.$.length.overlay.space};
|
|
15
|
+
top: 0;
|
|
16
|
+
touch-action: none;
|
|
17
|
+
width: 100%;
|
|
18
|
+
|
|
19
|
+
${hasBackground
|
|
20
|
+
? `
|
|
21
|
+
background: ${theme.$.color.overlay.background};
|
|
22
|
+
`
|
|
23
|
+
: ''}
|
|
24
|
+
`;
|
|
25
|
+
exports.default = (0, styled_components_1.default)(Div_1.default)(({ theme, breakpoint, hasBackground, isDisplayedWhenBreakpointNull }) => `
|
|
26
|
+
position: fixed;
|
|
27
|
+
z-index: ${theme.$.zIndex.overlay};
|
|
28
|
+
|
|
29
|
+
${breakpoint
|
|
30
|
+
? `
|
|
31
|
+
@media(max-width: ${theme.$.length.breakpoint[breakpoint] - 1}px) {
|
|
32
|
+
${overlayCSS({ theme, hasBackground })};
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
: isDisplayedWhenBreakpointNull ? overlayCSS({ theme, hasBackground }) : ''}
|
|
36
|
+
`);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClickEvents } from '@smart-react-components/core/element-props/click-events';
|
|
2
|
+
import { JSXElementProps } from '@smart-react-components/core/types';
|
|
3
|
+
import { Breakpoint } from '@smart-react-components/core/types/grid';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export interface Props extends ClickEvents {
|
|
6
|
+
breakpoint?: Breakpoint;
|
|
7
|
+
children: JSX.Element;
|
|
8
|
+
elementProps?: JSXElementProps;
|
|
9
|
+
hasBackground?: boolean;
|
|
10
|
+
hasBlurEffect?: boolean;
|
|
11
|
+
isInBody?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const Overlay: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
export default Overlay;
|
package/Overlay/index.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
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 element_props_1 = __importDefault(require("@smart-react-components/core/element-props"));
|
|
7
|
+
const click_events_1 = __importDefault(require("@smart-react-components/core/element-props/click-events"));
|
|
8
|
+
const dom_1 = require("@smart-react-components/core/util/dom");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const react_dom_1 = require("react-dom");
|
|
11
|
+
const styled_components_1 = require("styled-components");
|
|
12
|
+
const dom_2 = require("../util/dom");
|
|
13
|
+
const OverlayElement_1 = __importDefault(require("./OverlayElement"));
|
|
14
|
+
const Overlay = react_1.default.forwardRef((props, forwardRef) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const theme = react_1.default.useContext(styled_components_1.ThemeContext);
|
|
17
|
+
const ref = (_a = forwardRef) !== null && _a !== void 0 ? _a : react_1.default.useRef(null);
|
|
18
|
+
const getInBody = () => (props.isInBody || props.hasBlurEffect) && (0, dom_2.canBeRenderedInPortal)();
|
|
19
|
+
const getActive = () => (props.hasBlurEffect && (0, dom_2.canBeRenderedInPortal)()) && ((props.breakpoint && window.innerWidth < theme.$.length.breakpoint[props.breakpoint]) || !props.breakpoint);
|
|
20
|
+
const getFront = () => {
|
|
21
|
+
if (!isActive) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const activeOverlayEls = document.querySelectorAll('body > *[data-src-overlay="visible"]');
|
|
25
|
+
return activeOverlayEls[activeOverlayEls.length - 1] === ref.current;
|
|
26
|
+
};
|
|
27
|
+
const [isInBody, setInBody] = react_1.default.useState(() => getInBody());
|
|
28
|
+
const [isActive, setActive] = react_1.default.useState(() => getActive());
|
|
29
|
+
const [isFront, setFront] = react_1.default.useState(() => getFront());
|
|
30
|
+
const handleResize = () => setActive(getActive());
|
|
31
|
+
const handleMouseWheel = (e) => {
|
|
32
|
+
const container = ref.current;
|
|
33
|
+
const delta = ((e.deltaY || -e.wheelDelta || e.detail) >> 10) || 1;
|
|
34
|
+
const up = delta < 0;
|
|
35
|
+
const el = e.target;
|
|
36
|
+
let scrollEl = (0, dom_2.getScrollParent)(el);
|
|
37
|
+
while (scrollEl && (scrollEl === container || container.contains(scrollEl))) {
|
|
38
|
+
if ((up && scrollEl.scrollTop > 0)
|
|
39
|
+
|| (!up && scrollEl.scrollHeight > scrollEl.scrollTop)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
scrollEl = (0, dom_2.getScrollParent)(scrollEl);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
};
|
|
49
|
+
const handleSelectStart = (e) => {
|
|
50
|
+
if (e.target === ref.current) {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const applyBlurEffect = react_1.default.useCallback((el) => {
|
|
55
|
+
el.classList.add('src-blur-effect');
|
|
56
|
+
let value = 1;
|
|
57
|
+
el.style.filter = `blur(${value}px)`;
|
|
58
|
+
const interval = setInterval(() => {
|
|
59
|
+
value++;
|
|
60
|
+
if (value > 5 || !el.classList.contains('src-blur-effect')) {
|
|
61
|
+
clearInterval(interval);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
el.style.filter = `blur(${value}px)`;
|
|
65
|
+
}
|
|
66
|
+
}, 100);
|
|
67
|
+
}, []);
|
|
68
|
+
const removeBlurEffect = react_1.default.useCallback((el) => {
|
|
69
|
+
el.classList.remove('src-blur-effect');
|
|
70
|
+
let value = 4;
|
|
71
|
+
el.style.filter = `blur(${value}px)`;
|
|
72
|
+
const interval = setInterval(() => {
|
|
73
|
+
if (el.classList.contains('src-blur-effect')) {
|
|
74
|
+
value = 0;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
value--;
|
|
78
|
+
}
|
|
79
|
+
el.style.filter = `blur(${value}px)`;
|
|
80
|
+
if (value === 0) {
|
|
81
|
+
clearInterval(interval);
|
|
82
|
+
}
|
|
83
|
+
}, 100);
|
|
84
|
+
}, []);
|
|
85
|
+
react_1.default.useEffect(() => {
|
|
86
|
+
if (props.hasBlurEffect && !props.isInBody) {
|
|
87
|
+
(0, dom_1.displayWarning)('The component is always rendered directly in body when it has blur effect.');
|
|
88
|
+
}
|
|
89
|
+
setInBody(getInBody());
|
|
90
|
+
}, [props.hasBlurEffect, props.isInBody]);
|
|
91
|
+
react_1.default.useEffect(() => {
|
|
92
|
+
if (isInBody) {
|
|
93
|
+
(0, dom_1.addEventListener)(window, ['resize'], handleResize);
|
|
94
|
+
handleResize();
|
|
95
|
+
return () => {
|
|
96
|
+
(0, dom_1.removeEventListener)(window, ['resize'], handleResize);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
setActive(false);
|
|
101
|
+
}
|
|
102
|
+
}, [isInBody, props.breakpoint, isActive]);
|
|
103
|
+
react_1.default.useEffect(() => setFront(getFront()), [isActive]);
|
|
104
|
+
react_1.default.useEffect(() => {
|
|
105
|
+
if (isFront) {
|
|
106
|
+
(0, dom_1.addEventListener)(document, dom_2.mouseWheel, handleMouseWheel, { passive: false });
|
|
107
|
+
(0, dom_1.addEventListener)(window, ['selectstart'], handleSelectStart);
|
|
108
|
+
return () => {
|
|
109
|
+
(0, dom_1.removeEventListener)(document, dom_2.mouseWheel, handleMouseWheel, {});
|
|
110
|
+
(0, dom_1.removeEventListener)(window, ['selectstart'], handleSelectStart);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}, [isFront]);
|
|
114
|
+
react_1.default.useEffect(() => {
|
|
115
|
+
if (isFront) {
|
|
116
|
+
const list = document.querySelectorAll('body > *');
|
|
117
|
+
list.forEach(item => {
|
|
118
|
+
if (item.nodeName !== 'SCRIPT'
|
|
119
|
+
&& item !== ref.current
|
|
120
|
+
&& !item.classList.contains('src-blur-effect')
|
|
121
|
+
&& !item.classList.contains('src-replica')) {
|
|
122
|
+
applyBlurEffect(item);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return () => {
|
|
126
|
+
const activeOverlayEls = document.querySelectorAll('body > *[data-src-overlay="visible"]');
|
|
127
|
+
if (activeOverlayEls.length > 0) {
|
|
128
|
+
const activeOverlayEl = activeOverlayEls[activeOverlayEls.length - 1];
|
|
129
|
+
if (activeOverlayEl.classList.contains('src-blur-effect')) {
|
|
130
|
+
removeBlurEffect(activeOverlayEl);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
document.querySelectorAll('body > *').forEach(item => {
|
|
135
|
+
if (item.classList.contains('src-blur-effect')) {
|
|
136
|
+
removeBlurEffect(item);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}, [isFront]);
|
|
143
|
+
const Element = (react_1.default.createElement(OverlayElement_1.default, Object.assign({ isDisplayedWhenBreakpointNull: true }, props.elementProps, (0, element_props_1.default)(props, [click_events_1.default]), { breakpoint: props.breakpoint, hasBackground: props.hasBackground, ref: ref }, (isInBody && { 'data-src-overlay': isActive ? 'visible' : 'hidden' })), props.children));
|
|
144
|
+
return isInBody ? (0, react_dom_1.createPortal)(Element, document.body) : Element;
|
|
145
|
+
});
|
|
146
|
+
Overlay.defaultProps = {
|
|
147
|
+
hasBackground: true,
|
|
148
|
+
isInBody: true,
|
|
149
|
+
};
|
|
150
|
+
exports.default = Overlay;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StyledProps } from '@smart-react-components/core/styled-props';
|
|
2
|
+
import { PaletteProp, TimingFunction } from '@smart-react-components/core/types';
|
|
3
|
+
export declare const Bar: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const Percentage: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
interface Props extends StyledProps {
|
|
6
|
+
hasStripedAnimation: boolean;
|
|
7
|
+
isFilled: boolean;
|
|
8
|
+
isNested: boolean;
|
|
9
|
+
isStriped: boolean;
|
|
10
|
+
palette: PaletteProp;
|
|
11
|
+
stripedAnimationDuration: number;
|
|
12
|
+
transitionDuration: number;
|
|
13
|
+
transitionTimingFunction: TimingFunction;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: import("styled-components").StyledComponent<"div", any, StyledProps & Props, never>;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,86 @@
|
|
|
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.Percentage = exports.Bar = void 0;
|
|
7
|
+
const Div_1 = __importDefault(require("@smart-react-components/core/Element/Div"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
exports.Bar = styled_components_1.default.div `
|
|
10
|
+
align-items: center;
|
|
11
|
+
display: flex;
|
|
12
|
+
height: 100%;
|
|
13
|
+
left: 0;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
position: absolute;
|
|
16
|
+
`;
|
|
17
|
+
exports.Percentage = styled_components_1.default.div `
|
|
18
|
+
flex: 0 0 auto;
|
|
19
|
+
position: relative;
|
|
20
|
+
`;
|
|
21
|
+
exports.default = (0, styled_components_1.default)(Div_1.default)(({ theme, hasStripedAnimation, height, isFilled, isNested, isStriped, palette, stripedAnimationDuration, transitionDuration, transitionTimingFunction }) => `
|
|
22
|
+
align-items: center;
|
|
23
|
+
color: ${theme.$.palette[palette].progressBar.active};
|
|
24
|
+
display: flex;
|
|
25
|
+
fill: ${theme.$.palette[palette].progressBar.active};
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
position: relative;
|
|
28
|
+
|
|
29
|
+
${exports.Bar} {
|
|
30
|
+
background: ${theme.$.palette[palette].progressBar.active};
|
|
31
|
+
color: ${theme.$.palette[palette].progressBar.font};
|
|
32
|
+
fill: ${theme.$.palette[palette].progressBar.font};
|
|
33
|
+
transition: width ${transitionDuration}ms 0s ${transitionTimingFunction};
|
|
34
|
+
|
|
35
|
+
${isNested
|
|
36
|
+
? `
|
|
37
|
+
background: ${theme.$.palette[palette].progressBar.nestedBackground};
|
|
38
|
+
`
|
|
39
|
+
: `
|
|
40
|
+
border-radius: .125rem;
|
|
41
|
+
`}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
${isFilled
|
|
45
|
+
? `
|
|
46
|
+
background: ${theme.$.palette[palette].progressBar.filledBackground};
|
|
47
|
+
`
|
|
48
|
+
: ''}
|
|
49
|
+
|
|
50
|
+
${isNested
|
|
51
|
+
? `
|
|
52
|
+
flex: 1 1 auto;
|
|
53
|
+
`
|
|
54
|
+
: `
|
|
55
|
+
border-radius: .125rem;
|
|
56
|
+
`}
|
|
57
|
+
|
|
58
|
+
${isStriped
|
|
59
|
+
? `
|
|
60
|
+
&,
|
|
61
|
+
${exports.Bar} {
|
|
62
|
+
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
|
|
63
|
+
background-size: ${height} ${height};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
${hasStripedAnimation
|
|
67
|
+
? `
|
|
68
|
+
&,
|
|
69
|
+
${exports.Bar} {
|
|
70
|
+
animation: src-progress-bar-stripes ${stripedAnimationDuration}ms 0s ${transitionTimingFunction} infinite;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@keyframes src-progress-bar-stripes {
|
|
74
|
+
from {
|
|
75
|
+
background-position: ${height} 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
to {
|
|
79
|
+
background-position: 0 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`
|
|
83
|
+
: ''}
|
|
84
|
+
`
|
|
85
|
+
: ''}
|
|
86
|
+
`);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JSXElementProps, PaletteProp, TimingFunction } from '@smart-react-components/core/types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface Props {
|
|
4
|
+
displayValue?: boolean;
|
|
5
|
+
elementProps?: JSXElementProps;
|
|
6
|
+
hasStripedAnimation?: boolean;
|
|
7
|
+
isFilled?: boolean;
|
|
8
|
+
isNested?: boolean;
|
|
9
|
+
isStriped?: boolean;
|
|
10
|
+
palette?: PaletteProp;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
separator?: string;
|
|
13
|
+
suffix?: string;
|
|
14
|
+
transitionDuration?: number;
|
|
15
|
+
transitionTimingFunction?: TimingFunction;
|
|
16
|
+
totalValue?: number;
|
|
17
|
+
value: number;
|
|
18
|
+
}
|
|
19
|
+
declare const ProgressBar: React.FC<Props>;
|
|
20
|
+
export default ProgressBar;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const useChangeEffect_1 = __importDefault(require("@smart-react-components/core/hooks/useChangeEffect"));
|
|
30
|
+
const dom_1 = require("@smart-react-components/core/util/dom");
|
|
31
|
+
const react_1 = __importDefault(require("react"));
|
|
32
|
+
const styled_components_1 = require("styled-components");
|
|
33
|
+
const ProgressBarElement_1 = __importStar(require("./ProgressBarElement"));
|
|
34
|
+
const ProgressBar = ({ displayValue, elementProps = {}, hasStripedAnimation = true, isFilled, isNested, isStriped, palette = 'primary', prefix, separator, suffix, transitionDuration = 450, transitionTimingFunction = 'linear', totalValue, value }) => {
|
|
35
|
+
const theme = react_1.default.useContext(styled_components_1.ThemeContext);
|
|
36
|
+
const getStripedAnimationDuration = () => displayValue ? 400 : 1500;
|
|
37
|
+
const getHeight = () => elementProps.height ? (typeof elementProps.height === 'string' ? elementProps.height : `${elementProps.height}px`) : (isNested ? '100%' : (displayValue ? '16px' : '4px'));
|
|
38
|
+
const getPercentage = () => {
|
|
39
|
+
const label = {
|
|
40
|
+
prefix: prefix !== null && prefix !== void 0 ? prefix : theme.$.i18n.progressBar.prefix,
|
|
41
|
+
separator: separator !== null && separator !== void 0 ? separator : theme.$.i18n.progressBar.separator,
|
|
42
|
+
suffix: suffix !== null && suffix !== void 0 ? suffix : theme.$.i18n.progressBar.suffix,
|
|
43
|
+
};
|
|
44
|
+
if (totalValue) {
|
|
45
|
+
return {
|
|
46
|
+
label: `${label.prefix}${value}${label.suffix} ${label.separator} ${label.prefix}${totalValue}${label.suffix}`,
|
|
47
|
+
value: Math.round((value / totalValue) * 100),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
value,
|
|
52
|
+
label: `${label.prefix}${value}${label.suffix}`,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const [stripedAnimationDuration, setStripedAnimationDuration] = react_1.default.useState(() => getStripedAnimationDuration());
|
|
56
|
+
const [height, setHeight] = react_1.default.useState(() => getHeight());
|
|
57
|
+
const [left, setLeft] = react_1.default.useState(() => -1);
|
|
58
|
+
const [percentage, setPercentage] = react_1.default.useState(() => getPercentage());
|
|
59
|
+
const el = react_1.default.useRef(null);
|
|
60
|
+
const percentageEl = react_1.default.useRef(null);
|
|
61
|
+
const handleResize = () => setLeft((el.current.offsetWidth / 2) - (percentageEl.current.offsetWidth / 2));
|
|
62
|
+
(0, useChangeEffect_1.default)(() => {
|
|
63
|
+
setStripedAnimationDuration(getStripedAnimationDuration());
|
|
64
|
+
}, [stripedAnimationDuration]);
|
|
65
|
+
(0, useChangeEffect_1.default)(() => {
|
|
66
|
+
setHeight(getHeight());
|
|
67
|
+
}, [elementProps.height, displayValue]);
|
|
68
|
+
(0, useChangeEffect_1.default)(() => {
|
|
69
|
+
setPercentage(getPercentage());
|
|
70
|
+
}, [value, totalValue, prefix, separator, suffix]);
|
|
71
|
+
react_1.default.useEffect(() => {
|
|
72
|
+
if (displayValue) {
|
|
73
|
+
(0, dom_1.addEventListener)(window, ['resize'], handleResize);
|
|
74
|
+
return () => {
|
|
75
|
+
(0, dom_1.removeEventListener)(window, ['resize'], handleResize);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}, [displayValue]);
|
|
79
|
+
react_1.default.useEffect(() => {
|
|
80
|
+
if (displayValue) {
|
|
81
|
+
handleResize();
|
|
82
|
+
}
|
|
83
|
+
}, [percentage]);
|
|
84
|
+
const PercentageEl = displayValue && react_1.default.createElement(ProgressBarElement_1.Percentage, { ref: percentageEl, style: { left: `${left}px`, visibility: left > -1 ? 'visible' : 'hidden' } }, percentage.label);
|
|
85
|
+
return (react_1.default.createElement(ProgressBarElement_1.default, Object.assign({}, elementProps, { hasStripedAnimation: hasStripedAnimation, height: height, isFilled: isFilled, isNested: isNested, isStriped: isStriped, palette: palette, ref: el, stripedAnimationDuration: stripedAnimationDuration, transitionDuration: transitionDuration, transitionTimingFunction: transitionTimingFunction }),
|
|
86
|
+
PercentageEl,
|
|
87
|
+
react_1.default.createElement(ProgressBarElement_1.Bar, { style: { width: `${percentage.value}%` } }, !isNested && PercentageEl)));
|
|
88
|
+
};
|
|
89
|
+
exports.default = ProgressBar;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
export { default as FixedBox } from './FixedBox';
|
|
1
2
|
export * from './Grid';
|
|
3
|
+
export { default as Loading } from './Loading';
|
|
4
|
+
export { default as Overlay } from './Overlay';
|
|
5
|
+
export { default as ProgressBar } from './ProgressBar';
|
|
2
6
|
export { default as WaveEffect } from './WaveEffect';
|
package/index.js
CHANGED
|
@@ -17,7 +17,15 @@ 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.ProgressBar = exports.Overlay = exports.Loading = exports.FixedBox = void 0;
|
|
21
|
+
var FixedBox_1 = require("./FixedBox");
|
|
22
|
+
Object.defineProperty(exports, "FixedBox", { enumerable: true, get: function () { return __importDefault(FixedBox_1).default; } });
|
|
21
23
|
__exportStar(require("./Grid"), exports);
|
|
24
|
+
var Loading_1 = require("./Loading");
|
|
25
|
+
Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return __importDefault(Loading_1).default; } });
|
|
26
|
+
var Overlay_1 = require("./Overlay");
|
|
27
|
+
Object.defineProperty(exports, "Overlay", { enumerable: true, get: function () { return __importDefault(Overlay_1).default; } });
|
|
28
|
+
var ProgressBar_1 = require("./ProgressBar");
|
|
29
|
+
Object.defineProperty(exports, "ProgressBar", { enumerable: true, get: function () { return __importDefault(ProgressBar_1).default; } });
|
|
22
30
|
var WaveEffect_1 = require("./WaveEffect");
|
|
23
31
|
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-2",
|
|
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-9",
|
|
68
|
+
"@smart-react-components/router": "2.0.0-alpha-4",
|
|
69
|
+
"@smart-react-components/transition": "2.0.0-alpha-5",
|
|
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-9",
|
|
87
|
+
"@smart-react-components/router": "^2.0.0-alpha-4",
|
|
88
|
+
"@smart-react-components/transition": "^2.0.0-alpha-5",
|
|
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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TriggerInteraction = exports.Position = void 0;
|
|
4
|
+
var Position;
|
|
5
|
+
(function (Position) {
|
|
6
|
+
Position[Position["LEFT"] = 1] = "LEFT";
|
|
7
|
+
Position[Position["RIGHT"] = 2] = "RIGHT";
|
|
8
|
+
Position[Position["TOP"] = 4] = "TOP";
|
|
9
|
+
Position[Position["BOTTOM"] = 8] = "BOTTOM";
|
|
10
|
+
})(Position = exports.Position || (exports.Position = {}));
|
|
11
|
+
var TriggerInteraction;
|
|
12
|
+
(function (TriggerInteraction) {
|
|
13
|
+
TriggerInteraction[TriggerInteraction["NONE"] = 0] = "NONE";
|
|
14
|
+
TriggerInteraction[TriggerInteraction["CLICK"] = 1] = "CLICK";
|
|
15
|
+
TriggerInteraction[TriggerInteraction["HOVER"] = 2] = "HOVER";
|
|
16
|
+
})(TriggerInteraction = exports.TriggerInteraction || (exports.TriggerInteraction = {}));
|
package/util/dom.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const mouseWheel: string[];
|
|
2
|
+
/**
|
|
3
|
+
* Checks if an element can be rendered in the React portal.
|
|
4
|
+
*/
|
|
5
|
+
export declare const canBeRenderedInPortal: () => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Gets scroll parent of the given element.
|
|
8
|
+
*
|
|
9
|
+
* @param el
|
|
10
|
+
*/
|
|
11
|
+
export declare const getScrollParent: (el: HTMLElement) => HTMLElement;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if target is a clickable element.
|
|
14
|
+
*/
|
|
15
|
+
export declare const isTargetClickable: (target: HTMLElement, container: HTMLElement) => boolean;
|
package/util/dom.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTargetClickable = exports.getScrollParent = exports.canBeRenderedInPortal = exports.mouseWheel = void 0;
|
|
4
|
+
const dom_1 = require("@smart-react-components/core/util/dom");
|
|
5
|
+
exports.mouseWheel = ['wheel', 'mousewheel', 'DOMMouseScroll'];
|
|
6
|
+
/**
|
|
7
|
+
* Checks if an element can be rendered in the React portal.
|
|
8
|
+
*/
|
|
9
|
+
const canBeRenderedInPortal = () => !dom_1.isServer && process.env.NODE_ENV !== 'test';
|
|
10
|
+
exports.canBeRenderedInPortal = canBeRenderedInPortal;
|
|
11
|
+
/**
|
|
12
|
+
* Gets scroll parent of the given element.
|
|
13
|
+
*
|
|
14
|
+
* @param el
|
|
15
|
+
*/
|
|
16
|
+
const getScrollParent = (el) => {
|
|
17
|
+
for (let parent = el; (parent = parent.parentElement);) {
|
|
18
|
+
const style = window.getComputedStyle(parent, null);
|
|
19
|
+
if (/(auto|scroll|hidden)/.test(style.overflow + style.overflowX + style.overflowY)) {
|
|
20
|
+
return parent;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
exports.getScrollParent = getScrollParent;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if target is a clickable element.
|
|
28
|
+
*/
|
|
29
|
+
const isTargetClickable = (target, container) => {
|
|
30
|
+
while (container.contains(target)) {
|
|
31
|
+
if (target.hasAttribute('data-src-not-clickable')) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
target = target.parentNode;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
exports.isTargetClickable = isTargetClickable;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Position } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates position of the fixed box based on X axis.
|
|
4
|
+
*/
|
|
5
|
+
export declare const calculateXAxisBasedPosition: (triggerRect: DOMRect, boxReplicaRect: DOMRect, position: Position, width: number, space: number, windowWidth: number, windowHeight: number) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Calculates position of the fixed box based on Y axis.
|
|
8
|
+
*/
|
|
9
|
+
export declare const calculateYAxisBasedPosition: (triggerRect: DOMRect, boxReplicaRect: DOMRect, position: Position, width: number, space: number, windowWidth: number, windowHeight: number) => string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateYAxisBasedPosition = exports.calculateXAxisBasedPosition = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
/**
|
|
6
|
+
* Calculates position of the fixed box based on X axis.
|
|
7
|
+
*/
|
|
8
|
+
const calculateXAxisBasedPosition = (triggerRect, boxReplicaRect, position, width, space, windowWidth, windowHeight) => {
|
|
9
|
+
let style = `width: ${width}px;`;
|
|
10
|
+
// left
|
|
11
|
+
const diffLeft = triggerRect.left - (space + width);
|
|
12
|
+
const diffRight = windowWidth - (triggerRect.left + triggerRect.width + space + width);
|
|
13
|
+
if ((position === types_1.Position.LEFT && (diffLeft >= 0 || diffLeft >= diffRight))
|
|
14
|
+
|| (position === types_1.Position.RIGHT && diffRight < 0 && diffLeft > diffRight)) {
|
|
15
|
+
style += `left: ${diffLeft}px;`;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
style += `left: ${triggerRect.left + triggerRect.width + space}px;`;
|
|
19
|
+
}
|
|
20
|
+
// top
|
|
21
|
+
const triggerHeight = triggerRect.height + triggerRect.top <= windowHeight ? triggerRect.height : (windowHeight - triggerRect.top);
|
|
22
|
+
const diffBottom = windowHeight - (triggerRect.top + boxReplicaRect.height);
|
|
23
|
+
const diffTop = (triggerRect.top + triggerHeight) - boxReplicaRect.height;
|
|
24
|
+
if (diffBottom >= 0 || diffBottom >= diffTop) {
|
|
25
|
+
const height = diffBottom > 0 ? boxReplicaRect.height : windowHeight - (triggerRect.top + boxReplicaRect.height);
|
|
26
|
+
style += `
|
|
27
|
+
height: ${height}px;
|
|
28
|
+
top: ${triggerRect.top}px;
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const height = boxReplicaRect.height + Math.min(diffTop, 0);
|
|
33
|
+
const top = (height > triggerHeight) ? ((triggerRect.top + triggerHeight) - height) : triggerRect.top;
|
|
34
|
+
style += `
|
|
35
|
+
height: ${height}px;
|
|
36
|
+
top: ${top}px;
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
return style;
|
|
40
|
+
};
|
|
41
|
+
exports.calculateXAxisBasedPosition = calculateXAxisBasedPosition;
|
|
42
|
+
/**
|
|
43
|
+
* Calculates position of the fixed box based on Y axis.
|
|
44
|
+
*/
|
|
45
|
+
const calculateYAxisBasedPosition = (triggerRect, boxReplicaRect, position, width, space, windowWidth, windowHeight) => {
|
|
46
|
+
let style = `width: ${width}px;`;
|
|
47
|
+
// left
|
|
48
|
+
const diffLeft = windowWidth - (triggerRect.left + width);
|
|
49
|
+
const diffRight = triggerRect.left - width;
|
|
50
|
+
if (diffLeft >= 0 || diffLeft >= diffRight) {
|
|
51
|
+
style += `left: ${triggerRect.left}px;`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
style += `left: ${triggerRect.left + triggerRect.width - width}px;`;
|
|
55
|
+
}
|
|
56
|
+
// top
|
|
57
|
+
const diffBottom = windowHeight - (triggerRect.top + triggerRect.height + boxReplicaRect.height + space);
|
|
58
|
+
const diffTop = (triggerRect.top + triggerRect.height) - (boxReplicaRect.height + 1);
|
|
59
|
+
if ((position === types_1.Position.BOTTOM && (diffBottom >= 0 || diffBottom >= diffTop))
|
|
60
|
+
|| (position === types_1.Position.TOP && diffTop < 0 && diffBottom > diffTop)) {
|
|
61
|
+
const height = diffBottom > 0 ? boxReplicaRect.height : (windowHeight - (triggerRect.top + triggerRect.height + space));
|
|
62
|
+
style += `
|
|
63
|
+
height: ${height}px;
|
|
64
|
+
top: ${triggerRect.top + triggerRect.height + space}px;
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const height = diffTop > 0 ? boxReplicaRect.height : triggerRect.top;
|
|
69
|
+
style += `
|
|
70
|
+
height: ${height}px;
|
|
71
|
+
top: ${(triggerRect.top + triggerRect.height) - (height + 1)}px;
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
return style;
|
|
75
|
+
};
|
|
76
|
+
exports.calculateYAxisBasedPosition = calculateYAxisBasedPosition;
|