UNPKG

@elastic/eui

Version:

Elastic UI Component Library

152 lines (151 loc) 8.04 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.EuiTable = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _classnames = _interopRequireDefault(require("classnames")); var _services = require("../../services"); var _responsive_context = require("./mobile/responsive_context"); var _table_context = require("./table_context"); var _table = require("./table.styles"); var _component_defaults = require("../provider/component_defaults"); var _global_styling = require("../../global_styling"); var _const = require("./const"); var _sticky_scrollbar = require("./sticky_scrollbar"); var _sticky_header = require("./sticky_header/sticky_header"); var _provider = require("./store/provider"); var _react2 = require("@emotion/react"); var _excluded = ["children", "className", "compressed", "tableLayout", "hasBackground", "responsiveBreakpoint", "scrollableInline", "stickyScrollbar", "stickyHeader"]; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * EuiTable is a low-level building block component used to render tabular data * in a customized way. * * It should only be used when confirmed that [EuiBasicTable]{@link EuiBasicTable} * and [EuiInMemoryTable]{@link EuiInMemoryTable} are not flexible enough * for the purposes of the job. * * @see {@link https://eui.elastic.co/docs/components/tables/custom/|EuiTable documentation} */ var EuiTable = exports.EuiTable = function EuiTable(originalProps) { var _usePropsWithComponen = (0, _component_defaults.usePropsWithComponentDefaults)('EuiTable', originalProps), children = _usePropsWithComponen.children, className = _usePropsWithComponen.className, compressed = _usePropsWithComponen.compressed, _usePropsWithComponen2 = _usePropsWithComponen.tableLayout, tableLayout = _usePropsWithComponen2 === void 0 ? 'fixed' : _usePropsWithComponen2, _usePropsWithComponen3 = _usePropsWithComponen.hasBackground, hasBackground = _usePropsWithComponen3 === void 0 ? true : _usePropsWithComponen3, responsiveBreakpoint = _usePropsWithComponen.responsiveBreakpoint, _usePropsWithComponen4 = _usePropsWithComponen.scrollableInline, scrollableInline = _usePropsWithComponen4 === void 0 ? false : _usePropsWithComponen4, _usePropsWithComponen5 = _usePropsWithComponen.stickyScrollbar, stickyScrollbar = _usePropsWithComponen5 === void 0 ? false : _usePropsWithComponen5, _usePropsWithComponen6 = _usePropsWithComponen.stickyHeader, stickyHeader = _usePropsWithComponen6 === void 0 ? false : _usePropsWithComponen6, rest = (0, _objectWithoutProperties2.default)(_usePropsWithComponen, _excluded); var tableWrapperRef = (0, _react.useRef)(null); var tableRef = (0, _react.useRef)(null); var isResponsive = (0, _responsive_context.useIsEuiTableResponsive)(responsiveBreakpoint); var classes = (0, _classnames.default)('euiTable', className); var styles = (0, _services.useEuiMemoizedStyles)(_table.euiTableStyles); var tableStyles = [styles.euiTable, scrollableInline && styles.euiTableScrollableInline, styles.layout[tableLayout], (!compressed || isResponsive) && styles.uncompressed, compressed && !isResponsive && styles.compressed, hasBackground && styles.hasBackground, isResponsive ? styles.mobile : styles.desktop]; var cssStyles = [(0, _global_styling.euiContainerCSS)('normal', _const.EUI_TABLE_CSS_CONTAINER_NAME, true), scrollableInline && styles.scrollableWrapper]; return (0, _react2.jsx)(_provider.EuiTableStoreProvider, null, stickyHeader && (0, _react2.jsx)(_sticky_header.EuiTableStickyHeader, { scrollableInline: scrollableInline, tableRef: tableRef, tableWrapperRef: tableWrapperRef, compressed: compressed, isResponsive: isResponsive }), (0, _react2.jsx)("div", { css: cssStyles, ref: tableWrapperRef }, (0, _react2.jsx)("table", (0, _extends2.default)({ tabIndex: -1, css: tableStyles, className: classes, ref: tableRef }, rest), (0, _react2.jsx)(_responsive_context.EuiTableIsResponsiveContext.Provider, { value: isResponsive }, (0, _react2.jsx)(_table_context.EuiTableVariantContext.Provider, { value: { hasBackground: hasBackground } }, children)))), scrollableInline && stickyScrollbar && (0, _react2.jsx)(_sticky_scrollbar.EuiTableStickyScrollbar, { tableWrapperRef: tableWrapperRef })); }; EuiTable.propTypes = { compressed: _propTypes.default.bool, /** * Named breakpoint. Below this size, the table will collapse * into responsive cards. * * Pass `false` to never collapse to a mobile view, or inversely, * `true` to always render mobile-friendly cards. * * @default m */ responsiveBreakpoint: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.bool.isRequired]), /** * Sets the table-layout CSS property * @default 'fixed' */ tableLayout: _propTypes.default.oneOf(["fixed", "auto"]), /** * Toggle the table's background * @default true */ hasBackground: _propTypes.default.bool, /** * Allow the table to grow over 100% of the container inline size * (width in horizontal writing-mode) and enable scrolling on overflow. * * This should only be used with [`tableLayout`]{@link EuiTableProps#tableLayout} * set to `auto`. * @beta * @default false */ scrollableInline: _propTypes.default.bool, /** * Make the horizontal scrollbar visible even if the table is larger * than the viewport height. Useful for long tables when the native browser * scrollbar is at the bottom of the table and hard to reach. * * This prop requires [`scrollableInline`](#scrollableInline) to be `true`. * @beta * @default false */ stickyScrollbar: _propTypes.default.bool, /** * When enabled, the table header will stick to the top of the viewport as users * scroll through long tables. This enhances usability by maintaining column * context during vertical scrolling and unifies the scrolling experience * between EuiTable components and EuiDataGrid. * * This feature should be used in places where it's possible for the table * to grow longer than the viewport. * * @beta * @default false */ stickyHeader: _propTypes.default.bool, className: _propTypes.default.string, "aria-label": _propTypes.default.string, "data-test-subj": _propTypes.default.string, css: _propTypes.default.any };