@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
95 lines (86 loc) • 4.25 kB
JavaScript
import { __rest } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, CardContent, Typography } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useThemeProps } from '@mui/system';
import { GoogleMap, MarkerF } from '@react-google-maps/api';
import { useSCGoogleApiLoader, useSCFetchEvent } from '@selfcommunity/react-core';
import { SCEventLocationType } from '@selfcommunity/types';
import classNames from 'classnames';
import { FormattedMessage } from 'react-intl';
import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
import { formatEventLocationGeolocation } from '../../utils/string';
import Widget from '../Widget';
import { PREFIX } from './constants';
import EventLocationWidgetSkeleton from './Skeleton';
const classes = {
root: `${PREFIX}-root`,
title: `${PREFIX}-title`,
map: `${PREFIX}-map`,
locationTitle: `${PREFIX}-location-title`,
address: `${PREFIX}-address`
};
const Root = styled(Widget, {
name: PREFIX,
slot: 'Root'
})(() => ({}));
/**
* > API documentation for the Community-JS Group Info Widget component. Learn about the available props and the CSS API.
*
*
* This component renders a widget containing the event info.
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/EventLocationWidget)
#### Import
```jsx
import {EventLocationWidget} from '@selfcommunity/react-ui';
```
#### Component Name
The name `SCEventLocationWidget` can be used when providing style overrides in the theme.
#### CSS
|Rule Name|Global class|Description|
|---|---|---|
|root|.SCEventLocationWidget-root|Styles applied to the root element.|
|title|.SCEventLocationWidget-title|Styles applied to the title element.|
|map|.SCEventLocationWidget-map|Styles applied to the map element.|
|locationTitle|.SCEventLocationWidget-location-title|Styles applied to the location title element.|
|address|.SCEventLocationWidget-address|Styles applied to the address element.|
*
* @param inProps
*/
export default function EventLocationWidget(inProps) {
// PROPS
const props = useThemeProps({
props: inProps,
name: PREFIX
});
const { className, event, eventId } = props, rest = __rest(props, ["className", "event", "eventId"]);
// STATE
const { scEvent } = useSCFetchEvent({ id: eventId, event });
// HOOKS
const { isLoaded, geocodingApiKey } = useSCGoogleApiLoader();
const mapOptions = {
fullscreenControl: false,
mapTypeControl: false,
streetViewControl: false,
zoomControl: false // Disables the zoom control (+/- buttons)
};
if (!geocodingApiKey || (scEvent === null || scEvent === void 0 ? void 0 : scEvent.location) === SCEventLocationType.ONLINE) {
return _jsx(HiddenPlaceholder, {});
}
/**
* Loading event
*/
if (!isLoaded || !scEvent) {
return _jsx(EventLocationWidgetSkeleton, {});
}
/**
* Renders root object
*/
return (_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: _jsxs(CardContent, { children: [_jsx(Typography, Object.assign({ variant: "h4", className: classes.title, gutterBottom: true }, { children: _jsx(FormattedMessage, { id: "ui.eventLocationWidget.title", defaultMessage: "ui.eventLocationWidget.title" }) })), _jsx(Box, Object.assign({ className: classes.map }, { children: _jsx(GoogleMap, Object.assign({ mapContainerClassName: classes.map, center: {
lat: scEvent.geolocation_lat,
lng: scEvent.geolocation_lng
}, options: mapOptions, zoom: 15 }, { children: _jsx(MarkerF, { position: {
lat: scEvent.geolocation_lat,
lng: scEvent.geolocation_lng
} }) })) })), _jsx(Typography, Object.assign({ variant: "h4", className: classes.locationTitle }, { children: formatEventLocationGeolocation(scEvent.geolocation, true) })), _jsx(Typography, Object.assign({ variant: "body1", className: classes.address }, { children: formatEventLocationGeolocation(scEvent.geolocation) }))] }) })));
}