UNPKG

@onesy/ui-react

Version:
125 lines (124 loc) 9.74 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const utils_1 = require("@onesy/utils"); const style_react_1 = require("@onesy/style-react"); const IconMaterialMapW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialMapW100")); const IconMaterialCallW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialCallW100")); const IconMaterialMailW100_1 = __importDefault(require("@onesy/icons-material-rounded-react/IconMaterialMailW100")); const Line_1 = __importDefault(require("../Line")); const Properties_1 = __importDefault(require("../Properties")); const Section_1 = __importDefault(require("../Section/Section")); const Type_1 = __importDefault(require("../Type")); const useMediaQuery_1 = __importDefault(require("../useMediaQuery")); const utils_2 = require("../utils"); const useStyle = (0, style_react_1.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 = react_1.default.forwardRef((props_, ref) => { const theme = (0, style_react_1.useOnesyTheme)(); const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.onesySectionContact) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]); const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]); const Properties = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Properties) || Properties_1.default; }, [theme]); const Section = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Section) || Section_1.default; }, [theme]); const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]); const { map, mapPosition: mapPosition_ = 'bottom', heading, summary, address, phone, email, IconAddress = IconMaterialMapW100_1.default, IconPhone = IconMaterialCallW100_1.default, IconEmail = IconMaterialMailW100_1.default, MapProps, HeadingProps, SummaryProps, PropertiesProps, className } = props, other = __rest(props, ["map", "mapPosition", "heading", "summary", "address", "phone", "email", "IconAddress", "IconPhone", "IconEmail", "MapProps", "HeadingProps", "SummaryProps", "PropertiesProps", "className"]); const { classes } = useStyle(); const refs = { root: react_1.default.useRef(undefined) }; const mobile = (0, useMediaQuery_1.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 ? 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 = Object.assign(Object.assign({}, 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) && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ fullWidth: true, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('SectionContact', theme) && [ 'onesy-SectionContact-map' ], classes.map ]) }, { children: [map.overlay && ((0, jsx_runtime_1.jsx)("div", { className: (0, style_react_1.classNames)([ classes.backgroundOverlay ]), style: Object.assign({}, styleOverlay) })), (0, jsx_runtime_1.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 ? 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: (0, jsx_runtime_1.jsx)(IconAddress, {}), value: address }); if (phone) properties.push({ name: (0, jsx_runtime_1.jsx)(IconPhone, {}), value: phone }); if (email) properties.push({ name: (0, jsx_runtime_1.jsx)(IconEmail, {}), value: email }); return ((0, jsx_runtime_1.jsxs)(Section, Object.assign({ ref: (item) => { if (ref) { if ((0, utils_1.is)('function', ref)) ref(item); else ref.current = item; } refs.root.current = item; }, MainProps: { gap: 4 }, className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('SectionContact', theme) && [ 'onesy-SectionContact-root' ], className, classes.root ]) }, other, { children: [mapPosition === 'top' && mapElement, (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 4, direction: 'row', fullWidth: true }, { children: [mapPosition === 'left' && mapElement, (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 5, flex: true, fullWidth: true, style: { paddingTop: ['left', 'right'].includes(mapPosition) ? 24 : 0 } }, { children: [(heading || summary) && ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.5 }, { children: [heading && ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 't1', dangerouslySetInnerHTML: { __html: (0, utils_1.textToInnerHTML)(heading) } }, HeadingProps, { className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('SectionContact', theme) && [ 'onesy-SectionContact-heading' ], HeadingProps === null || HeadingProps === void 0 ? void 0 : HeadingProps.className, classes.text ]) }))), summary && ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: 'b3', dangerouslySetInnerHTML: { __html: (0, utils_1.textToInnerHTML)(summary) } }, SummaryProps, { className: (0, style_react_1.classNames)([ (0, utils_2.staticClassName)('SectionContact', theme) && [ 'onesy-SectionContact-summary' ], SummaryProps === null || SummaryProps === void 0 ? void 0 : SummaryProps.className, classes.text ]) })))] }))), !!properties.length && ((0, jsx_runtime_1.jsx)(Properties, Object.assign({ version: 'row', gap: 1, values: properties }, PropertiesProps, { PropertyProps: Object.assign({ responsive: false }, PropertiesProps === null || PropertiesProps === void 0 ? void 0 : PropertiesProps.PropertyProps) })))] })), mapPosition === 'right' && mapElement] })), mapPosition === 'bottom' && mapElement] }))); }); Element.displayName = 'onesy-SectionContact'; exports.default = Element;