🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@okiba/component

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@okiba/component

DOM Component for okiba.js

latest
Source
npmnpm
Version
2.0.7
Version published
Maintainers
3
Created
Source

Okiba / Component

Manages a DOM component, binds UI and recursively binds child components. Can be extended or instantiated

__

// ./components/Slider.js

import Component from '@okiba/component'
import SliderControls from '@components/SliderControls'

const ui = {
  slides: '.slide',
}

const components = {
  controls: {
    selector: '.slider-controls', type: SliderControls, options: {big: true}
  }
}

class Slider extends Component {
  constructor({el, options}) {
    super({el, ui, components, options})

    this.ui.slides.forEach(
      slide => slide.style.opacity = 0
    )

    this.components.controls.forEach(
      controls => controls.onNext(this.next.bind(this))
    )
  }
}
// ./main.js

import {qs} from '@okiba/dom'
import Component from '@okiba/component'
import Slider from './components/Slider'

const app = new Component({
  el: qs('#app'),
  components: {
    selector: '.slider', type: Slider
  }
})

Installation

npm i --save @okiba/component

Or import it directly in the browser

<script type="module" src="https://unpkg.com/@okiba/component/index.js"></script>

Usage

import Component from '@okiba/component'

Untranspiled code 🛑

Okiba Core packages are not transpiled, so don't forget to transpile them with your favourite bundler. For example, using Babel with Webpack, you should prevent imports from okiba to be excluded from transpilation, like follows:

{
  test: /\.js$/,
  exclude: /node_modules\/(?!(@okiba)\/).*/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env']
    }
  }
}

constructor(args: {el, ui, components, options})

Arguments

+ args: Object

Arguments to create a component

+ el: Element

DOM Element to be bound

+ ui: Object | optional

UI hash where keys are name and values are selectors

{ buttonNext: '#buttonNext' }
// or
{ buttonNext: selector: '#buttonNext', asArray: true, required: true }

Becomes:

this.ui.buttonNext
+ components: Object | optional

Components hash for childs to bind, keys are names and values are component initialization props:

{
  slider: {
    // Matched using [qs]('https://github/okiba-gang/okiba/packages/dom'), scoped to the current component element
    selector: '.domSelector',
    // Component class, extending Okiba Component
    type: Slider,
    // Options hash
    options: {fullScreen: true},
    // Required component, default is false
    required: true
  }
 viewProgress: {
    // Bind ViewProgress component on parent Component dom node
    ghost: true,
    // Component class, extending Okiba Component
    type: ViewProgress
  },
  buttons: {
    selector: 'button',
    type: Button,
    asArray: true,
  }
}

Becomes:

this.components.slider
+ options: Object | optional

Custom options passed to the component

onDestroy()

Virtual method, needs to be overridden It's the place to call cleanup functions as it will be called when your component is destroyed

destroy()

Should not be overridden, will call onDestroy and forward destruction to all child components

FAQs

Package last updated on 26 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts