UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

478 lines 32.9 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { createElement as _createElement } from "react"; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; /* eslint-disable @typescript-eslint/no-explicit-any */ /** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { flexRender, } from '@tanstack/react-table'; import { forwardRef, Fragment, useCallback, useEffect, useMemo, useRef, useState, } from 'react'; import { classNames } from '../_common/defaultImports'; import { Menu } from '../context-menu'; import { IconButton } from '../icon-button'; import { Bars3CenterLeftIconOutline, BarsArrowDownIconOutline, BarsArrowUpIconOutline, ChevronDownIconSolid, ChevronLeftIconOutline, ChevronRightIconOutline, DatagridNodataIcon, EllipsisHorizontalIconOutline, } from '../icons'; import { LoadingSpinner } from '../loading-spinner'; import { Select } from '../select'; import { Skeleton } from '../skeleton'; import { Typography } from '../typography'; import { useDataGridContext } from './DataGridContext'; import { resizeColumn, ResizeDirection, userFriendlyPagination, } from './helpers'; import NoDataIllustration from './illustrations/NoData'; /** Table results per page, with the first option being the default */ const TABLE_RESULTS = { DEFAULT: 10, values: [10, 25, 50, 100], }; const getPaginationOptions = (pageSize) => { return [...new Set([...TABLE_RESULTS.values, pageSize])] .sort((a, b) => a - b) .map((option) => ({ value: option, label: `${option}`, })); }; export const DEFAULT_SORT_ACTIONS = (cell) => ({ asc: { title: 'Sort ascending', icon: _jsx(BarsArrowUpIconOutline, {}), onClick: () => cell.column.toggleSorting(false), }, desc: { title: 'Sort descending', icon: _jsx(BarsArrowDownIconOutline, {}), onClick: () => cell.column.toggleSorting(true), }, default: { title: 'Default sort', icon: _jsx(Bars3CenterLeftIconOutline, {}), onClick: () => cell.column.clearSorting(), }, }); const ResizingBar = ({ header, children, innerProps, }) => { const _a = innerProps || {}, { className = undefined, htmlAttributes = undefined } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); const { isKeyboardNavigationEnabled } = useDataGridContext(); const handleKeyDown = (event) => { if (event.key === 'ArrowLeft') { event.stopPropagation(); event.preventDefault(); resizeColumn(ResizeDirection.LEFT, header); } else if (event.key === 'ArrowRight') { event.stopPropagation(); event.preventDefault(); resizeColumn(ResizeDirection.RIGHT, header); } }; return (_jsx(_Fragment, { children: children || (_jsx("button", Object.assign({}, restInnerProps, { type: "button", className: classNames('ndl-data-grid-resizer', className, { 'ndl-data-grid-is-resizing': header.column.getIsResizing(), }), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), onKeyDown: handleKeyDown, "aria-label": "Resizing bar", tabIndex: isKeyboardNavigationEnabled ? -1 : 0 }, htmlAttributes))) })); }; const Scrollable = forwardRef(function Scrollable({ children, innerProps }, ref) { const _a = innerProps || {}, { className, htmlAttributes = undefined } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({ ref: ref }, restInnerProps, { className: classNames('ndl-data-grid-scrollable', className) }, htmlAttributes, { children: children }))); }); const Header = ({ children, innerProps }) => { const { tableProps, components } = useDataGridContext(); const { getHeaderGroups, getState } = tableProps; const _a = innerProps || {}, { className = undefined, htmlAttributes = undefined } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({}, restInnerProps, { role: "rowgroup", className: classNames('ndl-data-grid-thead', className, { 'ndl-data-grid-is-resizing': getState().columnSizingInfo.isResizingColumn, }) }, htmlAttributes, { children: children || (_jsx(_Fragment, { children: getHeaderGroups().map((headerGroup) => (_jsx("div", { className: "ndl-data-grid-tr", role: "row", children: headerGroup.headers.map((header) => components.HeaderCell && (_jsx(components.HeaderCell, { cell: header }, header.id))) }, headerGroup.id))) })) }))); }; export const ActionButton = ({ action, children, onClose, innerProps, }) => { const _a = innerProps || {}, { className, htmlAttributes = undefined } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); const { onClick } = action; const interceptedOnClick = useCallback((e) => { const providedOnClick = onClick || (innerProps === null || innerProps === void 0 ? void 0 : innerProps.onClick); if (typeof providedOnClick === 'function') { providedOnClick(e); } onClose(); }, [innerProps === null || innerProps === void 0 ? void 0 : innerProps.onClick, onClick, onClose]); const commonProps = Object.assign(Object.assign(Object.assign(Object.assign({}, restInnerProps), action), { className: classNames('ndl-data-grid-column-action', className), onClick: interceptedOnClick }), htmlAttributes); return _jsx(_Fragment, { children: children || _jsx(Menu.Item, Object.assign({}, commonProps)) }); }; const RowActionCell = ({ cell, innerIconButtonProps, innerMenuProps, }) => { var _a, _b; const { components, isSkeletonLoading, portalTarget } = useDataGridContext(); const actionsButtonRef = useRef(null); const [isActionsOpen, setIsActionsOpen] = useState(false); if (!cell || !cell.column.columnDef.meta || typeof ((_b = (_a = cell.column.columnDef) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.isActionCell) !== 'object') return null; const { actions, onOpenChange } = cell.column.columnDef.meta.isActionCell; if (isSkeletonLoading) return null; return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ as: "button", isClean: true, size: "medium", ariaLabel: `Row actions for row id: ${cell.row.id}`, ref: actionsButtonRef, isActive: isActionsOpen, onClick: () => { onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(!isActionsOpen); setIsActionsOpen(!isActionsOpen); } }, innerIconButtonProps, { htmlAttributes: Object.assign({ tabIndex: 0 }, innerIconButtonProps === null || innerIconButtonProps === void 0 ? void 0 : innerIconButtonProps.htmlAttributes), children: (innerIconButtonProps === null || innerIconButtonProps === void 0 ? void 0 : innerIconButtonProps.children) || _jsx(EllipsisHorizontalIconOutline, {}) })), _jsx(Menu, Object.assign({ isOpen: isActionsOpen, anchorRef: actionsButtonRef, onClose: () => { onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false); setIsActionsOpen(false); } }, innerMenuProps, { portalTarget: portalTarget, children: (innerMenuProps === null || innerMenuProps === void 0 ? void 0 : innerMenuProps.children) || (_jsx(Menu.Items, { children: actions.map((action, i) => components.ActionButton && (_jsx(components.ActionButton, { action: Object.assign(Object.assign({}, action), { onClick: (e) => { var _a; (_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action, e, cell); } }), onClose: () => setIsActionsOpen(false) }, `${cell.column.id}-action-${i}`))) })) }))] })); }; export const ColumnControls = ({ cell, children, innerProps, }) => { var _a; const _b = innerProps || {}, { className, htmlAttributes } = _b, restInnerProps = __rest(_b, ["className", "htmlAttributes"]); const { components, portalTarget } = useDataGridContext(); const sort = cell.column.getIsSorted(); const canSort = cell.column.getCanSort(); const { hasDefaultSortingActions = true, actions } = ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.columnActions) || {}; const sortingActions = useMemo(() => { if (canSort) { if (sort !== 'asc' && sort !== 'desc') { return [ DEFAULT_SORT_ACTIONS(cell).asc, DEFAULT_SORT_ACTIONS(cell).desc, ]; } if (sort === 'asc') { return [ DEFAULT_SORT_ACTIONS(cell).default, DEFAULT_SORT_ACTIONS(cell).desc, ]; } if (sort === 'desc') { return [ DEFAULT_SORT_ACTIONS(cell).default, DEFAULT_SORT_ACTIONS(cell).asc, ]; } } // Default case return []; }, [sort, cell, canSort]); const newActions = [ ...(hasDefaultSortingActions ? sortingActions : []), ...(actions !== null && actions !== void 0 ? actions : []), ]; const actionsButtonRef = useRef(null); const [isActionsOpen, setIsActionsOpen] = useState(false); if (!actions || actions.length === 0) return null; return newActions.length > 0 ? (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('ndl-header-action-group', className), style: { zIndex: 100000, position: 'relative', right: '0px', } }, htmlAttributes, { children: children || (_jsxs(Fragment, { children: [_jsx(IconButton, { isClean: true, size: "small", ariaLabel: `Column actions for ${cell.column.id} column`, ref: actionsButtonRef, isActive: isActionsOpen, onClick: () => { setIsActionsOpen(!isActionsOpen); }, htmlAttributes: { tabIndex: 0, }, children: _jsx(ChevronDownIconSolid, {}) }), _jsx(Menu, { isOpen: isActionsOpen, anchorRef: actionsButtonRef, onClose: () => setIsActionsOpen(false), portalTarget: portalTarget, children: _jsx(Menu.Items, { children: newActions.map((action, i) => components.ActionButton && (_jsx(components.ActionButton, { action: action, onClose: () => setIsActionsOpen(false) }, `${cell.column.id}-action-${i}`))) }) })] })) }))) : null; }; const HeaderCell = ({ cell, children, innerProps, }) => { const { components, isResizable, isKeyboardNavigationEnabled } = useDataGridContext(); const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); const sort = cell.column.getIsSorted(); const canSort = cell.column.getCanSort(); const ariaSortRole = useMemo(() => { switch (sort) { case 'asc': return 'ascending'; case 'desc': return 'descending'; default: return 'none'; } }, [sort]); const Icon = useMemo(() => { switch (sort) { case 'asc': return _jsx(BarsArrowUpIconOutline, { className: "ndl-header-icon" }); case 'desc': return _jsx(BarsArrowDownIconOutline, { className: "ndl-header-icon" }); default: return (_jsx(Bars3CenterLeftIconOutline, { className: "ndl-hoverable-indicator ndl-header-icon" })); } }, [sort]); const ariaDescription = useMemo(() => { return canSort ? `Press ENTER or SPACE to sort column ${cell.column.id}` : `Column id: ${cell.column.id}`; }, [canSort, cell.column.id]); const ref = useRef(null); const isActionColumn = useMemo(() => { var _a; return typeof ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.isActionCell) === 'object'; }, [cell.column.columnDef.meta]); const Tag = canSort ? 'button' : 'div'; const InnerHeaderCell = () => (_jsxs("div", { className: "ndl-header-cell", children: [cell.isPlaceholder ? null : flexRender(cell.column.columnDef.header, cell.getContext()), canSort && Icon] })); return (_jsx("div", Object.assign({ tabIndex: isKeyboardNavigationEnabled && !isActionColumn ? 0 : undefined, role: "columnheader" }, restInnerProps, { className: classNames('ndl-data-grid-th', className, { 'ndl-focusable-cell': isKeyboardNavigationEnabled, 'ndl-data-grid-row-action': isActionColumn, 'ndl-data-grid-pinned-cell': cell.column.getIsPinned(), 'ndl-data-grid-pinned-cell-right': cell.column.getIsPinned() === 'right', 'ndl-data-grid-pinned-cell-left': cell.column.getIsPinned() === 'left', 'ndl-data-grid-is-resizing': cell.column.getIsResizing(), }), "aria-sort": ariaSortRole, style: { width: isActionColumn ? 40 : cell.getSize(), maxWidth: cell.column.columnDef.maxSize ? `${cell.column.columnDef.maxSize}px` : 'none', } }, (isKeyboardNavigationEnabled ? { onKeyDown: (e) => { if (isResizable && e.altKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) { const direction = e.key === 'ArrowLeft' ? ResizeDirection.LEFT : ResizeDirection.RIGHT; resizeColumn(direction, cell); e.preventDefault(); e.stopPropagation(); return; } }, } : {}), htmlAttributes, { ref: ref, children: children || (_jsxs(_Fragment, { children: [_jsx(Tag, { className: "ndl-header-group", style: { cursor: canSort ? 'pointer' : 'default', }, "aria-describedby": ariaDescription, onClick: () => canSort && cell.column.toggleSorting(), tabIndex: canSort ? 0 : undefined, children: components.HeaderTitle ? (_jsx(components.HeaderTitle, { cell: cell, children: _jsx(InnerHeaderCell, {}) })) : (_jsx(InnerHeaderCell, {})) }), components.ColumnControls && (_jsx(components.ColumnControls, { cell: cell })), isResizable && cell.column.getCanResize() && components.ResizingBar && _jsx(components.ResizingBar, { header: cell })] })) }), cell.id)); }; const HeaderTitle = ({ cell, children, innerProps, }) => { const _a = innerProps || {}, { htmlAttributes } = _a, restInnerProps = __rest(_a, ["htmlAttributes"]); const { column, id } = cell; const title = typeof column.columnDef.header === 'string' ? column.columnDef.header : id; return (_jsx("div", Object.assign({}, restInnerProps, { title: title }, htmlAttributes, { children: children }))); }; const Body = ({ children, innerProps }) => { const { tableProps, components, isLoading } = useDataGridContext(); const { getRowModel } = tableProps; const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('ndl-data-grid-tbody', className), role: "rowgroup", "aria-busy": isLoading ? 'true' : 'false' }, htmlAttributes, { children: children || (_jsxs(_Fragment, { children: [isLoading && components.LoadingPlaceholder && (_jsx(components.LoadingPlaceholder, {})), !isLoading && getRowModel().rows.length === 0 && components.NoDataPlaceholder && _jsx(components.NoDataPlaceholder, {}), !isLoading && getRowModel().rows.map((row, idx) => components.BodyRow && (_jsx(components.BodyRow, { row: row }, `table-row-${idx}`)))] })) }))); }; const BodyCell = ({ cell, children, innerProps, }) => { var _a, _b, _c; const isResizing = cell.column.getIsResizing(); const _d = innerProps || {}, { className, htmlAttributes } = _d, restInnerProps = __rest(_d, ["className", "htmlAttributes"]); const isActionColumn = Boolean((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.isActionCell); const isInlineEditCell = Boolean((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.isInlineEditCell); const isDropDownCell = Boolean((_c = cell.column.columnDef.meta) === null || _c === void 0 ? void 0 : _c.isDropDownCell); const isCustomCell = isActionColumn || isDropDownCell; const { isKeyboardNavigationEnabled, isSkeletonLoading, skeletonProps } = useDataGridContext(); return (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('ndl-data-grid-td', className, { 'ndl-focusable-cell': isKeyboardNavigationEnabled, 'ndl-data-grid-is-resizing': isResizing, 'ndl-data-grid-custom-cell': isCustomCell, 'ndl-data-grid-row-action': isActionColumn, 'ndl-data-grid-inline-edit': isInlineEditCell, 'ndl-data-grid-dropdown-cell': isDropDownCell, 'ndl-data-grid-pinned-cell': cell.column.getIsPinned(), 'ndl-data-grid-pinned-cell-right': cell.column.getIsPinned() === 'right', 'ndl-data-grid-pinned-cell-left': cell.column.getIsPinned() === 'left', }), role: "cell", tabIndex: isKeyboardNavigationEnabled ? 0 : undefined, style: Object.assign(Object.assign({}, innerProps === null || innerProps === void 0 ? void 0 : innerProps.style), { width: isActionColumn ? 40 : cell.column.getSize() }) }, htmlAttributes, { children: _jsx(Skeleton, Object.assign({ onBackground: "weak", variant: "rectangular", width: "100%" }, skeletonProps, { isLoading: isSkeletonLoading && !isActionColumn, children: children || flexRender(cell.column.columnDef.cell, cell.getContext()) })) }), cell.id)); }; const BodyRow = ({ row, children, innerProps, }) => { const { components } = useDataGridContext(); const _a = innerProps || {}, { className, style = {}, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "style", "htmlAttributes"]); return (_createElement("div", Object.assign({}, restInnerProps, { key: row.id, className: classNames('ndl-data-grid-tr', className), role: "row", style: Object.assign({ display: 'flex', flexDirection: 'row' }, style) }, htmlAttributes), children || (_jsx(_Fragment, { children: row .getVisibleCells() .map((cell) => components.BodyCell && (_jsx(components.BodyCell, { cell: cell }, cell.id))) })))); }; const TableResults = ({ children, innerProps, manualPagination, }) => { const { tableProps, isSkeletonLoading, skeletonProps } = useDataGridContext(); const { getState, getRowModel, getCoreRowModel } = tableProps; const { pagination: { pageSize, pageIndex }, } = getState(); const { rows } = getRowModel(); const { from, to, totalRows } = useMemo(() => manualPagination || { from: 1 + pageIndex * pageSize, to: rows.length + pageIndex * pageSize, totalRows: getCoreRowModel().rows.length, }, [pageIndex, pageSize, manualPagination, rows, getCoreRowModel]); const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx(Skeleton, Object.assign({ onBackground: "weak", variant: "rectangular" }, skeletonProps, { isLoading: isSkeletonLoading, children: _jsx("span", Object.assign({}, restInnerProps, { className: classNames('ndl-data-grid-results', className) }, htmlAttributes, { children: children || (_jsxs("span", { children: ["Showing", ' ', _jsx("b", { children: totalRows ? `${from}${to !== from ? `-${to}` : ''}` : 0 }), " of", ' ', _jsx("b", { children: totalRows }), " results"] })) })) }))); }; const RowsPerPage = ({ children, innerProps, menuPortalTarget: menuPortalTargetProp, }) => { const { tableProps, portalTarget } = useDataGridContext(); const { setPageSize, getState } = tableProps; const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); const { pagination: { pageSize }, } = getState(); const paginationOptions = getPaginationOptions(pageSize); const defaultPaginationOption = paginationOptions.find((option) => option.value === pageSize); const menuPortalTarget = menuPortalTargetProp === undefined ? portalTarget : menuPortalTargetProp; return (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('ndl-data-grid-rows-per-page', className) }, htmlAttributes, { children: children || (_jsxs(_Fragment, { children: ["Show", _jsx(Select, { type: "select", size: "medium", selectProps: { 'aria-label': 'Select page size', defaultValue: defaultPaginationOption, options: paginationOptions, isSearchable: false, menuPosition: 'fixed', menuPortalTarget: menuPortalTarget, onChange: (option) => { if (option) { setPageSize(option.value); } }, styles: { container: () => ({ width: '100%', }), }, } })] })) }))); }; const PaginationArrowButton = ({ action, children, innerProps, }) => { const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); const PaginationIcon = action === 'previous' ? ChevronLeftIconOutline : ChevronRightIconOutline; const ariaLabel = action === 'previous' ? 'Previous table page' : 'Next table page'; const classes = classNames('ndl-data-grid-pagination-icon-button', className); return (_jsx(IconButton, Object.assign({}, restInnerProps, { className: classes, ariaLabel: ariaLabel, isClean: true }, htmlAttributes, { children: children || _jsx(PaginationIcon, { className: "ndl-data-grid-pagination-icon" }) }))); }; const PaginationNumericButton = ({ currentIndex, isSelected, children, innerProps, }) => { const _a = innerProps || {}, { className, onClick, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "onClick", "htmlAttributes"]); return (_jsx("button", Object.assign({}, restInnerProps, { type: "button", "data-testid": `ndl-table-${currentIndex}`, className: classNames('ndl-data-grid-pagination-numeric-button', className, { 'ndl-not-selected-numeric': typeof currentIndex === 'number' && !isSelected, 'ndl-is-selected': isSelected, 'ndl-not-selected': !isSelected, }), onClick: (e) => typeof currentIndex === 'number' && onClick && onClick(e), tabIndex: typeof currentIndex === 'number' ? 0 : -1 }, htmlAttributes, { children: children || currentIndex }))); }; const PaginationNumericButtons = () => { const { tableProps, components } = useDataGridContext(); const { getState, setPageIndex, getPageCount } = tableProps; const { pagination: { pageIndex }, } = getState(); return (_jsx(_Fragment, { children: userFriendlyPagination(pageIndex + 1, getPageCount()).map((option, idx) => components.PaginationNumericButton && (_jsx(components.PaginationNumericButton /** Use index to avoid situations where two "..." values will appear, causing a key conflict */ , { innerProps: { onClick: () => typeof option === 'number' && setPageIndex(option - 1), }, currentIndex: option, isSelected: option === pageIndex + 1 }, `${option}-${idx}`))) })); }; const Pagination = ({ children, innerProps, }) => { const { tableProps, components } = useDataGridContext(); const { getCanPreviousPage, getCanNextPage, previousPage, nextPage } = tableProps; const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("nav", Object.assign({}, restInnerProps, { className: classNames('ndl-data-grid-nav', className), "aria-label": "Pagination" }, htmlAttributes, { children: children || (_jsxs(_Fragment, { children: [getCanPreviousPage() ? components.PaginationArrowButton && (_jsx(components.PaginationArrowButton, { action: "previous", innerProps: { htmlAttributes: { onClick: previousPage, }, } })) : null, components.PaginationNumericButtons && (_jsx(components.PaginationNumericButtons, {})), getCanNextPage() ? components.PaginationArrowButton && (_jsx(components.PaginationArrowButton, { action: "next", innerProps: { onClick: nextPage, } })) : null] })) }))); }; const Navigation = ({ children, innerProps, }) => { const { tableProps, components, isSkeletonLoading, skeletonProps } = useDataGridContext(); const { getPageCount } = tableProps; const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('ndl-data-grid-navigation', className) }, htmlAttributes, { children: _jsx(_Fragment, { children: children || (_jsxs(_Fragment, { children: [components.TableResults && _jsx(components.TableResults, {}), _jsx(Skeleton, Object.assign({ onBackground: "weak", variant: "rectangular", height: "36px" }, skeletonProps, { isLoading: isSkeletonLoading, children: _jsxs("div", { className: "ndl-data-grid-navigation-right-items", children: [getPageCount() > 1 && components.Pagination && (_jsx(components.Pagination, {})), components.RowsPerPage && _jsx(components.RowsPerPage, {})] }) }))] })) }) }))); }; const LoadingPlaceholder = ({ children, innerProps, }) => { const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('nld-table-placeholder-wrapper', className), role: "row" }, htmlAttributes, { children: children || (_jsx("div", { role: "cell", className: "ndl-data-grid-placeholder", children: _jsxs("div", { className: "ndl-data-grid-loading-placeholder", children: [_jsx(LoadingSpinner, {}), _jsx("h6", { children: "Loading data" })] }) })) }))); }; const NoDataPlaceholder = ({ children, innerProps, }) => { const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({}, restInnerProps, { className: classNames('nld-table-placeholder-wrapper', className), role: "row" }, htmlAttributes, { children: children || (_jsxs(NoDataPlaceholderContentWrapper, { children: [_jsx(NoDataIcon, {}), _jsx(Typography, { variant: "subheading-small", children: "No data available" })] })) }))); }; export const NoDataPlaceholderContentWrapper = ({ children, innerProps, }) => { const _a = innerProps || {}, { className, htmlAttributes } = _a, restInnerProps = __rest(_a, ["className", "htmlAttributes"]); return (_jsx("div", Object.assign({ role: "cell", className: classNames('ndl-data-grid-placeholder', className) }, restInnerProps, htmlAttributes, { children: children }))); }; const InlineEditCell = ({ cell, value, ariaLabel, }) => { var _a; const [inputValue, setInputValue] = useState(value); useEffect(() => { setInputValue(value); }, [value]); const { dataGridNav } = useDataGridContext(); if (!((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.isInlineEditCell)) { return null; } return (_jsx("input", { onChange: (e) => setInputValue(e.target.value), value: inputValue, onFocus: () => { dataGridNav.disable(); }, onKeyDown: (e) => { var _a, _b, _c, _d; if (e.key === 'Enter') { (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.isInlineEditCell) === null || _b === void 0 ? void 0 : _b.onEditChange(inputValue, cell); (_c = e.currentTarget.parentElement) === null || _c === void 0 ? void 0 : _c.focus(); return; } else if (e.key === 'Escape') { (_d = e.currentTarget.parentElement) === null || _d === void 0 ? void 0 : _d.focus(); return; } }, onBlur: () => { setInputValue(value); dataGridNav.enable(); }, "aria-label": ariaLabel })); }; const DropDownCell = ({ cell, options, // TODO v4: remove default value, default should be on the DataGrid root component portalTarget: portalTargetProp = document.body, ariaLabel, }) => { var _a; const { dataGridNav, portalTarget } = useDataGridContext(); const ref = useRef(null); if (!((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.isDropDownCell)) { return null; } const defaultOption = options.find((option) => { var _a; return option.value === ((_a = cell.getValue()) === null || _a === void 0 ? void 0 : _a.toString()); }); const menuPortalTarget = portalTargetProp === undefined ? portalTarget : portalTargetProp; return (_jsx(Select, { ref: ref, isFluid: true, hasBorder: false, style: { width: '100%', height: '100%' }, type: "select", size: "medium", selectProps: { defaultValue: defaultOption, options: options, menuPortalTarget: menuPortalTarget, menuPosition: 'fixed', styles: { container: () => ({ width: '100%', height: '100%' }), control: () => ({ backgroundColor: 'transparent', height: '100%', borderRadius: 0, }), }, onChange: (e) => { var _a, _b; const value = e === null || e === void 0 ? void 0 : e.value; (_b = (_a = cell === null || cell === void 0 ? void 0 : cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.isDropDownCell) === null || _b === void 0 ? void 0 : _b.onChange(value === null || value === void 0 ? void 0 : value.toString(), cell); dataGridNav.enable(); (ref === null || ref === void 0 ? void 0 : ref.current) && dataGridNav.focusParentCell(ref.current); }, onMenuOpen: () => { dataGridNav.disable(); }, 'aria-label': ariaLabel, } })); }; const NoDataIcon = forwardRef((props, ref) => { const { className } = props, restProps = __rest(props, ["className"]); const classes = classNames('n-size-token-10', className); return _jsx(DatagridNodataIcon, Object.assign({ ref: ref, className: classes }, restProps)); }); NoDataIcon.displayName = 'NoDataIcon'; export { ResizingBar, Header, Body, BodyCell, BodyRow, InlineEditCell, DropDownCell, RowActionCell, HeaderCell, HeaderTitle, Navigation, TableResults, RowsPerPage, Pagination, PaginationNumericButtons, PaginationArrowButton, PaginationNumericButton, NoDataPlaceholder, NoDataIllustration, NoDataIcon, LoadingPlaceholder, Scrollable, }; //# sourceMappingURL=Components.js.map