@talend/react-components
Version:
Set of react components.
88 lines • 2.48 kB
JavaScript
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withTranslation } from 'react-i18next';
import I18N_DOMAIN_COMPONENTS from '../../constants';
import getDefaultT from '../../translate';
import Action from '../../Actions/Action';
import theme from './Header.module.scss';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export function headerClasses() {
return classNames(theme['tc-listview-header'], 'tc-listview-header');
}
function getAction(action, index) {
function onClick(event) {
if (action.onClick) {
action.onClick(event, {
value: event.target.value
});
}
}
return /*#__PURE__*/_jsx(Action, {
label: action.label,
icon: action.icon,
onClick: onClick,
disabled: action.disabled,
tooltipPlacement: "bottom",
inProgress: action.inProgress,
hideLabel: true,
link: true
}, `${index}-listview-header-action`);
}
export function renderActions(headerDefault = []) {
if (headerDefault.length) {
return /*#__PURE__*/_jsx("div", {
className: "actions",
children: headerDefault.map(getAction)
});
}
return null;
}
function Header({
headerDefault,
headerLabel,
labelProps,
nbItemsSelected,
nbItems,
required,
t
}) {
function renderTitle() {
const computedHeaderLabel = headerLabel || t('LISTVIEW_HEADER_TITLE', {
defaultValue: 'Values'
});
return /*#__PURE__*/_jsxs("strong", {
...labelProps,
children: [computedHeaderLabel, required && '*']
});
}
function renderCount() {
if (nbItems >= 1 && nbItemsSelected >= 1) {
return /*#__PURE__*/_jsxs("small", {
children: ["(", t('LISTVIEW_HEADER_SELECTED', {
count: nbItemsSelected,
total: nbItems,
defaultValue: '{{count}}/{{total}} selected'
}), ")"]
});
}
return null;
}
return /*#__PURE__*/_jsxs("header", {
className: headerClasses(),
children: [renderTitle(), renderCount(), renderActions(headerDefault)]
});
}
Header.propTypes = {
headerDefault: PropTypes.arrayOf(PropTypes.shape(Action.propTypes)).isRequired,
headerLabel: PropTypes.string,
labelProps: PropTypes.object,
required: PropTypes.bool,
nbItems: PropTypes.number,
nbItemsSelected: PropTypes.number,
t: PropTypes.func
};
Header.defaultProps = {
t: getDefaultT()
};
export default withTranslation(I18N_DOMAIN_COMPONENTS)(Header);
//# sourceMappingURL=Header.component.js.map