Once you have configured your CLI settings, you can parse components using the CLI:
interplay parse
To set up your CLI settings, please see Running the CLI
This page describes how you can control the specific config generated for each component.
Once you have got the basic import working, there are various ways you can control the configuration generated for each component.
There are 2 ways to exclude components from the Interplay config created by the CLI:
The easiest way to control which components are imported is to create a custom index file for Interplay that only exports the components you want in Interplay.
If you use this same index file for parsing and bundling (i.e. in the src
and build
package settings in your CLI settings) then both the build and the config will only contain the components in the index.
Your index file must:
default
)After creating your custom index, update the src
setting for the relevant package in your CLI settings file to tell the CLI to use this custom index.
If you are using an index file that contains exports you want to exclude from Interplay, you can set a list of exports to exclude using the ignoreExports
CLI setting.
Use this approach for exports that still need to be present in your build (for example, if they are used by other components) but you want to avoid having them registered as components in Interplay.
Before attempting to modify the component config it is useful to see an example of how it is structured. You can see the config the CLI has created for your components in your .interplay/deploy/code.json
file.
"< identifier value >": {
"id": "< identifier value >",
"name": "Button
"description": "Here is the component description",
"code": {
"packageName": "reactstrap",
"exportName": "Button",
"lib": "reactstrap"
},
"path": "Actions/Buttons"
"props": {
"variant": {
"name": "variant",
"type": "string"
},
"size": {
"name": "size",
"type": "string",
"enum": [
"small",
"medium",
"large"
],
"default": "medium",
"ui": {
"hidden": true
}
},
//...(more props)
},
"relativePath": "src/Button.js"
},
Component
name
- the component name to display in Interplay
description
- the description text displayed in Interplay
code
- this block specifies how the Interplay accesses this component in the your build
path
- Interplay folder structure for Button (available CLI 2.0.0+)
Component props
type
- how Interplay should treat the value set for this prop
string
, number
, boolean
, object
, date
, array
, Node
, Event
, Component
, fnNode
, unknown
enum
- sets the allowed values for the prop - these will appear as a dropdown in properties panel
ui.hidden
- prevent prop displaying in Interplay and plugins (can still edit online in Edit Properties)
The Interplay parser will generate metadata from the structure of your code. For React components you can set:
displayName - to set the name that Interplay will use for your component. If this is not set it will default to the filename containing the component.
class StatefulButton extends React.Component {
//(StatefulButton implementation)
}
StatefulButton.displayName = "Button"
propTypes (react) or type definitions for your props - we recommend controlling property type information information using prop-types or typescript types definitions in your code. The CLI parser will find this type information and use it to generate Interplay configuration.
e.g. Using proptypes to specify the allowed values for a property, which will appear as dropdown in Interplay props panel
//Button.js
import PropTypes from 'prop-types';
//(Button implementation)
Button.propTypes = {
variant: PropTypes.oneOf(['success', 'warning', 'error']),
//more Button props
}
e.g. Using typescript to specify allowed values
//Button.ts
export type Size = 'small' | 'medium' | 'large'
export interface IButtonProps {
/** The size of the button */
size?: Size //using variable
variant?: 'success' | 'warning' | 'error'; //inline values
//more Button props
}
const Button = ({ children, ...props }: IButtonProps) => {
//Button implementation
}
You can modify the component config generated by adding JSDoc tags to the component definition, or to the props definitions.
Components
description
You can add normal JSDoc comments to your components and their properties and they will be used as the component description
in Interplay when discovered by the parser:
/**
* Normal JSDoc description will be set on component by Interplay
*/
class Button extends React.Component {
You can set a custom description for Interplay with the @interplaydesc
tag
/**
* Default description of Button
* @interplaydesc Custom description parsed by Interplay CLI
* */
class Button extends React.Component {
path (CLI 2.0.0+)
You can create and control the folder that your component is displayed in by setting the path
attribute using the @interplaypath
tag. On running the import, the equivalent folders will be created in Interplay if they do not already exist:
/**
* Description of Button component
* @interplaypath Actions/Buttons
*/
class Button extends React.Component {
Props
description
As for components, can set description
on props using a normal jsDocs tag on their propTypes in javascript or in type definitions for Typescript...
/**
* The size of Button to display
* */
size: PropTypes.string,
...and you can set a custom description for Interplay with the @interplaydesc
tag
/**
* The size of Button to display
* @interplaydesc Custom description parsed by Interplay CLI
* */
size: PropTypes.string,
ui.hidden
You can hide component properties by setting the ui.hidden
attribute, using the @interplayignore
tag (CLI1.x.x) or @interplayhidden
(CLI 2.0.0)
/** @interplayhidden */
ref: PropTypes.string,
type (e.g. for Render Props)
There is a shortcut tag @interplaytype
available for overriding type for a prop.
We recommend type information for props setting this via propTypes or typescript type definitions rather than JSDocs as outlined above.
There are two cases where you might need to modify the type
/**
* Here is the description for this prop
* @interplaytype string
* */
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
() => React.ReactNode
this will cause the type of 'fnNode' (function node) to be set in the config/** Description of the render prop
* @interplaytype () => React.ReactNode
*/
myRenderProp: PropTypes.func.isRequired,
Setting other attributes on both components and props (CLI 2.0.0+)
JSDocs can be also used to modify or set other config attributes by using one or more interplay tags, which use the format @interplay {type} attribute - value
type
is the type of value you are providing (string
, number
, boolean, object
or array
)-
is used as delimiter between attribute and valuevalue
is the value to set, parsed based on {type}
Here are some examples setting attributes on the component object
/**
* Default description of Button
* @interplay {string} description - Custom description of Button for Interplay
* @interplay {string} path - Actions/Buttons
*/
class Button extends React.Component {
These examples are the equivalent of setting the @interplaydesc
and @interplaypath
tags above.
Here are some examples setting attributes on a prop declaration.