@talend/react-components
Version:
Set of react components.
84 lines • 2.46 kB
JavaScript
import { useCallback } from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import I18N_DOMAIN_COMPONENTS from '../constants';
import { getTheme } from '../theme';
import Resource from './Resource';
import ResourceListPropTypes from './ResourceList.propTypes';
import Toolbar from './Toolbar';
import VirtualizedList from '../VirtualizedList';
import getRowSelectionRenderer from '../VirtualizedList/RowSelection';
import cssModule from './ResourceList.module.scss';
import Icon from '../Icon';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const theme = getTheme(cssModule);
function isFiltered({
state
} = {}) {
return state && (state.certified || state.favorites);
}
function ResourceList({
className,
collection,
isLoading,
onRowClick,
renderAs,
toolbar,
rowProps,
...rest
}) {
const {
t
} = useTranslation(I18N_DOMAIN_COMPONENTS);
const Renderer = getRowSelectionRenderer(Resource, {
as: renderAs,
getRowData: ({
index
}) => collection[index],
rowProps
});
const noRowsRenderer = useCallback(() => /*#__PURE__*/_jsx("div", {
className: theme('tc-resource-list--no-results'),
children: /*#__PURE__*/_jsxs("span", {
className: theme('tc-resource-list--no-results-text'),
role: "status",
"aria-live": "polite",
children: [/*#__PURE__*/_jsx(Icon, {
className: theme('tc-resource-list--no-results-icon'),
name: "talend-fieldglass"
}), ' ', t('RESOURCELIST_NO_RESULTS', {
defaultValue: 'No results'
})]
})
}), [t]);
return /*#__PURE__*/_jsxs("div", {
className: theme('tc-resource-list'),
children: [toolbar && /*#__PURE__*/_jsx(Toolbar, {
...toolbar
}), /*#__PURE__*/_jsx("div", {
className: classNames(className, theme('tc-resource-list-items'), {
[theme('filtered')]: isFiltered(toolbar)
}),
children: /*#__PURE__*/_jsx(VirtualizedList, {
rowHeight: 100,
...rest,
collection: collection,
inProgress: isLoading,
onRowClick: onRowClick,
rowRenderers: {
resource: Renderer
},
noRowsRenderer: noRowsRenderer,
type: "resource"
})
})]
});
}
ResourceList.defaultProps = {
collection: []
};
ResourceList.propTypes = {
...ResourceListPropTypes
};
export default ResourceList;
//# sourceMappingURL=ResourceList.component.js.map