Skip to content

Commit fa6ad47

Browse files
committed
Support forward ref for Section
1 parent 5f1a535 commit fa6ad47

File tree

2 files changed

+49
-41
lines changed

2 files changed

+49
-41
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@near-pagoda/ui",
3-
"version": "3.1.9",
3+
"version": "3.1.10",
44
"description": "A React component library that implements the official NEAR design system.",
55
"license": "MIT",
66
"repository": {

src/components/Section.tsx

+48-40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type CSSProperties, type ReactNode } from 'react';
1+
import { type CSSProperties, forwardRef, type ReactNode } from 'react';
22

33
import { type ThemeColor, type ThemeGap } from '../utils/theme';
44
import { Container } from './Container';
@@ -18,46 +18,54 @@ export type SectionProps = {
1818
tabs?: boolean;
1919
};
2020

21-
export const Section = ({
22-
background,
23-
bleed, // No container
24-
children,
25-
className = '',
26-
gap = 'l',
27-
grow,
28-
padding,
29-
style,
30-
tabs,
31-
...props
32-
}: SectionProps) => {
33-
const variables = {
34-
'--section-background-color': `var(--${background})`,
35-
};
21+
export const Section = forwardRef<HTMLElement, SectionProps>(
22+
(
23+
{
24+
background,
25+
bleed, // No container
26+
children,
27+
className = '',
28+
gap = 'l',
29+
grow,
30+
padding,
31+
style,
32+
tabs,
33+
...props
34+
},
35+
ref,
36+
) => {
37+
const variables = {
38+
'--section-background-color': `var(--${background})`,
39+
};
3640

37-
return (
38-
<section
39-
className={`${s.section} ${className}`}
40-
data-background={background}
41-
data-grow={grow}
42-
data-padding={padding}
43-
data-tabs={tabs}
44-
style={{
45-
...style,
46-
...variables,
47-
}}
48-
{...props}
49-
>
50-
{bleed ? (
51-
<Flex direction="column" gap={gap}>
52-
{children}
53-
</Flex>
54-
) : (
55-
<Container>
41+
return (
42+
<section
43+
className={`${s.section} ${className}`}
44+
data-background={background}
45+
data-grow={grow}
46+
data-padding={padding}
47+
data-tabs={tabs}
48+
style={{
49+
...style,
50+
...variables,
51+
}}
52+
ref={ref}
53+
{...props}
54+
>
55+
{bleed ? (
5656
<Flex direction="column" gap={gap}>
5757
{children}
5858
</Flex>
59-
</Container>
60-
)}
61-
</section>
62-
);
63-
};
59+
) : (
60+
<Container>
61+
<Flex direction="column" gap={gap}>
62+
{children}
63+
</Flex>
64+
</Container>
65+
)}
66+
</section>
67+
);
68+
},
69+
);
70+
71+
Section.displayName = 'Section';

0 commit comments

Comments
 (0)