@onesy/ui-react
Version:
UI for React
175 lines (174 loc) • 9.73 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 _utils = require("@onesy/utils");
var _styleReact = require("@onesy/style-react");
var _IconMaterialMapW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialMapW100"));
var _IconMaterialCallW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialCallW100"));
var _IconMaterialMailW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialMailW100"));
var _Line = _interopRequireDefault(require("../Line"));
var _Properties = _interopRequireDefault(require("../Properties"));
var _Section = _interopRequireDefault(require("../Section/Section"));
var _Type = _interopRequireDefault(require("../Type"));
var _useMediaQuery = _interopRequireDefault(require("../useMediaQuery"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["ref", "map", "mapPosition", "heading", "summary", "address", "phone", "email", "IconAddress", "IconPhone", "IconEmail", "MapProps", "HeadingProps", "SummaryProps", "PropertiesProps", "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: {},
text: {
wordBreak: 'break-word'
},
map: {
position: 'relative',
height: '400px',
borderRadius: theme.methods.shape.radius.value(3),
overflow: 'hidden'
},
backgroundOverlay: {
position: 'absolute',
inset: '0',
zIndex: '4'
}
}), {
name: 'onesy-SectionContact'
});
const Element = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3, _theme$elements4;
const theme = (0, _styleReact.useOnesyTheme)();
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.onesySectionContact) === 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 Properties = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Properties) || _Properties.default;
const Section = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Section) || _Section.default;
const Type = (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.Type) || _Type.default;
const {
ref,
map,
mapPosition: mapPosition_ = 'bottom',
heading,
summary,
address,
phone,
email,
IconAddress = _IconMaterialMapW.default,
IconPhone = _IconMaterialCallW.default,
IconEmail = _IconMaterialMailW.default,
MapProps,
HeadingProps,
SummaryProps,
PropertiesProps,
className
} = props,
other = (0, _objectWithoutProperties2.default)(props, _excluded);
const {
classes
} = useStyle();
const refs = {
root: _react.default.useRef(undefined)
};
const mobile = (0, _useMediaQuery.default)('(max-width: 768px)', {
element: refs.root.current
});
let mapPosition = mapPosition_;
if (mobile) {
if (mapPosition === 'left') mapPosition = 'top';else if (mapPosition === 'right') mapPosition = 'bottom';
}
let styleOverlay = {};
if (map !== null && map !== void 0 && map.overlay) {
const palette = theme.palette.color[map === null || map === void 0 ? void 0 : map.overlay] || theme.methods.color(map === null || map === void 0 ? void 0 : map.overlay);
styleOverlay = _objectSpread(_objectSpread({}, styleOverlay), {}, {
backgroundColor: theme.methods.palette.color.alpha(theme.methods.palette.color.value(undefined, 95, true, palette), 0.54)
});
}
const mapElement = (map === null || map === void 0 ? void 0 : map.apiKey) && (map === null || map === void 0 ? void 0 : map.latitude) && (map === null || map === void 0 ? void 0 : map.longitude) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
fullWidth: true,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionContact', theme) && ['onesy-SectionContact-map'], classes.map]),
children: [map.overlay && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _styleReact.classNames)([classes.backgroundOverlay]),
style: _objectSpread({}, styleOverlay)
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", {
title: "onesy-google-map",
src: `https://www.google.com/maps/embed/v1/place?q=${map === null || map === void 0 ? void 0 : map.latitude},${map === null || map === void 0 ? void 0 : map.longitude}${map !== null && map !== void 0 && map.apiKey ? `&key=${map === null || map === void 0 ? void 0 : map.apiKey}` : ''}`,
width: "100%",
height: "100%",
loading: "lazy",
allowFullScreen: true,
referrerPolicy: "no-referrer-when-downgrade"
})]
});
const properties = [];
if (address) properties.push({
name: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconAddress, {}),
value: address
});
if (phone) properties.push({
name: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconPhone, {}),
value: phone
});
if (email) properties.push({
name: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconEmail, {}),
value: email
});
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Section, _objectSpread(_objectSpread({
ref: item => {
if (ref) {
if ((0, _utils.is)('function', ref)) ref(item);else ref.current = item;
}
refs.root.current = item;
},
MainProps: {
gap: 4
},
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionContact', theme) && ['onesy-SectionContact-root'], className, classes.root])
}, other), {}, {
children: [mapPosition === 'top' && mapElement, /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 4,
direction: "row",
fullWidth: true,
children: [mapPosition === 'left' && mapElement, /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 5,
flex: true,
fullWidth: true,
style: {
paddingTop: ['left', 'right'].includes(mapPosition) ? 24 : 0
},
children: [(heading || summary) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 0.5,
children: [heading && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({
version: "t1",
dangerouslySetInnerHTML: {
__html: (0, _utils.textToInnerHTML)(heading)
}
}, HeadingProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionContact', theme) && ['onesy-SectionContact-heading'], HeadingProps === null || HeadingProps === void 0 ? void 0 : HeadingProps.className, classes.text])
})), summary && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({
version: "b3",
dangerouslySetInnerHTML: {
__html: (0, _utils.textToInnerHTML)(summary)
}
}, SummaryProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionContact', theme) && ['onesy-SectionContact-summary'], SummaryProps === null || SummaryProps === void 0 ? void 0 : SummaryProps.className, classes.text])
}))]
}), !!properties.length && /*#__PURE__*/(0, _jsxRuntime.jsx)(Properties, _objectSpread(_objectSpread({
version: "row",
gap: 1,
values: properties
}, PropertiesProps), {}, {
PropertyProps: _objectSpread({
responsive: false
}, PropertiesProps === null || PropertiesProps === void 0 ? void 0 : PropertiesProps.PropertyProps)
}))]
}), mapPosition === 'right' && mapElement]
}), mapPosition === 'bottom' && mapElement]
}));
};
Element.displayName = 'onesy-SectionContact';
var _default = exports.default = Element;