1.0.15 • Published 4 years ago

atomicatoms v1.0.15

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

Atomic Atoms

A small library for little components based in atomic design

Install

To install the library, run on terminal

npm i atomicatoms

Make sure that you have installed type script loader.

Import

To import an atomicatom in your project

import {button} from 'atomicatoms';

All components

All the components have 3 params in common that you must pass when instanciate the component. This params are:

parent

Is the parent container of component. When the component will be creted, will do into parent.

example:

parent: '#container1'

className

Class name that you would add to component. Separate with space.

example:

className: 'myClass1 myClass2'

events

It's an object with the events that you want to add in the component.

example:

events: {
    click: (e) => 
        console.log('click', e.target.value),
    change: (e) => 
        console.log('change', e.target.value),
}

Container

This component is a little different than the others. Component doesn't accept className and events. The component only creates an array of container that displays into parent.

container({
    type: 'div',
    parent: 'body',        container: ['container1','container2','container3']
});

Button

import {button} from 'atomicatoms';

example:

button({
    parent: '#container1',
    className:'login__button',
    atomicName: 'button', // optional
    text: 'Login',
    events: {
        click: () =>
            console.log('hello world')
    }
});

Radio button

import {radioButton} from 'atomicatoms';

example:

radioButton({
    parent: '.genders',
    className: 'gender__radio',
    atomicName: 'radioButtons', // optional
    list: [{
        name: 'gender',
        text: 'male',
        value: '1',
        checked: true
    },{
        name: 'gender',
        text: 'female',
        value: '2',
        checked: false
    }],
    events: {
        click: (e) => console.log(e.target.parentElement.getValue())
    }
});

Checkbox

import {checkBox} from 'atomicatoms';

example

checkBox({
    parent: '#container1',
    className: 'hello eoo',
    atomicName: 'checkBoxers', // optional
    list: [{
        text: 'hello',
        value: '1',
        checked: true
    },{
        text: 'ssss',
        value: '2',
        checked: true
    }], 
    events: {
        click: (e) => console.log(e.target.parentElement.getValue())
    }
});

Select

import {select} from 'atomicatoms';

example

select({
    parent: '#container1',
    className: 'class',
    atomicName: 'selector', // optional
    options: [{
        text: 'opt1',
        value: '1',
        selected: false
    },{
        text: 'opt2',
        value: '2',
        selected: false
    }],
    events: {
        change: (e) => console.log(e.target.value)
    }
});

Input

import {input} from 'atomicatoms';

example

input({
    parent: '#container1',
    className: 'ssss',
    atomicName: 'input', // optional
    type:'text',
    value:'value',
    placeholder:'Placeholder', 
    events: {
        change: (e) => console.log(e.target.value)
    }
});

Textarea

import {textarea} from 'atomicatoms';

example

input({
    parent: '#container1',
    className: 'ssss',
    atomicName: 'textarea', // optional
    value:'value',
    placeholder:'Placeholder', 
    events: {
        change: (e) => console.log(e.target.value)
    }
});

Img

import {img} from 'atomicatoms';

example

img({
    parent: '.img',
    className: 'myClass',
    atomicName: 'img', // optional
    src:'https://res.cloudinary.com/glovoapp/w_1200,f_auto,q_auto/Stores/gfcwneqwjwva7whbg8oa',
    alt: 'myAlt',
    events: {
        change: (e) => console.log(e.target.value)
    }
});

Link

import {link} from 'atomicatoms';

example

link({
    parent: '#container1',
    className: 'classer',
    atomicName: 'link', // optional
    text: 'My link text',
    href:'https://res.cloudinary.com/glovoapp/w_1200,f_auto,q_auto/Stores/gfcwneqwjwva7whbg8oa',
    title: 'My link title',
    target: '_blank',
    events: {
        change: (e) => console.log(e.target.value)
    }
});

Text

import {text} from 'atomicatoms';

example

text({
    parent: '#container1',
    className: 'ssss',
    atomicName: 'text', // optional
    title: 'My title', 
    type: 'h1',
    events: {
        change: (e) => console.log(e.target.value)
    }
});

List

List component has a data-id to identify each li element.

import {list} from 'atomicatoms';

example

list({
    parent: '#container1',
    className: 'ssss',
    atomicName: 'list', // optional
    list: [{
        text: 'helo',
        id: '1'
    },{
        text: 'uuuu',
        id: '2'
    }], 
    events: {
        click: (e) => console.log(e.target)
    }
});

Events

getData

When this function is triged, all atomicAtoms in document put their data into an object with their atomicName.

example

import {button, getData} from 'atomicAtoms';

button({
    parent: '#container1',
    className:'login__button',
    atomicName: 'button', // optional
    text: 'Login',
    events: {
        click: () => getData()
    }
});

output

{
    checkBox: (2) ["1", "2"]
    input: "value"
    inputFile: ""
    radio: "1"
    select: "1"
    textarea: "value"
}

Thank you :)

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.5

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.0

5 years ago