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

ui-builder

v2.0.1

Published

Frontend library to generate user interface.

Downloads

5

Readme

UIBuilder

A small frontend library for quick generation and management of DOM structure blocks.

Main concept

The idea is in reusing predefined interface parts schemes for building instances of this parts. All data generated is stored in the objects and can be quickly got by reference.

Also objects that represents single DOM nodes has few very useful methods implements jQuery syntax.

Example:

Lets create classic tasks list: input field and adding button. User can input text in the field and add task by clicking button.

The tasks list interface:

UI.register({
    name : 'Tasks list',
	
    scheme : {
        wrap : {
            list : '|Task', // Task - is the name of UI that will be used as regular item of list.
            toolbar : {
                titleInput : '@input [type = text]',
                addButton : '@button [type = button] (html = Add task)'
            }
        }
    },
    
    // Some parameters
    parameters : {
        width : 400,
        height: 600
    },
	
    // Set interface appearance
    styles : {
        wrap : {
            display: 'flex',
            flexDirection : 'column',
            margin: '40px auto',
            backgroundColor: '#fff',
            boxShadow : '0 0 5px rgba(0,0,0,0.4)',
            padding: '20px'
        },
        
        // And so on...
    },
	
    // Function that will be called on each instance creation
    onrender : function(inst, params)
    {
        // Apply parameters.
        inst.wrap.css({
            width : params.width + 'px',
            height : params.height + 'px'
        });
        
        // Add click event handler to the adding button
        inst.addButton.on('click', function(){
            var text = inst.titleInput.val().trim();
            if(text === '') return;
            var newItem = inst.list.addOne().load({title : text});
            
            // Show sliding animation
            newItem.wrap.css({height:0});
            newItem.wrap.slideDown();

            // And empty input box
            inst.titleInput.val('');
        });
    }
});

Then lets describe scheme of the single task record:

UI.register({
    name : 'Task',
	
    scheme : {
        wrap : {
            checkbox : {
                chk : '@input [type = checkbox]',
                box : '@div'
            },
            title : '@span',
            deleteButton : "(html = ✕)"
        }
    },
	
    // Additional rules
    rules : {
        checkbox : '@label'
    },
	
    // Again some styles...
    styles : {
        wrap : {
            display: 'flex',
            flexShrink: 0,
            margin: '5px',
            backgroundColor: '#f6f6f6'
        },
        
        // And so on...
    },
	
    // Lets set some manipulations with newly created instances.
    onrender : function(inst)
    {
        // Add handler for deleting task.
        inst.deleteButton.on('click', function(taskInst){
            
            // Show collapsing animation.
            taskInst.wrap.animate({
                height : 0,
                opacity : 0,
                marginTop : 0,
                marginBottom : 0
            }, 250, function(){taskInst.remove();});   
        });
    }
});

Then lets we have some container node in which we want to render our interface:

<div id="container"></div>

Now we can render our tasks list:

var TasksList = UI('Tasks list').renderTo('#container', {width : 600, height : 400});

Also this lib can a lot:

  • Gathering forms (and not only forms)
  • Animating functions
  • Extensions support
  • UI extending functionality
  • Data providers (basic generator, ajax, WebSocket)
  • Loading data to the elements or whole instance structures from given data or data providers.
  • Common UI solutions such as tabs, spinner, dropdowns, dragging.
  • Themes (with CSS regeneration on the fly)
  • Validation (will be implemented later)

More documentation will be ready soon. Enjoy :)