UNPKG

@navinc/base-react-components

Version:
39 lines 1.86 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Feature = exports.FeatureProvider = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const utils_1 = require("@navinc/utils"); const FeatureContext = (0, react_1.createContext)(); const FeatureProvider = (_a) => { var { children } = _a, props = __rest(_a, ["children"]); (0, utils_1.deprecationWarning)(true, 'the <Feature/> and <FeatureProvider /> components are deprecated.'); return (0, jsx_runtime_1.jsx)(FeatureContext.Provider, Object.assign({}, props, { children: children }), void 0); }; exports.FeatureProvider = FeatureProvider; const Feature = ({ children, name = '', search = '' }) => { (0, utils_1.deprecationWarning)(true, 'the <Feature/> and <FeatureProvider /> components are deprecated.'); const featureContext = (0, react_1.useContext)(FeatureContext); if (featureContext === undefined) { throw new Error('Feature must be used within a FeatureProvider'); } const queryParams = (0, utils_1.parseQueryString)(search); const features = Object.assign(Object.assign({}, featureContext), queryParams); const isOn = ['true', true].includes(features[name]); if (!isOn) return null; return children; }; exports.Feature = Feature; //# sourceMappingURL=index.js.map