From eff5f9026fc97b6cb88107da4cf637f81c08fc7b Mon Sep 17 00:00:00 2001 From: Igor Dykhta Date: Tue, 16 Aug 2022 15:55:18 +0300 Subject: [PATCH] Map Control: Use MapControlTooltip with TippyTooltip (#1920) --- src/components/map/locale-panel.tsx | 14 ++--------- src/components/map/map-control-tooltip.tsx | 27 ++++++++++++++-------- src/components/map/map-control.tsx | 13 +++++------ src/components/map/map-draw-panel.tsx | 22 ++++-------------- src/components/map/map-legend-panel.tsx | 18 ++++----------- src/components/map/split-map-button.tsx | 19 ++++++--------- src/components/map/toggle-3d-button.tsx | 20 ++++++---------- 7 files changed, 48 insertions(+), 85 deletions(-) diff --git a/src/components/map/locale-panel.tsx b/src/components/map/locale-panel.tsx index 5a0d2475fd..96178abe0b 100644 --- a/src/components/map/locale-panel.tsx +++ b/src/components/map/locale-panel.tsx @@ -25,8 +25,6 @@ import ToolbarItem from 'components/common/toolbar-item'; import {MapControlButton} from 'components/common/styled-components'; import MapControlTooltipFactory from './map-control-tooltip'; import MapControlToolbarFactory from './map-control-toolbar'; -import {FormattedMessage} from '@kepler.gl/localization'; -import TippyTooltip from 'components/common/tippy-tooltip'; import {MapControls} from 'reducers'; LocalePanelFactory.deps = [MapControlTooltipFactory, MapControlToolbarFactory]; @@ -43,7 +41,6 @@ function LocalePanelFactory( MapControlTooltip: ReturnType, MapControlToolbar: ReturnType ) { - /** @type {import('./locale-panel').LocalePanelComponent} */ const LocalePanel: React.FC = React.memo( ({availableLocales, onToggleMapControl, onSetLocale, locale: currentLocal, mapControls}) => { const {active: isActive, show} = mapControls.mapLocale || {}; @@ -81,14 +78,7 @@ function LocalePanelFactory( ))} ) : null} - ( -
- -
- )} - > + {currentLocal.toUpperCase()} -
+ ); } diff --git a/src/components/map/map-control-tooltip.tsx b/src/components/map/map-control-tooltip.tsx index 8969d871ca..bfd2d4487f 100644 --- a/src/components/map/map-control-tooltip.tsx +++ b/src/components/map/map-control-tooltip.tsx @@ -18,24 +18,31 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import React from 'react'; -import {Tooltip} from 'components/common/styled-components'; +import React, {ReactElement, JSXElementConstructor} from 'react'; import {FormattedMessage} from '@kepler.gl/localization'; +import TippyTooltip from '../common/tippy-tooltip'; export type MapControlTooltipProps = { id: string; message: string; + children?: ReactElement>; }; function MapControlTooltipFactory() { - /** @type {import('./map-control-tooltip').MapControlTooltipComponent} */ - const MapControlTooltip: React.FC = React.memo(({id, message}) => ( - - - - - - )); + const MapControlTooltip: React.FC = React.memo( + ({id, message, children}) => ( + ( +
+ +
+ )} + > + {children} +
+ ) + ); MapControlTooltip.displayName = 'MapControlTooltip'; diff --git a/src/components/map/map-control.tsx b/src/components/map/map-control.tsx index a641b19a50..47799e9f56 100644 --- a/src/components/map/map-control.tsx +++ b/src/components/map/map-control.tsx @@ -110,10 +110,7 @@ function MapControlFactory( ]; /** @type {import('./map-control').MapControl} */ - const MapControl: React.FC = ({ - actionComponents = DEFAULT_ACTIONS, - ...props - }) => { + const MapControl: React.FC = React.memo(({actionComponents, ...props}) => { return ( {actionComponents.map((ActionComponent, index) => ( @@ -121,18 +118,20 @@ function MapControlFactory( ))} ); - }; + }); MapControl.defaultProps = { isSplit: false, top: 0, mapIndex: 0, - logoComponent: LegendLogo + logoComponent: LegendLogo, + // @ts-expect-error + actionComponents: DEFAULT_ACTIONS }; MapControl.displayName = 'MapControl'; - return React.memo(MapControl); + return MapControl; } export default MapControlFactory; diff --git a/src/components/map/map-draw-panel.tsx b/src/components/map/map-draw-panel.tsx index 2d03178bed..e21f11aa0f 100644 --- a/src/components/map/map-draw-panel.tsx +++ b/src/components/map/map-draw-panel.tsx @@ -33,18 +33,11 @@ import { import {MapControlButton} from 'components/common/styled-components'; import ToolbarItem from 'components/common/toolbar-item'; import MapControlTooltipFactory from './map-control-tooltip'; -import MapControlPanelFactory from './map-control-panel'; import MapControlToolbarFactory from './map-control-toolbar'; -import {FormattedMessage} from '@kepler.gl/localization'; -import TippyTooltip from 'components/common/tippy-tooltip'; import {Editor, MapControls} from 'reducers'; import {BaseProps} from 'components/common/icons/base'; -MapDrawPanelFactory.deps = [ - MapControlTooltipFactory, - MapControlPanelFactory, - MapControlToolbarFactory -]; +MapDrawPanelFactory.deps = [MapControlTooltipFactory, MapControlToolbarFactory]; export type MapDrawPanelProps = { editor: Editor; @@ -55,7 +48,7 @@ export type MapDrawPanelProps = { actionIcons: {[id: string]: React.ComponentType>}; }; -function MapDrawPanelFactory(MapControlTooltip, MapControlPanel, MapControlToolbar) { +function MapDrawPanelFactory(MapControlTooltip, MapControlToolbar) { const defaultActionIcons = { visible: EyeSeen, hidden: EyeUnseen, @@ -114,14 +107,7 @@ function MapDrawPanelFactory(MapControlTooltip, MapControlPanel, MapControlToolb /> ) : null} - ( -
- -
- )} - > + { @@ -132,7 +118,7 @@ function MapDrawPanelFactory(MapControlTooltip, MapControlPanel, MapControlToolb > -
+ ); } diff --git a/src/components/map/map-legend-panel.tsx b/src/components/map/map-legend-panel.tsx index c26b318ead..2ed44c6634 100644 --- a/src/components/map/map-legend-panel.tsx +++ b/src/components/map/map-legend-panel.tsx @@ -22,18 +22,17 @@ import React, {ComponentType, useState} from 'react'; import styled from 'styled-components'; import {Legend} from 'components/common/icons'; -import {FormattedMessage} from '@kepler.gl/localization'; import {MapControlButton} from 'components/common/styled-components'; +import MapControlTooltipFactory from './map-control-tooltip'; import MapControlPanelFactory from './map-control-panel'; import MapLegendFactory from './map-legend'; import Tippy from '@tippyjs/react/headless'; -import TippyTooltip from 'components/common/tippy-tooltip'; import {createPortal} from 'react-dom'; import {DIMENSIONS} from '@kepler.gl/constants'; import {MapControl, MapControls} from 'reducers'; import {Layer} from '@kepler.gl/layers'; -MapLegendPanelFactory.deps = [MapControlPanelFactory, MapLegendFactory]; +MapLegendPanelFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory, MapLegendFactory]; const PinToBottom = styled.div` position: absolute; @@ -56,7 +55,7 @@ export type MapLegendPanelProps = { mapHeight?: number; }; -function MapLegendPanelFactory(MapControlPanel, MapLegend) { +function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) { const defaultActionIcons = { legend: Legend }; @@ -142,18 +141,11 @@ function MapLegendPanelFactory(MapControlPanel, MapLegend) { appendTo={document.body} >
- ( -
- -
- )} - > + -
+
diff --git a/src/components/map/split-map-button.tsx b/src/components/map/split-map-button.tsx index 061e3bed57..73d6898aa3 100644 --- a/src/components/map/split-map-button.tsx +++ b/src/components/map/split-map-button.tsx @@ -22,11 +22,10 @@ import React, {ComponentType, useCallback, useMemo} from 'react'; import classnames from 'classnames'; import {MapControlButton} from 'components/common/styled-components'; import {Delete, Split} from 'components/common/icons'; -import {FormattedMessage} from '@kepler.gl/localization'; -import TippyTooltip from '../common/tippy-tooltip'; +import MapControlTooltipFactory from './map-control-tooltip'; import {MapControl, MapControls} from 'reducers'; -SplitMapButtonFactory.deps = []; +SplitMapButtonFactory.deps = [MapControlTooltipFactory]; interface SplitMapButtonIcons { delete: ComponentType; @@ -42,7 +41,7 @@ export type SplitMapButtonProps = { mapControls: MapControls; }; -function SplitMapButtonFactory() { +function SplitMapButtonFactory(MapControlTooltip) { const defaultActionIcons = { delete: Delete, split: Split @@ -72,13 +71,9 @@ function SplitMapButtonFactory() { return null; } return isVisible ? ( - ( -
- -
- )} + {isSplit ? : } -
+ ) : null; }; diff --git a/src/components/map/toggle-3d-button.tsx b/src/components/map/toggle-3d-button.tsx index 8d14ae14bb..b76092eea7 100644 --- a/src/components/map/toggle-3d-button.tsx +++ b/src/components/map/toggle-3d-button.tsx @@ -20,14 +20,12 @@ import React, {ComponentType, useCallback, useMemo} from 'react'; import classnames from 'classnames'; - import {Cube3d} from 'components/common/icons'; import {MapControlButton} from 'components/common/styled-components'; -import {FormattedMessage} from '@kepler.gl/localization'; -import TippyTooltip from 'components/common/tippy-tooltip'; +import MapControlTooltipFactory from './map-control-tooltip'; import {MapControls} from 'reducers'; -Toggle3dButtonFactory.deps = []; +Toggle3dButtonFactory.deps = [MapControlTooltipFactory]; interface Toggle3dButtonIcons { cube: ComponentType; @@ -40,7 +38,7 @@ export type Toggle3dButtonProps = { mapControls: MapControls; }; -function Toggle3dButtonFactory() { +function Toggle3dButtonFactory(MapControlTooltip) { const defaultActionIcons = { cube: Cube3d }; @@ -64,13 +62,9 @@ function Toggle3dButtonFactory() { }, [mapControls]); return isVisible ? ( - ( -
- -
- )} + -
+ ) : null; };