npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ojs-components

v1.7.1

Published

Module with ready to use components

Downloads

7

Readme

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'

| Property | description | Type | |:------------:|:---------------------:|:------:| | attributes | custom attributes to input. For example: [ { 'placeholder': 'exampleText' } ] | array | change / keyup / focus / blur etc. | fire event will run defined function | function | db | defined store object | object | disabled | defined input is disabled or no | boolean | events | custom events. For example: [ { name: 'change', fn: () => {} } ] | array | index | When name is array, we can define index of input value | string/number | inputClass | defined class name of input. "ojsInput__input" by default | string | inputStyle | defined inline styles of input | string | label | defines text above the input - label | string | labelStyle | defined inline styles of label | string | labelClass | defined class name of label. "ojsInput__label" by default | string | name | defined name that is declared in db | string | placeholder | defined input placeholder | string | required | defined input is required or no | boolean | type | defined type of input: text, number, password etc. text is declared by default | string

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:

| Property | description | Type | |:------------:|:---------------------:|:------:| | attributes | custrom attributes. For example: [ { 'name': 'hello' } ] | array | classNames | your custom classes for button | string | click and other events | run function while event happen | function | disabled | defined if button is disabled | boolean | style | defined inline styles | string | submit | if true, button will be type submit. type is button by default | boolean | text | defined button text | string | | type | there are few types: primary, secondary, primary-confirm, primary-cancel, secondary-confirm, secondary-cancel, link, link-confirm, link-cancel. There specified style of button | string |

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:

| Property | description | Type | |:------------:|:---------------------:|:------:| | attributes | custom attributes to input. For example: [ { 'placeholder': 'exampleText' } ] | array | change / click / focus / blur etc. | fire event will run defined function | function | db | defined store object | object | disabled | defined input is disabled or no | boolean | events | custom events. For example: [ { name: 'change', fn: () => {} } ] | array | index | When name is array, we can define index of input value | string/number | label | defines text above the input - label | string | labelClass | defined class name of label. "ojsInput__label" by default | string | labelStyle | defined inline styles of label | string | name | defined name that is declared in db | string | options | options list for select: [ { text: 'Apple', value: 'apple' } ] | array | required | defined select is required or no | boolean | selectClass | defined class name of select. "ojsSelect" by default | string | selectStyle | defined inline styles of select | string

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:

| Property | description | Type | |:------------:|:---------------------:|:------:| | change / click / focus / blur etc. | fire event will run defined function | function | checkboxClass | defined class name of checkbox. | string | | checkboxStyle | defined inline styles of checkbox. | string | | db | defined store object | object | disabled | defined input is disabled or no | boolean | events | custom events. For example: [ { name: 'change', fn: () => {} } ] | array | label | defines text next to the checkbox - label | string | labelClass | defined class name of label. "ojsCheckbox__label" by default | string | labelStyle | defined inline styles of label | string | name | defined name that is declared in db | string | required | defined select is required or no | boolean | spanClass | defined class name of span. "ojsCheckbox__span" by default | string | spanStyle | defined inline styles of span | string

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:

| Property | description | Type | |:------------:|:---------------------:|:------:| | change / click / focus / blur etc. | fire event will run defined function | function | db | defined store object | object | disabled | defined input is disabled or no | boolean | events | custom events. For example: [ { name: 'change', fn: () => {} } ] | array | label | defines text next to the checkbox - label | string | labelClass | defined class name of label. "ojsCheckbox__label" by default | string | labelStyle | defined inline styles of label | string | name | defined name that is declared in db | string | radioClass | defined class name of radio. | string | | radioStyle | defined inline styles of checkbox. | string | | required | defined select is required or no | boolean | spanClass | defined class name of span. "ojsCheckbox__span" by default | string | spanStyle | defined inline styles of span | string | value | optional, if not defined value = label | string

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

  • disabled
  • enabled
  • getId