0.6.1 • Published 5 years ago

@clubajax/react-form v0.6.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

React Form

Basic form elements for use in React.

The components are Dropdown, Popup, List, ActionMenu, Radios, Checkbox

Why React Forms?

There are many React libraries - unfortunately, because of the divide caused by CSS-in-JS, this cuts down on the libraies that will easily work in a project. Further factors, such as a code-bloated library, opinionated in style or icons

Install

yarn add @clubajax/react-form

npm install @clubajax/react-form

Demo

See React Form in action on clubajax.io

Accessibility

React Form aims to achieve ADA AA 2.0 - Americans with Disabilities Act, version 2.0, "Double A" compliance (not triple A)

Components have been tested for use without a mouse and with a screen reader.

TypeScript Safe

React Form comes with a tsconfig.json file for typings.

Style

React Form is styled with SCSS, so a stylesheet will need to be imported:

@import 'node_modules/@clubajax/react-form/lib/react-form.css';

React Form is very lightly styled, using grays and moderate padding and margins, so it will be easy to override to suit the application's needs.

Dropdown/ActionMenu Style

The Dropdown is an "inline" style, meaning that its popup is a descendant of the dropdown element tree, not an absolutely positioned DOMNode floating over the document. There are pros and cons to each style.

Inline Pros:

  • Can be "stretchy" to the same size of the Dropdown button
  • Can have custom positioning, left/right/center
  • It is easy to inspect the DOM and debug
  • It's easier to conditionally style the popup, since it is a descendant of the Dropdown and whatever className is used on it.
  • Less complexity in the positioning, which leads to less code to maintain and relatively fewer bugs

Inline Cons:

  • Certain page layouts cannot be used. Specifically anything with position: absolute (rare) or overflow: hidden (more common).
  • The width of the popup is based on the component width, not the window width.

Absolute Positioned Pros and Cons are the inverse of the lists above.

Controlled vs Uncontrolled

You can choose whether to use the components as controlled or uncontrolled.

Controlled, which does not maintain its own state and expects the value to change via props, is the default. Use the value props as usual.

For uncontrolled, use defaultValue. This will maintain state internally. If you do not want to set an initial value but still wish to use it uncontrolled, pass: defaultValue={null}.

Usage

import { Dropdown } from '@clubajax/react-form';

const options = [
    {
        value: 'a',
        label: 'H Form 1'
    }, {
        value: 'b',
        label: 'H Form 2'
    }, {
        value: 'c',
        label: 'H Form 3'
    }
];

<Dropdown options={options} value="a" placeholder="Choose your kata..." label="Forms" />

Properties

Checkbox

  • value boolean, optional: (Controlled) If provided, sets the value of the Checkbox, true checks the Checkbox
  • defaultValue boolean, optional: (Uncontrolled) If provided, sets the value of the Checkbox, true checks the Checkbox
  • label string, optional: If provided, creates a label element above the Dropdown
  • checkAfter boolean, optional: If true, the check will be rendered after the label
  • name string, optional: The name of the component (as used in forms). Will change the event (see below)
  • onChange function, optional: The callback event when an item is selected (see Events below)

Radios

Dropdown

  • options array, required: The items that will be used to create the drop-down list
  • value string|integer, optional: (Controlled) If provided, sets the value of the Dropdown, and the display to the label of the option of that value
  • defaultValue string|integer, optional: (Uncontrolled) If provided, sets the value of the Dropdown, and the display to the label of the option of that value
  • label string, optional: If provided, creates a label element above the Dropdown
  • name string, optional: The name of the component (as used in forms). Will change the event (see below)
  • placeholder string, optional: The button display if no item is selected (defaults to "Select one...")
  • onChange function, optional: The callback event when an item is selected (see Events below)

ActionMenu

ActionMenu is a button that opens a drop-down list. When an item is selected in the menu, an onAction event is called. The onAction event will fire, passing teh value from the list item.

Popup

The Popup will show/hide its contents, positioning itself relative to its parent/owner component. It will display whatever children are created in the JSX markup.

List

The List is a sub-component of the Dropdown, so it will look and work in a similar fashion.

Events for Dropdown, Radios, and Checkbox

If the name prop is not used, the onChange event simply passes the value.

If the name prop is used, the event has the following shape, for maximum versatility:

{
    value: value,
    name: props.name
    [props.name]: value,
    target: <DomNode> {
        ...
        value: value,
        name: props.name
    }
}

License

Free as in beer.

0.6.1

5 years ago

0.6.0

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago