choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
198 lines (160 loc) • 4.31 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import { Component } from 'react';
import PropTypes from 'prop-types';
import { get } from 'mobx';
import { ColumnAlign, ColumnLock } from './enum';
import { ShowHelp } from '../field/enum';
export var defaultMinWidth = 100;
/* eslint-disable react/prefer-stateless-function,react/no-unused-prop-types */
var Column =
/*#__PURE__*/
function (_Component) {
_inherits(Column, _Component);
var _super = _createSuper(Column);
function Column() {
_classCallCheck(this, Column);
return _super.apply(this, arguments);
}
return Column;
}(Component);
export { Column as default };
Column.propTypes = {
/**
* 列对照的字段名
*/
name: PropTypes.string,
/**
* 列宽
* 不推荐给所有列设置宽度,而是给某一列不设置宽度达到自动宽度的效果
*/
width: PropTypes.number,
/**
* 最小列宽
*/
minWidth: PropTypes.number,
/**
* 列头
*/
header: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func]),
/**
* 列脚
*/
footer: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func]),
/**
* 单元格渲染回调
*/
renderer: PropTypes.func,
/**
* 编辑器
*/
editor: PropTypes.oneOfType([PropTypes.element, PropTypes.func, PropTypes.bool]),
/**
* 是否锁定
* 可选值: false | true | 'left' | 'right'
* @default false
*/
lock: PropTypes.oneOf([ColumnLock.left, ColumnLock.right, true, false]),
/**
* 文字对齐方式
* 可选值: 'left' | 'center' | 'right'
*/
align: PropTypes.oneOf([ColumnAlign.left, ColumnAlign.center, ColumnAlign.right]),
/**
* 是否可调整宽度
* @default true
*/
resizable: PropTypes.bool,
/**
* 是否可排序
* @default false
*/
sortable: PropTypes.bool,
/**
* 是否可隐藏,设为false时不会出现在列过滤选项中
* @default true
*/
hideable: PropTypes.bool,
/**
* 是否可排序
* @default false
*/
/**
* 列头提示信息
*/
help: PropTypes.string,
/**
* 显示提示信息的方式
*
*/
showHelp: PropTypes.oneOf([ShowHelp.tooltip, ShowHelp.newLine, ShowHelp.none]),
hidden: PropTypes.bool,
colSpan: PropTypes.number,
rowSpan: PropTypes.number,
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
};
Column.__PRO_TABLE_COLUMN = true;
Column.defaultProps = {
hidden: false,
lock: false,
resizable: true,
sortable: false,
hideable: true,
minWidth: defaultMinWidth,
showHelp: ShowHelp.tooltip
};
export function minColumnWidth(col) {
var hidden = get(col, 'hidden');
if (hidden) {
return 0;
}
var width = get(col, 'width');
var min = get(col, 'minWidth');
var minWidth = min === undefined ? defaultMinWidth : min;
if (width === undefined) {
return minWidth;
}
return Math.min(width, minWidth);
}
export function columnWidth(col) {
var hidden = get(col, 'hidden');
if (hidden) {
return 0;
}
var width = get(col, 'width');
if (width === undefined) {
var minWidth = get(col, 'minWidth');
if (minWidth === undefined) {
return defaultMinWidth;
}
return minWidth;
}
return width;
}
//# sourceMappingURL=Column.js.map