Skip to content

Commit

Permalink
Add types to <Card /> and its subcomponents
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jun 9, 2021
1 parent a8f786a commit 77445ff
Show file tree
Hide file tree
Showing 8 changed files with 114 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 & { className: string } } 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 & { className: string } } 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 { import('../types').MediaProps & 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
87 changes: 87 additions & 0 deletions packages/components/src/card/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* 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';

export type Props = SurfaceProps & {
/**
* Renders without a border.
*
* @default false
*/
isBorderless?: boolean;
/**
* Renders with rounded corners.
*
* @default true
*/
isRounded?: boolean;
/**
* Determines the amount of padding within the component.
*
* @default 'medium'
*/
size?: SizeOptions;
/**
* Renders with elevation styles (box shadow).
*
* @default false
*/
isElevated?: boolean;
};

type BaseSubComponentProps = {
/**
* The children elements.
*/
children: React.ReactNode;
/**
* Renders with a light gray background color.
*
* @default false
*/
isShady?: boolean;
/**
* Determines the amount of padding within the component.
*
* @default 'medium'
*/
size?: SizeOptions;
};

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

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

export type FooterProps = HeaderProps & {
justify: CSSProperties[ 'justifyContent' ];
};

export type MediaProps = {
/**
* The children elements.
*/
children: React.ReactNode;
};
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 77445ff

Please sign in to comment.