@uncinc/uncinc-react-kitchen-sink 2.16.9 → 2.16.10
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/dist/components/Lottie/LottieAnimation/index.d.ts +4 -2
- package/dist/components/Lottie/LottieAnimation/index.js +137 -62
- package/dist/components/Lottie/index.d.ts +3 -2
- package/dist/components/Lottie/index.js +7 -54
- package/dist/components/Lottie/types.d.ts +22 -0
- package/dist/components/Lottie/types.js +1 -0
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export default LottieAnimation;
|
|
2
|
-
declare const LottieAnimation: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
3
1
|
import React from 'react';
|
|
2
|
+
import type { LottieProps } from '../types';
|
|
3
|
+
import './style.scss';
|
|
4
|
+
declare const LottieAnimation: React.ForwardRefExoticComponent<Omit<LottieProps, "delay"> & React.RefAttributes<import("lottie-web").AnimationItem>>;
|
|
5
|
+
export default LottieAnimation;
|
|
@@ -1,86 +1,145 @@
|
|
|
1
|
-
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
|
+
import React, { useEffect, useCallback, useRef, useMemo } from 'react';
|
|
2
9
|
import c from 'classnames';
|
|
3
10
|
import lottie from 'lottie-web';
|
|
4
11
|
import './style.scss';
|
|
12
|
+
var DIRECTION_FORWARD = 1;
|
|
13
|
+
var DIRECTION_BACKWARDS = -1;
|
|
5
14
|
var LottieAnimation = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
6
15
|
var id = props.id,
|
|
7
16
|
className = props.className,
|
|
8
|
-
ariaLabel = props.ariaLabel,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
_props$ariaLabel = props.ariaLabel,
|
|
18
|
+
ariaLabel = _props$ariaLabel === void 0 ? 'animation' : _props$ariaLabel,
|
|
19
|
+
data = props.data,
|
|
20
|
+
path = props.path,
|
|
21
|
+
_props$renderer = props.renderer,
|
|
22
|
+
renderer = _props$renderer === void 0 ? 'svg' : _props$renderer,
|
|
23
|
+
_props$rendererSettin = props.rendererSettings,
|
|
24
|
+
rendererSettings = _props$rendererSettin === void 0 ? {
|
|
25
|
+
preserveAspectRatio: 'xMidYMid meet'
|
|
26
|
+
} : _props$rendererSettin,
|
|
27
|
+
_props$loop = props.loop,
|
|
28
|
+
loop = _props$loop === void 0 ? true : _props$loop,
|
|
29
|
+
_props$autoPlay = props.autoPlay,
|
|
30
|
+
autoPlay = _props$autoPlay === void 0 ? true : _props$autoPlay,
|
|
31
|
+
_props$speed = props.speed,
|
|
32
|
+
speed = _props$speed === void 0 ? 1 : _props$speed,
|
|
33
|
+
startPosition = props.startPosition,
|
|
34
|
+
_props$direction = props.direction,
|
|
35
|
+
direction = _props$direction === void 0 ? 1 : _props$direction,
|
|
36
|
+
segments = props.segments,
|
|
37
|
+
_props$activateOnHove = props.activateOnHover,
|
|
38
|
+
activateOnHover = _props$activateOnHove === void 0 ? false : _props$activateOnHove,
|
|
39
|
+
_props$pauseOnClick = props.pauseOnClick,
|
|
40
|
+
pauseOnClick = _props$pauseOnClick === void 0 ? false : _props$pauseOnClick,
|
|
41
|
+
onInit = props.onInit,
|
|
42
|
+
onDestroy = props.onDestroy;
|
|
43
|
+
var refInternal = useRef();
|
|
14
44
|
var lottieAnimation = ref || refInternal;
|
|
15
|
-
var
|
|
45
|
+
var rendererSettingsRef = useRef(rendererSettings);
|
|
46
|
+
var onInitRef = useRef(onInit);
|
|
47
|
+
var lottieClasses = c('Lottie', className);
|
|
48
|
+
var lottieId = useMemo(function () {
|
|
49
|
+
if (id) {
|
|
50
|
+
return id;
|
|
51
|
+
}
|
|
52
|
+
if (_typeof(data) === 'object' && data !== null && 'nm' in data && typeof data.nm === 'string') {
|
|
53
|
+
return data.nm;
|
|
54
|
+
}
|
|
55
|
+
return '';
|
|
56
|
+
}, [data, id]);
|
|
16
57
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
rendererSettings = props.rendererSettings,
|
|
23
|
-
direction = props.direction,
|
|
24
|
-
loop = props.loop,
|
|
25
|
-
autoPlay = props.autoPlay,
|
|
26
|
-
path = props.path,
|
|
27
|
-
speed = props.speed,
|
|
28
|
-
segments = props.segments,
|
|
29
|
-
activateOnHover = props.activateOnHover,
|
|
30
|
-
startPosition = props.startPosition,
|
|
31
|
-
onInit = props.onInit;
|
|
32
|
-
lottieAnimation.current = lottie.loadAnimation({
|
|
58
|
+
/**
|
|
59
|
+
* Create a Lottie config object from the given props
|
|
60
|
+
*/
|
|
61
|
+
var config = useMemo(function () {
|
|
62
|
+
return {
|
|
33
63
|
animationData: data,
|
|
34
|
-
|
|
64
|
+
path: path,
|
|
35
65
|
renderer: renderer,
|
|
36
|
-
rendererSettings: rendererSettings,
|
|
37
|
-
direction: direction,
|
|
38
66
|
loop: activateOnHover ? false : loop,
|
|
39
67
|
autoplay: activateOnHover ? false : autoPlay,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
68
|
+
speed: speed,
|
|
69
|
+
startPosition: startPosition,
|
|
70
|
+
direction: direction,
|
|
71
|
+
segments: segments
|
|
72
|
+
};
|
|
73
|
+
}, [data, path, renderer, loop, autoPlay, speed, startPosition, direction, segments, activateOnHover]);
|
|
74
|
+
|
|
75
|
+
/*
|
|
76
|
+
* Initial load of the Lottie animation
|
|
77
|
+
*/
|
|
78
|
+
var loadAnimation = useCallback(function () {
|
|
79
|
+
if (!lottieAnimation || !('current' in lottieAnimation)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var container = document.getElementById("lottie--".concat(lottieId)) || document.documentElement;
|
|
83
|
+
lottieAnimation.current = lottie.loadAnimation(_objectSpread(_objectSpread({}, config), {}, {
|
|
84
|
+
container: container,
|
|
85
|
+
rendererSettings: rendererSettingsRef.current
|
|
86
|
+
}));
|
|
87
|
+
if (onInitRef.current) {
|
|
88
|
+
onInitRef.current(lottieAnimation.current);
|
|
89
|
+
}
|
|
43
90
|
|
|
44
91
|
// Set the default speed.
|
|
45
|
-
lottieAnimation.current.setSpeed(speed);
|
|
92
|
+
lottieAnimation.current.setSpeed(config.speed);
|
|
93
|
+
|
|
94
|
+
// Set the default direction.
|
|
95
|
+
lottieAnimation.current.setDirection(config.direction);
|
|
96
|
+
|
|
46
97
|
// Play segments if we have them.
|
|
47
|
-
if (segments) {
|
|
48
|
-
lottieAnimation.current.playSegments(segments);
|
|
98
|
+
if (config.segments) {
|
|
99
|
+
lottieAnimation.current.playSegments(config.segments);
|
|
49
100
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
101
|
+
|
|
102
|
+
// If startPosition is defined use it as a starting frame,
|
|
103
|
+
// startPosition should be between 0 and 1.
|
|
104
|
+
if (config.startPosition) {
|
|
105
|
+
var startingFrame = Math.round(lottieAnimation.current.totalFrames * config.startPosition);
|
|
53
106
|
lottieAnimation.current.goToAndStop(startingFrame, true);
|
|
54
107
|
}
|
|
55
|
-
}, [
|
|
108
|
+
}, [config, lottieAnimation, lottieId]);
|
|
56
109
|
|
|
57
110
|
/*
|
|
58
111
|
* Reverse direction on Mouse enter.
|
|
59
112
|
*/
|
|
60
|
-
var onMouseEnter = function
|
|
61
|
-
|
|
113
|
+
var onMouseEnter = useCallback(function () {
|
|
114
|
+
if (!(_typeof(lottieAnimation) === 'object' && lottieAnimation.current)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
62
117
|
if (activateOnHover) {
|
|
63
118
|
lottieAnimation.current.setDirection(DIRECTION_FORWARD);
|
|
64
119
|
lottieAnimation.current.play();
|
|
65
120
|
}
|
|
66
|
-
};
|
|
121
|
+
}, [activateOnHover, lottieAnimation]);
|
|
67
122
|
|
|
68
123
|
/*
|
|
69
124
|
* Reverse direction on Mouse leave
|
|
70
125
|
*/
|
|
71
|
-
var onMouseLeave = function
|
|
72
|
-
|
|
126
|
+
var onMouseLeave = useCallback(function () {
|
|
127
|
+
if (!(_typeof(lottieAnimation) === 'object' && lottieAnimation.current)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
73
130
|
if (activateOnHover) {
|
|
74
131
|
lottieAnimation.current.setDirection(DIRECTION_BACKWARDS);
|
|
75
132
|
lottieAnimation.current.play();
|
|
76
133
|
}
|
|
77
|
-
};
|
|
134
|
+
}, [activateOnHover, lottieAnimation]);
|
|
78
135
|
|
|
79
136
|
/*
|
|
80
137
|
* Toggle the animation on click
|
|
81
138
|
*/
|
|
82
|
-
var onClick = function
|
|
83
|
-
|
|
139
|
+
var onClick = useCallback(function () {
|
|
140
|
+
if (!(_typeof(lottieAnimation) === 'object' && lottieAnimation.current)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
84
143
|
if (pauseOnClick) {
|
|
85
144
|
if (lottieAnimation.current.isPaused) {
|
|
86
145
|
lottieAnimation.current.play();
|
|
@@ -88,29 +147,45 @@ var LottieAnimation = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
88
147
|
lottieAnimation.current.pause();
|
|
89
148
|
}
|
|
90
149
|
}
|
|
91
|
-
};
|
|
150
|
+
}, [lottieAnimation, pauseOnClick]);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Handle keyboard interaction for accessibility
|
|
154
|
+
* @param event - keyboard event
|
|
155
|
+
*/
|
|
156
|
+
var onKeyDown = useCallback(function (event) {
|
|
157
|
+
if (pauseOnClick && (event.key === 'Enter' || event.key === ' ')) {
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
onClick();
|
|
160
|
+
}
|
|
161
|
+
}, [onClick, pauseOnClick]);
|
|
92
162
|
|
|
93
163
|
// Init the Lottie animation.
|
|
94
164
|
useEffect(function () {
|
|
95
|
-
var onDestroy = props.onDestroy;
|
|
96
165
|
loadAnimation();
|
|
97
166
|
return function () {
|
|
98
|
-
|
|
167
|
+
if (!(_typeof(lottieAnimation) === 'object' && lottieAnimation.current)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (onDestroy) {
|
|
171
|
+
onDestroy(lottieAnimation.current);
|
|
172
|
+
}
|
|
99
173
|
lottieAnimation.current.destroy();
|
|
100
174
|
};
|
|
101
|
-
}, [
|
|
102
|
-
return (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
175
|
+
}, [loadAnimation, lottieAnimation, onDestroy]);
|
|
176
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
177
|
+
className: lottieClasses,
|
|
178
|
+
id: "lottie--".concat(lottieId),
|
|
179
|
+
"aria-label": ariaLabel
|
|
180
|
+
// Only make the Lottie interactable if we provide the necessary props,
|
|
181
|
+
// otherwise it's just a plain div.
|
|
182
|
+
}, pauseOnClick || activateOnHover ? {
|
|
183
|
+
role: 'button',
|
|
184
|
+
tabIndex: 0,
|
|
185
|
+
onMouseEnter: onMouseEnter,
|
|
186
|
+
onMouseLeave: onMouseLeave,
|
|
187
|
+
onClick: onClick,
|
|
188
|
+
onKeyDown: onKeyDown
|
|
189
|
+
} : {}));
|
|
115
190
|
});
|
|
116
191
|
export default LottieAnimation;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export default Lottie;
|
|
2
|
-
declare const Lottie: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
3
1
|
import React from 'react';
|
|
2
|
+
import type { LottieProps } from './types';
|
|
3
|
+
declare const Lottie: React.ForwardRefExoticComponent<LottieProps & React.RefAttributes<import("lottie-web").AnimationItem>>;
|
|
4
|
+
export default Lottie;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
var _excluded = ["delay"];
|
|
1
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2
5
|
import React, { lazy, Suspense } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
6
|
// Lazy-load Lottie animations with a delay.
|
|
6
7
|
var Lottie = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
7
|
-
var delay = props.delay
|
|
8
|
+
var delay = props.delay,
|
|
9
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
8
10
|
var LottieAnimation = /*#__PURE__*/lazy(function () {
|
|
9
11
|
return new Promise(function (resolve) {
|
|
12
|
+
// @ts-expect-error
|
|
10
13
|
setTimeout(function () {
|
|
11
14
|
return resolve(import('./LottieAnimation'));
|
|
12
15
|
}, delay);
|
|
@@ -14,56 +17,6 @@ var Lottie = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
14
17
|
});
|
|
15
18
|
return /*#__PURE__*/React.createElement(Suspense, null, /*#__PURE__*/React.createElement(LottieAnimation, _extends({
|
|
16
19
|
ref: ref
|
|
17
|
-
},
|
|
20
|
+
}, restProps)));
|
|
18
21
|
});
|
|
19
|
-
Lottie.propTypes = {
|
|
20
|
-
id: PropTypes.string,
|
|
21
|
-
className: PropTypes.string,
|
|
22
|
-
renderer: PropTypes.string,
|
|
23
|
-
rendererSettings: PropTypes.shape({
|
|
24
|
-
preserveAspectRatio: PropTypes.string
|
|
25
|
-
}),
|
|
26
|
-
data: PropTypes.object,
|
|
27
|
-
path: PropTypes.string,
|
|
28
|
-
segments: PropTypes.array,
|
|
29
|
-
// Events
|
|
30
|
-
onInit: PropTypes.func,
|
|
31
|
-
onDestroy: PropTypes.func,
|
|
32
|
-
// Options
|
|
33
|
-
delay: PropTypes.number,
|
|
34
|
-
autoPlay: PropTypes.bool,
|
|
35
|
-
loop: PropTypes.bool,
|
|
36
|
-
speed: PropTypes.number,
|
|
37
|
-
direction: PropTypes.number,
|
|
38
|
-
activateOnHover: PropTypes.bool,
|
|
39
|
-
pauseOnClick: PropTypes.bool,
|
|
40
|
-
olaTime: PropTypes.number,
|
|
41
|
-
startPosition: PropTypes.number,
|
|
42
|
-
ariaLabel: PropTypes.string
|
|
43
|
-
};
|
|
44
|
-
Lottie.defaultProps = {
|
|
45
|
-
id: null,
|
|
46
|
-
className: null,
|
|
47
|
-
renderer: 'svg',
|
|
48
|
-
rendererSettings: {
|
|
49
|
-
preserveAspectRatio: 'xMidYMid meet'
|
|
50
|
-
},
|
|
51
|
-
data: null,
|
|
52
|
-
path: null,
|
|
53
|
-
segments: null,
|
|
54
|
-
// Events
|
|
55
|
-
onInit: function onInit() {},
|
|
56
|
-
onDestroy: function onDestroy() {},
|
|
57
|
-
// Options
|
|
58
|
-
delay: null,
|
|
59
|
-
autoPlay: true,
|
|
60
|
-
loop: true,
|
|
61
|
-
speed: 1,
|
|
62
|
-
direction: 1,
|
|
63
|
-
activateOnHover: false,
|
|
64
|
-
pauseOnClick: false,
|
|
65
|
-
ariaLabel: 'animation',
|
|
66
|
-
olaTime: 300,
|
|
67
|
-
startPosition: null
|
|
68
|
-
};
|
|
69
22
|
export default Lottie;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnimationConfig, AnimationConfigWithData, AnimationConfigWithPath, AnimationDirection, AnimationItem, RendererType } from 'lottie-web';
|
|
2
|
+
export type LottieItem = AnimationItem;
|
|
3
|
+
export interface LottieConfig<T extends RendererType = 'svg'> extends Omit<AnimationConfig<T>, 'container'> {
|
|
4
|
+
animationData?: AnimationConfigWithData['animationData'];
|
|
5
|
+
path?: AnimationConfigWithPath['path'];
|
|
6
|
+
speed: number;
|
|
7
|
+
startPosition?: number;
|
|
8
|
+
direction: AnimationDirection;
|
|
9
|
+
segments?: Array<any>;
|
|
10
|
+
}
|
|
11
|
+
export interface LottieProps extends Omit<Partial<LottieConfig>, 'animationData' | 'autoplay'> {
|
|
12
|
+
id?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
ariaLabel?: string;
|
|
15
|
+
data?: unknown;
|
|
16
|
+
autoPlay?: AnimationConfig['autoplay'];
|
|
17
|
+
delay?: number;
|
|
18
|
+
activateOnHover?: boolean;
|
|
19
|
+
pauseOnClick?: boolean;
|
|
20
|
+
onInit?: (lottie: LottieItem) => void;
|
|
21
|
+
onDestroy?: (lottie: LottieItem) => void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|