UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

47 lines (46 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useArrayLimit; var _react = require("react"); var _index = require("../../hooks/index.js"); var _useSharedState = require("../../../../shared/helpers/useSharedState.js"); function useArrayLimit(path) { const sharedState = (0, _useSharedState.useSharedState)(path + '-iterate-limit'); const { set, update, extend, data } = sharedState || {}; const { limit, total, show } = data || {}; const setLimitProps = (0, _react.useCallback)(props => { if (props.total !== total) { update(props); } else { set(props); } }, [set, total, update]); const setShowStatus = (0, _react.useCallback)(show => { extend({ show }); }, [extend]); const hasReachedLimit = typeof limit === 'number' && total >= limit; const { itemsLimitReached } = (0, _index.useTranslation)().IteratePushContainer; const error = show ? new Error(itemsLimitReached.replace('{limit}', String(limit))) : undefined; return { setShowStatus, setLimitProps, error, hasReachedLimit }; } //# sourceMappingURL=useArrayLimit.js.map