Skip to content

Commit

Permalink
feat(InfoWindow): title props support JSX.Element
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 2, 2022
1 parent c637afb commit c9b2021
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"type-check": "npm exec --ws -- tsc --noEmit",
"test": "tsbb test --env=jsdom",
"coverage": "tsbb test --env=jsdom --coverage",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
"build": "lerna exec --scope @uiw/* --ignore @uiw/react-baidu-map-types -- tsbb build",
"doc": "npm run-script doc --workspace=website --if-present",
"start": "npm run-script start --workspace=website",
Expand Down
2 changes: 1 addition & 1 deletion packages/info-window/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const Example = () => {
console.log(':onClose');
}}
position={{ lng: 121.501365, lat: 31.224942 }}
title="地址信息二"
title={<div>地址信息二</div>}
content="test"
>
上海市 <del>青浦区</del> 徐泾镇盈港东路 Good!
Expand Down
4 changes: 3 additions & 1 deletion packages/info-window/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ describe('<InfoWindow />', () => {
it('InfoWindow test case', () => {
expect(typeof InfoWindow).toEqual('object');
expect(typeof useInfoWindow).toEqual('function');
const component = TestRenderer.create(<InfoWindow position={{ lng: 121.501365, lat: 31.224942 }} />);
const component = TestRenderer.create(
<InfoWindow title={<div>xxx</div>} position={{ lng: 121.501365, lat: 31.224942 }} />,
);
let tree = component.toJSON();
expect(tree).toBeNull();
});
Expand Down
15 changes: 8 additions & 7 deletions packages/info-window/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import { useInfoWindow } from './useInfoWindow';

export * from './useInfoWindow';

export interface InfoWindowProps extends OverlayProps, BMap.InfoWindowOptions, BMap.InfoWindowEvent {
export interface InfoWindowProps extends OverlayProps, Omit<BMap.InfoWindowOptions, 'title'>, BMap.InfoWindowEvent {
/**
* 窗口是否打开
* @default true
*/
isOpen?: boolean;
/**
* 窗口位置经纬度
*/
/** 窗口位置经纬度 */
position: BMap.Point;
/**
* 展示文本内容,支持 HTML 内容字符串
*/
/** 展示文本内容,支持 HTML 内容字符串 */
content?: string | HTMLElement;
/** 信息窗标题文字 */
title?: string | HTMLElement | JSX.Element;
/**
* 信息窗口最大化时所显示内容,支持HTML内容
*/
Expand All @@ -33,9 +31,12 @@ export default React.forwardRef<InfoWindowProps & { infoWindow?: BMap.InfoWindow
const { children } = props;
const container = useMemo(() => document.createElement('div'), []);
useEffect(() => render(<Fragment>{children}</Fragment>, container), [children]);
const title = useMemo(() => document.createElement('div'), []);
useEffect(() => render(<Fragment>{props.title}</Fragment>, title), [props.title]);

const { infoWindow, setIsOpen } = useInfoWindow({
...props,
title,
content: props.children ? container : props.content,
});

Expand Down

0 comments on commit c9b2021

Please sign in to comment.