-
Notifications
You must be signed in to change notification settings - Fork 33
Custom JS Components
Geoff Cox edited this page Aug 8, 2021
·
6 revisions
Custom components consist of 2 pieces:
- A MSON-layer component that wraps the properties, e.g.
import compile from 'mson/lib/compiler/compile';
const CustomComponent = compile({
component: 'UIComponent',
name: 'CustomComponent',
schema: {
component: 'Form',
fields: [
{
component: 'TextField',
name: 'name',
},
{
component: 'TextField',
name: 'label',
},
],
},
});
- A view-layer component for rendering, e.g. one written in React:
import React from 'react';
import attach from '../../attach';
import Typography from '@material-ui/core/Typography';
let ReactCustomComponent = (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
ReactCustomComponent = attach(['name', 'label'])(ReactCustomComponent);
See custom-component.js for a working example in the MSON Demo.