Giter Club home page Giter Club logo

slab's Introduction

Slab

Slab is a JavaScript component that handles search filters and queries.

Getting Started

Demo

A demo of the library in action can be found here.

Supported Browsers

So far tested on Chrome, Firefox, Safari and Opera.

Dependencies

Slab has 1 dependency – and that is Complete Me.

To Run

$ git clone [email protected]:callum-hart/Slab.git
$ cd Slab
$ npm install
$ grunt watch

To Use

Include CSS and JavaScript from Complete Me. Both need to be included before the CSS and JavaScript for Slab:

<!-- CSS -->
<link href="complete-me.min.css" rel="stylesheet">
<link href="slab.min.css" rel="stylesheet">

<!-- JavaScript -->
<script type="text/javascript" src="complete-me.min.js"></script>
<script type="text/javascript" src="slab.min.js"></script>

Create an instance:

var instance = new Slab(element, { options });

element can be a selector or a DOM element.

Configuration

firstComplete

  • Details
  • Type Object
  • Required Yes

secondComplete

  • Details
  • Type Object
  • Required Yes

withButton

  • Details
    • Give the Slab input a submit button.
  • Type Boolean
  • Default False

buttonClass

  • Details
    • Change what class is applied to the button.
  • Type String
  • Default ss-button
  • Condition

firstComplete.defaultKey

  • Details
    • Key that should be taken as the search filter if Slab is submitted when no filter has been selected by the user. The key is a reference to an object in the data option from Complete Me. data type for firstComplete will need to be Array <Object>.
  • Type String

Callbacks

onSubmit

onSubmit: (searchKey, searchValue) {}

  • Details
    • When the Slab input is submitted.
  • Arguments (searchKey, searchValue)
  • Condition
    • Only called when the search filter and query are valid.

Markup

Generated HTML

The HTML generated by Slab is:

<div class="sb-container">
  <span class="sb-label"></span>
  <div class="sb-complete first-complete-me cm-container">
    <div class="cm-input-wrap">
      <input type="text" class="cm-input">
      <input type="text" class="cm-suggestion">
    </div>
    <div class="cm-results-wrap">
      <ul class="cm-results">
        <li><a href="#"></a></li>
      </ul>
    </div>
  </div>
  <div class="sb-complete second-complete-me cm-container">
    <div class="cm-input-wrap">
      <input type="text" class="cm-input">
      <input type="text" class="cm-suggestion">
    </div>
    <div class="cm-results-wrap">
      <ul class="cm-results">
        <li><a href="#"></a></li>
      </ul>
    </div>
  </div>
  <span class="ss-tab"></span>
</div>

Conditional CSS Classes

Classes that are applied when a certain condition is true.

label-showing

.label-showing

  • Condition
    • Applied when the search filter is selected.
  • Element
    • Applied to .sb-container

focussed

.focussed

  • Condition
    • Applied when the Slab input is focussed.
  • Element
    • Applied to .sb-container

Conditional classes are applied to the Complete Me's rendered inside Slab. These can be found here.

slab's People

Contributors

callum-hart avatar

Stargazers

Lukács József avatar Matías Agustín Méndez avatar Luca D'Alessandro avatar Thomas Li avatar  avatar

Watchers

Bohonyi Balazs - Zsolt avatar James Cloos avatar  avatar  avatar

Forkers

wprobot

slab's Issues

Small glitch in Firefox

Steps to replicate:

  • firstComplete is initialized with a value and secondComplete is empty
  • click into Slab (secondComplete is focussed)
  • press delete (firstComplete is focussed)
  • issue: the cursor jumps to the beginning of the text (rather than the end)

Delete icon to clear Slab input

Add a cross on the right hand side that clears firstComplete and secondComplete when clicked.

("ss-tab" show show in front of the cross, when you hover over "ss-tab" it should go behind the cross).

Allow @setFirstComplete to work when data is a flat array

Currently firstComplete can only be set by the selectedKey option (which relies on data type being Array <Object>).

Add an option called selectedValue to firstComplete that selects an item in data when it's type is Array <String>.

For example:

data = ["a", "b", "c"]

selectedValue: "b"

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.