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

ontime-layout

v1.1.0

Published

ontime-layout is used to generate any layouts from JSON using React components

Downloads

10

Readme

The library is used to create any layouts or forms from JSON configuration.

// npm
npm install ontime-layout

// yarn
yarn add ontime-layout

Please see the storybook page where you are able to see and test all components with documentation and examples.

ontime-layout/storybook

ontime-layout is library to create and manage UI for React 16.

Register components, functions etc for using

You are able to register only - component, function, class, object, exec

  • component - React component
  • function - any function
  • class - any class
  • object - any object
  • exec - any function which will we called after parse
  • pipeline - pipeline functionality

You should use pipeline only as an array. Where the first argument must be 'pipeline' and other arguments must be registered functions, objects etc.

// pipeline example 
props: {
  onClick: ['pipeline', ['function/fn1', {a: 1}], 'function/fn2', 'function/fn3']
}

When the user clicks on the element then the function 'function/fn1' will be called and the first argument will be an onClick event (Proxy) and the second argument will be an object {a: 1}. Result of the first function will be passed to the function 'function/fn2' and so on. All functions will be called like async functions.

Register components, functions and abjects etc

import { Row, Input, Button } from 'ontime-components';
import { config } from 'ontime-layout';
import i18n from 'i18n';

config.set('component', 'Row', Row);
config.set('component', 'Input', Input);
config.set('component', 'Button', Button);

config.set('function', 'populateSelect', async () => ['John Snow', 'Rob Stark']);
config.set('exec', 'translate', (key, options) => i18n.t(key, options));

Register translating function for validator

If you want to use ontime-layout validator and see correct errors. You shloud register translating function. Please see below example how to do.

import { config } from 'ontime-layout';
import i18n from 'i18n';

config.setI18n((key, options) => i18n.t(key, options));

How to use registered components, function etc in JSON configuration

import { Layout } from 'ontime-layout';

const data = [
  {
    component: 'Row',
    children: [
      {
        component: 'Input',
        props: {
          name: 'name',
          label: ['exec/translate', 'user.name'],
          leftIcon: 'user'
        }
      },
      {
        component: 'Select',
        props: {
          name: 'region',
          label: ['exec/translate', 'user.alias'],
          dataSource: 'function/populateSelect'
        }
      }
    ]
  },
  {
    component: 'Row',
    children: [
      {
        component: 'Button',
        props: {
          type: 'submit',
          label: ['exec/translate', 'save'],
          primary: true
        }
      },
      {
        component: 'Button',
        props: {
          label: ['exec/translate', 'cancel']
        }
      }
    ]
  }
];

<Layout data={ data } />

For From details please see ontime-layout/storybook/form

For Layout details please see ontime-layout/storybook/layout

How to use validator

import { validator } from 'ontime-layout';

// Create rules
const rules = {
  name: {
    req: true,
    maxLen: 100
  },
  email: {
    req: true,
    email: true
  }
};

// Create data
const data = {
  name: '',
  email: '111'
};

// create validate function for rules
const validate = validator(rules);

// validate
try {
  await validate(data);
} catch (err) {
  console.error(err);
}

// if need to validate only one field
try {
  await validate(data, 'email');
} catch (err) {
  console.error(err);
}

// Use validate into Form
<Form 
  data={ data }
  validate={ validate }
/>

List of predefined rules

  • req - Value must be required
  • email - Check email
  • url - Check URL
  • max - Value must be less then
  • min - Value must be more then
  • maxLen - Value length must be less then
  • minLen - Value length must be more then
  • confirm - Value and another value must be the same
  • regExp - Check value by regular expression
  • gt - Value must be greater or equal
  • ge - Value must be greater
  • lt - Value must be less or equal
  • le - Value must be less
  • list - Minimum one value must be selected
  • listSelect - Minimum one value must be selected
  • alphabet - You can only enter letters and numbers
  • all - An invalid character

MIT