@onesy/ui-react
Version:
UI for React
238 lines (236 loc) • 14.8 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _reactRouterDom = require("react-router-dom");
var _utils = require("@onesy/utils");
var _styleReact = require("@onesy/style-react");
var _Section = _interopRequireDefault(require("../Section/Section"));
var _Line = _interopRequireDefault(require("../Line"));
var _Type = _interopRequireDefault(require("../Type"));
var _Button = _interopRequireDefault(require("../Button"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["ref", "size", "values", "responsive", "ItemProps", "ItemsProps", "className"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
const useStyle = (0, _styleReact.style)(theme => ({
root: {},
item: {
position: 'relative',
maxWidth: '768px',
zIndex: '14',
flex: '1 1'
},
item_size_small: {
padding: `${theme.methods.space.value(4.25, 'px')} ${theme.methods.space.value(2, 'px')}`
},
item_size_regular: {
padding: `${theme.methods.space.value(6.75, 'px')} ${theme.methods.space.value(3, 'px')}`
},
item_size_large: {
padding: `${theme.methods.space.value(9.25, 'px')} ${theme.methods.space.value(4, 'px')}`
},
actions: {
marginTop: 12
},
text: {
'&.onesy-Type-root': {
color: 'white',
mixBlendMode: 'difference'
}
},
button: {
transition: theme.methods.transitions.make('transform'),
'&:active': {
transform: 'scale(0.94)'
}
},
backgroundImage: {
backgroundSize: 'cover',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat'
},
backgroundVideo: {
position: 'absolute',
inset: '0',
minHeight: '100%',
minWidth: '100%',
top: '50%',
transform: 'translateY(-50%)',
zIndex: '1'
},
backgroundOverlay: {
position: 'absolute',
inset: '0'
},
backgroundOverlayBlur: {
backdropFilter: 'blur(12px)'
}
}), {
name: 'onesy-SectionBoxes'
});
const Element = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3, _theme$elements4;
const theme = (0, _styleReact.useOnesyTheme)();
const l = theme.l;
const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesySectionBoxes) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
const Section = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Section) || _Section.default;
const Type = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Type) || _Type.default;
const Button = (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.Button) || _Button.default;
const {
ref,
size = 'regular',
values: values_ = [],
responsive = true,
ItemProps,
ItemsProps,
className
} = props,
other = (0, _objectWithoutProperties2.default)(props, _excluded);
const {
classes
} = useStyle();
const navigate = (0, _utils.isEnvironment)('browser') && (0, _reactRouterDom.useNavigate)();
const refs = {
root: _react.default.useRef(undefined)
};
// Max 4
const values = values_ === null || values_ === void 0 ? void 0 : values_.slice(0, 4);
const getItem = (item, index) => {
var _item$backgroundVideo, _item$backgroundVideo2, _item$propsWrapperTex, _item$propsName, _item$propsDescriptio, _item$propsActions, _item$propsButton;
let styleBackground = {};
const themed = [undefined, true].includes(item.themed);
if (item.backgroundColor) {
const palette = theme.palette.color[item.backgroundColor] || theme.methods.color(item.backgroundColor);
styleBackground = _objectSpread(_objectSpread({}, styleBackground), {}, {
backgroundColor: themed ? theme.methods.palette.color.value(undefined, 95, true, palette) : palette === null || palette === void 0 ? void 0 : palette.main
});
}
if ((0, _utils.is)('array', item.backgroundGradient) && item.backgroundGradient.length >= 2) {
var _item$backgroundGradi, _item$backgroundGradi2;
const palette1 = theme.palette.color[item.backgroundGradient[0]] || theme.methods.color(item.backgroundGradient[0]);
const palette2 = theme.palette.color[item.backgroundGradient[1]] || theme.methods.color(item.backgroundGradient[1]);
const palette3 = theme.palette.color[item.backgroundGradient[2]] || theme.methods.color(item.backgroundGradient[2]);
let backgroundImageStyle = '';
if (((_item$backgroundGradi = item.backgroundGradient) === null || _item$backgroundGradi === void 0 ? void 0 : _item$backgroundGradi.length) === 2) {
backgroundImageStyle = themed ? `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${theme.methods.palette.color.colorToRgb(palette1.main, 0.14)} 0%, ${theme.methods.palette.color.colorToRgb(palette2.main, 0.14)} 100%)` : `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${palette1.main} 0%, ${palette2.main} 100%)`;
}
if (((_item$backgroundGradi2 = item.backgroundGradient) === null || _item$backgroundGradi2 === void 0 ? void 0 : _item$backgroundGradi2.length) === 3) {
backgroundImageStyle = themed ? `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${theme.methods.palette.color.colorToRgb(palette1.main, 0.14)} 0%, ${theme.methods.palette.color.colorToRgb(palette2.main, 0.14)} 40%, ${theme.methods.palette.color.colorToRgb(palette3.main, 0.14)} 100%)` : `linear-gradient(${theme.palette.light ? '130deg' : '330deg'}, ${palette1.main} 0%, ${palette2.main} 40%, ${palette3.main} 100%)`;
}
styleBackground = _objectSpread(_objectSpread({}, styleBackground), {}, {
backgroundImage: backgroundImageStyle
});
}
if (item.backgroundImage) {
var _item$backgroundImage, _item$backgroundImage2;
const url = ((_item$backgroundImage = item.backgroundImage) === null || _item$backgroundImage === void 0 ? void 0 : _item$backgroundImage.url) || ((_item$backgroundImage2 = item.backgroundImage) === null || _item$backgroundImage2 === void 0 ? void 0 : _item$backgroundImage2.urlSmall) || ((0, _utils.is)('string', item.backgroundImage) ? item.backgroundImage : '');
if (url) {
styleBackground = _objectSpread(_objectSpread({}, styleBackground), {}, {
backgroundImage: `url('${url}')`
});
}
}
let styleOverlay = {};
if (item.overlay) {
const palette_0 = theme.palette.color[item.overlay] || theme.methods.color(item.overlay);
styleOverlay = _objectSpread(_objectSpread({}, styleOverlay), {}, {
backgroundColor: themed ? theme.methods.palette.color.alpha(theme.methods.palette.color.value(undefined, 95, true, palette_0), 0.74) : palette_0 === null || palette_0 === void 0 ? void 0 : palette_0.main
});
}
const urlVideo = ((_item$backgroundVideo = item.backgroundVideo) === null || _item$backgroundVideo === void 0 ? void 0 : _item$backgroundVideo.url) || ((_item$backgroundVideo2 = item.backgroundVideo) === null || _item$backgroundVideo2 === void 0 ? void 0 : _item$backgroundVideo2.urlSmall) || ((0, _utils.is)('string', item.backgroundVideo) ? item.backgroundVideo : '');
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({
gap: 1,
align: "flex-start",
justify: "center",
fullWidth: true
}, ItemProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item'], ItemProps === null || ItemProps === void 0 ? void 0 : ItemProps.className, classes.item, classes[`item_size_${size}`], item.backgroundImage && styleBackground.backgroundImage && classes.backgroundImage]),
style: _objectSpread({}, styleBackground),
children: [urlVideo && /*#__PURE__*/(0, _jsxRuntime.jsx)("video", {
autoPlay: true,
muted: true,
loop: true,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-background-video'], classes.backgroundVideo]),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("source", {
src: urlVideo
})
}), item.overlay && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-background-overlay'], classes.backgroundOverlay, item.overlayBlur && classes.backgroundOverlayBlur]),
style: _objectSpread({}, styleOverlay)
}), (item.name || item.description) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({
gap: 1,
align: "center",
fullWidth: true
}, item.propsWrapperText), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-wrapper-text'], (_item$propsWrapperTex = item.propsWrapperText) === null || _item$propsWrapperTex === void 0 ? void 0 : _item$propsWrapperTex.className, classes.wrapperText]),
children: [item.name && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'h2' : size === 'regular' ? 'h3' : 't1',
align: "center",
fullWidth: true,
dangerouslySetInnerHTML: {
__html: (0, _utils.textToInnerHTML)(item.name)
}
}, item.propsName), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-name'], (_item$propsName = item.propsName) === null || _item$propsName === void 0 ? void 0 : _item$propsName.className, classes.text])
})), item.description && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3',
align: "center",
fullWidth: true,
dangerouslySetInnerHTML: {
__html: (0, _utils.textToInnerHTML)(item.description)
}
}, item.propsDescription), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-description'], (_item$propsDescriptio = item.propsDescription) === null || _item$propsDescriptio === void 0 ? void 0 : _item$propsDescriptio.className, classes.text])
}))]
})), item.buttonText && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({
align: "center",
fullWidth: true
}, item.propsActions), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-actions'], (_item$propsActions = item.propsActions) === null || _item$propsActions === void 0 ? void 0 : _item$propsActions.className, classes.actions]),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, _objectSpread(_objectSpread({
version: "filled",
color: "primary",
size: size,
onClick: () => item.to ? navigate(item.to) : window.open(item.link, 'blank')
}, item.propsButton), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-item-button'], (_item$propsButton = item.propsButton) === null || _item$propsButton === void 0 ? void 0 : _item$propsButton.className, classes.button]),
children: item.buttonText || l('Click here')
}))
}))]
}), index);
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Section, _objectSpread(_objectSpread({
ref: item_0 => {
if (ref) {
if ((0, _utils.is)('function', ref)) ref(item_0);else ref.current = item_0;
}
refs.root.current = item_0;
},
maxWidth: false,
padding: !(values !== null && values !== void 0 && values.length),
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-root', `onesy-SectionBoxes-size-${size}`], className, classes.root])
}, other), {}, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({
gap: 0,
align: "unset",
fullWidth: true,
direction: responsive ? {
default: 'row',
1100: 'column'
} : 'row'
}, ItemsProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionBoxes', theme) && ['onesy-SectionBoxes-items'], ItemsProps === null || ItemsProps === void 0 ? void 0 : ItemsProps.className, classes.items]),
children: values === null || values === void 0 ? void 0 : values.map((item_1, index_0) => getItem(item_1, index_0))
}))
}));
};
Element.displayName = 'onesy-SectionBoxes';
var _default = exports.default = Element;