Skip to content

Commit 0860e75

Browse files
committed
Add ref to Card and SimpleCard
1 parent 1228b74 commit 0860e75

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).
66

7+
## [0.9.5] - 2025-05-30
8+
### Added
9+
* *Nothing*
10+
11+
### Changed
12+
* *Nothing*
13+
14+
### Deprecated
15+
* *Nothing*
16+
17+
### Removed
18+
* *Nothing*
19+
20+
### Fixed
21+
* Allow `ref` to be passed to `Card` and its nested components.
22+
23+
724
## [0.9.4] - 2025-05-29
825
### Added
926
* Add `sticky-cell` tailwind utility.

src/tailwind/surfaces/Card.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
import clsx from 'clsx';
2-
import type { FC, HTMLProps } from 'react';
2+
import type { HTMLProps } from 'react';
3+
import { forwardRef } from 'react';
34

4-
export type CardProps = HTMLProps<HTMLDivElement>;
5+
export type CardProps = Omit<HTMLProps<HTMLDivElement>, 'ref'>;
56

6-
const Header: FC<CardProps> = ({ className, ...rest }) => (
7+
const Header = forwardRef<HTMLDivElement, CardProps>(({ className, ...rest }, ref) => (
78
<div
89
className={clsx(
910
'tw:px-4 tw:py-3 tw:rounded-t-md',
1011
'tw:bg-lm-primary tw:dark:bg-dm-primary tw:border-b tw:border-lm-border tw:dark:border-dm-border',
1112
className,
1213
)}
1314
{...rest}
15+
ref={ref}
1416
/>
15-
);
17+
));
1618

17-
const Body: FC<CardProps> = ({ className, ...rest }) => (
19+
const Body = forwardRef<HTMLDivElement, CardProps>(({ className, ...rest }, ref) => (
1820
<div
1921
className={clsx(
2022
'tw:p-4 tw:bg-lm-primary tw:dark:bg-dm-primary tw:first:rounded-t-md',
2123
'tw:first:rounded-t-md tw:last:rounded-b-md',
2224
className,
2325
)}
2426
{...rest}
27+
ref={ref}
2528
/>
26-
);
29+
));
2730

28-
const Footer: FC<CardProps> = ({ className, ...rest }) => (
31+
const Footer = forwardRef<HTMLDivElement, CardProps>(({ className, ...rest }, ref) => (
2932
<div
3033
className={clsx(
3134
'tw:px-4 tw:py-3 tw:rounded-b-md',
3235
'tw:bg-lm-primary tw:dark:bg-dm-primary tw:border-t tw:border-lm-border tw:dark:border-dm-border',
3336
className,
3437
)}
3538
{...rest}
39+
ref={ref}
3640
/>
37-
);
41+
));
3842

39-
const BaseCard: FC<CardProps> = ({ className, ...props }) => (
43+
const BaseCard = forwardRef<HTMLDivElement, CardProps>(({ className, ...props }, ref) => (
4044
<div
4145
className={clsx(
4246
'tw:group/card tw:rounded-md tw:shadow-md',
4347
'tw:border tw:border-lm-border tw:dark:border-dm-border tw:bg-lm-primary tw:dark:bg-dm-primary',
4448
className)}
4549
{...props}
50+
ref={ref}
4651
/>
47-
);
52+
));
4853

4954
export const Card = Object.assign(BaseCard, { Body, Header, Footer });

src/tailwind/surfaces/SimpleCard.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { FC, ReactNode } from 'react';
1+
import type { ReactNode } from 'react';
2+
import { forwardRef } from 'react';
23
import type { Size } from '../types';
34
import type { CardProps } from './Card';
45
import { Card } from './Card';
@@ -17,15 +18,15 @@ export type SimpleCardProps = Omit<CardProps, 'title' | 'size'> & {
1718
bodyClassName?: string;
1819
} & (TitleProps | NoTitleProps);
1920

20-
export const SimpleCard: FC<SimpleCardProps> = ({ bodyClassName, children, ...rest }) => {
21+
export const SimpleCard = forwardRef<HTMLDivElement, SimpleCardProps>(({ bodyClassName, children, ...rest }, ref) => {
2122
const { title, titleSize = 'md', ...cardProps } = 'title' in rest ? rest : {
2223
...rest,
2324
title: undefined,
2425
titleSize: undefined,
2526
};
2627

2728
return (
28-
<Card {...cardProps}>
29+
<Card {...cardProps} ref={ref}>
2930
{title && (
3031
<Card.Header>
3132
{titleSize === 'lg' && <h4>{title}</h4>}
@@ -38,4 +39,4 @@ export const SimpleCard: FC<SimpleCardProps> = ({ bodyClassName, children, ...re
3839
</Card.Body>
3940
</Card>
4041
);
41-
};
42+
});

0 commit comments

Comments
 (0)