/* Copyright 2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, { ReactNode, useState } from 'react'; import classNames from 'classnames'; import { RoomMember } from 'matrix-js-sdk/src/matrix'; import { Icon as LocationIcon } from '../../../../res/img/element-icons/location.svg'; import { getUserNameColorClass } from '../../../utils/FormattingUtils'; import MemberAvatar from '../avatars/MemberAvatar'; interface Props { id?: string; // renders MemberAvatar when provided roomMember?: RoomMember; // use member text color as background useMemberColor?: boolean; tooltip?: ReactNode; } /** * Wrap with tooltip handlers when * tooltip is truthy */ const OptionalTooltip: React.FC<{ tooltip?: ReactNode; children: ReactNode; }> = ({ tooltip, children }) => { const [isVisible, setIsVisible] = useState(false); if (!tooltip) { return <>{ children }; } const show = () => setIsVisible(true); const hide = () => setIsVisible(false); const toggleVisibility = (e: React.MouseEvent) => { // stop map from zooming in on click e.stopPropagation(); setIsVisible(!isVisible); }; return
{ children } { isVisible && tooltip }
; }; /** * Generic location marker */ const Marker = React.forwardRef(({ id, roomMember, useMemberColor, tooltip }, ref) => { const memberColorClass = useMemberColor && roomMember ? getUserNameColorClass(roomMember.userId) : ''; return
{ roomMember ? : }
; }); export default Marker;