UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

27 lines (26 loc) 1.33 kB
import { generateUniqueId } from '../../internal/hooks/use-unique-id'; import { useState, useCallback, useMemo } from 'react'; export var useSelectedTokens = function (_a) { var disabled = _a.disabled, tokenLimit = _a.tokenLimit, i18nStrings = _a.i18nStrings, _b = _a.selectedOptions, selectedOptions = _b === void 0 ? [] : _b, updateSelectedOption = _a.updateSelectedOption, updateFocus = _a.updateFocus; var _c = useState(false), tokensExpanded = _c[0], setTokensExpanded = _c[1]; var handleTokensClick = useCallback(function () { setTokensExpanded(!tokensExpanded); }, [tokensExpanded, setTokensExpanded]); var handleTokenDismiss = useCallback(function (index) { var optionToDeselect = selectedOptions[index]; updateSelectedOption(optionToDeselect); updateFocus && updateFocus(); }, [updateSelectedOption, selectedOptions, updateFocus]); var controlId = useMemo(function () { return generateUniqueId(); }, []); var selectedTokensProps = { controlId: controlId, expanded: tokensExpanded, disabled: disabled, tokenLimit: tokenLimit, selectedOptions: selectedOptions, i18nStrings: i18nStrings, onToggleClick: handleTokensClick, onTokenDismiss: handleTokenDismiss }; return selectedTokensProps; };