1 Star 1 Fork 0

yc-plugins/yc-highlight

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
# Highlight Component A React component to highlight specific text within its child elements. Users can define the highlight style by passing a custom class name, with a default highlight style of `color: red`. <a href="./README.md">English</a>|<a href="./README.zh_CN.md">简体中文</a> ## Installation You can install the component using npm or Yarn. ### Using npm ```bash npm install yc-highlight ``` ### USing yarn ```bash yarn add yc-highlight ``` ## Basic Usage Here’s an example of how to use the Highlight component in your React application: ```ts // app.tsx import React, { useRef } from 'react'; import Highlight, { HighlightHandle } from 'yc-highlight'; import { Input, Button } from 'antd'; import './App.css'; const App: React.FC = () => { const [value, setValue] = useState<string>(''); const highlightRef = useRef<HighlightHandle>(null); const handleSearch = () => { highlightRef.current?.highlight(value); }; const handleRemoveHighlight = () => { highlightRef.current?.removeHighlight(); }; return ( <> <div style={{ display: 'flex' }}> <Input value={value} onChange={(e) => setValue(e.target.value)} /> <Button onClick={handleSearch}>Search</Button> <Button onClick={handleRemoveHighlight}>Remove Highlight</Button> </div> <Highlight ref={highlightRef} highlightClassName="custom-highlight"> <p>This is a sample text to demonstrate the highlight feature.</p> </Highlight> </> ); }; export default App; ``` ```css // APP.css .custom-highlight { color: red; background-color: yellow; } ``` ## API ### Props - ``` children ``` (React.ReactNode): The child elements to be searched and highlighted. - ```highlightClassName``` (string, optional): A custom class name for the highlight style. Default is color: red. ### Methods - ``` highlight(text: string) ``` : Highlights the specified text within the child elements. - `removeHighlight()`: Removes all highlights from the child elements. ## License MIT

简介

一个 React 组件,用于在其子元素中高亮特定文本。 展开 收起
TSX 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yc-plugins/yc-highlight.git
git@gitee.com:yc-plugins/yc-highlight.git
yc-plugins
yc-highlight
yc-highlight
main

搜索帮助