Skip to content

Commit

Permalink
Support forward ref for Section
Browse files Browse the repository at this point in the history
  • Loading branch information
calebjacob committed Feb 21, 2025
1 parent 5f1a535 commit fa6ad47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-pagoda/ui",
"version": "3.1.9",
"version": "3.1.10",
"description": "A React component library that implements the official NEAR design system.",
"license": "MIT",
"repository": {
Expand Down
88 changes: 48 additions & 40 deletions src/components/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type CSSProperties, type ReactNode } from 'react';
import { type CSSProperties, forwardRef, type ReactNode } from 'react';

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

export const Section = ({
background,
bleed, // No container
children,
className = '',
gap = 'l',
grow,
padding,
style,
tabs,
...props
}: SectionProps) => {
const variables = {
'--section-background-color': `var(--${background})`,
};
export const Section = forwardRef<HTMLElement, SectionProps>(
(
{
background,
bleed, // No container
children,
className = '',
gap = 'l',
grow,
padding,
style,
tabs,
...props
},
ref,
) => {
const variables = {
'--section-background-color': `var(--${background})`,
};

return (
<section
className={`${s.section} ${className}`}
data-background={background}
data-grow={grow}
data-padding={padding}
data-tabs={tabs}
style={{
...style,
...variables,
}}
{...props}
>
{bleed ? (
<Flex direction="column" gap={gap}>
{children}
</Flex>
) : (
<Container>
return (
<section
className={`${s.section} ${className}`}
data-background={background}
data-grow={grow}
data-padding={padding}
data-tabs={tabs}
style={{
...style,
...variables,
}}
ref={ref}
{...props}
>
{bleed ? (
<Flex direction="column" gap={gap}>
{children}
</Flex>
</Container>
)}
</section>
);
};
) : (
<Container>
<Flex direction="column" gap={gap}>
{children}
</Flex>
</Container>
)}
</section>
);
},
);

Section.displayName = 'Section';

0 comments on commit fa6ad47

Please sign in to comment.