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

react-at-editor

v1.0.1

Published

react组件,文本输入关键词弹出列表,选中变成标签,删除一块删除,例如微信输入框艾特@

Downloads

3

Readme

AtEditor

react组件,文本输入关键词弹出列表,选中变成标签,删除一块删除,例如微信输入框艾特@

GitHub地址:https://github.com/LZF-fe/AtEditor

npm地址:https://www.npmjs.com/package/react-at-editor

安装和使用

要安装和使用这个项目,你需要按照以下步骤操作:

直接
npm i react-at-editor

或者:

  1. 克隆或下载项目代码。
  2. 在终端中进入项目目录。
  3. 运行 npm install 来安装依赖项。
  4. 运行 npm run dev 来启动项目。

效果示例

alt text

使用示例

const defaultList = [
 {
     label: "小李1",
     value: "小李1",
 },
 {
     label: "小李2",
     value: "小李2",
 },
];

function App() {
 const atRef = useRef(null)

 return (
   <div>
     <AtEditor
       ref={atRef}
       trigger='@'
       style={{width: '400px'}}
       atList={defaultList}
     >
     </AtEditor>
   </div>
 )
}

参数说明

/**
* 
* @param {React.RefObject} refInstance 组件ref
* @param {Array} atList: 下拉框的选项
* @param {String} trigger: 关键字
* @param {String} placeholder 占位符
* @param {String} className 样式类名
* @param {Object} style 样式style
* @param {Object} showCount 是否显示输入框字符长度、最大长度、是否显示message提示
* @param {Function} onInput 输入框变化时的回调
* @param {Function} replaceNormalToHtml 自定义构造回显格式,普通字符串替换成html字符串
* @returns 
*/
const AtEditor = ({
 refInstance,
 atList = defaultList,
 trigger = '@',
 placeholder = '请输入',
 className = '',
 style = {},
 showCount = {},
 onInput,
 replaceNormalToHtml = _replaceNormalToHtml
}) => {

}

其他说明

forwardRef+useImperativeHandle向外抛出了这五个方法用于获取和设置输入框的值

useImperativeHandle(refInstance, () => {
  return {
    getNormalData, // 得到输入框显示的字符串,没经过任何包装
    getHtmlData, // 得到html字符串
    setDataFromNormal, // 把后台拿到的普通字符串赋到输入框,用于回显
    setDataFromHtml, // 把html字符串直接值赋到输入框,用于回显
    resetData, // 重置输入框
  }
}, []);
export default forwardRef(
  (props, ref) => <AtEditor {...props} refInstance={ref} />
)

在父组件使用:例如atRef.current.getHtmlData()、atRef.current.setDataFromHtml(xxx)


有用的话点个免费的star谢谢