Skip to content

Commit 4344f2a

Browse files
author
Vlad Balin
committed
fixed docs and tags.jsx
1 parent d16675d commit 4344f2a

File tree

3 files changed

+118
-7
lines changed

3 files changed

+118
-7
lines changed

README.md

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Features:
2424
- Support for 'pure render' optimization.
2525
- Reference implementation of 'linked' UI controls (`tags.jsx`).
2626
- Standard tags: `<Input />` and `<TextArea />` (with validation), `<Select />`,
27-
- Custom tags: `<Radio />`, `<Checkbox />`
27+
- Custom tags: `<Radio />`, `<Checkbox />`, `<NumberInput />`
2828
- TypeScript source and type definitions.
2929
- Backward compatible with standard React 0.14 links API
3030

@@ -50,6 +50,7 @@ Features:
5050
- `link.clone()` creates shallow copy of the enclosed object.
5151
- Added "Users List" application example.
5252
- `link.toggle` is _removed_. Use `link.update( x => !x )` instead.
53+
- `<NumberInput/>` tag with input rejection for numbers.
5354

5455
# Installation
5556

@@ -323,14 +324,120 @@ const numLink = List.state( this, 'num' )
323324
console.log( numLink.error );
324325
```
325326

326-
# Data binding examples
327+
## Data binding examples
327328

328329
Here are the set of [working](https://volicon.github.io/valuelink/databinding.html) [examples](/databinding.html) for typical data binding use cases.
329330

330331
Also, there's [working](https://volicon.github.io/valuelink) [example](/example/userslist.jsx) of an application managing the users list.
331332

332333
[Custom elements boilerplate](/tags.jsx) which is used by both examples is another good example.
333334

335+
### Text and number form fields
336+
337+
##### <Input type="text"/>, <TextArea />
338+
339+
`tags.jsx` contains wrappers for standard `<input>` and `<textarea>` tags,
340+
which can be directly bound to the string state elements.
341+
342+
These wrappers will add `invalid` class to enclosed HTML element, if an error is present in the bound link.
343+
344+
```jsx
345+
<Input type="text" valueLink={ link } />
346+
<TextArea valueLink={ link } />
347+
```
348+
349+
##### <NumberInput/>
350+
351+
There's also cross-browser implementation of *numeric input* tag. It has following differences compared to `<Input>`:
352+
353+
- Keyboard input which obviously leads to invalid values (e.g. letters) are rejected.
354+
- Value is being always converted to valid number.
355+
- There are `integer` and `positive` boolean props controlling input rejection. They can be combined.
356+
357+
`<NumberInput>` validates its value, and adds `invalid` class to enclosed input element if it's not a number.
358+
359+
```jsx
360+
<NumberInput valueLink={ link } />
361+
<NumberInput valueLink={ link } integer={ true }/>
362+
<NumberInput valueLink={ link } positive={ true }/>
363+
```
364+
365+
### Checkboxes
366+
367+
##### <Input type="checkbox">
368+
369+
Wrapper for the standard `<input>`. Directly binds boolean value with `checkedLink` property.
370+
371+
```jsx
372+
<Input type="text" checkedLink={ booleanLink } />
373+
<Input type="text" checkedLink={ arrayLink.contains( 'option' ) } />
374+
```
375+
376+
##### <Checkbox>
377+
378+
Internally, it's `<div>` element which toggles `selected` class on click.
379+
Thus, it can be easily styled.
380+
381+
By default, it has `checkbox` CSS class, which can be overridden by passing `className` prop.
382+
383+
It passes through anything else, including `children`.
384+
385+
```jsx
386+
<Checkbox checkedLink={ booleanLink } />
387+
<Checkbox checkedLink={ arrayLink.contains( 'option' ) } />
388+
```
389+
390+
### Radio Groups and Select list
391+
392+
##### <Select>
393+
394+
Wrapper for standard <select/>. Regular <option/> tags must be used. All props are passed through.
395+
396+
```jsx
397+
<Select valueLink={ linkToSelectedValue }>
398+
<option value="a">A</option>
399+
<option value="b">B</option>
400+
</Select>
401+
```
402+
403+
##### <Input type="radio">
404+
405+
Wrapper for the standard `<input>`. Directly binds boolean value with `checkedLink` property.
406+
407+
Can be directly bound to the state member using `valueLink` property.
408+
409+
```jsx
410+
<label>
411+
A:
412+
<Input type="radio" valueLink={ flagLink } value="a" />
413+
</label>
414+
<label>
415+
B:
416+
<Input type="radio" valueLink={ flagLink } value="b" />
417+
</label>
418+
```
419+
420+
##### <Radio>
421+
422+
Internally, it's `<div>` element which always sets `selected` class on click. Thus,
423+
it can be easily styled.
424+
425+
By default, it has `radio` CSS class, which can be overridden by passing `className` prop.
426+
It passes through anything else, including `children`.
427+
428+
It *must* be used in conjunction with `link.equals( 'value' )` method.
429+
430+
```jsx
431+
<label>
432+
A:
433+
<Radio checkedLink={ flagLink.equals( 'a' ) } />
434+
</label>
435+
<label>
436+
B:
437+
<Radio checkedLink={ flagLink.equals( 'b' ) } />
438+
</label>
439+
```
440+
334441
[method]: /images/method.png
335442
[static]: /images/static.png
336443
[var]: /images/var.png

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "valuelink",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "React valueLink implementation with links to objects, validation, and purely functional state updates.",
55
"main": "valuelink.js",
66
"repository": {

tags.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ export const Select = ( { valueLink, children, ...props } ) => (
173173
* <Radio checkedLink={ linkToValue.equals( optionValue ) />
174174
*/
175175

176-
export const Radio = ( { className = 'radio', checkedLink } ) => (
176+
export const Radio = ( { className = 'radio', checkedLink, children } ) => (
177177
<div className={ className + ( checkedLink.value ? ' selected' : '' ) }
178178
onClick={ checkedLink.action( () => true ) }
179-
/>
179+
>
180+
{ children }
181+
</div>
180182
);
181183

182184
/**
@@ -186,8 +188,10 @@ export const Radio = ( { className = 'radio', checkedLink } ) => (
186188
* <Checkbox checkedLink={ boolLink } />
187189
*/
188190

189-
export const Checkbox = ( { className = 'checkbox', checkedLink } ) => (
191+
export const Checkbox = ( { className = 'checkbox', checkedLink, children } ) => (
190192
<div className={ className + ( checkedLink.value ? ' selected' : '' ) }
191193
onClick={ checkedLink.action( x => !x ) }
192-
/>
194+
>
195+
{ children }
196+
</div>
193197
);

0 commit comments

Comments
 (0)