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

@metablock/react

v0.26.8

Published

React Components for Metablock

Downloads

28

Readme

Metablock React

React components, views and utilities for building metablocks.

Components

NoSsr

Disable server-side rendering

import { NoSsr } from "@metablock/react";
<NoSsr>...</NoSsr>;

This is useful for private/login-protected pages for example.

Header

import {Header} from "@metablock/react";
<Header paddingTop={1}, paddingBottom={1}/>

Image

Progressively load background images

Hooks

useIntersectionObserver

Originally from montezume/medium-style-progressively-loaded-images repo. This hook allows to progressively load images.

useWindowSize

useForm

A hook for managing Form submission workflow and optionally for rendering form fields

import { useForm } from "@metablock/react";

const form = useForm(
  {
    handleSubmit,
    defaultValues,
    fieldCallback,
  },
  []
);

The handleSubmit function is an async function for handling form submissions, defaultValues are the initial/default values of the form and fieldCallback is an optional function for customizing props of form fields.

The optional callback function can be used to further customize the UI. The signature is

const fieldCallback = (
  name: str,
  extraProps: Record<string, any>
): Record<string, any> => {
  return extraProps;
};

where name is the input name and extraProps are the additional props passed to the original FormFromSchema component. If the function returns nothing for a given field name, the field is not displayed in the form.

Forms

The library has a tooling for rending Forms specified via JSON schema.

FormFromSchema

The entry-point component for rendering forms from JSON schema

import {FormFromSchema, useForm} from "@metablock/react";

const MyForm = () => {
  const form = useForm({...});

  return <FormFromSchema form={form} schema={...} data={...} {...extraProps}/>
};

The schema is a valid subset of the JSON schema. For example a simple name input can be defined as:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 3,
      "description": "Please enter your name",
      "format": "optional format"
    }
  }
}

SchemaRegistry

This is a global object which controls how form fields are rendered. By defaults it provide the basic input fields, but it can be extended or overwritten if required.

import { SchemaRegistry } from "@metablock/react";

SchemaRegistry.set("string", StringSchema);
SchemaRegistry.set("boolean", BooleanSchema);
SchemaRegistry.set("integer", NumberSchema);
SchemaRegistry.set("number", NumberSchema);
SchemaRegistry.set("object", ObjectSchema);

CrudForm

This is a higher level component to render Forms with side actions. It uses the FormFromSchema component in conjunction with the useForm hook.

ApiDataGrid

A Component for rendering tabular data, it allows to fetch server side data via the ApiData interface.