mofron-comp-accordion
Advanced tools
Comparing version 0.0.6 to 0.1.0
183
index.js
/** | ||
* @file accordion.js | ||
* @file mofron-comp-accordion/index.js | ||
* @brief accordion component for mofron | ||
* @author simpart | ||
*/ | ||
require('mofron-comp-heading'); | ||
require('mofron-event-click'); | ||
const mf = require('mofron'); | ||
const Text = require('mofron-comp-text'); | ||
const Switch = require('mofron-comp-switch'); | ||
const Horiz = require('mofron-layout-horizon'); | ||
const Click = require('mofron-event-click'); | ||
const VisClk = require('mofron-event-visiclick'); | ||
@@ -12,14 +17,10 @@ /** | ||
*/ | ||
mofron.comp.Accordion = class extends mofron.Component { | ||
mf.comp.Accordion = class extends mf.Component { | ||
constructor (prm,opt) { | ||
constructor (po, p2) { | ||
try { | ||
super(prm); | ||
super(); | ||
this.name('Accordion'); | ||
this.chg_evt = null; | ||
if (null !== opt) { | ||
this.option(opt); | ||
} | ||
this.prmMap(['headComp', 'child']); | ||
this.prmOpt(po, p2); | ||
} catch (e) { | ||
@@ -34,7 +35,38 @@ console.error(e.stack); | ||
* | ||
* @param vd : (mofron.util.Vdom) vdom object | ||
* @note private method | ||
*/ | ||
initDomConts (prm) { | ||
initDomConts () { | ||
try { | ||
this.target(this.vdom()); | ||
super.initDomConts(); | ||
/* init status component */ | ||
let sts = new Switch([ | ||
new Text('-'), | ||
new Text('+') | ||
]); | ||
this.stsComp(sts); | ||
/* init index component */ | ||
let conts = new mf.Component(); | ||
let clk_swh = (clk1_cmp, clk2, clk3_prm) => { | ||
try { | ||
/* change open status */ | ||
clk3_prm.isOpen(!clk3_prm.isOpen()); | ||
sts.swComp(); | ||
} catch (e) { | ||
console.error(e.stack); | ||
throw e; | ||
} | ||
} | ||
let idx = new mf.Component({ | ||
layout : [ new Horiz() ], | ||
event : [ | ||
new Click([clk_swh, this]), | ||
new VisClk('switch', conts) | ||
], | ||
child : [ this.stsComp(), this.headComp() ] | ||
}); | ||
this.child([idx, conts]); | ||
this.target(conts.target()); | ||
} catch (e) { | ||
@@ -46,12 +78,11 @@ console.error(e.stack); | ||
changeEvent (fnc) { | ||
try { | ||
if (undefined === fnc) { | ||
return this.chg_evt; | ||
} | ||
if ('function' !== (typeof fnc)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
this.chg_evt = fnc; | ||
} catch (e) { | ||
/** | ||
* status component setter/getter | ||
* | ||
* @param p1 (Component) set status component | ||
* @param p1 (undefined) call as getter | ||
* @return (Component) status component | ||
*/ | ||
stsComp (prm) { | ||
try { return this.innerComp('stsComp', prm, mf.Component); } catch (e) { | ||
console.error(e.stack); | ||
@@ -62,41 +93,16 @@ throw e; | ||
add (ttl, cnt) { | ||
/** | ||
* head component setter/getter | ||
* | ||
* @param p1 (Component) set head component | ||
* @param p1 (undefined) call as getter | ||
* @return (Component) head component | ||
*/ | ||
headComp (prm) { | ||
try { | ||
if ( (undefined === cnt) || | ||
(null === cnt) || | ||
('object' !== (typeof cnt)) ) { | ||
throw new Error('invalid parameter'); | ||
let ret = this.innerComp('headComp', prm, mf.Component); | ||
if (undefined !== prm) { | ||
prm.sizeValue('margin-left', '0.1rem'); | ||
} | ||
var hdg_thm = this.theme().getComp('Heading'); | ||
if (null === hdg_thm) { | ||
hdg_thm = mofron.comp.Heading; | ||
} | ||
var hdg = new hdg_thm(ttl,{ | ||
level : 2 | ||
}); | ||
hdg.addEvent(new mofron.event.Click(function(clk_prm) { | ||
try { | ||
var acd_obj = clk_prm[0]; | ||
var conts = clk_prm[1]; | ||
var idx = clk_prm[2]; | ||
/* switch display contents */ | ||
conts.visible(!(acd_obj.state(idx))); | ||
var evt = acd_obj.changeEvent(); | ||
if (null !== evt) { | ||
evt(acd_obj,idx); | ||
} | ||
} catch (e) { | ||
console.error(e.stack); | ||
throw e; | ||
} | ||
},[this,cnt,this.getChild().length])); | ||
var wrp = new mofron.Component(); | ||
wrp.addChild(hdg); | ||
wrp.addChild(cnt, false); | ||
this.addChild(wrp); | ||
return ret; | ||
} catch (e) { | ||
@@ -108,5 +114,20 @@ console.error(e.stack); | ||
remove (idx) { | ||
/** | ||
* change event function setter/getter | ||
* | ||
* @param p1 (function) change event function | ||
* @param p1 (undefined) call as getter | ||
* @param p2 (mixed) function parameter | ||
* @return (array) [function, parameter] | ||
*/ | ||
changeEvent (fnc, prm) { | ||
try { | ||
this.getChild(idx).visible(false); | ||
if ( (undefined !== fnc) && ('function' === typeof fnc) ) { | ||
throw new Error('invalid parameter'); | ||
} | ||
return this.arrayMember( | ||
'changeEvent', | ||
'array', | ||
(undefined === prm) ? undefined : [fnc, prm] | ||
); | ||
} catch (e) { | ||
@@ -118,21 +139,19 @@ console.error(e.stack); | ||
state (idx) { | ||
/** | ||
* open status setter/getter | ||
* | ||
* @param p1 (boolean) set open status | ||
* @param p1 (undefined) call as getter | ||
* @return (boolean) open status | ||
*/ | ||
isOpen (prm) { | ||
try { | ||
if ('number' !== typeof idx) { | ||
throw new Error('invalid parameter'); | ||
let ret = this.member('isOpen', 'boolean', prm, true); | ||
if (undefined !== prm) { | ||
/* execute change event */ | ||
let evt = this.changeEvent(); | ||
for (let eidx in evt) { | ||
evt[eidx][0](this, prm, evt[eidx][1]); | ||
} | ||
} | ||
var chdlen = this.getChild(); | ||
if ((chdlen.length <= idx) || (0 > idx)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
if (false === chdlen[idx].isRendered()) { | ||
return false; | ||
} | ||
var disp = chdlen[idx].getChild(1).vdom().style('display'); | ||
if ('none' === disp) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} catch (e) { | ||
@@ -144,1 +163,3 @@ console.error(e.stack); | ||
} | ||
module.exports = mf.comp.Accordion; | ||
/* end of file */ |
{ | ||
"name": "mofron-comp-accordion", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"description": "accordion component for mofron", | ||
@@ -13,2 +13,9 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"mofron-comp-text" : "", | ||
"mofron-comp-switch" : "", | ||
"mofron-layout-horizon" : "", | ||
"mofron-event-click" : "", | ||
"mofron-event-visiclick" : "" | ||
}, | ||
"keywords": [ | ||
@@ -15,0 +22,0 @@ "mofron" |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 5 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7638
148
0
5
4
6
+ Addedmofron-comp-switch@
+ Addedmofron-comp-text@
+ Addedmofron-event-click@
+ Addedmofron-event-visiclick@
+ Addedmofron-layout-horizon@
+ Addedmofron-comp-switch@0.0.9(transitive)
+ Addedmofron-comp-text@0.15.2(transitive)
+ Addedmofron-event-click@0.7.1(transitive)
+ Addedmofron-event-common@0.4.1(transitive)
+ Addedmofron-event-visiclick@0.0.7(transitive)
+ Addedmofron-layout-horizon@0.3.0(transitive)