@carbon/ibm-products
Version:
Carbon for IBM Products
113 lines (111 loc) • 3.84 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { getGlobalFilterValues, normalize } from "./add-select-utils.js";
import { AddSelectBody } from "./AddSelectBody.js";
import React, { forwardRef } from "react";
import PropTypes from "prop-types";
//#region src/components/AddSelect/AddSelect.tsx
const componentName = "AddSelect";
const AddSelect = forwardRef(({ items = { entries: [] }, globalFilters, ...props }, ref) => {
const useNormalizedItems = !!items.entries.find((item) => item.children);
const normalizedItems = useNormalizedItems ? normalize(items) : null;
const globalFilterOpts = props.multi && globalFilters?.length ? getGlobalFilterValues(globalFilters, normalizedItems) : null;
const defaultModifiers = props.multi && items.modifiers ? items.entries.map((item) => {
const modifierAttribute = items?.modifiers?.id;
return {
id: item.id,
...modifierAttribute && { [modifierAttribute]: item[modifierAttribute] }
};
}) : [];
return /* @__PURE__ */ React.createElement(AddSelectBody, {
...props,
ref,
items,
normalizedItems,
useNormalizedItems,
globalFilterOpts,
defaultModifiers
});
});
AddSelect.propTypes = {
className: PropTypes.string,
clearFiltersText: PropTypes.string,
closeIconDescription: PropTypes.string.isRequired,
columnInputPlaceholder: PropTypes.string,
description: PropTypes.string.isRequired,
filterByLabel: PropTypes.string,
/**@ts-ignore */
globalFilters: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
label: PropTypes.string
})),
globalFiltersIconDescription: PropTypes.string,
globalFiltersLabel: PropTypes.string,
globalFiltersPlaceholderText: PropTypes.string,
globalFiltersPrimaryButtonText: PropTypes.string,
globalFiltersSecondaryButtonText: PropTypes.string,
globalSearchLabel: PropTypes.string.isRequired,
globalSearchPlaceholder: PropTypes.string,
globalSortBy: PropTypes.array,
illustrationTheme: PropTypes.oneOf(["light", "dark"]),
influencerTitle: PropTypes.string,
/**@ts-ignore */
items: PropTypes.shape({
modifiers: PropTypes.shape({
id: PropTypes.string,
label: PropTypes.string,
options: PropTypes.array,
multiSelect: PropTypes.bool
}),
sortBy: PropTypes.array,
filterBy: PropTypes.array,
entries: PropTypes.arrayOf(PropTypes.shape({
avatar: PropTypes.shape({
alt: PropTypes.string,
icon: PropTypes.func,
src: PropTypes.string,
theme: PropTypes.oneOf(["light", "dark"])
}),
children: PropTypes.object,
icon: PropTypes.func,
id: PropTypes.string.isRequired,
meta: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
title: PropTypes.string,
value: PropTypes.string
})), PropTypes.node]),
subtitle: PropTypes.string,
title: PropTypes.string.isRequired,
value: PropTypes.string.isRequired
})).isRequired
}).isRequired,
itemsLabel: PropTypes.string.isRequired,
metaIconDescription: PropTypes.string,
metaPanelTitle: PropTypes.string,
multi: PropTypes.bool.isRequired,
navIconDescription: PropTypes.string,
noResultsDescription: PropTypes.string.isRequired,
noResultsTitle: PropTypes.string.isRequired,
noSelectionDescription: PropTypes.string,
noSelectionTitle: PropTypes.string,
onClose: PropTypes.func.isRequired,
onCloseButtonText: PropTypes.string.isRequired,
onSubmit: PropTypes.func.isRequired,
onSubmitButtonText: PropTypes.string.isRequired,
open: PropTypes.bool.isRequired,
/**
* portal target for the all tags modal
*/
/**@ts-ignore */
portalTarget: PropTypes.node,
searchResultsTitle: PropTypes.string,
sortByLabel: PropTypes.string,
title: PropTypes.string.isRequired
};
AddSelect.displayName = componentName;
//#endregion
export { AddSelect };