UNPKG

@amaui/ui-react

Version:
160 lines 7.14 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["map", "mapPosition", "heading", "summary", "address", "phone", "email", "IconAddress", "IconPhone", "IconEmail", "MapProps", "HeadingProps", "SummaryProps", "PropertiesProps", "className"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import React from 'react'; import { is, textToInnerHTML } from '@amaui/utils'; import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react'; import IconMaterialMap from '@amaui/icons-material-rounded-react/IconMaterialMapW100'; import IconMaterialCall from '@amaui/icons-material-rounded-react/IconMaterialCallW100'; import IconMaterialMail from '@amaui/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'; 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: 'amaui-SectionContact' }); const Element = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useAmauiTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiSectionContact?.props?.default), props_), [props_]); const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]); const Properties = React.useMemo(() => theme?.elements?.Properties || PropertiesElement, [theme]); const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]); const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]); const { 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__*/React.createElement(Line, { fullWidth: true, className: classNames([staticClassName('SectionContact', theme) && ['amaui-SectionContact-map'], classes.map]) }, map.overlay && /*#__PURE__*/React.createElement("div", { className: classNames([classes.backgroundOverlay]), style: _objectSpread({}, styleOverlay) }), /*#__PURE__*/React.createElement("iframe", { title: "amaui-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__*/React.createElement(IconAddress, null), value: address }); if (phone) properties.push({ name: /*#__PURE__*/React.createElement(IconPhone, null), value: phone }); if (email) properties.push({ name: /*#__PURE__*/React.createElement(IconEmail, null), value: email }); return /*#__PURE__*/React.createElement(Section, _extends({ 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) && ['amaui-SectionContact-root'], className, classes.root]) }, other), mapPosition === 'top' && mapElement, /*#__PURE__*/React.createElement(Line, { gap: 4, direction: "row", fullWidth: true }, mapPosition === 'left' && mapElement, /*#__PURE__*/React.createElement(Line, { gap: 5, flex: true, fullWidth: true, style: { paddingTop: ['left', 'right'].includes(mapPosition) ? 24 : 0 } }, (heading || summary) && /*#__PURE__*/React.createElement(Line, { gap: 0.5 }, heading && /*#__PURE__*/React.createElement(Type, _extends({ version: "t1", dangerouslySetInnerHTML: { __html: textToInnerHTML(heading) } }, HeadingProps, { className: classNames([staticClassName('SectionContact', theme) && ['amaui-SectionContact-heading'], HeadingProps?.className, classes.text]) })), summary && /*#__PURE__*/React.createElement(Type, _extends({ version: "b3", dangerouslySetInnerHTML: { __html: textToInnerHTML(summary) } }, SummaryProps, { className: classNames([staticClassName('SectionContact', theme) && ['amaui-SectionContact-summary'], SummaryProps?.className, classes.text]) }))), !!properties.length && /*#__PURE__*/React.createElement(Properties, _extends({ version: "row", gap: 1, values: properties }, PropertiesProps, { PropertyProps: _objectSpread({ responsive: false }, PropertiesProps?.PropertyProps) }))), mapPosition === 'right' && mapElement), mapPosition === 'bottom' && mapElement); }); Element.displayName = 'amaui-SectionContact'; export default Element;