-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabeledField.tsx
More file actions
58 lines (54 loc) · 1.89 KB
/
Copy pathLabeledField.tsx
File metadata and controls
58 lines (54 loc) · 1.89 KB
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
54
55
56
57
58
import type { ReactNode } from 'react';
import { useModalRef, Modal } from '../../../../styles/containers/Modal';
interface LabeledFieldProps {
/**
* The text label displayed above the field
*/
label: string;
/**
* The form control element(s) to be displayed under the label
*/
children: React.ReactNode;
/**
* Optional informational content displayed in a modal when the user clicks the "?" button.
* If provided, a help button will be shown next to the label.
*/
info?: ReactNode;
/**
* Optional error message displayed below the field.
*/
error?: string;
}
export function LabeledField({ label, children, info, error }: LabeledFieldProps) {
const modalRef = useModalRef();
return (
<div className='form-control'>
<div className={`flex flex-row items-baseline justify-between gap-2 ${info !== undefined ? 'mb-2' : ''}`}>
<label className='label'>
<span className='label-text'>{label}</span>
</label>
{info !== undefined && (
<>
<button
type='button'
className='btn btn-xs'
onClick={() => modalRef.current?.showModal()}
aria-label={`Show information about ${label}`}
>
?
</button>
<Modal modalRef={modalRef} size='large'>
{info}
</Modal>
</>
)}
</div>
{children}
{error !== undefined && (
<label className='label'>
<span className='label-text-alt text-error'>{error}</span>
</label>
)}
</div>
);
}