rn-fade-wrapper
Version:
68 lines (67 loc) • 1.87 kB
JavaScript
;
import { useMemo } from 'react';
import { default as RnFadeWrapperView__ } from './RnFadeWrapperViewNativeComponent';
import { jsx as _jsx } from "react/jsx-runtime";
export * from './RnFadeWrapperViewNativeComponent';
export let FadeWrapperOrientation = /*#__PURE__*/function (FadeWrapperOrientation) {
FadeWrapperOrientation["HORIZONTAL"] = "horizontal";
FadeWrapperOrientation["VERTICAL"] = "vertical";
return FadeWrapperOrientation;
}({});
const defaultStyle = {
zIndex: 2
};
const makePreset = (top, right, bottom, left) => {
return {
sizeTop: top,
sizeRight: right,
sizeBottom: bottom,
sizeLeft: left
};
};
export const FadeWrapper = ({
children,
color,
size = 20,
sizes,
orientation = FadeWrapperOrientation.VERTICAL,
inward = false,
style
}) => {
const preparedSizes = () => {
if (sizes) {
return makePreset(sizes.top ?? 0, sizes.right ?? 0, sizes.bottom ?? 0, sizes.left ?? 0);
}
if (orientation) {
const sizedByOrientation = {
horizontal: makePreset(0, size, 0, size),
vertical: makePreset(size, 0, size, 0)
};
return sizedByOrientation[orientation];
}
return makePreset(size, 0, size, 0);
};
const withInward = useMemo(() => {
const __sizes = preparedSizes();
if (inward) {
return {
sizeTop: -__sizes.sizeTop,
sizeRight: -__sizes.sizeRight,
sizeBottom: -__sizes.sizeBottom,
sizeLeft: -__sizes.sizeLeft
};
}
return __sizes;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [size, orientation, sizes, inward]);
const __style = useMemo(() => {
return [defaultStyle, style];
}, [style]);
return /*#__PURE__*/_jsx(RnFadeWrapperView__, {
...withInward,
color: color,
style: __style,
children: children
});
};
//# sourceMappingURL=index.js.map