1.0.0 • Published 6 years ago

ssuggestor v1.0.0

Weekly downloads
27
License
MIT
Repository
github
Last release
6 years ago

ssuggestor

GitHub license GitHub release Travis branch Coverage Status Codacy Badge npm npm Package Quality PeerDependencies code style: prettier Twitter

React component that enables users to quickly find and select from a pre-populated list of values as they type. Current theme provided use Bootstrap styles.

Demo

Live Demo: carloluis.github.io/ssuggestor

Suggestor example on CodePen

Instalation

# using yarn
yarn add ssuggestor

# using npm
npm i ssuggestor

Usage

npm

import React from 'react';
import { render } from 'react-dom';
import 'ssuggestor/dist/styles.css';
import b3Theme from 'ssuggestor/dist/bootstrap-3.json';
import Suggestor from 'ssuggestor';

render(
    <Suggestor
        list={['suggestion-a', 'suggestion-b', 'suggestion-c', '...', 'suggestion-z']}
        theme={b3Theme}
        onChange={value => {}}
        onSelect={(value, suggestion) => {}}
        placeholder="placeholder text..."
    />,
    document.querySelector('#app')
);

browser

Include react dependencies and ssuggestor scripts:

<script src="https://unpkg.com/react@16.3.0/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16.3.0/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/ssuggestor@0.9.0/dist/ssuggestor.min.js"></script>

<!-- bootstrap styles -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Description

This Simple Suggestor package provides a React component as default export: It handles clicks outside of DOM component in order to close the suggestion list. All pattern matches are highlighted.

Example:

  • input pattern: sugge
  • items on suggestion list: autoSuggest, ssüggèstor and suggests

Then,

  • matches are case insensitive: autoSuggest
  • pattern test is performed removing accents: ssüggèstor

Suggestion Objects

Suggestion objects use requires a selector function to convert each object into string representation which will be displayed on the suggestion list.

Props:

PropTypeDefaultDescription
accentsBooleanfalsewhether to differentiate chars with accents or not
arrowBooleantrue▼ icon - open suggestion list
themeObject{}JSON theme with css classes for each dom element
closeBooleantrue✖︎ icon - delete current value
listArray--suggestions (required)
selectorFunctions => ssuggestions selector (must return a string)
openOnClickBooleantruewhether suggestion list opens on click or not
onSelectFunction() => {}onSelect handler: (value, suggestion) => { }
onChangeFunction() => {}onChange handler: (value) => { }
onKeyFunction() => {}onKey handler: (keyEvent) => { }
placeholderString--input placeholder text
requiredBooleanfalseif true, set required attribute on <input> element
selectOnTabBooleanfalseif true, enables Tab key to select ssuggestion
styleObject--inline styles for component's root element
suggestOnNumber1minimum size of search string to show suggestions
tooltipString--input title text (simple tooltip)
valueString''initial value
useKeysBooleantruewhether to use supported keys or not

Supported Keys

Up, Down, Enter, Escape & Tab.

Theme

Provide JSON with classes for styling the component:

{
    "root": "class(es) used on wrapper element",
    "input": "<input> element class(es)",
    "arrow": "open <span> indicator class(es)",
    "close": "remove <span> indicator class(es)",
    "list": "<ul> class(es)",
    "item": "<li> class(es)",
    "activeItem": "active <li> class(es)"
}

This package also provides a theme using custom classes from styles.css and others from Bootstrap.

  • Custom class names start with the ss- prefix. Required to import ssuggestor/dist/styles.css
  • Bootstrap classes: input-group, form-group and dropdown-menu.
{
    "root": "input-group ss-root",
    "input": "form-control ss-input",
    "arrow": "ss-arrow",
    "close": "ss-remove",
    "list": "dropdown-menu ss-list",
    "item": "",
    "activeItem": "ss-over-item"
}

Note that you need to import the Bootstrap3 theme from ssuggestor/dist/bootstrap-3.json

Check usage on npm section.

{
    "root": "input-group ss-root",
    "input": "form-control ss-input",
    "arrow": "ss-arrow",
    "close": "ss-remove",
    "list": "dropdown-menu ss-list",
    "item": "dropdown-item",
    "activeItem": "ss-over-item"
}

Note that you need to import the Bootstrap4 theme from ssuggestor/dist/bootstrap-4.json

Check usage on npm section.

Focus

Use public method focus to set focus in <input> element.

<suggestor-instance>.focus();

Development

In order to run this project locally clone this repo, restore dependencies and execute dev task:

git clone https://github.com/carloluis/ssuggestor.git
cd ssuggestor
yarn
yarn dev

Open browser on localhost:9000

License

MIT © Carloluis

1.0.0

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago