@elastic/eui
Version:
Elastic UI Component Library
82 lines (81 loc) • 4.53 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
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.
*/
import React, { useRef } from 'react';
import classNames from 'classnames';
import { useEuiMemoizedStyles } from '../../services';
import { useIsEuiTableResponsive, EuiTableIsResponsiveContext } from './mobile/responsive_context';
import { EuiTableVariantContext } from './table_context';
import { euiTableStyles } from './table.styles';
import { usePropsWithComponentDefaults } from '../provider/component_defaults';
import { euiContainerCSS } from '../../global_styling';
import { EUI_TABLE_CSS_CONTAINER_NAME } from './const';
import { EuiTableStickyScrollbar } from './sticky_scrollbar';
import { EuiTableStickyHeader } from './sticky_header/sticky_header';
import { EuiTableStoreProvider } from './store/provider';
import { jsx as ___EmotionJSX } from "@emotion/react";
/**
* 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}
*/
export var EuiTable = function EuiTable(originalProps) {
var _usePropsWithComponen = 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 = _objectWithoutProperties(_usePropsWithComponen, _excluded);
var tableWrapperRef = useRef(null);
var tableRef = useRef(null);
var isResponsive = useIsEuiTableResponsive(responsiveBreakpoint);
var classes = classNames('euiTable', className);
var styles = useEuiMemoizedStyles(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 = [euiContainerCSS('normal', EUI_TABLE_CSS_CONTAINER_NAME, true), scrollableInline && styles.scrollableWrapper];
return ___EmotionJSX(EuiTableStoreProvider, null, stickyHeader && ___EmotionJSX(EuiTableStickyHeader, {
scrollableInline: scrollableInline,
tableRef: tableRef,
tableWrapperRef: tableWrapperRef,
compressed: compressed,
isResponsive: isResponsive
}), ___EmotionJSX("div", {
css: cssStyles,
ref: tableWrapperRef
}, ___EmotionJSX("table", _extends({
tabIndex: -1,
css: tableStyles,
className: classes,
ref: tableRef
}, rest), ___EmotionJSX(EuiTableIsResponsiveContext.Provider, {
value: isResponsive
}, ___EmotionJSX(EuiTableVariantContext.Provider, {
value: {
hasBackground: hasBackground
}
}, children)))), scrollableInline && stickyScrollbar && ___EmotionJSX(EuiTableStickyScrollbar, {
tableWrapperRef: tableWrapperRef
}));
};