forked from neherlab/covid19_scenarios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormHelpButton.tsx
53 lines (45 loc) · 1.28 KB
/
FormHelpButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react'
import { Button, Card, CardBody, UncontrolledPopover } from 'reactstrap'
import { FaQuestion } from 'react-icons/fa'
import './FormHelpButton.scss'
function safeId(id: string) {
return id.replace('.', '-')
}
export interface HelpProps {
label: string
content: string | React.ReactNode
}
export function help(label: string, content: string | React.ReactNode): HelpProps {
return { label, content }
}
export interface FormHelpButtonProps {
identifier: string
help?: HelpProps
}
export default function FormHelpButton({ identifier, help }: FormHelpButtonProps) {
return (
<>
<Button
id={safeId(identifier)}
className="help-button ml-2"
type="button"
aria-label="help"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
}}
>
<FaQuestion className="help-button-icon" />
</Button>
<UncontrolledPopover placement="right" target={safeId(identifier)} trigger="legacy" hideArrow>
<Card className="card--help">
<CardBody>
{help && <h4>{help.label}</h4>}
{help && <p>{help.content}</p>}
{!help && <p>No help attribute assigned.</p>}
</CardBody>
</Card>
</UncontrolledPopover>
</>
)
}