Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Card: add types #32561

Merged
merged 5 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 & {
ciampo marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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