|
1 |
| -import React, { useContext, ReactNode } from 'react' |
| 1 | +import React, { useContext, Children, ReactNode } from 'react' |
2 | 2 | import {
|
3 | 3 | Alert as BAlert,
|
4 | 4 | Dialog as BDialog,
|
5 | 5 | Overlay as BOverlay,
|
6 |
| - AlertProps as BAlertProps, |
7 |
| - DialogProps as BDialogProps, |
8 |
| - OverlayProps as BOverlayProps, |
9 | 6 | Popover as BPopover,
|
10 | 7 | Tooltip as BTooltip,
|
11 |
| - PopoverProps as BPopoverProps, |
12 |
| - TooltipProps as BTooltipProps, |
| 8 | + type AlertProps, |
| 9 | + type DialogProps, |
| 10 | + type OverlayProps, |
| 11 | + type PopoverProps, |
| 12 | + type TooltipProps, |
13 | 13 | } from '@blueprintjs/core'
|
14 | 14 | import { WindowEnv } from './window-env'
|
15 | 15 |
|
16 |
| -interface AlertProps extends BAlertProps { |
17 |
| - children: ReactNode |
18 |
| -} |
| 16 | +const getSecondChildren = (children: ReactNode) => |
| 17 | + Children.count(children) > 1 |
| 18 | + ? (Children.toArray(children)[1] as PopoverProps['content']) |
| 19 | + : undefined |
19 | 20 |
|
20 | 21 | export const Alert: React.FC<AlertProps> = ({ children, ...props }) => (
|
21 | 22 | <BAlert portalContainer={useContext(WindowEnv).mountPoint} {...props}>
|
22 | 23 | {children}
|
23 | 24 | </BAlert>
|
24 | 25 | )
|
25 | 26 |
|
26 |
| -interface DialogProps extends BDialogProps { |
27 |
| - children: ReactNode |
28 |
| -} |
29 |
| - |
30 | 27 | export const Dialog: React.FC<DialogProps> = ({ children, ...props }) => (
|
31 | 28 | <BDialog portalContainer={useContext(WindowEnv).mountPoint} {...props}>
|
32 | 29 | {children}
|
33 | 30 | </BDialog>
|
34 | 31 | )
|
35 | 32 |
|
36 |
| -interface TooltipProps extends BTooltipProps { |
37 |
| - children: ReactNode |
38 |
| -} |
39 |
| - |
40 |
| -export const Tooltip: React.FC<TooltipProps> = ({ children, ...props }) => ( |
41 |
| - <BTooltip portalContainer={useContext(WindowEnv).mountPoint} {...props}> |
| 33 | +export const Tooltip: React.FC<TooltipProps> = ({ children, content, ...props }) => ( |
| 34 | + <BTooltip |
| 35 | + portalContainer={useContext(WindowEnv).mountPoint} |
| 36 | + {...props} |
| 37 | + content={content || getSecondChildren(children)} |
| 38 | + > |
42 | 39 | {children}
|
43 | 40 | </BTooltip>
|
44 | 41 | )
|
45 | 42 |
|
46 |
| -interface PopoverProps extends BPopoverProps { |
47 |
| - children: ReactNode |
48 |
| -} |
49 |
| - |
50 |
| -export const Popover: React.FC<PopoverProps> = ({ children, ...props }) => ( |
51 |
| - <BPopover portalContainer={useContext(WindowEnv).mountPoint} {...props}> |
| 43 | +export const Popover: React.FC<PopoverProps> = ({ children, content, ...props }) => ( |
| 44 | + <BPopover |
| 45 | + portalContainer={useContext(WindowEnv).mountPoint} |
| 46 | + {...props} |
| 47 | + content={content || getSecondChildren(children)} |
| 48 | + > |
52 | 49 | {children}
|
53 | 50 | </BPopover>
|
54 | 51 | )
|
55 | 52 |
|
56 |
| -interface OverlayProps extends BOverlayProps { |
57 |
| - children: ReactNode |
58 |
| -} |
59 |
| - |
60 | 53 | export const Overlay: React.FC<OverlayProps> = ({ children, ...props }) => (
|
61 | 54 | <BOverlay portalContainer={useContext(WindowEnv).mountPoint} {...props}>
|
62 | 55 | {children}
|
|
0 commit comments