-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathSection.tsx
More file actions
85 lines (79 loc) · 1.89 KB
/
Copy pathSection.tsx
File metadata and controls
85 lines (79 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import React from 'react';
import styled from 'styled-components';
import {isDefined} from 'gmp/utils/identity';
import {
type FoldToggleComponentProps,
withFolding,
withFoldToggle,
} from 'web/components/folding/Folding';
import FoldStateIcon from 'web/components/icon/FoldStateIcon';
import Layout from 'web/components/layout/Layout';
import SectionHeader from 'web/components/section/SectionHeader';
interface SectionProps extends FoldToggleComponentProps {
children?: React.ReactNode;
className?: string;
'data-testid'?: string;
extra?: React.ReactNode;
foldable?: boolean;
header?: React.ReactNode;
img?: React.ReactNode;
title?: string;
}
const FoldableLayout = withFolding(Layout);
const FoldLayout = styled(Layout)`
margin-left: 3px;
margin-top: -2px;
`;
const Section = ({
children,
className,
extra,
foldable,
foldState,
header,
img,
title,
['data-testid']: dataTestId,
onFoldToggle,
onFoldStepEnd,
}: SectionProps) => {
if (!isDefined(header)) {
header = (
<SectionHeader img={img} title={title}>
<Layout flex align={['space-between', 'center']}>
{extra}
{foldable && (
<FoldLayout>
<FoldStateIcon
className="section-fold-icon"
foldState={foldState}
onClick={onFoldToggle}
/>
</FoldLayout>
)}
</Layout>
</SectionHeader>
);
}
return (
<section className={className} data-testid={dataTestId}>
{header}
{foldable ? (
<FoldableLayout
foldState={foldState}
grow="1"
onFoldStepEnd={onFoldStepEnd}
>
{children}
</FoldableLayout>
) : (
children
)}
</section>
);
};
export default withFoldToggle(Section);