diff --git a/.storybook/manager.ts b/.storybook/manager.ts index b357cc3..b74f8e1 100644 --- a/.storybook/manager.ts +++ b/.storybook/manager.ts @@ -2,7 +2,7 @@ import { addons } from '@storybook/addons'; import { create } from '@storybook/theming/create'; const theme = create({ - base: 'light', + base: 'dark', // Brand assets brandTitle: 'ReactMaoboxGl', @@ -11,6 +11,6 @@ const theme = create({ addons.setConfig({ theme, - showPanel: true, // show addons panel by default - panelPosition: 'right', // position addons panel on the right by default + showPanel: true, + panelPosition: 'right', }); diff --git a/src/map/constant.ts b/src/map/constant.ts index 474d379..33df2f0 100644 --- a/src/map/constant.ts +++ b/src/map/constant.ts @@ -1,6 +1,13 @@ +import React from 'react'; import type { EventMapping } from './types'; import type { KeysOfUnion } from '../types'; +export const defaultContainerStyle: React.CSSProperties = { + width: '100%', + height: '100%', + position: 'relative', +}; + export const MapEventMap: EventMapping = { onError: 'error', diff --git a/src/map/map.css b/src/map/map.css index 3518e8f..51f7915 100644 --- a/src/map/map.css +++ b/src/map/map.css @@ -1,4 +1,5 @@ a.mapboxgl-ctrl-logo, +.mapboxgl-ctrl.mapboxgl-ctrl-attrib, .mapboxgl-ctrl-attrib.mapboxgl-compact { display: none; } diff --git a/src/map/map.tsx b/src/map/map.tsx index 4564ced..0b6bda2 100644 --- a/src/map/map.tsx +++ b/src/map/map.tsx @@ -3,7 +3,7 @@ import { useRef, useState, useEffect, forwardRef, useImperativeHandle } from 're import { MapContext } from './context'; import { useReact } from '@/hooks/useReact'; import { allProps, setterMap, converterMap } from './config'; -import { MapEventMap, MapEventList } from './constant'; +import { defaultContainerStyle, MapEventMap, MapEventList } from './constant'; import { useEvents } from '@/hooks/useEvents'; import 'mapbox-gl/dist/mapbox-gl.css'; @@ -16,7 +16,7 @@ Mapbox.accessToken = 'pk.eyJ1IjoienQyMDIzMTEwOSIsImEiOiJjbG9xdGgxcDMwbDAyMmpwODVrNG5seXphIn0.1xKSk8Ll-80kkEwtzfLWhw'; export const Map = forwardRef((props, ref) => { - const { loading, children } = props; + const { className, loading, containerStyle, children } = props; const containerRef = useRef(null); const [mapInstance, setMapInstance] = useState(); @@ -72,7 +72,14 @@ export const Map = forwardRef((props, ref) => { }; return ( -
+
{!mapInstance && loading} {mapInstance && {children}}
diff --git a/src/map/types.ts b/src/map/types.ts index b656da9..84568db 100644 --- a/src/map/types.ts +++ b/src/map/types.ts @@ -72,6 +72,9 @@ export type MapboxOptionKeys = KeysOfUnion; export interface MapProps extends Omit, Partial { /** 地图加载前的加载效果 */ loading?: React.ReactNode; + /** 额外的样式类 */ className?: string; + /** 地图挂载节点样式 */ + containerStyle?: React.CSSProperties; children?: React.ReactNode; } diff --git a/stories/Map.stories.ts b/stories/Map.stories.ts index 9ebd607..c113f79 100644 --- a/stories/Map.stories.ts +++ b/stories/Map.stories.ts @@ -6,10 +6,15 @@ const meta = { title: '组件/Map', component: Map, parameters: { - layout: 'centered', + layout: 'fullscreen', }, tags: ['autodocs'], argTypes: {}, + args: { + containerStyle: { + height: 500, + }, + }, } satisfies Meta; export default meta;