简体中文

卡片

卡片模块。

基础
import React, {Component} from 'react';
import {Card, Text} from 'hana-ui';

/**
 * @en
 * Base
 *
 * A base card example.
 *
 * @cn
 * 基础
 *
 * 一个基本的`Card`。
 */
export default class ExampleBase extends Component {
  render() {
    return (
      <div style={{background: '#fff', padding: 20}}>
        <Card title="Example Title" style={{width: 400}}>
          <section style={{display: 'flex', alignItems: 'center', padding: '6px 0'}}>
            <p style={{display: 'inline-block', fontSize: 14, marginRight: 10}}>Input:</p>
            <Text auto withIcon={false} />
          </section>
          <section style={{display: 'flex', alignItems: 'center', padding: '6px 0'}}>
            <p style={{display: 'inline-block', fontSize: 14, marginRight: 10}}>Input:</p>
            <Text auto withIcon={false} />
          </section>
        </Card>
      </div>
    );
  }
}

一个基本的Card

Example Title

Input:

Input:

可伸缩的卡片
import React, {Component} from 'react';
import {Card, Image, Button} from 'hana-ui';
import ExampleBlock from 'demo/ExampleBlock';

/**
 * @en
 * expand
 *
 * Create an expand card by using prop `expand`.
 * Use prop `expandIcon` to have a custom button.
 * Use prop `open` to control the card's open state.
 *
 * @cn
 * 可伸缩的卡片
 *
 * 使用属性`expand`使得卡片可以展开收起,`expandIcon`用以自定义展开收起的按钮,
 * `open`可以控制卡片的展开状态。
 */
export default class ExampleBase extends Component {
  state = {
    open: false
  }
  render() {
    return (
      <div style={{background: '#fff', paddingLeft: 20}}>
        <ExampleBlock
          cn={<p>使用<b className="sign"> defaultOpen </b>来控制卡片的初始展开</p>}
          en={<p>Using prop<b className="sign"> defaultOpen </b>to let the card open at first-time.</p>}
        >
          <Card title="Example Title" style={{width: 400}} expand defaultOpen>
            <Image src="https://t4.kn3.net/taringa/5/C/0/6/C/9/DogeDogOficial/59C.jpg" />
          </Card>
        </ExampleBlock>

        <ExampleBlock
          cn={<p>点击按钮来控制卡片的展开收起</p>}
          en={<p>Using Button to control open state with custom icon.</p>}
        >
          <Card
            title="Example Title"
            subtitle="(Sub)"
            style={{width: 400, marginBottom: 10}}
            expand
            expandIcon={<Button>replaced</Button>}
            open={this.state.open}
          >
            <Image src="https://t4.kn3.net/taringa/5/C/0/6/C/9/DogeDogOficial/59C.jpg" />
            Doge !
          </Card>
          <Button onClick={() => this.setState({open: !this.state.open})}>toggle</Button>
        </ExampleBlock>
      </div>
    );
  }
}

使用属性expand使得卡片可以展开收起,expandIcon用以自定义展开收起的按钮, open可以控制卡片的展开状态。

使用 defaultOpen 来控制卡片的初始展开

Example Title

点击按钮来控制卡片的展开收起

Example Title(Sub)
Doge !

属性说明

属性名 类型 默认值 说明
children node 子节点
title string 卡片的标题
subtitle string 卡片的副标题
titleStyle object 卡片标题的style
containerStyle object 卡片内容的style
icon node 卡片标题的icon
expand bool false 卡片是否可以伸缩
expandIcon node null 伸缩的图标
open bool 卡片的伸缩状态
defaultOpen bool false 是否默认打开
className string 卡片的class
onClick function onClick

未在文档中说明的属性将会被自动加到根元素或form元素上。