@onesy/ui-react
Version:
UI for React
80 lines (79 loc) • 6.77 kB
JavaScript
"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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const utils_1 = require("@onesy/utils");
const style_react_1 = require("@onesy/style-react");
const Button_1 = __importDefault(require("../Button"));
const Type_1 = __importDefault(require("../Type"));
const Surface_1 = __importDefault(require("../Surface"));
const Slide_1 = __importDefault(require("../Slide"));
const Line_1 = __importDefault(require("../Line"));
const utils_2 = require("../utils");
const useStyle = (0, style_react_1.style)(theme => ({
root: {
position: 'fixed',
left: '0',
bottom: '0',
zIndex: theme.z_index.modal,
boxShadow: '0px 4px 32px 0px rgba(0,0,0,0.014)'
},
size_small: {
padding: '12px 16px'
},
size_regular: {
padding: '20px 18px'
},
size_large: {
padding: '28px 20px'
},
main: {
maxWidth: '1100px'
}
}), { name: 'onesy-CookieBanner' });
const CookieBanner = react_1.default.forwardRef((props_, ref) => {
const theme = (0, style_react_1.useOnesyTheme)();
const l = theme.l;
const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.onesyBanner) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]);
const Slide = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Slide) || Slide_1.default; }, [theme]);
const Surface = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Surface) || Surface_1.default; }, [theme]);
const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]);
const Button = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Button) || Button_1.default; }, [theme]);
const { name, description, size = 'regular', startActions, endActions, onReject, onAllow, in: inProp, TransitionElement: TransitionElementProps = Slide, noTransition, MainProps, NameProps, DescriptionProps, ButtonProps, RejectButtonProps, AllowButtonProps, TransitionProps, className, children } = props, other = __rest(props, ["name", "description", "size", "startActions", "endActions", "onReject", "onAllow", "in", "TransitionElement", "noTransition", "MainProps", "NameProps", "DescriptionProps", "ButtonProps", "RejectButtonProps", "AllowButtonProps", "TransitionProps", "className", "children"]);
const { classes } = useStyle();
const TransitionElement = noTransition ? react_1.default.Fragment : TransitionElementProps;
const WrapperProps = noTransition ? undefined : Object.assign(Object.assign({}, TransitionProps), { in: inProp });
const buttonProps = Object.assign({ size }, ButtonProps);
return ((0, jsx_runtime_1.jsx)(TransitionElement, Object.assign({}, WrapperProps, { children: (0, jsx_runtime_1.jsx)(Line, Object.assign({ ref: ref, gap: 1.5, align: 'center', fullWidth: true, Component: Surface, color: 'default', role: 'region', "aria-label": l('Cookie Banner'), className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('CookieBanner', theme) && [
'onesy-CookieBanner-root',
`onesy-CookieBanner-size-${size}`
],
className,
classes.root,
classes[`size_${size}`]
]) }, other, { children: (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1.5, direction: 'row', wrap: 'wrap', align: 'center', justify: 'space-between', fullWidth: true }, MainProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('CookieBanner', theme) && [
'onesy-CookieBanner-main'
],
MainProps === null || MainProps === void 0 ? void 0 : MainProps.className,
classes.main
]) }, { children: [(0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.25 }, { children: [(0, utils_1.is)('string', name) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3', weight: 500 }, NameProps, { children: name }))) : name, (0, utils_1.is)('string', description) ? ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3' }, DescriptionProps, { children: description }))) : description] })), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1, direction: 'row', align: 'center' }, { children: [startActions, (0, jsx_runtime_1.jsx)(Button, Object.assign({ onClick: onReject, color: 'default' }, buttonProps, RejectButtonProps, { children: l('Reject All') })), (0, jsx_runtime_1.jsx)(Button, Object.assign({ onClick: onAllow, color: 'primary', version: 'filled' }, buttonProps, AllowButtonProps, { children: l('Accept All') })), endActions] }))] })) })) })));
});
CookieBanner.displayName = 'onesy-CookieBanner';
exports.default = CookieBanner;