UNPKG

react-native-autocomplete-dropdown

Version:

Dropdown Item picker with search and autocomplete (typeahead) functionality for react native

98 lines (97 loc) 3.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScrollViewListItem = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _diacriticless = _interopRequireDefault(require("./diacriticless")); var _theme = require("./theme"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const ScrollViewListItem = exports.ScrollViewListItem = /*#__PURE__*/(0, _react.memo)(({ highlight, title, style, onPress, ignoreAccents, numberOfLines = 2, theme }) => { const listTheme = theme ?? (0, _reactNative.useColorScheme)() ?? 'light'; const styles = (0, _react.useMemo)(() => getStyles(listTheme), [listTheme]); const titleParts = (0, _react.useMemo)(() => { let titleHighlighted = ''; let titleStart = title; let titleEnd = ''; if (typeof title === 'string' && title?.length > 0 && highlight?.length > 0) { const highlightIn = ignoreAccents ? (0, _diacriticless.default)(title?.toLowerCase()) : title?.toLowerCase(); const highlightWhat = ignoreAccents ? (0, _diacriticless.default)(highlight?.toLowerCase()) : highlight?.toLowerCase(); const substrIndex = highlightIn?.indexOf(highlightWhat); if (substrIndex !== -1) { titleStart = title?.slice(0, substrIndex); titleHighlighted = title?.slice(substrIndex, substrIndex + highlight?.length); titleEnd = title?.slice(substrIndex + highlight?.length); } } return { titleHighlighted, titleStart, titleEnd }; }, [highlight, ignoreAccents, title]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { onPress: onPress, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.container, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, { numberOfLines: numberOfLines, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { numberOfLines: 1, style: { ...styles.text, ...style }, children: titleParts.titleStart }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { numberOfLines: 1, style: { ...styles.text, ...style, ...styles.textBold }, children: titleParts.titleHighlighted }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { numberOfLines: 1, style: { ...styles.text, ...style }, children: titleParts.titleEnd })] }) }) }); }); const getStyles = (themeName = 'light') => _reactNative.StyleSheet.create({ container: { padding: 15, flex: 1, flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'flex-start', flexWrap: 'nowrap', width: '100%' }, text: { color: _theme.theme[themeName].listItemTextColor, fontSize: 16, flexGrow: 1, flexShrink: 0 }, textBold: { fontWeight: 'bold' } }); //# sourceMappingURL=ScrollViewListItem.js.map