@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
88 lines • 5.11 kB
JavaScript
import { __rest } from "tslib";
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import { getAnalyticsMetadataAttribute } from '@awsui/component-toolkit/internal/analytics-metadata';
import { AnalyticsFunnelSubStep } from '../internal/analytics/components/analytics-funnel';
import { getAnalyticsMetadataProps } from '../internal/base-component';
import { CollectionPreferencesMetadata } from '../internal/context/collection-preferences-metadata-context';
import useBaseComponent from '../internal/hooks/use-base-component';
import { applyDisplayName } from '../internal/utils/apply-display-name';
import { getSortingColumnId } from './header-cell/utils';
import InternalTable, { InternalTableAsSubstep } from './internal';
const Table = React.forwardRef((_a, ref) => {
var _b, _c, _d;
var { items = [], selectedItems = [], variant = 'container', contentDensity = 'comfortable', cellVerticalAlign = 'middle', firstIndex = 1 } = _a, props = __rest(_a, ["items", "selectedItems", "variant", "contentDensity", "cellVerticalAlign", "firstIndex"]);
const analyticsMetadata = getAnalyticsMetadataProps(props);
const hasHiddenColumns = (props.visibleColumns && props.visibleColumns.length < props.columnDefinitions.length) ||
((_b = props.columnDisplay) === null || _b === void 0 ? void 0 : _b.some(col => !col.visible));
const hasStickyColumns = !!((_c = props.stickyColumns) === null || _c === void 0 ? void 0 : _c.first) || !!((_d = props.stickyColumns) === null || _d === void 0 ? void 0 : _d.last);
const baseComponentProps = useBaseComponent('Table', {
props: {
contentDensity,
resizableColumns: props.resizableColumns,
selectionType: props.selectionType,
stickyHeader: props.stickyHeader,
stripedRows: props.stripedRows,
variant,
wrapLines: props.wrapLines,
enableKeyboardNavigation: props.enableKeyboardNavigation,
totalItemsCount: props.totalItemsCount,
flowType: analyticsMetadata.flowType,
cellVerticalAlign,
},
metadata: {
expandableRows: !!props.expandableRows,
progressiveLoading: !!props.getLoadingStatus,
inlineEdit: props.columnDefinitions.some(def => !!def.editConfig),
disabledInlineEdit: props.columnDefinitions.some(def => { var _a; return !!((_a = def.editConfig) === null || _a === void 0 ? void 0 : _a.disabledReason); }),
hasSortableColumns: props.columnDefinitions.some(def => def.sortingField || def.sortingComparator),
hasHiddenColumns,
hasStickyColumns,
hasFilterSlot: !!props.filter,
hasPaginationSlot: !!props.pagination,
itemsCount: items.length,
hasInstanceIdentifier: Boolean(analyticsMetadata === null || analyticsMetadata === void 0 ? void 0 : analyticsMetadata.instanceIdentifier),
usesVisibleColumns: !!props.visibleColumns,
usesColumnDisplay: !!props.columnDisplay,
usesColumnDefinitionsVerticalAlign: props.columnDefinitions.some(def => def.verticalAlign !== cellVerticalAlign),
},
}, analyticsMetadata);
const analyticsComponentMetadata = {
name: 'awsui.Table',
label: { root: 'self' },
properties: {
selectionType: props.selectionType || 'none',
itemsCount: `${items.length}`,
selectedItemsCount: `${selectedItems.length}`,
variant,
},
};
const sortingColumnId = getSortingColumnId(props.columnDefinitions, props.sortingColumn);
if (sortingColumnId) {
analyticsComponentMetadata.properties.sortingColumnId = sortingColumnId;
analyticsComponentMetadata.properties.sortingDescending = `${props.sortingDescending || false}`;
}
const tableProps = Object.assign(Object.assign(Object.assign(Object.assign({ items,
selectedItems,
variant,
contentDensity,
firstIndex,
cellVerticalAlign }, props), baseComponentProps), { ref }), getAnalyticsMetadataAttribute({ component: analyticsComponentMetadata }));
const collectionPreferencesMetadata = {
tableContentDensity: contentDensity,
tableHasStripedRows: !!props.stripedRows,
tableHasHiddenColumns: hasHiddenColumns,
tableHasStickyColumns: hasStickyColumns,
};
if (variant === 'borderless' || variant === 'embedded') {
return (React.createElement(CollectionPreferencesMetadata.Provider, { value: collectionPreferencesMetadata },
React.createElement(InternalTable, Object.assign({}, tableProps))));
}
return (React.createElement(CollectionPreferencesMetadata.Provider, { value: collectionPreferencesMetadata },
React.createElement(AnalyticsFunnelSubStep, null,
React.createElement(InternalTableAsSubstep, Object.assign({}, tableProps)))));
});
applyDisplayName(Table, 'Table');
export default Table;
//# sourceMappingURL=index.js.map