pricing4react
Version:
A library of components that ease the integration of feature toggling driven by pricing plans into your React application's UI.
54 lines (53 loc) • 2.38 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
exports.__esModule = true;
exports.EditorContextProvider = exports.EditorContext = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var utils_1 = require("../utils");
exports.EditorContext = (0, react_1.createContext)({
theme: "blue",
returnTo: "/",
attributes: [],
setAttributes: function () { return null; },
userContextAttributes: [],
setUserContextAttributes: function () { return null; },
plans: [],
setPlans: function () { return null; }
});
function EditorContextProvider(_a) {
var pricingContext = _a.pricingContext, theme = _a.theme, returnTo = _a.returnTo, children = _a.children;
var editorTheme = theme ? theme : "blue";
var retTo = returnTo ? returnTo : "/";
var features = pricingContext.features
? (0, utils_1.rawFeatureAttributesToAttributes)(pricingContext.features)
: [];
var initialPlans = pricingContext.plans
? (0, utils_1.rawPlansToPlans)(pricingContext.plans)
: [];
var initialUserAttributes = (0, utils_1.parseAttributeExpressionToUserAttributes)(features).filter(function (userAttribute) { return userAttribute.id !== ""; });
var _b = (0, react_1.useState)(features), attributes = _b[0], setAttributes = _b[1];
var _c = (0, react_1.useState)(initialUserAttributes), userContextAttributes = _c[0], setUserContextAttributes = _c[1];
var _d = (0, react_1.useState)(initialPlans), plans = _d[0], setPlans = _d[1];
return ((0, jsx_runtime_1.jsx)(exports.EditorContext.Provider, __assign({ value: {
attributes: attributes,
setAttributes: setAttributes,
userContextAttributes: userContextAttributes,
setUserContextAttributes: setUserContextAttributes,
plans: plans,
setPlans: setPlans,
theme: editorTheme,
returnTo: retTo
} }, { children: children })));
}
exports.EditorContextProvider = EditorContextProvider;