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

react-logic-block

v1.2.1

Published

Utils and components for using logic-block in react apps

Downloads

6

Readme

react-logic-block

Utils and components for using logic-block in react apps.

Typescript

The library originally written in typescript, so it fully support typescript. Provided types:

  • FieldValidateFunction
  • FieldInput
  • FieldComponentProps
  • FormErrors
  • FormContextType
  • FormProps
  • Form

The Form component implemented with generics, it is pretty cool to use it with it.

//block description
type FormValues = { data: string; };
type FormUtil = { calcDataHash: () => string; };
const SomeBlock = Block<FormValues, FormUtil>({ ... });

//... at some component
<Form<FormValues, FormUtil> block={SomeBlock}>

</Form>

Form API

Content:

Form

Form is a wrapper component for you fields. Form provides block values and some handy meta data for form, all values are provided via useForm hook or FormContext

Props:

| Name | Type | Optional? | Description | | --------------- | ---------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | block | BlockFactory | Mandatory | Block which will use for handling form values | | initialValues | Partial<TFormValues> | Optional | Initial values for form. Be carefull, if initialValues changes during life-time the component will re-render this new initialValues to form values | | children | React.Node | Optional | Any react components for rendering form. All nested components can use FormContext, Field and useField utils | | validate | (values: Object) => Object | Optional | Validation function, returns object with errors. Keys for errors should be the same as keys for invalid values in values parameter of that function | | onSubmit | (values: Object) => void | Optional | Callback of form submit action, in that moment values passed all validations | | onSubmitFailed | () => void | Optional | Callback for failed submit action | | onSubmitSuccess | () => void | Optional | Callback for successful submit action (Invokes once after submit action call) |

Field

Field is a wrapper component for inputs or any other component that should be able to change form values. All extra props to the component will pass to rendering component

Props:

| Name | Type | Optional? | Description | | --------- | ------------------------------- | --------- | ----------------------------------------- | | name | string | Mandatory | The path to form value (field) | | component | React.Component | Mandatory | Component that will be rendered for field | | validate | (fieldValue: any) => undefined | string | Optional | Field level validation function. It applies only field value on every change of field. Use for validation statically defined function, don't construct function in render body of a component |

useForm

React hook for gettings all the utilities for the form in which component wrapped. This hook does not apply any arguments, and returns the FormContext values.

// ...
const {
  values,
  util,
  submit,
  // ...etcs
} = useForm();
// ...

useField

React hook for field rendering functional component

Arguments:

| Name | Type | Optional? | Description | | -------- | ------------------------------- | --------- | ------------------------------ | | name | string | Mandatory | The path to form value (field) | | validate | (fieldValue: any) => undefined | string | Optional | Field level validation function. It applies only field value on every change of field. Use for validation statically defined function, don't construct function in render body of a component |

FormContext

Context of current form

Values:

| Name | Type | Description | | --------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------- | | values | TFormValues extends Object | Current values of form | | util | TFormUtil extends Object | Current util values of form | | errors | Object | Current errors of form | | hasError | boolean | Shows if form has any error | | formError | undefined \| string | Message of the form error | | submitted | boolean | Shows if the form where successfully submitted | | change | (fieldName: string, value: any) => void | Change field value function | | update | (RecursivePartial<TFormValues>) => void | Original update function from values block passed to the Form | | submit | () => void | Submit action function | | registerField | (name: string, field: FieldHandler) => number | Registering field function. Custom field component should be registered on mount | | unregisterField | (name: string, fieldId: number) => boolean | Unregistering field function. Custom field component should be unregistered on unmount |

Author

Ilya Melishnikov

LICENSE

MIT