Gathering detailed insights and metrics for env-autosuggest
Gathering detailed insights and metrics for env-autosuggest
Gathering detailed insights and metrics for env-autosuggest
Gathering detailed insights and metrics for env-autosuggest
npm install env-autosuggest
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
A React component that provides variable autosuggestion functionality with a rich text editor-like interface. This component allows users to type variables within curly braces {{}}
and get intelligent suggestions based on predefined variables.
1npm install env-autosuggest
1import React, { useRef } from 'react'; 2import AutoSuggest from 'variable-autosuggest-npm'; 3 4function App() { 5 const contentEditableDivRef = useRef(null); 6 7 const suggestions = { 8 "apiKey": { 9 "initialValue": "", 10 "currentValue": "", 11 "scope": "Global" 12 }, 13 "userToken": { 14 "initialValue": "token12345abcdef", 15 "currentValue": "token67890ghijkl", 16 "scope": "Private" 17 }, 18 "apiUrl": { 19 "initialValue": "https://api.example.com", 20 "currentValue": "https://api.tech.com", 21 "scope": "Global" 22 }, 23 "username": { 24 "initialValue": "user_one", 25 "currentValue": "user_two", 26 "scope": "Global" 27 }, 28 "password": { 29 "initialValue": "pass1234", 30 "currentValue": "securePass5678", 31 "scope": "Private" 32 }, 33 "sessionToken": { 34 "initialValue": "sdfg6789asdf1234", 35 "currentValue": "qwerty1234uiop5678", 36 "scope": "Private" 37 } 38 }; 39 40 const handleValueChange = () => { 41 // Handle value changes here 42 console.log(contentEditableDivRef.current.innerText); 43 }; 44 45 return ( 46 <AutoSuggest 47 suggestions={suggestions} 48 contentEditableDivRef={contentEditableDivRef} 49 initial="" 50 handleValueChange={handleValueChange} 51 disable={false} 52 placeholder="Type {{ to see suggestions" 53 /> 54 ); 55}
Prop | Type | Required | Description |
---|---|---|---|
suggestions | Object | Yes | Object containing variable suggestions with their metadata (initialValue, currentValue, scope) |
contentEditableDivRef | Ref | Yes | React ref for the content editable div |
initial | String | No | Initial content of the editor |
handleValueChange | Function | No | Callback function triggered on content change |
disable | Boolean | No | Disables the editor when true |
placeholder | String | No | Placeholder text when editor is empty |
The suggestions object should follow this structure:
1{ 2 "variableName": { 3 "initialValue": string, // Original/default value 4 "currentValue": string, // Current/modified value 5 "scope": string // Scope of the variable (e.g., "Global", "Private") 6 } 7}
1{ 2 "apiKey": { 3 "initialValue": "", 4 "currentValue": "", 5 "scope": "Global" 6 }, 7 "userToken": { 8 "initialValue": "token12345abcdef", 9 "currentValue": "token67890ghijkl", 10 "scope": "Private" 11 } 12}
{{
to trigger suggestions{{
The component comes with default styles but can be customized using CSS classes:
.parent-div
: Main container.main__div
: Editor container.__custom-autosuggest-block__
: Content editable area.placeholder-editable-div
: Placeholder container.disable-div
: Applied when editor is disabled.__suggestions__container__
: Suggestions dropdown container.suggestion-item-div
: Individual suggestion item.__main__suggestion__container__
: Main suggestions list container👨💻 Idris Bohra
Feel free to connect with me for any questions, suggestions, or collaboration opportunities!
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
No vulnerabilities found.
No security vulnerabilities found.