All files / src/components/Row index.js

0% Statements 0/15
100% Branches 0/0
100% Functions 0/0
0% Lines 0/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                                                                                                                                           
/**
 * @Component Row
 * @Type 布局组件
 * @Author 瞿龙俊 - qulongjun@shine.design
 * @Date 2019-03-16 02:02
 */
import React, {PureComponent} from 'react';
import _ from 'lodash';
import classNames from 'classnames';
import * as PropTypes from 'prop-types';
import {classPrefix} from '../../_variables';
import './style/index.scss';
 
/** 支持布局类型 */
const TYPES = ['flex'];
/** 交叉轴对齐方式 */
const ALIGN = ['top', 'middle', 'bottom'];
/** 主轴对齐方式 */
const JUSTIFY = ['start', 'end', 'center', 'space-around', 'space-between'];
 
class Row extends PureComponent {
 
  render() {
    const {
      justify,
      align,
      className,
      attributes,
      children,
    } = this.props;
 
    /** 计算样式 */
    const classes = classNames(
      `${classPrefix}-row`,
      `${classPrefix}-row--root`,
      {
        [`${classPrefix}-row--justify-${justify}`]: !_.isUndefined(justify),
        [`${classPrefix}-row--align-${align}`]: !_.isUndefined(align),
      },
      className,
    );
 
    return (
      <div
        className={classes}
        {...attributes}
      >
        {children}
      </div>
    );
  }
}
 
Row.propTypes = {
  /** 布局类型,目前仅支持 flex */
  type: PropTypes.oneOf(TYPES),
  /** 水平对齐方式,可选值:'start', 'end', 'center', 'space-around', 'space-between' */
  justify: PropTypes.oneOf(JUSTIFY),
  /** 垂直对齐方式,可选值:'top', 'middle', 'bottom' */
  align: PropTypes.oneOf(ALIGN),
  /** 用户自定义修饰符 */
  className: PropTypes.string,
  /** 用户自定义属性 */
  attributes: PropTypes.object,
};
 
Row.defaultProps = {
  type: 'flex',
  justify: 'start',
  align: 'top',
  className: '',
  attributes: {},
};
 
export default Row;