json-autocomplete-input
v1.0.7
Published
A JSON path-based autocomplete input React component.
Maintainers
Readme
json-autocomplete-input
A React component for JSON path-based autocomplete input fields. Easily integrate smart, context-aware autocompletion for JSON data structures in your React apps.
Features
Autocomplete suggestions based on JSON paths
Customizable and themeable
Lightweight and easy to use
TypeScript support
Installation
npm install json-autocomplete-inputor
yarn add json-autocomplete-inputUsage
import React,{useState} from 'react';
import JsonAutocompleteInput from 'json-autocomplete-input';
const [value,setValue] = useState<string>();
const data = {
user: {
name: 'John',
age: 30,
address: {
city: 'New York',
zip: '10001'
}
}
};
function App() {
return (
<JsonAutocompleteInput
jsonData={data}
onChange={value => console.log(value)}
placeholder="Type a JSON path..."
value={value}
/>
);
}
export default App;Props
| Prop | Type | Description |
|-------------------|-------------------------------|---------------------------------------------------------|
| jsonData | any | The JSON object to provide path suggestions |
| value | string | The current value of the input |
| onChange | (value: string) => void | Callback when input value changes |
| placeholder | string (optional) | Input placeholder text |
| label | string (optional) | Label for the input field |
| inputStyle | CSSProperties (optional) | Inline styles for the input |
| popoverStyle | CSSProperties (optional) | Inline styles for the suggestion popover |
| suggestionStyle | CSSProperties (optional) | Inline styles for each suggestion item |
| suggestionActiveStyle| CSSProperties (optional) | Inline styles for the active suggestion item |
| ...others | any | Pass other input props as needed |
Contributing
Contributions are welcome! Please open issues or submit pull requests for improvements and bug fixes.
- Fork the repository
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/YourFeature) - Open a pull request
License
MIT © Priyanshu Gupta
