1
1
import Link from "@mui/material/Link" ;
2
2
// This is used as base for the main HelpTooltip component
3
3
// eslint-disable-next-line no-restricted-imports -- Read above
4
- import Popover , { PopoverProps } from "@mui/material/Popover" ;
4
+ import Popover , { type PopoverProps } from "@mui/material/Popover" ;
5
5
import HelpIcon from "@mui/icons-material/HelpOutline" ;
6
6
import OpenInNewIcon from "@mui/icons-material/OpenInNew" ;
7
7
import {
8
8
createContext ,
9
9
useContext ,
10
10
useRef ,
11
11
useState ,
12
- FC ,
13
- PropsWithChildren ,
12
+ type FC ,
13
+ type PropsWithChildren ,
14
+ type HTMLAttributes ,
15
+ type ReactNode ,
14
16
} from "react" ;
15
17
import { Stack } from "components/Stack/Stack" ;
16
- import Box , { BoxProps } from "@mui/material/Box" ;
17
18
import { type CSSObject , css as className } from "@emotion/css" ;
18
19
import { css , type Interpolation , type Theme , useTheme } from "@emotion/react" ;
19
20
20
21
type Icon = typeof HelpIcon ;
21
22
22
23
type Size = "small" | "medium" ;
23
- export interface HelpTooltipProps {
24
- // Useful to test on storybook
25
- open ?: boolean ;
26
- size ?: Size ;
27
- icon ?: Icon ;
28
- iconClassName ?: string ;
29
- buttonClassName ?: string ;
30
- }
31
24
32
25
export const HelpTooltipContext = createContext <
33
26
{ open : boolean ; onClose : ( ) => void } | undefined
@@ -45,9 +38,17 @@ const useHelpTooltip = () => {
45
38
return helpTooltipContext ;
46
39
} ;
47
40
48
- export const HelpPopover : FC <
49
- PopoverProps & { onOpen : ( ) => void ; onClose : ( ) => void }
50
- > = ( { onOpen, onClose, children, ...props } ) => {
41
+ interface HelpPopoverProps extends PopoverProps {
42
+ onOpen : ( ) => void ;
43
+ onClose : ( ) => void ;
44
+ }
45
+
46
+ export const HelpPopover : FC < HelpPopoverProps > = ( {
47
+ onOpen,
48
+ onClose,
49
+ children,
50
+ ...props
51
+ } ) => {
51
52
const theme = useTheme ( ) ;
52
53
53
54
return (
@@ -86,7 +87,17 @@ export const HelpPopover: FC<
86
87
) ;
87
88
} ;
88
89
89
- export const HelpTooltip : FC < PropsWithChildren < HelpTooltipProps > > = ( {
90
+ export interface HelpTooltipProps {
91
+ // Useful to test on storybook
92
+ open ?: boolean ;
93
+ size ?: Size ;
94
+ icon ?: Icon ;
95
+ iconClassName ?: string ;
96
+ buttonClassName ?: string ;
97
+ children ?: ReactNode ;
98
+ }
99
+
100
+ export const HelpTooltip : FC < HelpTooltipProps > = ( {
90
101
children,
91
102
open = false ,
92
103
size = "medium" ,
@@ -161,12 +172,26 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
161
172
) ;
162
173
} ;
163
174
164
- export const HelpTooltipTitle : FC < PropsWithChildren > = ( { children } ) => {
165
- return < h4 css = { styles . title } > { children } </ h4 > ;
175
+ export const HelpTooltipTitle : FC < HTMLAttributes < HTMLHeadingElement > > = ( {
176
+ children,
177
+ ...attrs
178
+ } ) => {
179
+ return (
180
+ < h4 css = { styles . title } { ...attrs } >
181
+ { children }
182
+ </ h4 >
183
+ ) ;
166
184
} ;
167
185
168
- export const HelpTooltipText = ( props : BoxProps ) => {
169
- return < Box component = "p" css = { styles . text } { ...props } /> ;
186
+ export const HelpTooltipText : FC < HTMLAttributes < HTMLParagraphElement > > = ( {
187
+ children,
188
+ ...attrs
189
+ } ) => {
190
+ return (
191
+ < p css = { styles . text } { ...attrs } >
192
+ { children }
193
+ </ p >
194
+ ) ;
170
195
} ;
171
196
172
197
export const HelpTooltipLink : FC < PropsWithChildren < { href : string } > > = ( {
@@ -181,13 +206,19 @@ export const HelpTooltipLink: FC<PropsWithChildren<{ href: string }>> = ({
181
206
) ;
182
207
} ;
183
208
184
- export const HelpTooltipAction : FC <
185
- PropsWithChildren < {
186
- icon : Icon ;
187
- onClick : ( ) => void ;
188
- ariaLabel ?: string ;
189
- } >
190
- > = ( { children, icon : Icon , onClick, ariaLabel } ) => {
209
+ interface HelpTooltipActionProps {
210
+ children ?: ReactNode ;
211
+ icon : Icon ;
212
+ onClick : ( ) => void ;
213
+ ariaLabel ?: string ;
214
+ }
215
+
216
+ export const HelpTooltipAction : FC < HelpTooltipActionProps > = ( {
217
+ children,
218
+ icon : Icon ,
219
+ onClick,
220
+ ariaLabel,
221
+ } ) => {
191
222
const tooltip = useHelpTooltip ( ) ;
192
223
193
224
return (
@@ -206,9 +237,7 @@ export const HelpTooltipAction: FC<
206
237
) ;
207
238
} ;
208
239
209
- export const HelpTooltipLinksGroup : FC < PropsWithChildren < unknown > > = ( {
210
- children,
211
- } ) => {
240
+ export const HelpTooltipLinksGroup : FC < PropsWithChildren > = ( { children } ) => {
212
241
return (
213
242
< Stack spacing = { 1 } css = { styles . linksGroup } >
214
243
{ children }
0 commit comments