0.3.2 • Published 3 years ago

functionalities.js v0.3.2

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

Functionalities.js

Still under heavy development - v0.3.2

If you are looking for a library that gives you styled, prebuilt components you are in the wrong place!

Functionalities is a utility library for the frontend developers to help speed up development, and not impeed your websites design. It aims to offer solutions for all the common components such as sliders, forms, accordions and more, that you build in your frontend applications over and over again, but with one important fact: they only contain necessary CSS and core functions.

Links

Current Utilities

Instal via NPM

npm i functionalities.js

Utility: Sliders

released

Funcitonalities Sliders is a lightweight and very flexible slider utility. It has a lot of config so you can get it setup how you like, and we only serve the bare minimum of CSS so you can incorporate it into your design however you like.

Features

  • Supports vertical and horizontal sliders.
  • Can choose between slider types: loop, infinite and fade.
  • Can programatically slide in both directions.
  • Can programatically slide to a specific slide.
  • Supports touch/mouse drag, arrow keys and scroll wheel to navigate.
  • Can configure how many slides you want visible at once, or do that in your css with perPage: auto.
  • Has callback functions for before and after slide.
  • Has callback function for slide click events.

Example

Here is a basic exmaple of how to set up a slider. Feel free to conifgure it how you like, find out more about the config bellow.

<div id="sliderExample" class="slider">
    <div class="slide-wrapper">

        <div class="slide">
            <p>Slide 1</p>
        </div>
        <div class="slide">
            <p>Slide 2</p>
        </div>
        <div class="slide">
            <p>Slide 3</p>
        </div>

    </div>
</div>
import { Slider } from 'functionalities';

const sliderInstance = new Slider('sliderExample', {
    perPage: 3,
    autoPlay: true,
    gap: 10,
    slideDirection: 'rightDown',
    type: 'infinite',
    direction: 'horizontal',
    beforeSlide: (data) => {
        console.log('before', data);
    },
    afterSlide: (data) => {
        console.log('after', data);
    }
});

Config - Types

interface Config {
    perPage?: 'auto' | number,
    direction?: 'vertical' | 'horizontal',
    autoPlay?: boolean,
    slideDirection?: 'rightDown' | 'leftUp',
    gap?: number,
    speed?: number,
    type?: 'loop' | 'infinite' | 'fade',
    controls?: {
        touch?: boolean,
        arrows?: boolean,
        wheel?: boolean
    },
    classes?: {
        slider?: string,
        wrapper?: string,
        slide?: string
    },
    beforeSlide?: (response: {
        currentSlideIndex: number,
        totalSlides: number,
        lastDirection: string
    }) => void
    afterSlide?: (response: {
        currentSlideIndex: number,
        totalSlides: number,
        lastDirection: string
    }) => void
    clickEvent?: (response: {
        currentSlideIndex: number,
        totalSlides: number
    }) => void
};

Config - Breakdown

Refer to the config types above to see what values can be used for each config key.

KeyDescription
perPageSpecify how many slides you would like to fit within the width of the slider.
directionSpecify the direction you want the slider to orient in. This can be used to create both vertical and horizontal sliders.
autoPlaySpecify if you want the slider to auto play at set intervals.
slideDirectionSpecify the direction you want the slider to slide in. This is only used if autoPlay is true.
gapSpecify how large of a gap you want inbetween your slides. This is in pixels.
speedSpecify the delay between the autoPlay sliding through your slides. This is in ms.
typeSpecify how you want slides to behave when sliding. Either reset once reaching the end (loop), infinite or fade.
Key: controlsDescription
touchSpecify if you want mouse and touch navigation turned on for the slider.
arrowsSpecify if you want arrow key navigation turned on for the slider. In the future this will support custom keys being passed down in the config.
wheelSpecify if you want wheel navigation turned on for the slider.
Key: classesDescription
sliderSpecify the class you want to use to target your slider. This is what your would add in your markup to the slider element.
wrapperSpecify the class you want to use to target the slider wrapper.
slideSpecify the class you want to use for each slide.
CallbacksDescription
beforeSlideSpecify a callback function for beforeSlide. As the name suggests: this fires before the slider slides. Refer to the config types above for the response data.
afterSlideSpecify a callback function for afterSlide. As the name suggests: theis fires after the slider slides. Refer to the config types above for the repsonse data.
clickEventSpecify a callback function for clickEvent. This function is added as a click event on each slide and can be destroyed calling the destroy function.

Functions

