UNPKG

@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

30 lines 1.88 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { useEffect, useMemo } from 'react'; import { parseCountValue } from '../../internal/analytics/utils/parse-count-text'; import { useTableComponentsContext } from '../../internal/context/table-component-context'; /** * Custom hook that integrates table counter values with table component context. * * The extracted count value is automatically synchronized with the table header * component through the table context, updating the countText property. */ export const useTableIntegration = (filteringText, countText) => { const tableComponentContext = useTableComponentsContext(); const countValue = useMemo(() => parseCountValue(countText), [countText]); useEffect(() => { var _a; if ((_a = tableComponentContext === null || tableComponentContext === void 0 ? void 0 : tableComponentContext.filterRef) === null || _a === void 0 ? void 0 : _a.current) { tableComponentContext.filterRef.current.filterText = filteringText; tableComponentContext.filterRef.current.filterCount = countValue; tableComponentContext.filterRef.current.filtered = !!filteringText; return () => { var _a, _b, _c; (_a = tableComponentContext.filterRef.current) === null || _a === void 0 ? true : delete _a.filterText; (_b = tableComponentContext.filterRef.current) === null || _b === void 0 ? true : delete _b.filterCount; (_c = tableComponentContext.filterRef.current) === null || _c === void 0 ? true : delete _c.filtered; }; } }, [tableComponentContext === null || tableComponentContext === void 0 ? void 0 : tableComponentContext.filterRef, countValue, filteringText]); }; //# sourceMappingURL=use-table-integration.js.map