-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5114ad0
commit 8884a8a
Showing
47 changed files
with
6,276 additions
and
1,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea/ | ||
node_modules/ | ||
dist/ | ||
npm-debug.log | ||
.idea | ||
node_modules | ||
dist | ||
npm-debug.log | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
src/ | ||
examples/ | ||
docs/ | ||
tasks/ | ||
.gitignore | ||
.idea | ||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Amir Mohsen Abdolrazaghi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
UNLICENSED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,141 +1 @@ | ||
# Flex Form | ||
|
||
Flex Form is a JavaScript library for generating forms from Mongoose Schemas, using React components. | ||
**Note: This library is in a working condition. However, since it is the early days, things may rapidly change.** | ||
|
||
## Installation | ||
|
||
Make sure React and Mongoose are installed in your project. | ||
Mongoose has an npm package which has a lot of issues in the browser. | ||
For now, the CDN version is recommended. | ||
|
||
``` | ||
npm install --save flexform | ||
``` | ||
|
||
## Usage | ||
|
||
The followings can be imported from the `flexform` module. | ||
|
||
```js | ||
import FlexForm, {Field, FlexFormError, TypeNoMatchError, types, setType} from 'flexform'; | ||
``` | ||
|
||
### Field component | ||
|
||
Flex Form as the name suggests, is about providing flexibility. | ||
Unlike other form generators, it doesn't come with built-in fields, but it allows you to create any number of your own fields, both simple and complex. | ||
|
||
All fields that you create must extend the `Field` component. | ||
Here's a simple text field. Check the `examples` folder for more. | ||
|
||
```js | ||
import React from 'react'; | ||
import {Field} from 'flexform'; | ||
|
||
export default class Text extends Field { | ||
|
||
onChange = (e) => { | ||
this.save(e.target.value); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<input type="text" value={this.getData()} onChange={this.onChange} /> | ||
) | ||
} | ||
} | ||
``` | ||
|
||
### FlexForm component | ||
|
||
Provided with the following schema: | ||
|
||
```js | ||
export default new mongoose.Schema({ | ||
profile: { | ||
name: String, | ||
age: Number, | ||
higherEd: Boolean | ||
}, | ||
children: [ | ||
{ | ||
name: String, | ||
gender: { | ||
type: String, | ||
default: 'female' | ||
} | ||
} | ||
] | ||
}); | ||
``` | ||
|
||
We can easily generate a form (with or without existing data): | ||
|
||
```js | ||
import React, {Component} from 'react'; | ||
import schema from './schema'; | ||
import FlexForm from 'flexform'; | ||
import {GroupList, Group, Text, Radio, Checkbox} from '../BasicFields'; | ||
|
||
export default class Simple extends Component { | ||
|
||
onChange = (data) => { | ||
this.setState({ | ||
data | ||
}); | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
data: { | ||
profile: { | ||
age: 30 | ||
}, | ||
children: [ | ||
{ | ||
name: 'Julie' | ||
}, | ||
{ | ||
name: 'Ashley' | ||
} | ||
] | ||
} | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<FlexForm schema={schema} data={this.state.data} onInit={this.onChange} onChange={this.onChange} > | ||
<Group path="profile"> | ||
Name: <Text path="name"/> | ||
Age: <Text path="age"/> | ||
Has Higher Education Degree? <Checkbox path="higherEd"/> | ||
</Group> | ||
Children: | ||
<GroupList path="children"> | ||
<Group path="$"> | ||
Name: <Text path="name"/> | ||
Gender: | ||
Male: <Radio value="male" path="gender" /> | ||
Female: <Radio value="female" path="gender" /> | ||
</Group> | ||
</GroupList> | ||
<pre> | ||
{JSON.stringify(this.state.data, null, '\t')} | ||
</pre> | ||
</FlexForm> | ||
); | ||
} | ||
} | ||
``` | ||
|
||
### Other exports | ||
|
||
Other exports can be used for further customization, such as extra types. | ||
For more information, clone this repo and run `npm run dev` to get the example up. | ||
|
||
## License | ||
|
||
Flex Form is MIT licensed. | ||
# FlexForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
process.on('unhandledRejection', (reason, p) => { throw reason }); | ||
|
||
require('babel-polyfill'); | ||
const loader = require('flexbuilder').default; | ||
const argv = require('yargs').argv; | ||
|
||
loader({ | ||
root: __dirname, | ||
dev: !!argv.dev, | ||
library: 'FlexForm', | ||
sources: { | ||
client: { | ||
index: './src' | ||
}, | ||
server: { | ||
index: './src' | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/client'); |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.