![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
component-js
Advanced tools
component-js is a light weight library to create a web page by Javascript, it's philosophy component just a function return DOM element let us could flexibility compose component for create a new component.
Client-render, sometimes, you need client-render data to DOM element. Traditional way is splicing HTML string or using HTML template engine. However splicing HTML string is easy to wrong and using HTML template is too heavy. So component-js is a good way for you.
HTML component, component-js provider a flexible way to compose component. Although many framework do it excellently, but maybe you just need a simple way to reuse HTML rather than a giant.
npm install component-js
import {elm,txNode,comp} from 'component-js'
document.getElementById('root')
.appendChild(elm({
tag:'p',
attr:{
textContent:'hello world!'
}
}))
import {elm, comp, txNode} from 'component-js'
import j from 'berserk'
const el = comp.div(
[
comp.listGroup(
[
comp.div(
[
comp.btn({
evtLir: [
{
type: 'click',
handler: () => j.log('click first btn')
}
],
txt: 'add TODO'
}),
comp.btn({
evtLir: [
{
type: 'click',
handler: () => j.log('click second btn')
}
],
txt: 'show active'
}),
comp.btn(
{
evtLir: [
{
type: 'click',
handler: () => j.log('click second btn')
}
],
txt: 'show active'
}
)
]
),
txNode('dynamic')
]
)
]
)
document.getElementById('root').appendChild(el)
createElement
Create a DOM element by pass option
createTextNode
A function for create a textNode by pass text content, like document.createTextNode but bind 'document' as it's this
createElement
Create a DOM element by pass option
Kind: global constant
Returns: createElement
- a DOM element
Param | Type | Description |
---|---|---|
option | object | |
option.tag | string | The html tag |
option.attr | object | The option correspond element's attributes, default: {} |
option.children | array | A array of elements, these elements will append as children,default: [] |
option.evtLir | array | A array of event object, it will bind all event in object to return element example: [{type:click,handler:(e)=>console.log(e),opt:{capture:true}}...], default: [] |
Example
elm({
tag:'p',
attr:{
textContent:'hello world!'
}
})
createTextNode
A function for create a textNode by pass text content, like document.createTextNode but bind 'document' as it's this
Kind: global constant
Returns: createTextNode
- A textNode
Param | Type |
---|---|
text | string |
Example
import {comp,txNode} from 'component-js'
comp.div(
[
txNode('hello world!')
]
)
createElement
Create a button element with bootstrap className
createElement
Create a bootstrap listGroup by pass children element
createElement
Create a div with form by pass option, fromGroups(see bootstrap),submit button
createElement
Create a div with bootstrap 'formGroup' className for input
createElement
Create a div by pass it's children elements
createElement
Create a button element with bootstrap className
Kind: global function
Returns: createElement
- A button element with bootstrap@4.x className
Param | Type | Description |
---|---|---|
option | object | |
option.evtLir | array | Example: [{type:click,handler:(e)=>console.log(e),opt:{capture:true}}...] |
option.txt | string | Example: 'click me' |
option.styleType | string | Example: 'btn-error' default: 'btn-secondary' |
option.type | string | Example: 'submit' default: 'button' |
Example
btn({
evtLir: [
{
type: 'click',
handler: () => j.log('click second btn')
}
],
txt: 'show active'
})
createElement
Create a bootstrap listGroup by pass children element
Kind: global function
Param | Type | Description |
---|---|---|
children | array | example: [domElement...] a array of dom element, it will wrap with 'list-group-item' className |
Example
listGroup([buttonElm1,buttonElm2])
createElement
Create a div with form by pass option, fromGroups(see bootstrap),submit button
Kind: global function
Returns: createElement
- A form element with bootstrap style
Param | Type | Description |
---|---|---|
formGroups | array | A array of div with bootstrap 'form-groups' class |
submitBtn | Element | A button element with 'submit'type |
opt | object | A object of attribute |
Example
form(
[
formGroupDiv1,
formGroupDiv1,
],
submitBtn
)
createElement
Create a div with bootstrap 'formGroup' className for input
Kind: global function
Returns: createElement
- A div element which has label and input element children
as well as bootstrap 'formGroup' className
Param | Type | Description |
---|---|---|
label | string | The label text |
type | string | The input type |
Example
formGroup(
'password',
'password'
)
createElement
Create a div by pass it's children elements
Kind: global function
Returns: createElement
- A div element
Param | Type | Description |
---|---|---|
children | array | Children elements |
Example
div(
[childElm1,childElm2]
)
FAQs
Create web page by Javascript
We found that component-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.