UNPKG

@onesy/ui-react

Version:
167 lines 7.06 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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) { _defineProperty(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; } import React from 'react'; import { is, textToInnerHTML } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import IconMaterialMap from '@onesy/icons-material-rounded-react/IconMaterialMapW100'; import IconMaterialCall from '@onesy/icons-material-rounded-react/IconMaterialCallW100'; import IconMaterialMail from '@onesy/icons-material-rounded-react/IconMaterialMailW100'; import LineElement from '../Line'; import PropertiesElement from '../Properties'; import SectionElement from '../Section/Section'; import TypeElement from '../Type'; import useMediaQuery from '../useMediaQuery'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(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_ => { const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionContact?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const Properties = theme?.elements?.Properties || PropertiesElement; const Section = theme?.elements?.Section || SectionElement; const Type = theme?.elements?.Type || TypeElement; const { ref, map, mapPosition: mapPosition_ = 'bottom', heading, summary, address, phone, email, IconAddress = IconMaterialMap, IconPhone = IconMaterialCall, IconEmail = IconMaterialMail, MapProps, HeadingProps, SummaryProps, PropertiesProps, className } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const refs = { root: React.useRef(undefined) }; const mobile = useMediaQuery('(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?.overlay) { const palette = theme.palette.color[map?.overlay] || theme.methods.color(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?.apiKey && map?.latitude && map?.longitude && /*#__PURE__*/_jsxs(Line, { fullWidth: true, className: classNames([staticClassName('SectionContact', theme) && ['onesy-SectionContact-map'], classes.map]), children: [map.overlay && /*#__PURE__*/_jsx("div", { className: classNames([classes.backgroundOverlay]), style: _objectSpread({}, styleOverlay) }), /*#__PURE__*/_jsx("iframe", { title: "onesy-google-map", src: `https://www.google.com/maps/embed/v1/place?q=${map?.latitude},${map?.longitude}${map?.apiKey ? `&key=${map?.apiKey}` : ''}`, width: "100%", height: "100%", loading: "lazy", allowFullScreen: true, referrerPolicy: "no-referrer-when-downgrade" })] }); const properties = []; if (address) properties.push({ name: /*#__PURE__*/_jsx(IconAddress, {}), value: address }); if (phone) properties.push({ name: /*#__PURE__*/_jsx(IconPhone, {}), value: phone }); if (email) properties.push({ name: /*#__PURE__*/_jsx(IconEmail, {}), value: email }); return /*#__PURE__*/_jsxs(Section, _objectSpread(_objectSpread({ ref: item => { if (ref) { if (is('function', ref)) ref(item);else ref.current = item; } refs.root.current = item; }, MainProps: { gap: 4 }, className: classNames([staticClassName('SectionContact', theme) && ['onesy-SectionContact-root'], className, classes.root]) }, other), {}, { children: [mapPosition === 'top' && mapElement, /*#__PURE__*/_jsxs(Line, { gap: 4, direction: "row", fullWidth: true, children: [mapPosition === 'left' && mapElement, /*#__PURE__*/_jsxs(Line, { gap: 5, flex: true, fullWidth: true, style: { paddingTop: ['left', 'right'].includes(mapPosition) ? 24 : 0 }, children: [(heading || summary) && /*#__PURE__*/_jsxs(Line, { gap: 0.5, children: [heading && /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({ version: "t1", dangerouslySetInnerHTML: { __html: textToInnerHTML(heading) } }, HeadingProps), {}, { className: classNames([staticClassName('SectionContact', theme) && ['onesy-SectionContact-heading'], HeadingProps?.className, classes.text]) })), summary && /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({ version: "b3", dangerouslySetInnerHTML: { __html: textToInnerHTML(summary) } }, SummaryProps), {}, { className: classNames([staticClassName('SectionContact', theme) && ['onesy-SectionContact-summary'], SummaryProps?.className, classes.text]) }))] }), !!properties.length && /*#__PURE__*/_jsx(Properties, _objectSpread(_objectSpread({ version: "row", gap: 1, values: properties }, PropertiesProps), {}, { PropertyProps: _objectSpread({ responsive: false }, PropertiesProps?.PropertyProps) }))] }), mapPosition === 'right' && mapElement] }), mapPosition === 'bottom' && mapElement] })); }; Element.displayName = 'onesy-SectionContact'; export default Element;