UNPKG

@fluentui/react-northstar

Version:
105 lines (103 loc) 3.79 kB
import _invoke from "lodash/invoke"; import * as customPropTypes from '@fluentui/react-proptypes'; import { tableCellBehavior } from '@fluentui/accessibility'; import { Ref } from '@fluentui/react-component-ref'; import * as PropTypes from 'prop-types'; import * as React from 'react'; import { childrenExist, commonPropTypes, createShorthandFactory } from '../../utils'; import { useTelemetry, useStyles, useFluentContext, getElementType, useUnhandledProps, useAccessibility } from '@fluentui/react-bindings'; import { Box } from '../Box/Box'; export var tableCellClassName = 'ui-table__cell'; export var tableCellSlotClassNames = { content: tableCellClassName + "__content" }; /** * Component represents a table cell. */ export var TableCell = /*#__PURE__*/function () { var TableCell = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = useFluentContext(); var _useTelemetry = useTelemetry(TableCell.displayName, context.telemetry), setStart = _useTelemetry.setStart, setEnd = _useTelemetry.setEnd; setStart(); var cellRef = React.useRef(); var children = props.children, content = props.content, truncateContent = props.truncateContent, className = props.className, design = props.design, styles = props.styles, variables = props.variables; var hasChildren = childrenExist(children); var ElementType = getElementType(props); var unhandledProps = useUnhandledProps(TableCell.handledProps, props); var getA11yProps = useAccessibility(props.accessibility, { debugName: TableCell.displayName, actionHandlers: { focusCell: function focusCell(e) { e.preventDefault(); cellRef.current.focus(); }, performClick: function performClick(e) { if (e.currentTarget === e.target) { _invoke(props, 'onClick', e, props); e.preventDefault(); } } }, rtl: context.rtl }); var _useStyles = useStyles(TableCell.displayName, { className: tableCellClassName, mapPropsToStyles: function mapPropsToStyles() { return { truncateContent: truncateContent }; }, mapPropsToInlineStyles: function mapPropsToInlineStyles() { return { className: className, design: design, styles: styles, variables: variables }; }, rtl: context.rtl }), classes = _useStyles.classes, resolvedStyles = _useStyles.styles; var element = /*#__PURE__*/React.createElement(Ref, { innerRef: cellRef }, getA11yProps.unstable_wrapWithFocusZone( /*#__PURE__*/React.createElement(ElementType, getA11yProps('root', Object.assign({ className: classes.root, ref: ref }, unhandledProps)), hasChildren ? children : Box.create(content, { defaultProps: function defaultProps() { return { className: tableCellSlotClassNames.content, styles: resolvedStyles.content }; } })))); setEnd(); return element; }); TableCell.displayName = 'TableCell'; TableCell.propTypes = Object.assign({}, commonPropTypes.createCommon({ content: false }), { content: customPropTypes.every([customPropTypes.disallow(['children']), PropTypes.oneOfType([PropTypes.arrayOf(customPropTypes.nodeContent), customPropTypes.nodeContent])]), truncateContent: PropTypes.bool }); TableCell.handledProps = Object.keys(TableCell.propTypes); TableCell.defaultProps = { accessibility: tableCellBehavior }; TableCell.create = createShorthandFactory({ Component: TableCell, mappedProp: 'content' }); return TableCell; }(); //# sourceMappingURL=TableCell.js.map