UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

464 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 { 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 { useMergeRefs } from '@floating-ui/react'; import { flexRender, } from '@tanstack/react-table'; import classNames from 'classnames'; import { Fragment, useCallback, useEffect, useMemo, useRef, useState, } from 'react'; import { CleanIconButton } from '../clean-icon-button'; import { Bars3CenterLeftIconOutline, BarsArrowDownIconOutline, BarsArrowUpIconOutline, ChevronDownIconSolid, ChevronLeftIconOutline, ChevronRightIconOutline, DataGridCrossIcon, EllipsisHorizontalIconOutline, } from '../icons'; import { LoadingSpinner } from '../loading-spinner'; import { Menu } from '../menu'; import { Select } from '../select'; import { Skeleton } from '../skeleton'; import { Typography } from '../typography'; import { useDataGridContext } from './data-grid-context'; import { resizeColumn, ResizeDirection, userFriendlyPagination, } from './helpers'; /** 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) => ({ label: `${option}`, value: option, })); }; export const DEFAULT_SORT_ACTIONS = (cell) => ({ asc: { icon: _jsx(BarsArrowUpIconOutline, {}), onClick: () => cell.column.toggleSorting(false), title: 'Sort ascending', }, default: { icon: _jsx(Bars3CenterLeftIconOutline, {}), onClick: () => cell.column.clearSorting(), title: 'Default sort', }, desc: { icon: _jsx(BarsArrowDownIconOutline, {}), onClick: () => cell.column.toggleSorting(true), title: 'Sort descending', }, }); const ResizingBar = (_a) => { var { header, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["header", "className", "style", "htmlAttributes", "ref"]); 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("button", Object.assign({ ref: ref, type: "button", className: classNames('ndl-data-grid-resizer', className, { 'ndl-data-grid-is-resizing': header.column.getIsResizing(), }), style: style, onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), onKeyDown: handleKeyDown, "aria-label": "Resizing bar", tabIndex: isKeyboardNavigationEnabled ? -1 : 0 }, restProps, htmlAttributes))); }; const Scrollable = (_a) => { var { children, ref, className, style, htmlAttributes } = _a, restProps = __rest(_a, ["children", "ref", "className", "style", "htmlAttributes"]); return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('ndl-data-grid-scrollable', className) }, restProps, htmlAttributes, { children: children }))); }; const Header = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); const { tableProps, components } = useDataGridContext(); const { getHeaderGroups, getState } = tableProps; return (_jsx("div", Object.assign({ role: "rowgroup", className: classNames('ndl-data-grid-thead', className, { 'ndl-data-grid-is-resizing': getState().columnSizingInfo.isResizingColumn, }), style: style, ref: ref }, restProps, 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 = (_a) => { var { action, onClose, as, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["action", "onClose", "as", "className", "style", "htmlAttributes", "ref"]); const { onClick } = action, restAction = __rest(action, ["onClick"]); const interceptedOnClick = useCallback((e) => { const providedOnClick = onClick !== null && onClick !== void 0 ? onClick : action.onClick; if (typeof providedOnClick === 'function') { providedOnClick(e); } onClose === null || onClose === void 0 ? void 0 : onClose(); }, [action.onClick, onClick, onClose]); return (_jsx(Menu.Item, Object.assign({ onClick: interceptedOnClick, as: as, className: className, style: style, htmlAttributes: htmlAttributes, ref: ref }, restAction, restProps))); }; const ActionCell = ({ cell, innerCleanIconButtonProps, 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(CleanIconButton, Object.assign({ as: "button", size: "medium", description: "Actions", ref: actionsButtonRef, isActive: isActionsOpen, onClick: () => { onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(!isActionsOpen); setIsActionsOpen(!isActionsOpen); } }, innerCleanIconButtonProps, { htmlAttributes: Object.assign({ tabIndex: 0 }, innerCleanIconButtonProps === null || innerCleanIconButtonProps === void 0 ? void 0 : innerCleanIconButtonProps.htmlAttributes), children: (innerCleanIconButtonProps === null || innerCleanIconButtonProps === void 0 ? void 0 : innerCleanIconButtonProps.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 = (_a) => { var _b; var { cell, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["cell", "children", "className", "style", "htmlAttributes", "ref"]); const { components, portalTarget } = useDataGridContext(); const sort = cell.column.getIsSorted(); const canSort = cell.column.getCanSort(); const { hasDefaultSortingActions = true, actions } = ((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.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({ ref: ref, className: classNames('ndl-header-action-group', className), style: style }, restProps, htmlAttributes, { children: children || (_jsxs(Fragment, { children: [_jsx(CleanIconButton, { size: "small", description: "Actions", 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 = (_a) => { var { cell, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["cell", "children", "className", "style", "htmlAttributes", "ref"]); const { components, isResizable, isKeyboardNavigationEnabled } = useDataGridContext(); 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 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({ ref: ref, tabIndex: isKeyboardNavigationEnabled && !isActionColumn ? 0 : undefined, role: "columnheader", 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: Object.assign(Object.assign({}, 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; } }, } : {}), restProps, htmlAttributes, { children: children || (_jsxs(_Fragment, { children: [_jsx(Tag, { className: "ndl-header-group", style: { cursor: canSort ? 'pointer' : 'default', }, "aria-description": 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 = (_a) => { var { cell, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["cell", "children", "className", "style", "htmlAttributes", "ref"]); const { column, id } = cell; const title = typeof column.columnDef.header === 'string' ? column.columnDef.header : id; return (_jsx("div", Object.assign({ ref: ref, className: className, title: title, style: style }, restProps, htmlAttributes, { children: children }))); }; const Body = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); const { tableProps, components, isLoading } = useDataGridContext(); const { getRowModel } = tableProps; return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('ndl-data-grid-tbody', className), role: "rowgroup", "aria-busy": isLoading ? 'true' : 'false' }, restProps, 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 = (_a) => { var _b, _c, _d; var { cell, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["cell", "children", "className", "style", "htmlAttributes", "ref"]); const isResizing = cell.column.getIsResizing(); const isActionColumn = Boolean((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.isActionCell); const isInlineEditCell = Boolean((_c = cell.column.columnDef.meta) === null || _c === void 0 ? void 0 : _c.isInlineEditCell); const isDropDownCell = Boolean((_d = cell.column.columnDef.meta) === null || _d === void 0 ? void 0 : _d.isDropDownCell); const isCustomCell = isActionColumn || isDropDownCell; const { isKeyboardNavigationEnabled, isSkeletonLoading, skeletonProps } = useDataGridContext(); return (_jsx("div", Object.assign({ ref: ref, 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({}, style), { width: isActionColumn ? 40 : cell.column.getSize() }) }, restProps, htmlAttributes, { children: _jsx(Skeleton, Object.assign({ onBackground: "weak", shape: "rectangular", width: "100%" }, skeletonProps, { isLoading: isSkeletonLoading && !isActionColumn, children: children || flexRender(cell.column.columnDef.cell, cell.getContext()) })) }), cell.id)); }; const BodyRow = (_a) => { var { row, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["row", "children", "className", "style", "htmlAttributes", "ref"]); const { components } = useDataGridContext(); return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('ndl-data-grid-tr', className), role: "row" }, restProps, htmlAttributes, { children: children || (_jsx(_Fragment, { children: row .getVisibleCells() .map((cell) => components.BodyCell && (_jsx(components.BodyCell, { cell: cell }, cell.id))) })) }), row.id)); }; const TableResults = (_a) => { var { manualPagination, children, className, style, htmlAttributes, ref, resultsLabel = 'results' } = _a, restProps = __rest(_a, ["manualPagination", "children", "className", "style", "htmlAttributes", "ref", "resultsLabel"]); const { tableProps, isSkeletonLoading, skeletonProps, isSmallNavigation } = 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]); if (isSmallNavigation) { return null; } return (_jsx(Skeleton, Object.assign({ as: "span", onBackground: "weak", shape: "rectangular" }, skeletonProps, { isLoading: isSkeletonLoading, children: _jsx("span", Object.assign({ ref: ref, style: style, className: classNames('ndl-data-grid-results', className) }, restProps, htmlAttributes, { children: children || (_jsxs("span", { children: ["Showing", ' ', _jsx("b", { children: totalRows ? `${from}${to !== from ? `-${to}` : ''}` : 0 }), " of", ' ', _jsx("b", { children: totalRows }), " ", resultsLabel] })) })) }))); }; const RowsPerPage = (_a) => { var { portalTarget: portalTargetProp, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["portalTarget", "children", "className", "style", "htmlAttributes", "ref"]); const { tableProps, portalTarget } = useDataGridContext(); const { setPageSize, getState } = tableProps; const { pagination: { pageSize }, } = getState(); const paginationOptions = getPaginationOptions(pageSize); const defaultPaginationOption = paginationOptions.find((option) => option.value === pageSize); const menuPortalTarget = portalTargetProp === undefined ? portalTarget : portalTargetProp; return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('ndl-data-grid-rows-per-page', className) }, restProps, htmlAttributes, { children: children || (_jsxs(_Fragment, { children: ["Show", _jsx(Select, { type: "select", size: "medium", ariaLabel: "Select page size", selectProps: { defaultValue: defaultPaginationOption, isSearchable: false, menuPortalTarget: menuPortalTarget, menuPosition: 'fixed', onChange: (option) => { if (option) { setPageSize(option.value); } }, options: paginationOptions, styles: { container: () => ({ width: '100%', }), }, } })] })) }))); }; const PaginationArrowButton = (_a) => { var { action, children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["action", "children", "className", "style", "htmlAttributes", "ref"]); const PaginationIcon = action === 'previous' ? ChevronLeftIconOutline : ChevronRightIconOutline; const ariaLabel = action === 'previous' ? 'Previous page' : 'Next page'; const classes = classNames('ndl-data-grid-pagination-icon-button', className); return (_jsx(CleanIconButton, Object.assign({ ref: ref, style: style, className: classes, description: ariaLabel, htmlAttributes: htmlAttributes }, restProps, { children: children || _jsx(PaginationIcon, {}) }))); }; const PaginationNumericButton = (_a) => { var { currentIndex, isSelected, children, className, style, htmlAttributes, onClick, ref } = _a, restProps = __rest(_a, ["currentIndex", "isSelected", "children", "className", "style", "htmlAttributes", "onClick", "ref"]); return (_jsx("button", Object.assign({ ref: ref, style: style, type: "button", "data-testid": `ndl-table-${currentIndex}`, className: classNames('ndl-data-grid-pagination-numeric-button', className, { 'ndl-is-selected': isSelected, 'ndl-not-selected': !isSelected, 'ndl-not-selected-numeric': typeof currentIndex === 'number' && !isSelected, }), onClick: (e) => typeof currentIndex === 'number' && onClick && onClick(e), tabIndex: typeof currentIndex === 'number' ? 0 : -1 }, restProps, 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 */ , { onClick: () => typeof option === 'number' && setPageIndex(option - 1), currentIndex: option, isSelected: option === pageIndex + 1 }, `${option}-${idx}`))) })); }; const Pagination = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); const { tableProps, components, isMediumNavigation } = useDataGridContext(); const { getCanPreviousPage, getCanNextPage, previousPage, nextPage } = tableProps; return (_jsx("nav", Object.assign({ ref: ref, style: style, className: classNames('ndl-data-grid-nav', className), "aria-label": "Pagination" }, restProps, htmlAttributes, { children: children || (_jsxs(_Fragment, { children: [getCanPreviousPage() ? components.PaginationArrowButton && (_jsx(components.PaginationArrowButton, { action: "previous", onClick: previousPage })) : null, !isMediumNavigation && components.PaginationNumericButtons && (_jsx(components.PaginationNumericButtons, {})), getCanNextPage() ? components.PaginationArrowButton && (_jsx(components.PaginationArrowButton, { action: "next", onClick: nextPage })) : null] })) }))); }; const Navigation = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); const { tableProps, components, isSkeletonLoading, skeletonProps, isSmallNavigation, } = useDataGridContext(); const { getPageCount } = tableProps; return (_jsx("div", Object.assign({ ref: ref, style: Object.assign(Object.assign({}, style), (isSmallNavigation && { justifyContent: 'end' })), className: classNames('ndl-data-grid-navigation', className) }, restProps, htmlAttributes, { children: _jsx(_Fragment, { children: children || (_jsxs(_Fragment, { children: [components.TableResults && _jsx(components.TableResults, {}), _jsx(Skeleton, Object.assign({ onBackground: "weak", shape: "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 = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('nld-table-placeholder-wrapper', className), role: "row" }, restProps, 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 = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); return (_jsx("div", Object.assign({ ref: ref, style: style, className: classNames('nld-table-placeholder-wrapper', className), role: "row" }, restProps, htmlAttributes, { children: children || (_jsxs(NoDataPlaceholderContentWrapper, { children: [_jsx(NoDataIcon, {}), _jsx(Typography, { variant: "subheading-small", children: "No data available" })] })) }))); }; export const NoDataPlaceholderContentWrapper = (_a) => { var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]); return (_jsx("div", Object.assign({ role: "cell", className: classNames('ndl-data-grid-placeholder', className), ref: ref, style: style }, restProps, htmlAttributes, { children: children }))); }; const InlineEditCell = (_a) => { var _b; var { cell, value, ariaLabel, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["cell", "value", "ariaLabel", "className", "style", "htmlAttributes", "ref"]); const [inputValue, setInputValue] = useState(value); useEffect(() => { setInputValue(value); }, [value]); const { dataGridNav } = useDataGridContext(); if (!((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.isInlineEditCell)) { return null; } return (_jsx("input", Object.assign({ ref: ref, style: style, className: className, 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 }, restProps, htmlAttributes))); }; const DropDownCell = (_a) => { var _b; var { cell, options, portalTarget: portalTargetProp, ariaLabel, className, style, htmlAttributes, ref: forwardRef, isDisabled } = _a, restProps = __rest(_a, ["cell", "options", "portalTarget", "ariaLabel", "className", "style", "htmlAttributes", "ref", "isDisabled"]); const { dataGridNav, portalTarget } = useDataGridContext(); const ref = useRef(null); const mergedRef = useMergeRefs([ref, forwardRef]); if (!((_b = cell.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.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, Object.assign({ ref: mergedRef, className: className, isFluid: true, isClean: true, style: Object.assign(Object.assign({}, style), { height: '100%', width: '100%' }), type: "select", size: "medium", ariaLabel: ariaLabel, isDisabled: isDisabled, selectProps: { defaultValue: defaultOption, menuPortalTarget: menuPortalTarget, menuPosition: 'fixed', 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(); }, options: options, styles: { container: () => ({ height: '100%', width: '100%' }), control: () => ({ backgroundColor: 'transparent', borderRadius: 0, height: '100%', }), }, }, htmlAttributes: htmlAttributes }, restProps))); }; const NoDataIcon = (_a) => { var { className } = _a, restProps = __rest(_a, ["className"]); const classes = classNames('n-size-token-64', className); return _jsx(DataGridCrossIcon, Object.assign({ className: classes }, restProps)); }; export { ResizingBar, Header, Body, BodyCell, BodyRow, InlineEditCell, DropDownCell, ActionCell, HeaderCell, HeaderTitle, Navigation, TableResults, RowsPerPage, Pagination, PaginationNumericButtons, PaginationArrowButton, PaginationNumericButton, NoDataPlaceholder, NoDataIcon, LoadingPlaceholder, Scrollable, }; //# sourceMappingURL=Components.js.map