Last active
March 1, 2019 02:14
-
-
Save jtrein/43e1ace004f0400afdeb3d6936d629a5 to your computer and use it in GitHub Desktop.
Getting started with OpenLaw Elements
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { APIClient, Openlaw } from 'openlaw'; | |
import OpenLawForm from 'openlaw-elements'; | |
// our optional base styles — feel free to use them! | |
import 'openlaw-elements/dist/openlaw-elements.min.css'; | |
// OpenLaw APIClient: https://docs.openlaw.io/api-client/#authentication | |
// — Used to fetch geo data in our `Address` field type | |
// — To run against your own private OpenLaw instance: ‘https://[YOUR.INSTANCE.URL]'; | |
const apiClient = new APIClient('https://app.openlaw.io'); | |
// we strongly recommend using environment variables, not hard-coded strings. | |
apiClient.login('[YOUR_OPENLAW_EMAIL]', '[YOUR_OPENLAW_PASSWORD]'); | |
// https://docs.openlaw.io/openlaw-object/#compiletemplate | |
const { compiledTemplate } = Openlaw.compileTemplate('**Name**: [[First Name]] [[Last Name]]'); | |
// https://docs.openlaw.io/openlaw-object/#execute | |
const { executionResult, errorMessage } = Openlaw.execute(compiledTemplate, {}, {}); | |
// https://docs.openlaw.io/openlaw-object/#getexecutedvariables | |
const variables = Openlaw.getExecutedVariables(executionResult, {}); | |
// typically the parameters object will be updated in | |
// state via an `onChangeFunction` handler | |
// (or in a state manager like Redux or MobX) | |
// throughout the lifetime of the app | |
const parameters = {}; | |
// helpful for logging in development, or throwing exceptions at runtime | |
if (errorMessage) { | |
console.error('Openlaw Execution Error:', errorMessage); | |
} | |
const onChange = (key, value) => console.log('KEY:', key, 'VALUE:', value); | |
const App = () => ( | |
<OpenLawForm | |
apiClient={apiClient} | |
executionResult={executionResult} | |
parameters={parameters} | |
onChangeFunction={onChange} | |
// https://docs.openlaw.io/openlaw-object/ | |
openLaw={Openlaw} | |
variables={variables} | |
/> | |
); | |
ReactDOM.render(<App />, document.getElementById('your-id-here')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment