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

bluemoon-dyn-lib

v0.0.1

Published

Dynamic views

Downloads

3

Readme

bluemoon-dyn-lib

Dynamic views

NPM JavaScript Style Guide

Install

npm install --save bluemoon-dyn-lib

Usage

Define controls

DropdownList.tsx

import React, { ReactNode, ChangeEvent } from 'react';
import * as Dyn from 'bluemoon-dyn-lib';
export class DropdownList extends Dyn.BaseComponent{
    private onChangedHandler = (event: ChangeEvent<HTMLSelectElement>) => {
        const updatedVal = event.target.value;
        this.setState({value:updatedVal});
    }
    protected renderComponent(): ReactNode {
        const items = [];
        items.push(<option key={this.props.id+'i'} value="">[{this.props.label}]</option>);
        const data = this.state.dataSource;
        
        if(data!=null){
            for(let i=0;i<data.length;i++){
                items.push(<option key={this.props.id+i} value={data[i].value}>{data[i].text}</option>);
            }
        }
        
        return  <div className="form-group">
            <select className="form-control" id={this.props.id} value={this.state.value || ''} disabled={!this.state.enable} onChange={(event)=>this.onChangedHandler(event)}>
            {items} 
            </select>
        </div>
        
    }
    
}
...
...
//export to be used when defining fields
DynConfig.exportControls({
    'textbox': TextBox,
    'label': Label,
    'dropdownlist': DropdownList,
    'table': Table,
    'addmore': AddMore,
    'combobox': ComboBox,
    'searchbutton': SearchButton,
    'searchtextbox': SearchTextbox,
    'searchresultlist': SearchResultList
});

Define the fields as fields.js


window.utilities.importFieldDefs({
    'ctrl001': {
        name: 'ctrl001',
        label: 'Client Name',
        type: 'dropdownlist',
        validationFunc: function(s, n, o){
           if(n==='0') return 'Please select a client';
           else return null;
        },
        dataField: 'clientID',
        dataSourceApi: '/mock/clients.json',
        //this is for demo of post data
        //*
        getApiParams: function(s,u,c){
            console.log('context in field to get params');
            console.log(c);
            return null;
        }
        //*/
    },
    'ctrl002':{
        name: 'ctrl002',
        label: 'User Name',
        type: 'textbox',
        validationFunc: function(s, n, o){
            if(n===''){
                return 'User Name: required';
            }
            else{
                if(!n.match(/^[A-Za-z]+$/)){
                    return 'Only alphabet characters';
                }
            }
            return null;
        },
        dataField: 'userName'
    },
    'ctrl003':{
        name: 'ctrl003',
        label: 'Welcome',
        type: 'label',
        dataField: 'displayName'
    },
    ....
});

Define the views as views.js

window.utilities.importViewDefs({
    'view1':{
        name: 'view1',
        dataApi: 'mock/data.json',
        submitApi: 'submit',
        template: 'settings/layout1.htm',
        //this is for demo of post data
        //*
        getApiParams: function(s,url,ctx){
            console.log('context in view to get params');
            console.log(ctx);
            return null;
        },
        //*/
        fields: [
            {
                name: 'ctrl003',
                position: [1,2],
                label: null
            },
            {
                name: 'ctrl001',
                position: [1,2],
                valueChangeFunc: function(s,n,o){
                    const m = s.props.parent.find('ctrl002');
                    if(n==='2') m.reset();
                    m.setEnable(n!=='2');
                    
                }
            },
            {
                name: 'ctrl002',
                position: [1,2]
            },
            {
                name: 'ctrl005',
                position: [1,2]
            }

        ]
    },
    'view2':{
        name: 'view2',
        dataApi: '/mock/data.json',
        submitApi: '/submit',
        fields: [
            {
                name: 'ctrl003',
                position: [1,2]
            },
            {
                name: 'ctrl001',
                position: [1,2],
                valueChangeFunc: function(s,n,o){
                    s.props.parent.find('ctrl002').setVisible(n!=='2');
                }
            },
            {
                name: 'ctrl002',
                position: [1,2],
                label: 'Login Name'
            },
            {
                name: 'ctrl006',
                position: [1,2],
                label: 'Extra notes'
            }
        ]
    },
    ....
});

index.html

...
<div id="configLoader"></div>
<div role="react-loader" view="view1"></div>
...

index.tsx

import * as React from 'react';

//intial setup 
DynConfig.appDOM = ReactDOM;
DynConfig.customValidationMessage = (msg: string, sender: IComponent, newVal: string, oldVal: string, context: IAppContext) => {
    return <>
        <div className="alert alert-danger">{msg}</div>
    </>;

};

ReactDOM.render(<Dyn.ConfigLoader fieldUrls={'fields.js'} viewUrls={'views.js'} />, document.getElementById('configLoader'));

License

MIT © Blue Moon