1.0.14 β€’ Published 2 years ago

search-reactjs v1.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

npm Price License: ISC GitHub package version

Image text

search-reactjs πŸš€

Search-reactjs component allows the search or filter of objects by specifying a search criteria according to the properties of the object, providing flexibility to the developer at the time of implementation and allowing the fulfillment of the requested requirements.

The component displays an input text where the user enters the value they want to search for, it also displays the button to start the search action. This component also allows to perform the search automatically while the user enters the text in the input.

Installing πŸ”§

To install the component use the Node Package Manager (npm). You must open the command console at the root of your project and execute the command:

 npm install search-reactjs --save 

Demo πŸ’»

Click me to go to the demo on codeSandbox!

Usage πŸ› οΈ

Here is an example of how to implement the component:

import logo from './logo.svg';
import './App.css';
import SearchReact from 'search-reactjs';
function App() {
  const users = [
    {
      name:'marvin', 
      home:{
        location:'Heredia',
        local:{
          number: 3
        }
      }
    },
    { 
      name:'Jose', 
      home:{
        location:'Puntarenas',
        local:{
          number: 5
        }
      }
    },
    { 
      name:'Mario', 
      home:{
        location:'Cartago',
        local:{
          number: 1
        }
      }
    },
    { 
      name:'Luna', 
      home:{
        location:'San Jose',
        local:{
          number: 2
        }
      }
    },
  ];
  let callBack = (result)=>{
    console.log('result',result);
  }
  return (
    <div className="App">
      <header className="App-header">
        <h1>Search Component</h1>
        <img src={logo} className="App-logo" alt="logo" />
        <h2>search-react</h2>
        <br/>
        <SearchReact
          listObjects={users}
          btnName={'Search'} 
          placeholder={"Search by name"}
          borderRadius={'2px'}
          fontSize={'17px'}
          searchCriteria={'name'}
          btnHoverBackground={'red'}
          btnHoverTextColor={''}
          hideButton={false}
          callBack={callBack}
        />
      </header>
      
      
    </div>
  );
}

export default App;

Props of styles πŸ“¦

Props for component styles are displayed as a table with Name, Type, Default, and Description as headings.

Required props are marked with *.

NameTypeDefaultDescription
inputColorstringblueIndicates the text color for the input text element.
inputWidthstring200pxIndicates the width for the input text element.
placeholderstringSerachIndicates the placeholder for the input text element.
heightstring30pxIndicates the height for the input text element and the button element.
borderRadiusstring5pxIndicates the border radius for the input text element and the button element.
fontSizestringIndicates the text size for the input text element and the button element.
btnColorstringblackIndicates the text color for the button element.
btnWidthstring100pxIndicates the width for the button element.
btnBorderstring2px solid #61DAFBIndicates the border for the button element.
btnHoverBackgroundstring#3dbadcIndicates the background color for hover the button element.
btnHoverTextColorstring#ffffIndicates the text color for hover the button element.
btnNamestringSerachIndicates the name for the button element.

Additional usage information πŸ“‹

Additional information about using the component pros.

  • inputColor: Use this prop for indicate the text color for input text element. You can specify this value as a string, in the format RGB hex ("#AA00FF") or RGB decimal ("rgb (71, 98, 176)") or RGB percentage ("rgb (27%, 38%, 69% )") or the name of color ("blue").
  • inputWidth: Use this prop for indicate the width of input text. Indicate this as a string and in pixel format("200px") or percentage format("10%").
  • height: Use this prop for indicate the height of input text and the button element. Specify this as a string and in pixel format ("30px") or percentage format ("10%").
  • borderRadius: Use this prop for indicate the border radius of input text and button elements. Specify this as a string and in pixel format ("5px") or percentage format ("10%").
  • fontSize: Use this prop for indicate the size of text for input text and button elements. Specify this as a string and in pixel format ("20px") or REM format ("1rem") or EM format ("1em").
  • btnColor: Use this prop for indicate the color of text for button element. You can specify this value as a string, in the format RGB hex ("#AA00FF") or RGB decimal ("rgb (71, 98, 176)") or RGB percentage ("rgb (27%, 38%, 69% )") or the name of color ("blue").
  • btnWidth: Use this prop for indicate the width of button element. Specify this as a string and in pixel format ("200px") or percentage format ("10%")..
  • btnBorder:Use this property to indicate the border size, border type, and border color for the button element. You can express these values ​​in a string and in the same format as specified in css3, for example: "2px solid #61DAFB".
  • btnHoverBackground: Use this prop to indicate the background of button element when hover. You can specify this value as a string, in the format RGB hex ("#AA00FF") or RGB decimal ("rgb (71, 98, 176)") or RGB percentage ("rgb (27%, 38%, 69% ) ") or the name of color ("blue").
  • btnHoverTextColor: Use this prop to indicate the color of button element's text on hover. You can specify this value as a string, in the format RGB hex ("#AA00FF") or RGB decimal ("rgb (71, 98, 176)") or RGB percentage ("rgb (27%, 38%, 69% ) ") or the name of color ("blue").

Props for functionality πŸ“¦

Props for component functionality are displayed as a table with Name, Type, Default, and Description as headers.

Required props are marked with *.

NameTypeDefaultDescription
hideButtonboolfalseIndicates if the search button will be shown.
searchCriteria*stringSpecify the search criteria.
listObjects*arrayArray of objects to be filtered.
callBack*functionFunction that will receive array of filtered objects.

Additional usage information πŸ“‹

Additional information about using the component pros.

  • hideButton: Use this prop for indicate whether to display the search button. You must indicate this value as a boolean. By default the value is false. By specifying the value as true, the search button will be hidden and the search will be done automatically when the user types the text in the input text element.
  • listObjects: Use this prop to specify the list of objects. You must specify this as a list of objects in json format.
  • callBack: Use this prop to specify the callback function where the result of the data filtering will be sent. The specified function must receive a parameter.
  • searchCriteria: Use this prop to indicate the search criteria on the list of objects. This value is indicated as a string.To specify a search criteria on nested objects, you can do it using the curly brackets, for example:
//List objects
  const users = [
    {
      name:'marvin',
      home:{
        location:'Heredia',
        local:{
          number: 3
        }
      }
    },
    {
      name:'Jose',
      home:{
        location:'Puntarenas',
        local:{
          number: 5
        }
      }
    }
  ]
//Possible criteria
<SearchReact listObjects={users} searchCriteria={'name'} />
or
<SearchReact listObjects={users} searchCriteria={'home.location'} />
or
<SearchReact listObjects={users} searchCriteria={'home.local.number'} />

Authors βœ’οΈ

People who helped build the project from its inception

License πŸ“„

This project is licensed under the ISC License - see the file LICENSE.md for details.

1.0.14

2 years ago

1.0.13

2 years ago

1.0.11

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago