New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-ctrl-f

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ctrl-f

Ctrl + f function realized by react

latest
Source
npmnpm
Version
0.0.4
Version published
Weekly downloads
1.6K
22.43%
Maintainers
1
Weekly downloads
 
Created
Source

简体中文

react-ctrl-f

A library that use React to realize the function of Ctrl + F in web version

Usage

import {
  MatchText,
  SearchProvider,
  SearchContext,
  SearchEventContext,
} from 'react-ctrl-f';

MatchText properties

  • id is required, you need to set a unique ID
  • ignorecase is optional, default is true
  • case:
    <MatchText id='match-text-id-1'>Hello world</MatchText>
    

SearchContext

  • Provide store to search component
    const { searchValue, activeCount, totalCount } = useContext(SearchContext);
    

SearchEventContext

  • Three events are provided to update store

    const { onSearchChange, onPrev, onNext } = useContext(SearchEventContext);
    

SearchProvider

SearchProvider need to Wrap all SearchContext , SearchEventContext and MatchText

properties

  • value is optional

    • value.fixedHeaderHeight is optional, type is number
    • value.onScroll is optional, custom onScroll function
  • case:

    import React from 'react';
    import { MatchText, SearchProvider } from 'react-ctrl-f';
    export default function App() {
      const { searchValue, activeCount, totalCount } = useContext(SearchContext);
      const { onSearchChange, onPrev, onNext } = useContext(SearchEventContext);
      return (
        <SearchProvider>
          <div
            style={{
              position: 'fixed',
              top: '0px',
              left: '0px',
              width: '100%',
              border: '1px solid green',
            }}
          >
            <input
              style={{ width: 200, marginRight: '12px', height: '24px' }}
              value={searchValue}
              onChange={onSearchChange}
            />
            <button
              style={{ height: '28px' }}
              title='Up'
              onClick={() => onPrev(100)}
            >
              Prev
            </button>
            <span style={{ padding: '0px 12px' }}>
              {activeCount}/{totalCount}
            </span>
            <button
              style={{ height: '28px' }}
              title='Down'
              onClick={() => onNext(100)}
            >
              Next
            </button>
          </div>
          <p>
            <MatchText id='match-1'>
              React components implement a render() method that takes input data
              and returns what to display. This example uses an XML-like syntax
              called JSX. Input data that is passed into the component can be
              accessed by render() via this.props. JSX is optional and not
              required to use React.
            </MatchText>
          </p>
        </SearchProvider>
      );
    }
    

see example src/pages/Home.tsx and src/pages/Search.tsx

Keywords

React

FAQs

Package last updated on 19 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts