-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add different component choices to backend engine that include both class and function components - Add Class to current Async and Component templates - AsynComponent.react.js -> AsyncClassComponent.react.js - Component.react.js -> ClassComponent.react.js - Add 2 additional function components templates. - Replace use_async boolean choice with component_type list choices
- Loading branch information
Showing
9 changed files
with
143 additions
and
33 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
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
{{cookiecutter.project_shortname}}/cookiecutter_templates/AsyncFunctionComponent.react.js
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,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { {{cookiecutter.component_name}} as RealComponent } from '../LazyLoader'; | ||
|
||
/** | ||
* ExampleComponent is an example component. | ||
* It takes a property, `label`, and | ||
* displays it. | ||
* It renders an input with the property `value` | ||
* which is editable by the user. | ||
*/ | ||
const {{cookiecutter.component_name}} = (props) => { | ||
return ( | ||
<React.Suspense fallback={null}> | ||
<RealComponent {...props}/> | ||
</React.Suspense> | ||
); | ||
}; | ||
|
||
{{cookiecutter.component_name}}.defaultProps = {}; | ||
|
||
{{cookiecutter.component_name}}.propTypes = { | ||
/** | ||
* The ID used to identify this component in Dash callbacks. | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* A label that will be printed when this component is rendered. | ||
*/ | ||
label: PropTypes.string.isRequired, | ||
|
||
/** | ||
* The value displayed in the input. | ||
*/ | ||
value: PropTypes.string, | ||
|
||
/** | ||
* Dash-assigned callback that should be called to report property changes | ||
* to Dash, to make them available for callbacks. | ||
*/ | ||
setProps: PropTypes.func | ||
}; | ||
|
||
export default {{cookiecutter.component_name}}; | ||
|
||
export const defaultProps = {{cookiecutter.component_name}}.defaultProps; | ||
export const propTypes = {{ cookiecutter.component_name }}.propTypes; |
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
{{cookiecutter.project_shortname}}/cookiecutter_templates/FunctionComponent.react.js
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,61 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* ExampleComponent is an example component. | ||
* It takes a property, `label`, and | ||
* displays it. | ||
* It renders an input with the property `value` | ||
* which is editable by the user. | ||
*/ | ||
const {{cookiecutter.component_name}} = (props) => { | ||
const {id, label, setProps, value} = props; | ||
|
||
return ( | ||
<div id={id}> | ||
ExampleComponent: {label} | ||
<input | ||
value={value} | ||
onChange={ | ||
/* | ||
* Send the new value to the parent component. | ||
* setProps is a prop that is automatically supplied | ||
* by dash's front-end ("dash-renderer"). | ||
* In a Dash app, this will update the component's | ||
* props and send the data back to the Python Dash | ||
* app server if a callback uses the modified prop as | ||
* Input or State. | ||
*/ | ||
e => setProps({ value: e.target.value }) | ||
} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
{{cookiecutter.component_name}}.defaultProps = {}; | ||
|
||
{{cookiecutter.component_name}}.propTypes = { | ||
/** | ||
* The ID used to identify this component in Dash callbacks. | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* A label that will be printed when this component is rendered. | ||
*/ | ||
label: PropTypes.string.isRequired, | ||
|
||
/** | ||
* The value displayed in the input. | ||
*/ | ||
value: PropTypes.string, | ||
|
||
/** | ||
* Dash-assigned callback that should be called to report property changes | ||
* to Dash, to make them available for callbacks. | ||
*/ | ||
setProps: PropTypes.func | ||
}; | ||
|
||
export default {{cookiecutter.component_name}}; |
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,32 +1,24 @@ | ||
/* eslint no-magic-numbers: 0 */ | ||
import React, {Component} from 'react'; | ||
import React, { useState } from 'react'; | ||
|
||
import { {{cookiecutter.component_name}} } from '../lib'; | ||
|
||
class App extends Component { | ||
const App = () => { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
value: '' | ||
const [state, setState] = useState({value:'', label:'Type Here'}); | ||
const setProps = (newProps) => { | ||
setState(newProps); | ||
}; | ||
this.setProps = this.setProps.bind(this); | ||
} | ||
|
||
setProps(newProps) { | ||
this.setState(newProps); | ||
} | ||
return ( | ||
<div> | ||
<{{cookiecutter.component_name}} | ||
setProps={setProps} | ||
{...state} | ||
/> | ||
</div> | ||
) | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<{{cookiecutter.component_name}} | ||
setProps={this.setProps} | ||
{...this.state} | ||
/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default App; |
12 changes: 8 additions & 4 deletions
12
...kiecutter.project_shortname}}/src/lib/components/{{cookiecutter.component_name}}.react.js
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,5 +1,9 @@ | ||
{%- if cookiecutter.use_async == "True" -%} | ||
{%- include 'cookiecutter_templates/AsyncComponent.react.js' -%} | ||
{%- if "Async" in cookiecutter.component_type and "Class" in cookiecutter.component_type -%} | ||
{%- include 'cookiecutter_templates/AsyncClassComponent.react.js' -%} | ||
{%- elif "Async" in cookiecutter.component_type and "Function" in cookiecutter.component_type -%} | ||
{%- include 'cookiecutter_templates/AsyncFunctionComponent.react.js' -%} | ||
{%- elif "Class" in cookiecutter.component_type -%} | ||
{%- include 'cookiecutter_templates/ClassComponent.react.js' -%} | ||
{%- else -%} | ||
{%- include 'cookiecutter_templates/Component.react.js' -%} | ||
{%- endif -%} | ||
{%- include 'cookiecutter_templates/FunctionComponent.react.js' -%} | ||
{%- endif -%} |
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