UNPKG

@onesy/ui-react

Version:
257 lines (256 loc) 15.6 kB
"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", "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: {}, main: { maxWidth: '768px', zIndex: '14' }, items: { padding: `${theme.methods.space.value(2, 'px')} 0`, overflow: 'auto hidden', maxWidth: '100%' }, item: { position: 'relative', flex: '0 0 auto', width: '100%', background: theme.palette.background.default.primary, '&:active': { '& $background': { borderRadius: theme.methods.shape.radius.value(5) } } }, item_size_small: { maxWidth: '174px' }, item_size_regular: { maxWidth: '254px' }, item_size_large: { maxWidth: '314px' }, actions: { marginTop: 12 }, background: { position: 'relative', aspectRatio: '3 / 4', borderRadius: theme.methods.shape.radius.value(3), zIndex: '1', transition: theme.methods.transitions.make('border-radius') }, 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', zIndex: '4' }, backgroundOverlayBlur: { backdropFilter: 'blur(12px)' } }), { name: 'onesy-SectionCards' }); 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.onesySectionCards) === 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 = [], 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) }; const getItem = (item, index) => { var _item$backgroundVideo, _item$backgroundVideo2, _item$propsImage, _item$propsMain, _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: size === 'large' ? 3 : size === 'regular' ? 2 : 1, align: "center", justify: "center", fullWidth: true }, ItemProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-item'], ItemProps === null || ItemProps === void 0 ? void 0 : ItemProps.className, classes.item, classes[`item_size_${size}`]]), children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({ fullWidth: true }, item.propsImage), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-item-image'], (_item$propsImage = item.propsImage) === null || _item$propsImage === void 0 ? void 0 : _item$propsImage.className, classes.background, item.backgroundImage && styleBackground.backgroundImage && classes.backgroundImage]), style: _objectSpread({}, styleBackground), children: [urlVideo && /*#__PURE__*/(0, _jsxRuntime.jsx)("video", { autoPlay: true, muted: true, loop: true, className: classes.backgroundVideo, children: /*#__PURE__*/(0, _jsxRuntime.jsx)("source", { src: urlVideo }) }), item.overlay && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: (0, _styleReact.classNames)([classes.backgroundOverlay, item.overlayBlur && classes.backgroundOverlayBlur]), style: _objectSpread({}, styleOverlay) })] })), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({ gap: 1, align: "center", fullWidth: true }, item.propsMain), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-item-main'], (_item$propsMain = item.propsMain) === null || _item$propsMain === void 0 ? void 0 : _item$propsMain.className, classes.main]), children: [(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)('SectionCards', theme) && ['onesy-SectionCards-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' ? 'h3' : size === 'regular' ? 't1' : 't2', align: "center", fullWidth: true, dangerouslySetInnerHTML: { __html: (0, _utils.textToInnerHTML)(item.name) } }, item.propsName), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-item-name'], (_item$propsName = item.propsName) === null || _item$propsName === void 0 ? void 0 : _item$propsName.className]) })), item.description && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3', priority: "secondary", align: "center", fullWidth: true, dangerouslySetInnerHTML: { __html: (0, _utils.textToInnerHTML)(item.description) } }, item.propsDescription), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-item-description'], (_item$propsDescriptio = item.propsDescription) === null || _item$propsDescriptio === void 0 ? void 0 : _item$propsDescriptio.className]) }))] })), item.buttonText && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({ align: "center", fullWidth: true }, item.propsActions), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-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)('SectionCards', theme) && ['onesy-SectionCards-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, MainProps: { justify: 'center', align: 'center' }, className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-root', `onesy-SectionCards-size-${size}`], className, classes.root]) }, other), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({ gap: size === 'large' ? 3.5 : size === 'regular' ? 2.5 : 1.5, justify: "flex-start", align: "flex-start", direction: "row" }, ItemsProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionCards', theme) && ['onesy-SectionCards-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-SectionCards'; var _default = exports.default = Element;