Ctrl + f function realized by react
npm install react-ctrl-fA library that use React to realize the function of Ctrl + F in web version
``jsx`
import {
MatchText,
SearchProvider,
SearchContext,
SearchEventContext,
} from 'react-ctrl-f';
- id is required, you need to set a unique IDignorecase
- is optional, default is true`
- case:
jsx`
- Provide store to search component
`jsx`
const { searchValue, activeCount, totalCount } = useContext(SearchContext);
- Three events are provided to update store
`jsx`
const { onSearchChange, onPrev, onNext } = useContext(SearchEventContext);
SearchProvider need to Wrap all SearchContext , SearchEventContextMatchText
and
properties
- value is optional
- value.fixedHeaderHeight is optional, type is numbervalue.onScroll
- is optional, custom onScroll function
- case:
`jsx
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 (
style={{
position: 'fixed',
top: '0px',
left: '0px',
width: '100%',
border: '1px solid green',
}}
>
style={{ width: 200, marginRight: '12px', height: '24px' }}
value={searchValue}
onChange={onSearchChange}
/>
style={{ height: '28px' }}
title='Up'
onClick={() => onPrev(100)}
>
Prev
{activeCount}/{totalCount}
style={{ height: '28px' }}
title='Down'
onClick={() => onNext(100)}
>
Next
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.
see example
src/pages/Home.tsx and src/pages/Search.tsx`