Skip to content

Commit

Permalink
Card: add types (#32561)
Browse files Browse the repository at this point in the history
* Add types to `<Card />` and its subcomponents

* Extract `SizeableProps` type

* Extract `MarginalSubComponentProps` type for Header and Footer

* Remove unnecessary `MediaProps` type

* Moved the `className` prop to the `MarginalSubComponentProps` type
  • Loading branch information
ciampo authored Jun 10, 2021
1 parent 5dbddf9 commit a7ff42c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/components/src/card/card-body/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export const defaultProps = {
size: 'medium',
};

/* eslint-disable jsdoc/valid-types */
/**
* @param { import('../types').BodyProps & JSX.IntrinsicElements['div'] } props
*/
export function CardBody( props ) {
/* eslint-enable jsdoc/valid-types */
const { className, isShady, ...additionalProps } = props;
const mergedProps = { ...defaultProps, ...useCardContext(), ...props };
const { size } = mergedProps;
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/card/card-divider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import classnames from 'classnames';
*/
import { DividerUI } from '../styles';

/* eslint-disable jsdoc/valid-types */
/**
* @param { JSX.IntrinsicElements['hr'] } props
*/
export function CardDivider( props ) {
/* eslint-enable jsdoc/valid-types */
const { className, ...additionalProps } = props;

const classes = classnames( 'components-card__divider', className );
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/card/card-footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const defaultProps = {
size: 'medium',
};

/**
* @param { import('../types').FooterProps } props
*/
export function CardFooter( props ) {
const { className, isShady, ...additionalProps } = props;
const mergedProps = { ...defaultProps, ...useCardContext(), ...props };
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/card/card-header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const defaultProps = {
size: 'medium',
};

/**
* @param { import('../types').HeaderProps } props
*/
export function CardHeader( props ) {
const { className, isShady, ...additionalProps } = props;
const mergedProps = { ...defaultProps, ...useCardContext(), ...props };
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/card/card-media/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import classnames from 'classnames';
*/
import { MediaUI } from '../styles';

/* eslint-disable jsdoc/valid-types */
/**
* @param { JSX.IntrinsicElements['div'] } props
*/
export function CardMedia( props ) {
/* eslint-enable jsdoc/valid-types */
const { className, ...additionalProps } = props;

const classes = classnames( 'components-card__media', className );
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/card/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export const defaultProps = {
size: 'medium',
};

/* eslint-disable jsdoc/valid-types */
/**
* @param { import('../types').Props & JSX.IntrinsicElements['div'] } props
*/
export function Card( props ) {
/* eslint-enable jsdoc/valid-types */
const {
className,
isBorderless,
Expand Down
81 changes: 81 additions & 0 deletions packages/components/src/card/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { CSSProperties } from 'react';

/**
* Internal dependencies
*/
import type { Props as SurfaceProps } from '../surface/types';

export type SizeOptions = 'xSmall' | 'small' | 'medium' | 'large';

type SizeableProps = {
/**
* Determines the amount of padding within the component.
*
* @default 'medium'
*/
size?: SizeOptions;
};

export type Props = SurfaceProps &
SizeableProps & {
/**
* Renders without a border.
*
* @default false
*/
isBorderless?: boolean;
/**
* Renders with rounded corners.
*
* @default true
*/
isRounded?: boolean;
/**
* Renders with elevation styles (box shadow).
*
* @default false
*/
isElevated?: boolean;
};

type BaseSubComponentProps = SizeableProps & {
/**
* The children elements.
*/
children: React.ReactNode;
/**
* Renders with a light gray background color.
*
* @default false
*/
isShady?: boolean;
};

export type BodyProps = BaseSubComponentProps & {
/**
* Determines if the component is scrollable.
*
* @default true
*/
isScrollable?: boolean;
};

type MarginalSubComponentProps = BaseSubComponentProps & {
/**
* Renders without a border.
*
* @default false
*/
isBorderless?: boolean;
className?: string;
};

export type HeaderProps = MarginalSubComponentProps;

export type FooterProps = MarginalSubComponentProps & {
justify: CSSProperties[ 'justifyContent' ];
};
1 change: 1 addition & 0 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"src/animate/**/*",
"src/base-control/**/*",
"src/base-field/**/*",
"src/card/**/*",
"src/dashicon/**/*",
"src/disabled/**/*",
"src/divider/**/*",
Expand Down

0 comments on commit a7ff42c

Please sign in to comment.