Skip to content

Commit

Permalink
fix(card): fix props and className (#1726)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed Dec 23, 2021
1 parent 997a2a4 commit c2cab83
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
3 changes: 1 addition & 2 deletions src/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import classNames from 'classnames';
import { usePrefixCls } from '@gio-design/utils';
import { CardProps } from './interfaces';
import WithRef from '../utils/withRef';
import { WithCommonProps } from '../utils/interfaces';

export const Card = WithRef<HTMLDivElement, WithCommonProps<CardProps>>(
export const Card = WithRef<HTMLDivElement, CardProps>(
(
{
fullWidthContent = false,
Expand Down
49 changes: 21 additions & 28 deletions src/card/CardMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,35 @@ import classNames from 'classnames';
import { isString } from 'lodash/fp';
import { CardMetaProps } from './interfaces';

const CardMeta: React.FC<CardMetaProps> = ({
image = '',
title,
description,
action,
...resetProps
}: CardMetaProps) => {
const prefixCls = usePrefixCls('card-meta');
const CardMeta = React.forwardRef<HTMLDivElement, CardMetaProps>(
({ image = '', title, description, action, className, ...resetProps }, ref) => {
const prefixCls = usePrefixCls('card-meta');

const renderImage = () => {
if (isString(image)) return image ? <img src={image} className={`${prefixCls}-image`} alt="" /> : null;
return React.cloneElement(image, { className: classNames(`${prefixCls}-image`, image.props.className) });
};
const renderImage = () => {
if (isString(image)) return image ? <img src={image} className={`${prefixCls}-image`} alt="" /> : null;
return React.cloneElement(image, { className: classNames(`${prefixCls}-image`, image.props.className) });
};

const renderOption = (opt: React.ReactNode, type: 'title' | 'description') =>
opt && React.cloneElement(<div />, { title: isString(opt) ? opt : '', className: `${prefixCls}-${type}` }, opt);
const renderOption = (opt: React.ReactNode, type: 'title' | 'description') =>
opt && React.cloneElement(<div />, { title: isString(opt) ? opt : '', className: `${prefixCls}-${type}` }, opt);

const renderDetail = () =>
(title || description) && (
<div className={`${prefixCls}-detail`}>
{renderOption(title, 'title')}
{renderOption(description, 'description')}
</div>
);
const renderDetail = () =>
(title || description) && (
<div className={`${prefixCls}-detail`}>
{renderOption(title, 'title')}
{renderOption(description, 'description')}
</div>
);

const renderAction = () => (title || description || image) && <div className={`${prefixCls}-action`}>{action}</div>;
const renderAction = () => (title || description || image) && <div className={`${prefixCls}-action`}>{action}</div>;

const renderHeader =
title || description || image ? (
<div className={`${prefixCls}`} {...resetProps}>
return title || description || image ? (
<div className={classNames(className, prefixCls)} ref={ref} {...resetProps}>
{renderImage()}
{renderDetail()}
{renderAction()}
</div>
) : null;

return renderHeader;
};
}
);
export default CardMeta;
6 changes: 1 addition & 5 deletions src/card/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface CardMetaProps extends Omit<React.HTMLAttributes<HTMLDivElement>
action?: React.ReactNode;
}

export interface CardProps {
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
/**
* 是否宽度平铺
*/
Expand All @@ -44,8 +44,4 @@ export interface CardProps {
* 自定义className前缀
*/
prefixCls?: string;
/**
* 自定义className
*/
className?: string;
}

1 comment on commit c2cab83

@vercel
Copy link

@vercel vercel bot commented on c2cab83 Dec 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.