React 组件封装之 Card 卡片

一、Card 卡片

组件说明:
使列表成为卡片形式的布局。

效果展示:

在这里插入图片描述

二、使用案例

import {Card} from 'share';
import React from 'react';
export default class Example extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
          dataList:[{
	         productImgs:"",
	         desc:"这是一段描述",
	         createTime:"2019-9-29",
	         productPrice:200
         }]
       }
    }
    render(){
     const {dataList} = this.props;
      return      <div className="cm-plr-018">
                    {dataList.length>0?dataList.map((item,index)=>{
                            var productImgs = item.productImgs && item.productImgs.split(",");
                            var desc = item.productDesc && item.productDesc.slice(0,28);
                            return(
                                <Card key={index}>
                                    <div className="cm-flex cm-jc-sb cm-ai-c cm-plr-009 cm-ptb-018">
                                        <div className="cm-flex cm-ai-c">
                                            <img src={productImgs[0]} alt="" className="cm-img-14"/>
                                            <div className="cm-ml-018 cm-flex-1">
                                                <div className="cm-c-333 cm-fs-026">{desc}</div>
                                                <div className="cm-c-main cm-fs-030 cm-mt-018">{item.productPrice}</div>
                                                <div className="cm-c-999 cm-pt-018 cm-fs-022">{getTimeFormat(item.createTime)}</div>
                                            </div>
                                        </div>
                                    </div>                                 
                                </Card>
                            )
                        }):                    
                    }
                </div>
    }
}

三、API 使用指南

属性说明类型默认值
onClick点击卡片的回调Function

四、源代码

index.js

import React from 'react';
import {defaultProps} from './defaultProps';
import './index.css';
export default class Card extends React.Component {
    static defaultProps = defaultProps;
    render(){
        let {onClick,prefixCls} = this.props;
        return(
            <div className={prefixCls} onClick={()=>onClick?onClick():""}>
                {this.props.children}
        </div>
        )
    }
}

index.less

@import '../default';
@prefixCls: s-card;

/* 默认搜索bar */
.@{prefixCls}{
  //display: flex;
  margin: (@size-10)-2 0;
  padding:(@size-10)/(@size-10);
  box-shadow: 2px 2px 2px 2px #eee;
  background: #fff;
  border-radius: 1px;
}

defaultProps.js

export const defaultProps = {
    prefixCls: 's-card',
};
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值