FunctionsRequired ParamatersReturnsDescription
triggerSlidestring: 'rightDown' or 'leftUp'voidAs it sounds: calling this will trigger the slider to slide in the direction you specify. This function also fires the beforeSlide and afterSlide callbacks, which you can learn more about in the seciton above.
toSlidenumber: (index of the slide)voidCalling this function will navigate to the slide index that is passed to it. This can be used to in your pagination implementation. This function will fire the beforeSlide and afterSlide callbacks, which you can learn more about in the seciton above.
pauseN/ApromiseCalling this function, if you have autoPlay in the config enabled: will pause the slider for automatically sliding.
startN/ApromiseCalling this function, if you have autoPlay in the config enabled: will start the slider so it can automatically slide. This obviously only works if the slider has been paused previously, else will return an error.
destroyN/AvoidCalling this function will destroy all eventListeners for this slider. If you are using this in a spa, its probably best to call this if navigating away from its page.

Limitations / Future Features / Notes

features

  • Feature: Config will be added to support adding more keys to the controls keys navigation option.
  • Examples: A documentation site is in the works, which will contain a variety of exmaples on different configurations.

notes

  • Note: When using the config.type: 'fade' a default height will be set to the slider component with the class fixed-height. This is because the fade type makes the slides absolute to the wrapper so they can be overlayed on top of each other, and so needs a defined height to work. This should be overwritten to your liking.
  • Note: When using the config.direction: 'vertical' a default height will be set tot he slider component with the class fixed-height. This sldier type needs a defined height. This should be overwritten to your liking.

limitations

  • Limitations: As designed, this doesnt come with any pagination or arrow navigation prebuilt blocks, so we dont interfere with your sites design. We supply the functions you will need to add these.

Utility: Form/Input Validation

coming soon

Form/Input validation will be a simple solution to validating input fields based on a specified config.

Utility: Accordions

coming soon

Quickly get accordions up and running in a project. Just use our simple and felxible boiler plate, pass the parents ID into a new instance of accordions, configure it how you like or use the default config and you're done!

Utility: Animations

coming soon

Functionalities animations utility, makes adding animations to your elements, easier than ever. Create a new instance of animations, pass it some config where you will specify what attribute name and link the animation type you want to associate it with. Then all you have to do is add that attribute name to the elements you want it to apply on and the the utility will do the rest.

If you dont want to use any of our presets for animations, just set the animation type to false for that attribute name, and the library will add a class to those elements where you can then create your custom animation in your CSS.

Utility: Sticky Header

released

Sticky headers is as it sounds. Just add an ID to your header, create a new instance of the sticky header utility, pass it some config or use the defaults. This utility only adds functionality. No CSS! This is to ensure flexibility.

Then depending on the users scroll a handfull of classes will be added to the header. One for scrolled down, one for scrolled up and then one for when you are at the very top of the page. This will allow you to create headers that show and hide depennding on the direction the user scrolls, and that have different styles if not scrolled at all.

Features

  • Adds one of 3 configurable classes depending on scroll position.
  • Has a callback function you that fires on state change.

Example

Here is a basic exmaple of how to set up a slider. Feel free to conifgure it how you like, find out more about the config bellow.

<header id="siteHeader">

</header>
import { StickyHeaders } from 'functionalities.js';

const headerInstance = new StickyHeaders('siteHeader', {
    triggerDistance: 50,
    classes: {
        top: 'sticky-top',
        movedDown: 'sticky-down',
        movedUp: 'sticky-up'
    },
    onChange: (data) => {
        console.log(data);
    }
});

Config - Types

interface Config {
    triggerDistance?: number,
    classes?: {
        top?: string,
        movedDown?: string,
        movedUp?: string
    },
    onChange?: (response: {
        state: string,
        scrollPos: number
    }) => void
};

Config - Breakdown

Refer to the config types above to see what values can be used for each config key.

KeyDescription
triggerDistanceSpecify the total distance from the top of the page you want to add the movedDown and movedUp classes.
Key: classesDescription
topSpecify the class you want to use for when the header is above your triggerDistance value (at the top of the page).
movedDownSpecify the class you want to add to the header when you scroll down.
movedUpSpecify the class you want to add to the header when you scroll up.
CallbacksDescription
onChangeSpecify a callback function for onChange. Whenever the state of th. Refer to the config types above for the response data.

Functions

FunctionsRequired ParamatersReturnsDescription
destroyN/AvoidCalling this function will destroy all eventListeners for this instance of sticky headers.

Limitations / Future Features / Notes

notes

  • Note: As has been mentioned before, this does not include any CSS, it onyl adds classes to your header based on the scroll position.