semantic-ui-react
Version:
The official Semantic-UI-React integration.
105 lines (85 loc) • 3.86 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _without from "lodash-es/without";
import cx from 'clsx';
import PropTypes from 'prop-types';
import React from 'react';
import { childrenUtils, createShorthandFactory, customPropTypes, getElementType, getUnhandledProps, SUI, useKeyOnly, useTextAlignProp, useVerticalAlignProp, useWidthProp } from '../../lib';
import Icon from '../../elements/Icon';
/**
* A table row can have cells.
*/
function TableCell(props) {
var active = props.active,
children = props.children,
className = props.className,
collapsing = props.collapsing,
content = props.content,
disabled = props.disabled,
error = props.error,
icon = props.icon,
negative = props.negative,
positive = props.positive,
selectable = props.selectable,
singleLine = props.singleLine,
textAlign = props.textAlign,
verticalAlign = props.verticalAlign,
warning = props.warning,
width = props.width;
var classes = cx(useKeyOnly(active, 'active'), useKeyOnly(collapsing, 'collapsing'), useKeyOnly(disabled, 'disabled'), useKeyOnly(error, 'error'), useKeyOnly(negative, 'negative'), useKeyOnly(positive, 'positive'), useKeyOnly(selectable, 'selectable'), useKeyOnly(singleLine, 'single line'), useKeyOnly(warning, 'warning'), useTextAlignProp(textAlign), useVerticalAlignProp(verticalAlign), useWidthProp(width, 'wide'), className);
var rest = getUnhandledProps(TableCell, props);
var ElementType = getElementType(TableCell, props);
if (!childrenUtils.isNil(children)) {
return /*#__PURE__*/React.createElement(ElementType, _extends({}, rest, {
className: classes
}), children);
}
return /*#__PURE__*/React.createElement(ElementType, _extends({}, rest, {
className: classes
}), Icon.create(icon), content);
}
TableCell.handledProps = ["active", "as", "children", "className", "collapsing", "content", "disabled", "error", "icon", "negative", "positive", "selectable", "singleLine", "textAlign", "verticalAlign", "warning", "width"];
TableCell.defaultProps = {
as: 'td'
};
TableCell.propTypes = process.env.NODE_ENV !== "production" ? {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** A cell can be active or selected by a user. */
active: PropTypes.bool,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** A cell can be collapsing so that it only uses as much space as required. */
collapsing: PropTypes.bool,
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** A cell can be disabled. */
disabled: PropTypes.bool,
/** A cell may call attention to an error or a negative value. */
error: PropTypes.bool,
/** Add an Icon by name, props object, or pass an <Icon /> */
icon: customPropTypes.itemShorthand,
/** A cell may let a user know whether a value is bad. */
negative: PropTypes.bool,
/** A cell may let a user know whether a value is good. */
positive: PropTypes.bool,
/** A cell can be selectable. */
selectable: PropTypes.bool,
/** A cell can specify that its contents should remain on a single line and not wrap. */
singleLine: PropTypes.bool,
/** A table cell can adjust its text alignment. */
textAlign: PropTypes.oneOf(_without(SUI.TEXT_ALIGNMENTS, 'justified')),
/** A table cell can adjust its text alignment. */
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
/** A cell may warn a user. */
warning: PropTypes.bool,
/** A table can specify the width of individual columns independently. */
width: PropTypes.oneOf(SUI.WIDTHS)
} : {};
TableCell.create = createShorthandFactory(TableCell, function (content) {
return {
content: content
};
});
export default TableCell;