-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathSampleSection.tsx
More file actions
48 lines (42 loc) · 1.26 KB
/
SampleSection.tsx
File metadata and controls
48 lines (42 loc) · 1.26 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
import { type Flex, type Grid, type View } from '@deephaven/components';
import type { StyleProps } from '@react-types/shared';
import React, { type CSSProperties, type ReactNode } from 'react';
import {
getSectionIdFromName,
sampleSectionIdAndClasses,
sampleSectionIdAndClassesSpectrum,
useIsolateSectionHash,
} from './utils';
export interface SampleSectionProps extends StyleProps {
name: string;
className?: string;
component?: 'div' | typeof Flex | typeof Grid | typeof View;
style?: CSSProperties;
children: ReactNode;
}
export function SampleSection({
name,
className = '',
component: Component = 'div',
...styleProps
}: SampleSectionProps): JSX.Element | null {
const hash = useIsolateSectionHash();
const sectionId = getSectionIdFromName(name);
const shouldRender = hash === '' || hash === sectionId;
if (!shouldRender) {
return null;
}
const sectionIdAndClasses =
Component === 'div'
? sampleSectionIdAndClasses
: sampleSectionIdAndClassesSpectrum;
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...styleProps}
// eslint-disable-next-line react/jsx-props-no-spreading
{...sectionIdAndClasses(name, [className])}
/>
);
}
export default SampleSection;