1.7.1 • Published 3 years ago

ojs-components v1.7.1

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

ojs-components

Module with ready to use components. Like input, button, select and more

Quick start

npm i ojs-components
Components:
  • OInput
// import 
import { OInput } from 'ojs-components';

// declaration
const store = {
    example: ''
}
const input = new OInput({
    label: 'Example Input',
    type: 'text',
    db: store,
    name: 'example'
    change: () => { /* fired when input value change */ }
})

// use
document.body.appendChild(
    input.init()
);

OInput needs only one argument: configObject with properties

Value in the store object will be replaced everytime when input value changes. Attribute value is defined as store'example'. When we type something in input like: 'hello', result will be: store'example' = 'hello'

PropertydescriptionType
attributescustom attributes to input. For example: { 'placeholder': 'exampleText' } array
change / keyup / focus / blur etc.fire event will run defined functionfunction
dbdefined store objectobject
disableddefined input is disabled or noboolean
eventscustom events. For example: { name: 'change', fn: () => {} } array
indexWhen name is array, we can define index of input valuestring/number
inputClassdefined class name of input. "ojsInput__input" by defaultstring
inputStyledefined inline styles of inputstring
labeldefines text above the input - labelstring
labelStyledefined inline styles of labelstring
labelClassdefined class name of label. "ojsInput__label" by defaultstring
namedefined name that is declared in dbstring
placeholderdefined input placeholderstring
requireddefined input is required or noboolean
typedefined type of input: text, number, password etc. text is declared by defaultstring

We also have defined methods for use on our input component:

  • disabled
  • enabled
  • getId
// For example: disabled input when we typed something

const input = new OInput({
    label: 'Example Input',
    type: 'text',
    db: store,
    name: 'example'
    change: () => input.disabled(); 
})

// and enable when you want just by use: input.enabled()

  • OButton
// import
import { OButton } from 'ojs-components';

// declaration 
const button = new OButton({
    text: 'Example button',
    type: 'primary',
    click: () => {
        // run this script on click
    },
});

// use
document.body.appendChild(
    button.init()
);

OButton like OInput need one argument: configObject. There are list of properties:

PropertydescriptionType
attributescustrom attributes. For example: { 'name': 'hello' } array
classNamesyour custom classes for buttonstring
click and other eventsrun function while event happenfunction
disableddefined if button is disabledboolean
styledefined inline stylesstring
submitif true, button will be type submit. type is button by defaultboolean
textdefined button textstring
typethere are few types: primary, secondary, primary-confirm, primary-cancel, secondary-confirm, secondary-cancel, link, link-confirm, link-cancel. There specified style of buttonstring

We also have defined methods for use on our button component:

  • textToggle
  • disabled
  • enabled
  • getId
// For example, change text from On to Off when we clicking button

const button = new OButton({
    text: 'On',
    type: 'primary',
    click: () => {
        button.textToggle('On', 'Off');
        // we can also disabled this button after click
        button.disabled();
    },
});

// and enable when you want just by use: button.enabled()

  • OSelect
// import
import { OSelect } from 'ojs-components';

// declaration 
const store = {
    fruit: ''
}
const select = new OSelect({
    text: 'Your favourite fruit?',
    type: 'primary',
    name: 'fruit',
    db: store,
    options: [
        { text: 'Apple', value: 'apple'}
        { text: 'Pear', value: 'pear'}
    ]
});

// use
document.body.appendChild(
    select.init()
);

OSelect like others need one argument: configObject. There are list of properties:

PropertydescriptionType
attributescustom attributes to input. For example: { 'placeholder': 'exampleText' } array
change / click / focus / blur etc.fire event will run defined functionfunction
dbdefined store objectobject
disableddefined input is disabled or noboolean
eventscustom events. For example: { name: 'change', fn: () => {} } array
indexWhen name is array, we can define index of input valuestring/number
labeldefines text above the input - labelstring
labelClassdefined class name of label. "ojsInput__label" by defaultstring
labelStyledefined inline styles of labelstring
namedefined name that is declared in dbstring
optionsoptions list for select: { text: 'Apple', value: 'apple' } array
requireddefined select is required or noboolean
selectClassdefined class name of select. "ojsSelect" by defaultstring
selectStyledefined inline styles of selectstring

We also have defined methods for use on our select component like in button:

  • disabled
  • enabled
  • getId
// example: disable select component after select option
const select = new OSelect({
    text: 'Your favourite fruit?',
    type: 'primary',
    name: 'fruit',
    db: store,
    options: [
        { text: 'Apple', value: 'apple'}
        { text: 'Pear', value: 'pear'}
    ]
    change: () => select.disabled();
    
});

  • OCheckbox

example:

// import
import { OCheckbox } from 'ojs-components';

// declaration 
const store = {
    'likeApples': false,
}
const checkbox = new OCheckbox({
    label: 'I like apples',
    name: 'likeApples',
    db: store,
    change: () => // do something,
});

// use
document.body.appendChild(
    checkbox.init()
);

Properties list:

PropertydescriptionType
change / click / focus / blur etc.fire event will run defined functionfunction
checkboxClassdefined class name of checkbox.string
checkboxStyledefined inline styles of checkbox.string
dbdefined store objectobject
disableddefined input is disabled or noboolean
eventscustom events. For example: { name: 'change', fn: () => {} } array
labeldefines text next to the checkbox - labelstring
labelClassdefined class name of label. "ojsCheckbox__label" by defaultstring
labelStyledefined inline styles of labelstring
namedefined name that is declared in dbstring
requireddefined select is required or noboolean
spanClassdefined class name of span. "ojsCheckbox__span" by defaultstring
spanStyledefined inline styles of spanstring

We also have defined methods for use on our checkbox component like in others:

  • disabled
  • enabled
  • getId

  • ORadio
// import
import { ORadio } from 'ojs-components';

// declaration 
const store = {
    'favouriteFruit': '',
}

const oRadioFirst = new ORadio({
    label: 'Apple',
    value: 'Apple',
    name: 'favouriteFruit',
    db: store,
    change: () => // change function
});
const oRadioSecond = new ORadio({
    label: 'Pear',
    // if u don't add value property - input will set value = label, so here value will be Pear
    name: 'favouriteFruit',
    db: store,
    change: () => // change function
});

// use
document.body.appendChild(
    oRadioFirst.init()
    oRadioSecond.init()
);

Properties list:

PropertydescriptionType
change / click / focus / blur etc.fire event will run defined functionfunction
dbdefined store objectobject
disableddefined input is disabled or noboolean
eventscustom events. For example: { name: 'change', fn: () => {} } array
labeldefines text next to the checkbox - labelstring
labelClassdefined class name of label. "ojsCheckbox__label" by defaultstring
labelStyledefined inline styles of labelstring
namedefined name that is declared in dbstring
radioClassdefined class name of radio.string
radioStyledefined inline styles of checkbox.string
requireddefined select is required or noboolean
spanClassdefined class name of span. "ojsCheckbox__span" by defaultstring
spanStyledefined inline styles of spanstring
valueoptional, if not defined value = labelstring

We also have defined methods for use on our checkbox component like in others:

  • disabled
  • enabled
  • getId
1.7.1

3 years ago

1.7.0

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.6.9

3 years ago

1.6.11

3 years ago

1.6.8

3 years ago

1.6.10

3 years ago

1.6.7

3 years ago

1.6.13

3 years ago

1.6.6

3 years ago

1.6.12

3 years ago

1.6.5

3 years ago

1.6.14

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