@bemit/consent-ui-formanta
Version:
© 2022 [bemit](https://bemit.eu)
192 lines (191 loc) • 6.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ConsentUiBox = void 0;
var _react = _interopRequireDefault(require("react"));
var _ConsentUiProvider = require("@bemit/consent-ui-react/ConsentUiProvider");
var _ConsentUiBox = require("@bemit/consent-ui-formanta/ConsentUiBox");
var _usePreferState2 = require("@bemit/consent-ui-react/usePreferState");
var _IcGear = require("@bemit/consent-ui-formanta/Icons/IcGear");
var _IcLink = require("@bemit/consent-ui-formanta/Icons/IcLink");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var ConsentUiBox = exports.ConsentUiBox = function ConsentUiBox(_ref) {
var showDetails = _ref.showDetails,
setShowDetails = _ref.setShowDetails,
e2e = _ref.e2e,
showSelectEssential = _ref.showSelectEssential,
labels = _ref.labels;
var _useConsent = (0, _ConsentUiProvider.useConsent)(),
giveConsent = _useConsent.giveConsent,
locale = _useConsent.locale,
userPrefers = _useConsent.userPrefers,
prefersInitial = _useConsent.prefersInitial,
prefersDefault = _useConsent.prefersDefault,
ownId = _useConsent.ownId,
localeConsent = _useConsent.localeConsent;
var _usePreferState = (0, _usePreferState2.usePreferState)(userPrefers, prefersInitial),
nextUserPrefers = _usePreferState.nextUserPrefers,
toggleGroup = _usePreferState.toggleGroup;
var localeDefinition = localeConsent[locale];
var title = localeDefinition.title,
intro = localeDefinition.intro,
desc = localeDefinition.desc,
groups = localeDefinition.groups,
policies = localeDefinition.policies,
services = localeDefinition.services;
var links = (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [(0, _jsxRuntime.jsxs)("a", {
href: '#',
"data-e2e-cc": e2e ? 'cc-privacy' : undefined,
onClick: function onClick(e) {
e.preventDefault();
e.stopPropagation();
var link = policies[ownId];
if (!link) return;
if (link.indexOf('http') === 0) {
window.open(link, '_blank');
}
},
style: {
display: 'inline-flex',
alignItems: 'center',
marginRight: 6,
cursor: 'pointer'
},
children: [(0, _jsxRuntime.jsx)(_IcLink.IcLink, {
fontSize: '1em',
style: {
marginRight: 4
}
}), labels.policyLabel]
}), setShowDetails ? (0, _jsxRuntime.jsxs)("a", {
href: '#',
"data-e2e-cc": e2e ? 'cc-details' : undefined,
onClick: function onClick(e) {
e.preventDefault();
e.stopPropagation();
setShowDetails(function (o) {
return !o;
});
},
style: {
display: 'inline-flex',
alignItems: 'center',
marginRight: 6,
cursor: 'pointer'
},
children: [(0, _jsxRuntime.jsx)(_IcGear.IcGear, {
fontSize: '1em',
style: {
marginRight: 4
}
}), showDetails ? labels.detailsHide : labels.detailsShow]
}) : null]
});
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [(0, _jsxRuntime.jsxs)("div", {
className: 'pt2 px2',
children: [(0, _jsxRuntime.jsx)("p", {
className: 'h5',
style: {
marginTop: 0
},
children: title
}), intro === null || intro === void 0 ? void 0 : intro.map(function (d, i) {
return (0, _jsxRuntime.jsx)("p", {
className: 'body2',
style: {
marginTop: 0
},
children: d
}, i);
})]
}), showDetails ? (0, _jsxRuntime.jsxs)("div", {
style: {
display: 'flex',
flexDirection: 'column',
overflow: 'auto'
},
children: [(0, _jsxRuntime.jsxs)("div", {
className: 'px2',
children: [labels.detailsTitle ? (0, _jsxRuntime.jsx)("p", {
className: 'subtitle1',
children: labels.detailsTitle
}) : null, desc === null || desc === void 0 ? void 0 : desc.map(function (d, i) {
return (0, _jsxRuntime.jsx)("p", {
className: 'body2',
style: {
marginTop: 0,
marginBottom: 8
},
children: d
}, i);
})]
}), (0, _jsxRuntime.jsx)("div", {
className: 'pb2 px2',
children: groups === null || groups === void 0 ? void 0 : groups.map(function (s, i) {
var _nextUserPrefers$grou;
return [(0, _jsxRuntime.jsx)(_ConsentUiBox.ConsentUiBoxGroup, {
policies: policies,
groupPrefer: nextUserPrefers === null || nextUserPrefers === void 0 || (_nextUserPrefers$grou = nextUserPrefers.groups) === null || _nextUserPrefers$grou === void 0 ? void 0 : _nextUserPrefers$grou[s.id],
toggleGroup: toggleGroup,
group: s,
services: services.filter(function (sv) {
return sv.group === s.id;
}),
labels: labels,
e2e: e2e
}, i), i < groups.length - 1 ? (0, _jsxRuntime.jsx)("div", {
children: (0, _jsxRuntime.jsx)("hr", {})
}, i + '.b') : null];
})
})]
}) : null, (0, _jsxRuntime.jsxs)("div", {
className: 'pb2 px2',
style: {
display: 'flex',
marginTop: 4,
flexWrap: 'wrap',
alignItems: 'center',
justifyContent: 'center'
},
children: [(0, _jsxRuntime.jsx)("div", {
style: {
fontSize: '0.82rem'
},
className: 'py1',
children: links
}), (0, _jsxRuntime.jsxs)("div", {
style: {
marginLeft: 'auto'
},
children: [showSelectEssential ? (0, _jsxRuntime.jsx)("button", {
className: 'btn',
onClick: function onClick() {
return giveConsent();
},
style: {
marginRight: 8,
flexShrink: 0,
textTransform: 'none'
},
"data-e2e-cc": e2e ? 'cc-consent-essentials' : undefined,
children: labels.btnOnlyEssential
}) : null, (0, _jsxRuntime.jsx)("button", {
className: 'btn btn-primary',
style: {
textTransform: 'none',
flexShrink: 0
},
onClick: function onClick() {
return showDetails ? giveConsent(nextUserPrefers) : giveConsent(prefersDefault);
},
"data-e2e-cc": e2e ? 'cc-consent-accept' : undefined,
children: showDetails ? labels.btnAcceptSave : labels.btnAcceptDefault
})]
})]
})]
});
};