1.1.5 • Published 3 years ago

swapform v1.1.5

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

Build version bootstrap version JS gzip size CSS gzip size vulnerabilities license

Table of contents

Quick start

What's included

swapform/
└── dist/
    ├── css/
    │   ├── swapform.css
    │   ├── swapform.css.map
    │   ├── swapform.min.css
    │   └── swapform.min.css.map
    └── js/
        ├── swapform.js
        ├── swapform.js.map
        ├── swapform.min.js
        └── swapform.min.js.map

Documentation

Quite simply, wrap an input or textarea in a <div> element with an sf-form class. Then add the sf-label class to the <label> element. Swapform will automatically perform everything else.

Input examples

Basic

<div class="sf-form">
    <label class="sf-label">Enter username</label>
    <input type="text" class="form-control">
</div>

Basic swap

Swapping label when focused

<div class="sf-form">
    <label class="sf-label" data-description="Who are you?">Enter username</label>
    <input type="text" class="form-control">
</div>

Basic swap

Swapping multiple labels when focused and when input value is filled

<div class="sf-form">
    <label class="sf-label" data-description="Who are you?" data-filled="That's what she said">
        Enter username
    </label>
    <input type="text" class="form-control">
</div>

Basic swap

Textarea examples

The <textarea> element supports the same swapping methods outlined above, and also supports automatic height expansion, fixed heights and multiple sizes. Below is a table listing the available classes for a <textarea> depending on the features and size desired.

Expanding Textarea

Classes for fixed heights and auto-expanding heights

ClassSuffixSizesDescription
sf-textarea-sm, md, lg160px, 320px, 640pxAutomatically expands to a maximum height based on content
sf-textarea-fixed-sm, md, lg160px, 320px, 640pxHas a fixed height

Basic, medium, fixed height

Class: sf-textarea-fixed-md

<div class="sf-form">
    <label class="sf-label">Tell me a story</label>
    <textarea class="form-control sf-textarea-fixed-md"></textarea>
</div>

Basic, large, expanding height

Class: sf-textarea-lg

<div class="sf-form">
    <label class="sf-label">Tell me a story</label>
    <textarea class="form-control sf-textarea-lg"></textarea>
</div>

Basic, large, expanding height, with swapping texts

Class: sf-textarea-lg

Focused: Surprise me!

Filled: Cool story bro

<div class="sf-form">
    <label class="sf-label" data-description="Surprise me!" data-filled="Cool story bro">Tell me a story</label>
    <textarea class="form-control sf-textarea-lg"></textarea>
</div>

Supported classes

Basic

ClassDescription
sf-formUsed to wrap around a <label> with an accompanying <input> or <textarea>

Labels

ClassDescription
sf-label-smShould be used when using form-control-sm in your input/textarea elements
sf-labelShould be used when using regular form-control in your input/textarea elements
sf-label-lgShould be used when using form-control-lg in your input/textarea elements

Textarea

ClassDescription
sf-textarea-smAuto expanding height up to 160px
sf-textarea-mdAuto expanding height up to 320px
sf-textarea-lgAuto expanding height up to 640px
sf-textareaAuto expanding height infinitely
sf-textarea-fixed-smFixed height, 160px
sf-textarea-fixed-mdFixed height, 320px
sf-textarea-fixed-lgFixed height, 640px

Supported data attributes

These are used on <input> or <textarea> elements. The color and file input types are not supported at this time.

OptionDescription
data-descriptionThe value is swapped in when a form input or textarea is focused
data-filledThe value is swapped in when a form input or textarea has a value and is no longer focused

Screenshots

Basic

Basic swap

Using HTML

HTML Swap

Using emojis

Emoji Swap

Auto expanding textarea

Expanding Textarea

Builds

If you are using the npm build, you can rebuild the compiled assets after making any desired changes by running any of the following commands:

OptionDescription
css-compileGenerates a non-minified version of the css and stores it in ./dist/css/swapform.css
css-minifyGenerates a minified version of the css and stores it in ./dist/css/swapform.min.css
js-compile-devGenerates a non-minified version of the javascript and stores it in ./js/dist/swapform.js
js-minify-devGenerates a minified version of the javascript and stores it in ./js/dist/swapform.min.js
js-compile-prodGenerates a non-minified version of the javascript and stores it in ./dist/js/swapform.js
js-minify-prodGenerates a minified version of the javascript and stores it in ./dist/js/swapform.min.js

All the above commands also generate source maps

Todo

  • Add a new method to detect errors on form validation and allow handling

Creator

Robert Miller

1.1.1

3 years ago

1.1.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago