Giter VIP home page Giter VIP logo

acreto / react-structured-query-search-suggestions Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 2.64 MB

react-structured-query-search-suggestions is a javascript library that provides autocomplete search queries with dynamic/static suggestions.

Home Page: https://acreto.github.io/react-structured-query-search-suggestions/

JavaScript 66.93% HTML 1.59% CSS 0.32% SCSS 31.15%
react-structured-query-search react-structured-query-suggestions react-search react-search-component react-query react-query-builder react-visual-search visual-search react-token-input react-tokenizer

react-structured-query-search-suggestions's Introduction

react-structured-query-search-suggestions ๐ŸŽ‰

NPM JavaScript Style Guide

react-structured-query-search-suggestions is a javascript library that provides autocomplete search queries with dynamic/static suggestions. This was inspired by visualsearch, react-structured-filter and react-structured-query-search.

This plugin is written on top of react-structured-filter, which has been revamped to add React 16 support and the existing code has been overriden to support New features.

You can use all the react-typeahead, react-structured-filter API(options) as they are.

๐ŸŽ‰๐ŸŽŠ Features ๐ŸŽŠ๐ŸŽ‰

  • Allows user to search without any category & operator (Free text search) for maximum of one search term
  • Ajax support to retrieve values incrementally as the user types
  • Allows user to send values for Category in Array<String> or Array<Object>
  • Allows user to pass custom loader component.
  • Allows user to customize the header of dropdown (categories, operators, values).
  • Allows user to enable/disable operators in search.
  • Allows user to perform category-value search without operator (if isAllowOperator is false).
  • Switch between unique/duplicate categories (key).
  • Switch between unique/duplicate values
  • Allows user to send custom operators list.
  • Allows user to render custom tag(token) Component or the tag(token) Item.
  • Allows user to update Options(props) at runtime.
  • Allows user to set date with time (hh mm ss)

Install

npm install --save react-structured-query-search-suggestions

Usage (Example Code) (Demo)

If you want to use Tokenizer then you either import as follows:

import ReactStructuredQuerySearch from "react-structured-query-search-suggestions";
import "react-structured-query-search-suggestions/dist/index.css";

or

import {Tokenizer} from "react-structured-query-search-suggestions";
import "react-structured-query-search-suggestions/dist/index.css";

If you want to use Typeahead then you have to import as follows:

import {Typeahead} from "react-structured-query-search-suggestions";
import "react-structured-query-search-suggestions/dist/index.css";

API

New flexible modification/existing options

Parameter Type Default Description
options Array [] An array supplied to the filter function.
maxVisible Number Limit the number of options rendered in the results list.
customClasses Object Allowed Keys:
  • input
  • results
  • listItem
  • listAnchor
  • hover
  • typeahead
  • resultsTruncated
  • token
An object containing custom class names for child elements. Useful for integrating with 3rd party UI kits.
placeholder String Placeholder text for the typeahead input.
๐Ÿ†• disabled Boolean false Set to true for disabling the StructureQuerySearch
๐Ÿ†• defaultSelected function, Array [] Allows user to initialize the search with selected values (Include isAllowFreeSearch:true in the free search term selected option)
๐Ÿ†• categoryHeader String, Component "Category" Allows user the change the header title of Category
๐Ÿ†• clickToEditToken Boolean false Allows user to edit the selected token by clicking on it
๐Ÿ†• operatorHeader String, Component "Operator" Allows user the change the header title of Operator
๐Ÿ†• valueHeader String, Component "Value" Allows user the change the header title of Value
๐Ÿ†• isAllowSearchDropDownHeader Boolean "true" Allows user to enable/disable search drop-down header
๐Ÿ†• isAllowOperator Boolean false Allows user to enable/disable operators in search
๐Ÿ†• isAllowClearAll Boolean true Allows user to clear all selected data
onTokenRemove Function Event handler triggered whenever a token is removed.
onTokenAdd Function Event handler triggered whenever a token is added.
Params: (addedToken)
๐Ÿ†• onClearAll function Event handler triggered whenever clear all button clicked
onOptionSelected Function Event handler triggered whenever a user picks an option.
๐Ÿ†• updateOptions function Allows user to update the Options(props) at runtime, this function is called before onTokenRemove and onTokenAdd
๐Ÿ†• fuzzySearchEmptyMessage String "No result found" This message is shown when dropdown doesn't have search value
๐Ÿ†• renderLoading function, Component "Loading...." Show custom loader when values are retrieved using Ajax
๐Ÿ†• renderTokens function Allows user to render custome Token Component
๐Ÿ†• renderTokenItem function Allows user to render custome Token Item
๐Ÿ†• renderSearchItem function Allows user to render custome value
๐Ÿ†• fetchData function [] Allows user to fetch dynamic suggestions(options). (Required if any of the options has type:"textoptions" and dynamicOptions:true)
onKeyDown Function Event handler for the keyDown event on the typeahead input.
onKeyPress Function Event handler for the keyPress event on the typeahead input.
onKeyUp Function Event handler for the keyUp event on the typeahead input.
onBlur Function Event handler for the blur event on the typeahead input.
onFocus Function Event handler for the focus event on the typeahead input.

props.options (Data attributes)

Parameter Type Default Required Description
category String required Name of the first thing the user types.
type String text This can be one of the following:
  • text: Arbitrary text for the value. No autocomplete options.
    • Operator choices will be: "=", "!=", "contains", "!contains".
  • textoptions: You must additionally pass an options value.
    • Operator choices will be: "=", "!=".
  • number: Arbitrary text for the value. No autocomplete options.
    • Operator choices will be: "=", "!=", "<", "<=", ">", ">=".
  • date: Shows a calendar and user can choose date and time.".
    • Operator choices will be: "=", "!=", "<", "<=", ">", ">=".
๐Ÿ†• operator Array, function required, if isAllowOperator prop is set to true If this attribute is added then it would ignore the type check as described in type parameter and it would accept what you have passed
options Array required, if type="textoptions" Get the value according to selected category
dynamicOptions Boolean false A boolean which if set to true, dynamic search suggestions(options) will be loaded using fetchData function. If set to false, static options will be served
๐Ÿ†• isAllowCustomValue Boolean false
When this parameter is set to true, it allows you to send multiple custom values for type=textoptions
๐Ÿ†• isAllowDuplicateCategories Boolean true Switch between unique/duplicate categories (key)
๐Ÿ†• isAllowDuplicateOptions Boolean false Switch between unique/duplicate values
๐Ÿ†• fuzzySearchKeyAttribute String name If Category (options)values are Array<Object> then By default fuzzy search look for name attribute inside options(values) but you can change that attribut lookup key using fuzzySearchKeyAttribute

How to Contribute

Setting Up

Please run npm install in the root and example folders. then do the following:

  • Go to root folder and run npm start after this
  • Go to example folder and run npm run link (only for first time)
  • Go to example folder and run npm start it would run the plugin from link which we have created.

Now, anytime you make a change to your library in src/ or to the example app's example/src create-react-app will live-reload your local dev server so you can iterate on your component in real-time.

License

MIT

react-structured-query-search-suggestions's People

Contributors

vikasmagar512 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

react-structured-query-search-suggestions's Issues

Support conditional Operator AND/OR

hello, I love the component but I'm lacking some feature like:

  1. support of conditional operator AND/OR
  2. I notice it has maximum of 3 sequence to complete encapsulation (field + operator + value). It would be nice if can customize to four (4) sequence (conditional + field + operator + value).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.