-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): custom components (#276)
* feat(demo): custom components * refactor(demo): move contact-no-mson * refactor(custom-component): rename to react component * feat(demo): custom component no props * chore(mson): upgrade to v2.7.0 * fix(demo): compile path
- Loading branch information
Showing
8 changed files
with
145 additions
and
75 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
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import attach from '../../attach'; | ||
import Typography from '@material-ui/core/Typography'; | ||
|
||
import UIComponent from 'mson/lib/ui-component'; | ||
import Form from 'mson/lib/form'; | ||
import TextField from 'mson/lib/fields/text-field'; | ||
|
||
class CustomComponentJS extends UIComponent { | ||
// className is needed as JS minification strips the constructor name | ||
className = 'CustomComponentJS'; | ||
|
||
create(props) { | ||
super.create(props); | ||
|
||
this.set({ | ||
schema: new Form({ | ||
fields: [ | ||
new TextField({ | ||
name: 'name', | ||
}), | ||
new TextField({ | ||
name: 'label', | ||
}), | ||
], | ||
}), | ||
}); | ||
} | ||
} | ||
|
||
let ReactCustomComponentJS = (props) => { | ||
const { name, label } = props; | ||
return ( | ||
<div> | ||
<Typography variant="h3">Name: {name}</Typography> | ||
<Typography variant="h4">Label: {label}</Typography> | ||
</div> | ||
); | ||
}; | ||
|
||
// Bind React props to MSON component props | ||
ReactCustomComponentJS = attach(['name', 'label'])(ReactCustomComponentJS); | ||
|
||
export { CustomComponentJS, ReactCustomComponentJS }; |
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 @@ | ||
import React from 'react'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import compile from 'mson/lib/compiler/compile'; | ||
|
||
const CustomComponentNoProps = compile({ | ||
component: 'UIComponent', | ||
name: 'CustomComponentNoProps', | ||
}); | ||
|
||
const ReactCustomComponentNoProps = (/* props */) => { | ||
const text = 'This text is private to the React component'; | ||
return ( | ||
<div> | ||
<Typography variant="h5">Text: {text}</Typography> | ||
</div> | ||
); | ||
}; | ||
|
||
export { CustomComponentNoProps, ReactCustomComponentNoProps }; |
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