UNPKG

@fluentui/react-northstar

Version:
139 lines (137 loc) 7.31 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.tableSlotClassNames = exports.tableClassName = exports.Table = void 0; var _invoke2 = _interopRequireDefault(require("lodash/invoke")); var _map2 = _interopRequireDefault(require("lodash/map")); var _accessibility = require("@fluentui/accessibility"); var _reactBindings = require("@fluentui/react-bindings"); var customPropTypes = _interopRequireWildcard(require("@fluentui/react-proptypes")); var PropTypes = _interopRequireWildcard(require("prop-types")); var React = _interopRequireWildcard(require("react")); var _utils = require("../../utils"); var _TableRow = require("./TableRow"); var _TableCell = require("./TableCell"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var tableClassName = 'ui-table'; exports.tableClassName = tableClassName; var tableSlotClassNames = { header: tableClassName + "__header" }; exports.tableSlotClassNames = tableSlotClassNames; /** * A Table is used to display data in tabular layout * * @accessibility * Implements ARIA [Data Grid](https://www.w3.org/TR/wai-aria-practices/#dataGrid) design pattern for presenting tabular information. * When gridcell contains actionable element, use [gridCellWithFocusableElementBehavior](/components/table/accessibility#grid-cell-with-focusable-element-behavior-ts). [More information available in aria documentation.](https://www.w3.org/TR/wai-aria-practices/#gridNav_focus) * Use [gridCellMultipleFocusableBehavior](/components/table/accessibility#gridCellMultipleFocusableBehavior), when gridcell contains: * \- editable content * \- multiple actionable elements * \- component that utilizes arrow keys in its navigation, like menu button, dropdown, radio group, slider, etc. * [More information available in aria documentation.](https://www.w3.org/TR/wai-aria-practices/#gridNav_inside) * @accessibilityIssues * [NVDA narrate table title(aria-label) twice](https://github.com/nvaccess/nvda/issues/10548) * [Accessibility DOM > Table > gridcell > when gridcell is focused, then selected state is send to reader](https://bugs.chromium.org/p/chromium/issues/detail?id=1030378) * [JAWS narrate grid name twice, once as table and second time as grid](https://github.com/FreedomScientific/VFO-standards-support/issues/346) * [JAWS doesn't narrate grid column name, when focus is on actionable element in the cell] (https://github.com/FreedomScientific/VFO-standards-support/issues/348) * [aria-sort is not output at child elements](https://github.com/FreedomScientific/VFO-standards-support/issues/319) * [VoiceOver not announcing rows correctly for a grid with presentation elements inside](https://bugs.chromium.org/p/chromium/issues/detail?id=1054424) * VoiceOver doesn't narrate aria-rowcount value in table or grid */ var Table = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = (0, _reactBindings.useFluentContext)(); var _useTelemetry = (0, _reactBindings.useTelemetry)(Table.displayName, context.telemetry), setStart = _useTelemetry.setStart, setEnd = _useTelemetry.setEnd; setStart(); var children = props.children, rows = props.rows, header = props.header, compact = props.compact, accessibility = props.accessibility, className = props.className, design = props.design, styles = props.styles, variables = props.variables; var hasChildren = (0, _utils.childrenExist)(children); var ElementType = (0, _reactBindings.getElementType)(props); var unhandledProps = (0, _reactBindings.useUnhandledProps)(Table.handledProps, props); var getA11yProps = (0, _reactBindings.useAccessibility)(accessibility, { debugName: Table.displayName, rtl: context.rtl }); var _useStyles = (0, _reactBindings.useStyles)(Table.displayName, { className: tableClassName, mapPropsToInlineStyles: function mapPropsToInlineStyles() { return { className: className, design: design, styles: styles, variables: variables }; }, rtl: context.rtl }), classes = _useStyles.classes; var renderRows = function renderRows() { return (0, _map2.default)(rows, function (row) { return _TableRow.TableRow.create(row, { defaultProps: function defaultProps() { return getA11yProps('row', { compact: compact, onClick: function onClick(e, props) { (0, _invoke2.default)(row, 'onClick', e, props); } }); }, overrideProps: function overrideProps(predefinedProps) { return { variables: (0, _reactBindings.mergeVariablesOverrides)(variables, predefinedProps.variables) }; } }); }); }; var renderHeader = function renderHeader() { return _TableRow.TableRow.create(header, { defaultProps: function defaultProps() { return getA11yProps('row', { header: true, compact: compact, className: tableSlotClassNames.header }); }, overrideProps: function overrideProps(predefinedProps) { return { variables: (0, _reactBindings.mergeVariablesOverrides)(variables, predefinedProps.variables) }; } }); }; var element = getA11yProps.unstable_wrapWithFocusZone( /*#__PURE__*/React.createElement(ElementType, getA11yProps('root', Object.assign({ className: classes.root, ref: ref }, unhandledProps)), hasChildren && children, !hasChildren && renderHeader(), !hasChildren && renderRows())); setEnd(); return element; }); exports.Table = Table; Table.displayName = 'Table'; Table.Cell = _TableCell.TableCell; Table.Row = _TableRow.TableRow; Table.create = (0, _utils.createShorthandFactory)({ Component: Table }); Table.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon({ content: false }), { header: customPropTypes.itemShorthand, rows: customPropTypes.collectionShorthand, compact: PropTypes.bool }); Table.handledProps = Object.keys(Table.propTypes); Table.defaultProps = { accessibility: _accessibility.tableBehavior }; //# sourceMappingURL=Table.js.map