npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rnuk-search-highlighter

v1.0.5

Published

`SearchHighlight` is a React Native component that provides real-time search and text highlighting functionality for a list of items. It allows users to filter through a list based on the search input, with matching letters in the results highlighted. Add

Downloads

61

Readme

rnuk-search-highlighter

SearchHighlight

SearchHighlight is a React Native component that provides real-time search and text highlighting functionality for a list of items. It allows users to filter through a list based on the search input, with matching letters in the results highlighted. Additionally, it supports customizable styling and behavior.

Features

  • Search Filtering: Filters items as the user types, based on the search term.
  • Text Highlighting: Dynamically highlights the letters in the results that match the search term.
  • Custom Styling: Customize styles for the input field, list items, and highlighted text.
  • Custom Item Rendering: Option to provide a custom rendering function for list items.
  • Item Selection Callback: Invoke a callback when an item is selected from the list.
  • Preview : See Demo

Installation

To install this package, run the following command:

npm install search-highlight-component
yarn add search-highlight-component

Basic Example

import React from 'react';
import { View, Alert } from 'react-native';
import SearchHighlight from 'search-highlight-component';

const App = () => {
  const data = [
  "This",
  "IS",
  "SAMPLE",
  "DATA",
  "uday",
  "kiran",
  "Gurramu",
  "searc",
  "highlight",
  "package",
  "please",
  "contribute",
];

  const handleSelectItem = (item) => {
    Alert.alert(`You selected: ${item}`);
  };

  return (
    <View style={{ padding: 20 }}>
      <SearchHighlight
        data={data}
        onSelectItem={handleSelectItem}
        searchPlaceholder="Search Names"
        highlightStyle={{ backgroundColor: 'yellow' }}
        containerStyle={{ backgroundColor: 'white' }}
        inputStyle={{ color: 'black' }}
        listStyle={{ borderColor: 'gray', borderWidth: 1, borderRadius: 5 }}
      />
    </View>
  );
};

export default App;

Preview

Watch Demo

Search Preview1

Search Preview2

Props

| Prop Name | Type | Default Value | Description | |----------------------|---------------|------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------| | data | array | [] | The list of strings to be filtered and highlighted based on the search term. | | textbox | bool | true | Whether to show the search text input or not. | | searchPlaceholder | string | 'Search' | Placeholder text for the search input field. | | highlightStyle | object | { backgroundColor: 'yellow' } | Style applied to the highlighted letters in the filtered results. | | containerStyle | object | {} | Custom styling for the main container. | | inputContainerStyle | object | { height: 55, justifyContent: 'center', backgroundColor: 'grey' } | Custom styling for the search input container. | | inputStyle | object | { padding: 0, fontSize: 20, paddingHorizontal: 10, marginHorizontal: 20 } | Custom styling for the search text input field. | | listStyle | object | { height: 500 } | Custom styling for the list container. | | listContentStyle | object | {} | Custom styling for the content inside the list. | | renderCustomItem | function | null | Optional function to render a custom item component in the list. Receives { item, highlightedValue } as parameters. | | placeholderTextColor| string | 'blue' | Color of the placeholder text in the search input. | | onSelectItem | function | () => {} | Callback function called when an item is selected from the list. Receives the selected item as a parameter.

Developer Note

If you are using the renderCustomItem prop to customize how items are rendered in the list, you must implement your own TextInput or similar component for handling the selection of items from the search feed.

The SearchHighlight component provides the filtered data, but it does not manage the selection state or input control when using a custom render method. You need to manage how the selected item is displayed and handled in the TextInput component.

Example with Custom Input Handling

import React, { useState } from 'react';
import { View, TextInput, Text, TouchableOpacity, Alert } from 'react-native';
import SearchHighlight from 'search-highlight-component';

const App = () => {
  const [selectedItem, setSelectedItem] = useState('');
  const data = ['John Doe', 'Jane Smith', 'Emily Davis'];

  const handleSelectItem = (item) => {
    setSelectedItem(item); // Manually handle input when an item is selected
    Alert.alert(`Selected: ${item}`);
  };

  const renderCustomItem = ({ item, highlightedValue }) => (
    <TouchableOpacity onPress={() => handleSelectItem(item.value)}>
      <View style={{ padding: 10, backgroundColor: '#e0e0e0', borderRadius: 5 }}>
        <Text>{highlightedValue}</Text>
      </View>
    </TouchableOpacity>
  );

  return (
    <View style={{ padding: 20 }}>
      <TextInput
        value={selectedItem}
        onChangeText={setSelectedItem}
        placeholder="Select an item"
        style={{ borderWidth: 1, borderColor: 'gray', padding: 10, marginBottom: 10 }}
      />
      <SearchHighlight
        data={data}
        renderCustomItem={renderCustomItem}
        searchPlaceholder="Search People"
      />
    </View>
  );
};

export default App;