IO-3020 IO-3036 Update ESLint. Add LockWrapper for Header. Add Blur Wrapper.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import Dinero from "dinero.js";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { HasFeatureAccess } from "./feature-wrapper.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const blurringProps = {
|
||||
filter: "blur(6px)"
|
||||
};
|
||||
|
||||
export function BlurWrapper({
|
||||
bodyshop,
|
||||
featureName,
|
||||
styleProp = "style",
|
||||
valueProp = "value",
|
||||
overrideValue = true,
|
||||
overrideValueFunction,
|
||||
children
|
||||
}) {
|
||||
if (!HasFeatureAccess({ featureName, bodyshop })) {
|
||||
const childrenWithBlurProps = React.Children.map(children, (child) => {
|
||||
if (React.isValidElement(child)) {
|
||||
//Clone the child, and spread in our props to overwrite it.
|
||||
let newValueProp;
|
||||
if (!overrideValue) {
|
||||
newValueProp = child.props[valueProp];
|
||||
} else {
|
||||
if (typeof overrideValueFunction === "function") {
|
||||
newValueProp = overrideValueFunction();
|
||||
} else if (overrideValueFunction === "RandomDinero") {
|
||||
newValueProp = RandomDinero();
|
||||
} else {
|
||||
newValueProp = "This is some random text. Nothing interesting here.";
|
||||
}
|
||||
}
|
||||
|
||||
return React.cloneElement(child, {
|
||||
[valueProp]: newValueProp,
|
||||
[styleProp]: { ...child.props[styleProp], ...blurringProps }
|
||||
});
|
||||
}
|
||||
return child;
|
||||
});
|
||||
|
||||
return childrenWithBlurProps;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
export default connect(mapStateToProps, null)(BlurWrapper);
|
||||
|
||||
function RandomDinero() {
|
||||
return Dinero({ amount: Math.round(Math.exp(Math.random() * 100, 2)) }).toFormat();
|
||||
}
|
||||
Reference in New Issue
Block a user