Improve types

Signed-off-by: Charles de Dreuille <charles.dedreuille@gmail.com>
This commit is contained in:
Charles de Dreuille
2026-03-04 20:24:12 +00:00
parent 0c772a3223
commit 16d424276a
6 changed files with 53 additions and 32 deletions
+20 -11
View File
@@ -603,9 +603,12 @@ export interface CardBodyProps
// @public (undocumented)
export type CardButtonVariant = {
onPress: () => void;
onPress: NonNullable<ButtonProps_2['onPress']>;
href?: never;
label: string;
target?: never;
rel?: never;
download?: never;
};
// @public
@@ -695,20 +698,23 @@ export type CardLinkVariant = {
onPress?: never;
label: string;
target?: string;
};
// @public
export type CardOwnProps = {
children?: ReactNode;
className?: string;
onPress?: () => void;
href?: string;
label?: string;
target?: string;
rel?: string;
download?: boolean | string;
};
// @public
export type CardOwnProps = Pick<
CardBaseProps & (CardButtonVariant | CardLinkVariant | CardStaticVariant),
| 'children'
| 'className'
| 'onPress'
| 'href'
| 'label'
| 'target'
| 'rel'
| 'download'
>;
// @public
export type CardProps = CardBaseProps &
Omit<React.HTMLAttributes<HTMLDivElement>, 'onPress'> &
@@ -719,6 +725,9 @@ export type CardStaticVariant = {
onPress?: never;
href?: never;
label?: never;
target?: never;
rel?: never;
download?: never;
};
// @public (undocumented)
@@ -51,6 +51,7 @@
*/
.bui-Card[data-interactive] {
cursor: pointer;
overflow: hidden;
&::after {
content: '';
+1 -3
View File
@@ -24,7 +24,6 @@ import {
CardFooterDefinition,
} from './definition';
import type {
CardOwnProps,
CardProps,
CardHeaderProps,
CardBodyProps,
@@ -40,8 +39,7 @@ import { Box } from '../Box/Box';
export const Card = forwardRef<HTMLDivElement, CardProps>((props, ref) => {
const { ownProps, restProps, dataAttributes } = useDefinition(
CardDefinition,
props as CardOwnProps &
Omit<React.HTMLAttributes<HTMLDivElement>, 'onPress'>,
props,
);
const { classes, children, onPress, href, label, target, rel, download } =
ownProps;
+29 -16
View File
@@ -15,21 +15,7 @@
*/
import type { ReactNode } from 'react';
/**
* Flat own-props shape used by the component definition system.
* @public
*/
export type CardOwnProps = {
children?: ReactNode;
className?: string;
onPress?: () => void;
href?: string;
label?: string;
target?: string;
rel?: string;
download?: boolean | string;
};
import type { ButtonProps as RAButtonProps } from 'react-aria-components';
/** @public */
export type CardBaseProps = { children?: ReactNode; className?: string };
@@ -37,10 +23,13 @@ export type CardBaseProps = { children?: ReactNode; className?: string };
/** @public */
export type CardButtonVariant = {
/** Handler called when the card is pressed. Makes the card interactive as a button. */
onPress: () => void;
onPress: NonNullable<RAButtonProps['onPress']>;
href?: never;
/** Accessible label announced by screen readers for the interactive card. */
label: string;
target?: never;
rel?: never;
download?: never;
};
/** @public */
@@ -52,6 +41,10 @@ export type CardLinkVariant = {
label: string;
/** Specifies where to open the linked URL (e.g. `_blank` for a new tab). */
target?: string;
/** Relationship between the current document and the linked URL (e.g. `noopener`). */
rel?: string;
/** Prompts the user to save the linked URL. Pass `true` for default filename or a string for a custom filename. */
download?: boolean | string;
};
/** @public */
@@ -59,6 +52,9 @@ export type CardStaticVariant = {
onPress?: never;
href?: never;
label?: never;
target?: never;
rel?: never;
download?: never;
};
/**
@@ -70,6 +66,23 @@ export type CardProps = CardBaseProps &
Omit<React.HTMLAttributes<HTMLDivElement>, 'onPress'> &
(CardButtonVariant | CardLinkVariant | CardStaticVariant);
/**
* Flat own-props shape used by the component definition system.
* Derived from the Card variant types so it automatically stays in sync with CardProps.
* @public
*/
export type CardOwnProps = Pick<
CardBaseProps & (CardButtonVariant | CardLinkVariant | CardStaticVariant),
| 'children'
| 'className'
| 'onPress'
| 'href'
| 'label'
| 'target'
| 'rel'
| 'download'
>;
/** @public */
export type CardHeaderOwnProps = {
children?: ReactNode;