Skip to content

Commit c45ab7e

Browse files
author
Vlad Balin
committed
Updated docs
1 parent 8a70850 commit c45ab7e

File tree

11 files changed

+135
-132
lines changed

11 files changed

+135
-132
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![logo](/docs/images/value-link-logo.png)
1+
![logo](/images/value-link-logo.png)
22

33
# Painless React forms, validation, and state management
44

@@ -99,7 +99,7 @@ const $name = this.$at('name');
9999
const state$ = this.state$();
100100
```
101101

102-
Refer to the [databinding examples](/examples/databinding) and the [manual](/docs/databinding.md) for the typical data binding scenarios.
102+
Refer to the [databinding examples](/examples/databinding) and the [manual](/linked-controls/README.md) for the typical data binding scenarios.
103103

104104
* [/lib](/lib) folder contains ES5 modules prebuilt with ES6 exports suitable for modern build tools like `webpack 2`.
105105
* [/dist](/dist) folder contains minified UMD ES5 assembly exporting `NestedLink` global valiable.
@@ -118,9 +118,9 @@ You can either use `Link.value` inside to create links dynamically, or extend th
118118

119119
### Start hacking
120120

121-
![design](/docs/images/valuelinks.jpg)
121+
![design](/images/valuelinks.jpg)
122122

123-
If you want to play with the examples, fix the bug, or whatever:
123+
It's a very simple library written with TypeScript, there's no any magic inside (except some scary type annotations). If you want to play with the examples, fix the bug, or whatever:
124124

125125
`yarn` - installs the dependencies.
126126

@@ -153,4 +153,4 @@ React Hooks support.
153153
- `<input {...link.props} />` can be used to bind the link to any of the standard controls expecting `value` and `onChange` props.
154154

155155
---
156-
![usedby](/docs/images/usedby.png)
156+
![usedby](/images/usedby.png)

docs/databinding.md

Lines changed: 0 additions & 119 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

linked-controls/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Linked Controls
2+
3+
Reference implementation of linked form controls. Can be used as a starting boilerplate for
4+
your own controls with inlined validation errors.
5+
6+
Link can be bound to the any form control consuming `value` and `onChange` props, so linked controls from this package may be used but not really required.
7+
8+
```javascript
9+
<input {...$value.props} />
10+
```
11+
12+
However, it's beneficial to create a custom form control wrappers encapsulating your markup patterns for a form layout and validation in order to take a full advantage of the value link.
13+
14+
## Installation
15+
16+
npm install linked-controls --save-dev
17+
18+
## List of controls
19+
20+
### Text and number form fields
21+
22+
##### `<Input type="text"/>`, `<TextArea />`
23+
24+
Wrappers for standard `<input>` and `<textarea>` tags which can be directly bound to the string links.
25+
26+
These wrappers will add `invalid` class to enclosed HTML element if an error is present in the link.
27+
28+
```jsx
29+
<Input type="text" $value={ $link } />
30+
<TextArea $value={ $link } />
31+
```
32+
33+
##### `<NumberInput/>`
34+
35+
A cross-browser implementation of *numeric input* tag. It has following differences compared to `<Input>`:
36+
37+
- Keyboard input which obviously leads to invalid values (e.g. letters) are rejected.
38+
- Value is being always converted to valid number.
39+
- There are `integer` and `positive` boolean props controlling input rejection. They can be combined.
40+
41+
`<NumberInput>` validates its value and adds `invalid` class to enclosed input element if it's not a number.
42+
43+
```jsx
44+
<NumberInput $value={ $link } />
45+
<NumberInput $value={ $link } integer={ true }/>
46+
<NumberInput $value={ $link } positive={ true }/>
47+
```
48+
49+
### Checkboxes
50+
51+
##### `<Input type="checkbox" />`
52+
53+
Wrapper for the standard `<input>`. Directly binds boolean value with `checkedLink` property.
54+
55+
```jsx
56+
<Input type="text" $checked={ booleanLink } />
57+
<Input type="text" $checked={ $array.contains( 'option' ) } />
58+
```
59+
60+
##### `<Checkbox/>`
61+
62+
Internally, it's `<div>` element which toggles `selected` class on click.
63+
Thus, it can be easily styled.
64+
65+
By default, it has `checkbox` CSS class which can be overridden by passing `className` prop.
66+
67+
It passes through anything else including `children`.
68+
69+
```jsx
70+
<Checkbox $checked={ $boolean } />
71+
<Checkbox $checked={ $array.contains( 'option' ) } />
72+
```
73+
74+
### Radio Groups and Select list
75+
76+
##### `<Select/>`
77+
78+
Wrapper for standard `<select/>`. Regular `<option/>` tags must be used. All props are passed through.
79+
80+
```jsx
81+
<Select $value={ linkToSelectedValue }>
82+
<option value="a">A</option>
83+
<option value="b">B</option>
84+
</Select>
85+
```
86+
87+
##### `<Input type="radio"/>`
88+
89+
Wrapper for the standard `<input>`. Directly binds boolean value with `$checked` property.
90+
91+
Can be directly bound to the link of any type with `$value` or `$checked` property.
92+
93+
```jsx
94+
<label>
95+
A:
96+
<Input type="radio" $value={ $flag } value="a" />
97+
</label>
98+
<label>
99+
B:
100+
<Input type="radio" $checked={ $flag.equals( "b" ) } />
101+
</label>
102+
```
103+
104+
##### `<Radio/>`
105+
106+
Internally, it's `<div>` element which always sets `selected` class on click. Thus,
107+
it can be easily styled.
108+
109+
By default, it has `radio` CSS class, which can be overridden by passing `className` prop.
110+
It passes through anything else, including `children`.
111+
112+
It *must* be used in conjunction with `$link.equals( 'value' )` method.
113+
114+
```jsx
115+
<label>
116+
A:
117+
<Radio $checked={ $flag.equals( 'a' ) } />
118+
</label>
119+
<label>
120+
B:
121+
<Radio $checked={ $flag.equals( 'b' ) } />
122+
</label>
123+
```

docs/api.md renamed to valuelink/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ but returns `undefined` and leads to the proper purely functional update of the
373373
Evaluate given condition for the current link value, and assign
374374
given error object to the `link.error` when it fails. There are no restriction on the error object shape and type.
375375

376-
It's possible to assign default error message to the validator function. `tags.jsx` provides `isRequired` and `isEmail`
377-
generic validator functions as an examples. Excerpt from `tags.jsx`:
376+
It's possible to assign default error message to the validator function. `linked-controls` package provides `isRequired` and `isEmail`
377+
generic validator functions as an examples:
378378

379379
```jsx
380380
export const isRequired = x => x != null && x !== '';
@@ -385,9 +385,8 @@ Checks can be chained. In this case, the first check which fails will leave its
385385

386386
##### ![var] $link.error : any | void
387387

388-
This link field may be analyzed by custom `<Input />` control to indicate an error (see `tags.jsx` controls and supplied examples).
389-
390-
This mechanics can be used to add ad-hoc validation in `render`.
388+
This field is populated by the `link.check` method and must not be assigned manually.
389+
It should be used by a custom `<Input />` control to display an error (see `linked-controls` and examples).
391390

392391
```javascript
393392
// Simple check
@@ -410,6 +409,6 @@ const $num = this.$at( 'num' )
410409
console.log( $num.error );
411410
```
412411

413-
[method]: /docs/images/method.png
414-
[static]: /docs/images/static.png
415-
[var]: /docs/images/var.png
412+
[method]: /images/method.png
413+
[static]: /images/static.png
414+
[var]: /images/var.png

0 commit comments

Comments
 (0)