UNPKG

@chayns-components/core

Version:

A set of beautiful React components for developing your own applications with chayns.

61 lines 2.83 kB
import React, { useCallback, useMemo } from 'react'; import { useIsTouch } from '../../../utils/environment'; import Icon from '../../icon/Icon'; import { StyledComboBoxItem, StyledComboBoxItemContent, StyledComboBoxItemContentHeader, StyledComboBoxItemContentHeaderRightElement, StyledComboBoxItemContentHeaderWrapper, StyledComboBoxItemContentHeaderWrapperText, StyledComboBoxItemContentSubtext, StyledComboBoxItemIconsWrapper, StyledComboBoxItemImage } from './ComboBoxItem.styles'; const ComboBoxItem = ({ item, isSelected, onSelect, shouldShowBigImage, shouldShowRoundImage }) => { const { icons, imageUrl, isDisabled, imageBackground, suffixElement, textStyles, rightElement, text, value, subtext } = item; const id = value; const handleItemClick = useCallback(() => { if (!isDisabled) { onSelect({ text, value, suffixElement, imageUrl, icons }); } }, [icons, imageUrl, isDisabled, onSelect, suffixElement, text, value]); const isTouch = useIsTouch(); return useMemo(() => /*#__PURE__*/React.createElement(StyledComboBoxItem, { id: `combobox-item__${typeof id === 'number' ? String(id) : id}${isDisabled ? '--disabled-item' : ''}`, onClick: handleItemClick, $isDisabled: isDisabled, $isSelected: isSelected, $isTouch: isTouch }, imageUrl && /*#__PURE__*/React.createElement(StyledComboBoxItemImage, { src: imageUrl, $background: imageBackground, $shouldShowBigImage: shouldShowBigImage || typeof subtext === 'string' && subtext.trim() !== '', $shouldShowRoundImage: shouldShowRoundImage }), icons && /*#__PURE__*/React.createElement(StyledComboBoxItemIconsWrapper, null, /*#__PURE__*/React.createElement(Icon, { icons: icons })), /*#__PURE__*/React.createElement(StyledComboBoxItemContent, null, /*#__PURE__*/React.createElement(StyledComboBoxItemContentHeader, { $text: text, $subtext: subtext }, /*#__PURE__*/React.createElement(StyledComboBoxItemContentHeaderWrapper, { as: textStyles?.tagName, style: textStyles?.styles, className: textStyles?.className }, /*#__PURE__*/React.createElement(StyledComboBoxItemContentHeaderWrapperText, null, text), suffixElement), rightElement && /*#__PURE__*/React.createElement(StyledComboBoxItemContentHeaderRightElement, null, rightElement)), subtext && /*#__PURE__*/React.createElement(StyledComboBoxItemContentSubtext, null, subtext))), [handleItemClick, icons, id, imageBackground, imageUrl, isDisabled, isSelected, isTouch, rightElement, shouldShowBigImage, shouldShowRoundImage, subtext, suffixElement, text, textStyles?.styles, textStyles?.tagName, textStyles?.className]); }; ComboBoxItem.displayName = 'ComboBoxItem'; export default ComboBoxItem; //# sourceMappingURL=ComboBoxItem.js.map