5.0.6 • Published 8 months ago

@slimr/forms v5.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

🪶 @slimr/forms npm package

A slim (< 1kB), enhanced HTML form with auto-disabling, auto-reset, error handling, more JS events, and context to its children.

  • optimizes for vanilla, uncontrolled input elements
  • does not cause re-renders
  • disables form elements while submitting
  • can auto-reset the form is desired
  • uses browser accessibility APIs to share errors to form elements
  • wraps onSubmit to
    • auto call event.preventsDefault()
    • pass form values as an Object
  • provide JS events and React context for rejected, submitted, accepted states
  • < 1kB when bundled+gzipped with a broader application

Context

@slimr is a set of slim React (hence '@slimr') libs. Check them all out on github!

Usage

<SForm onSubmit={(_, vals) => console.log(vals)}>
  {[
    'checkbox',
    'color',
    'date',
    'email',
    'number',
    'password',
    'search',
    'text',
    'textarea',
    'tel',
    'url',
  ].map(type => (
    <InputBox key={type} label={type} name={type} type={type} required />
  ))}
  <RadioBox
    label="Radios"
    name="radio1"
    options={[
      {label: 'Choice 1', value: 'choice1'},
      {label: 'Choice 2', value: 'choice2'},
      {label: 'Choice 3', value: 'choice3'},
    ]}
    required
  />
  <SelectBox
    label={'Select Single'}
    name="select1"
    options={[
      {label: '--', value: ''},
      {label: 'Choice 1', value: 'choice1'},
      {label: 'Choice 2', value: 'choice2'},
      {label: 'Choice 3', value: 'choice3'},
    ]}
    required
  />
  <SelectBox
    label={'Select multiple'}
    multiple
    name="select2"
    options={[
      {label: 'Choice 1', value: 'choice1'},
      {label: 'Choice 2', value: 'choice2'},
      {label: 'Choice 3', value: 'choice3'},
    ]}
    required
  />
  <FormFooter />
  <RenderCheck />
</SForm>

API

SForm

An enhanced HTML form with auto-disabling, auto-reset, error handling, more JS events, and context to its children.

SFormError

An extension of Error that accepts an errorSet as a constructor property. It is used to share errors to form elements

throw new FormError({field1: 'This field is invalid'})

useSFormContext

A hook to get the current state of the form

5.0.6

8 months ago

5.0.5

8 months ago

5.0.4

8 months ago

5.0.3

8 months ago

5.0.2

8 months ago

5.0.1

8 months ago

4.1.30

9 months ago

4.1.31

9 months ago

4.1.32

9 months ago

4.1.33

8 months ago

4.1.35

8 months ago

4.1.36

8 months ago

4.1.37

8 months ago

4.1.41

8 months ago

4.1.42

8 months ago

4.1.43

8 months ago

4.1.44

8 months ago

4.1.40

8 months ago

4.1.49

8 months ago

4.1.29

9 months ago

4.1.45

8 months ago

4.1.46

8 months ago

4.1.48

8 months ago

4.1.28

1 year ago

4.1.27

1 year ago

4.1.26

1 year ago

4.1.25

1 year ago

4.1.24

1 year ago

4.1.23

1 year ago

3.1.22

1 year ago

2.1.20

1 year ago

2.1.19

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago