1.1.6 • Published 2 years ago

react-insect v1.1.6

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

Insect

⚡️ Features

  • Tiny size (~4kb Gzip)
  • 100% responsive.
  • Highly customisable.
  • Supports custom rem unit.
  • Zero third party dependency (asides react's recommended prop-types).
  • Typescript ready
  • Multi select options
  • Options search
  • Custom icons support

💾 Installation

$ yarn add react-insect

📄 Basic Usage

// Import Insect component
import { Insect } from 'react-insect';

// Use it in your code like so
export const MyComponent = () => {
  return (
    <>
      <Insect
        name="username"
        type="text"
        placeholder="Choose a username"
      />
    </>
  );
};

🪄 Props

Insect can be either an input field, a single select field or a multi select field. The props passed in determines what Insect is. Here's a table of all available props for input and for select.

🧩 General props

PropDescriptionTypedefault
nameSets the name of the input field.string
typeSets type of input fieldtext \| textarea \| number \| password \| email \| selecttext
labelAdds a label to the top of insect component.string
placeholderSets the placeholder for insect component.stringInput or select an option
prefixIconAdds an icon at the left of insect fieldstring \| React.ReactNode \| null
suffixIconAdds an icon at the right of insect fieldstring \| React.ReactNode \| null
classNameCustom classname for main insect containerstring
labelClassCustom classname for insect labelstring
inputWrapperClassCustom classname for the input field wrapper divstring
inputClassCustom classname for the main input fieldstring
iconsClassCustom classname for all iconsstring
onFocusFunction to trigger when input field is focused on.(e: React.FocusEvent<HTMLInputElement>) => void
onBlurFunction to trigger when input field goes out of focus.(e: React.FocusEvent<HTMLInputElement>) => void

🏁 For Input field type

PropDescriptionTypedefault
valueSets the value of the input field.string
rowsSets the number of rows for textareanumber
onChangeSets the placeholder for insect component.(e: React.FormEvent<HTMLInputElement>) => void

🔮 For Select field type

PropDescriptionTypedefault
allowMultipleEnables multi select by setting the number of selectable itemsnumber
searchToggles option searchboolean(false)
optionsA list of options for the select field{ title: string; value: string; }[]
onSelectFuntion to trigger when an item is selected. It returns the field name and then returns a single string for single select and an array of strings for multi select(value: string \| string[] \| null, name: string) => void
dropdownIconCustom icon for dropdown caretstring \| React.ReactNode \| null
checkmarkIconCustom selected item indicator iconstring \| React.ReactNode \| null
dropdownClassCustom classname for the dropdown container div. This div wraps the ul tag which in turn wraps the individual li tagsstring
checkerClassCustom classname for the selected items indicator iconstring
closeOnBlurDetermines if the dropdown should close when outside is clicked or notbooleantrue

🦄 Usage with custom PX - REM unit

Sometimes, you may want to set the default rem unit to 10rem/1px (or any value at all) by adding font-size: 10px (or some kind of viewport based value) to the html tag in order to simplify rem/px unit conversion. This will cause a lot of problems with third party components but don't worry, insect got you!

Just add the following css variable to your main stylesheet and insect will adapt to your new unit.

:root {
  --insect-rem: 10 !important;
}

👷🏽 Contribution Guide

Insect is an opensource project and public contribution is very welcome. You can check Issues for bugs to fix or features to add.

  1. Fork this repository.
  2. Clone the forked repository to your local machine.
  3. Create a new branch with a name like this - feature/name-of-feature.
  4. Run yarn to install dependencies.
  5. Write code and then commit changes.
  6. Run yarn build to compile a build into the dist folder.
  7. Now You can decide to manually copy the index.tsx and index.scss file from here into a local project in order to test the feature/bug you have fixed.
  8. Alternatively, run yarn link in your local insect root folder.
  9. On the local project you want to test the features on, run yarn link 'insect'.
  10. Now navigate back to the terminal on your local insect folder and then run npm link ../path-to-test-project/node_modules/react. This will make insect use the copy of react from your local test project. Now you can test your changes.
  11. After all is done, push to your forked repository and then send a pull request.

⚖️ Licence

MIT (c) Collins Enebeli.

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

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.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago