The macro
module inserts dynamic content into the user interface via an editor. Editor macros are
only compatible with the Atlassian editor. All cloud sites use the Atlassian editor by default.
The macro
module works in Confluence, where the macro is inserted by typing /
and selecting
from the quick insert menu of the editor. The macro
module is implemented by a Forge function.
For UI Kit 1, see the Macro component documentation for more information.
On apps that use Custom UI, module content is displayed inside a special Forge iframe which has the sandbox attribute configured. This means that HTML links (for example, <a href="https://domain.tld/path">...</a>
) in this iframe won't be clickable. To make them clickable, use the router.navigate API from the @forge/bridge
package.
Property | Type | Required | Description |
---|---|---|---|
key |
| Yes |
A key for the module, which other modules can refer to. Must be unique within the manifest. Regex: |
function | string | Required if using UI Kit 1 or triggers. | A reference to the function module that defines the module. |
resource | string | Required if using custom UI or the latest version of UI Kit. | A reference to the static resources entry that your context menu app wants to display. See resources for more details. |
render | 'native' | Yes for UI Kit. | Indicates the module uses UI Kit. |
resolver | { function: string } or{ endpoint: string } | Yes | Set the Set the |
viewportSize | 'small' , 'medium' , 'large' or 'xlarge' | The display size of resource . Can only be set if the module is using the resource property. Remove this property to enable automatic resizing of the module. | |
title | string or i18n object | Yes |
The title of the macro. In Confluence, this is displayed in the editor. The |
icon | string |
The icon displayed next to the For custom UI and UI Kit apps, the If no icon is provided, or if there's an issue preventing the icon from loading, a generic app icon will be displayed. | |
categories | string[] | The categories of the macro. In Confluence, this is used for categorisation in the macro browser.
| |
description | string or i18n object |
The description of the macro. In Confluence, this is displayed in the editor. The | |
config | { function: string } | Contains a function property, which references the function module that defines the macro configuration. | |
export | { function: string } | For UI Kit 1 and Custom UI use only. Contains a function property, which references the function module that defines the export view of the macro, specified in UI Kit 1 components. The specified function can consume the exportType from the extension context in order to specify different export views per export type.
| |
adfExport | { function: string } | For UI Kit and Custom UI use only. Contains a function property, which references the function module that defines the export view of the macro, specified in Atlassian document format.
The specified function can consume the exportType directly from the function's payload in order to specify different views per export type. The exportType can be one of pdf , word , or other . See this tutorial for more information.
| |
layout | 'inline' , 'block' | Sets whether the macro is treated as a For UI Kit apps, inline macros dynamically resize to wrap the content. A limitation exists for custom UI apps that prevents inline macros from dynamically resizing when the content of the macro is changed. |
Internationalization (i18n) for Forge apps is now available through Forge's Early Access Program (EAP). For details on how to sign up for the EAP, see the changelog announcement.
EAPs are offered to selected users for testing and feedback purposes. APIs and features under EAP are unsupported and subject to change without notice. APIs and features under EAP are not recommended for use in production environments.
For more details, see Forge EAP, Preview, and GA.
Key | Type | Required | Description |
---|---|---|---|
i18n | string | Yes | A key referencing a translated string in the translation files. For more details, see Translations. |
Property | Type | Description |
---|---|---|
type | string | The type of the module (macro ). |
content.id | string | A string that represents the unique identifier of the `content` object |
space.id | string | A string that represents the unique identifier of the `space` object. |
space.key | string | A string that represents the unique key of the `space` object. |
isEditing | boolean | Indicates whether the macro is opened in the editor or not. |
references | ReferenceEntity[] | An array of reference entities (if any). |
Property | Type | Description |
---|---|---|
type | string | The type of the module (macro ). |
exportType | string | The type of the current export. Available for the export function only. Valid values: One of pdf , email , word or other .Note: other implies export other than pdf, email or word. For example, when the macro is shown in the Page history or exported via API. |
Macro configuration allows you to customize what the macro displays by adjusting settings in a form. To access these settings, you need to go into the edit mode for the macro, as demonstrated below. This gives you the ability to customize the macro's output according to your preferences.
You can use UI Kit components to build this configuration.
You will need to add config: true
property in your manifest.yml
. For example:
1 2modules: macro: - key: config-example resource: main render: native resolver: function: resolver title: Favorite Color config: true function: - key: resolver handler: index.handler resources: - key: main path: src/frontend/index.jsx app: id: '<your app id>' runtime: name: 'nodejs18.x'
Configuration is stored in key-value pairs corresponding to each Form component.
src/frontend/index.jsx
file, create a component that constructs
the configuration of the UI Kit components you're using:1 2import React from 'react'; import { Label, Textfield } from '@forge/react'; const Config = () => { return ( <> <Label>First Name</Label> <Textfield name="firstName"/> </> ); };
src/frontend/index.jsx
file, call the addConfig
method on ForgeReconciler
with your config element. Ensure you have ForgeReconciler
imported at the top.1 2import React from 'react'; import ForgeReconciler, { Label, Textfield } from '@forge/react'; const Config = () => { return ( <> <Label>First Name</Label> <Textfield name="firstName"/> </> ); }; ForgeReconciler.addConfig(<Config />);
Use config to store general data, but not sensitive information. The config data is stored in plaintext, so other users and apps can access and modify the values.
You access the config for a macro in your app code with the
useProductContext hook. When this method resolves,
it returns the product context, which will include the key-value pairs set in the config.
The key is the name
property on the form component in configuration, and the value is what the user enters.
The index.jsx
file could look like this:
1 2import React from 'react'; import ForgeReconciler, { Label, Text, Textfield, useProductContext } from '@forge/react'; const Config = () => { return ( <> <Label>First Name</Label> <Textfield name="firstName" /> </> ); }; const App = () => { const context = useProductContext(); const config = context?.extension.config; const name = config?.firstName; return ( <Text>Hello {name || 'Fetching config...'}</Text> ); }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> ); ForgeReconciler.addConfig(<Config />);
You can create a function component that will return UI Kit components in a custom UI app.
Configuration is stored in key-value pairs corresponding to each Form component.
static/hello-world/src/Config.js
file, create a function component that constructs
the configuration of the UI Kit components you're using:1 2import React from 'react'; import { Label, Textfield } from '@forge/react'; const Config = () => { return ( <> <Label>First Name</Label> <Textfield name="firstName"/> </> ); }; export default Config;
static/hello-world/src/index.js
file, call the addConfig
method on ForgeReconciler
with your config element. Ensure you have ForgeReconciler
imported at the top.1 2import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import Config from './Config'; import ForgeReconciler from "@forge/react"; ReactDOM.render( <App />, document.getElementById('root') ); ForgeReconciler.addConfig(<Config />);
To retrieve the configuration, follow the same steps as above but in your static/hello-world/src/App.js
file instead. You can then use the configuration values in your app.
1 2import React, { useState, useEffect } from 'react'; import { view } from "@forge/bridge"; const App = () => { const [context, setContext] = useState(undefined); useEffect(() => { view.getContext().then(setContext); }, []); const config = context?.extension.config; const name = config?.firstName; return ( <div> {`Hello ${name}` || 'Fetching config...'} </div> ); } export default App;
The UI Kit components available for use in the configuration come with certain limitations and have restricted properties. In the latest version of the UI Kit, we support the following components:
To label the fields in the configuration panel, use the Label component:
Name | Type | Required | Description |
---|---|---|---|
children | string | No | Content of the label. |
The following subset of UI Kit Checkbox group props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
options | Array<{ label: string; value: string; isDisabled?: boolean; }> | Yes | An array of objects, each object is mapped onto a Checkbox element within the group. |
defaultValue | Array<string> | No | Sets the initial selected value on the CheckboxGroup . |
isRequired | boolean | No | Sets the required state of all Radio elements in the group. Should only be set when using within a Form component. |
name | string | Yes | Sets the name prop on each of the Checkbox elements in the group. |
The following subset of UI Kit Date picker props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
defaultValue | string | No | The initial date value to display. It should be formatted as 'YYYY-MM-DD' . |
isRequired | boolean | No | Indicates to the user whether or not a value is required in this field to submit the form. If a field is required, an asterisk appears at the end of that field’s label. |
name | string | Yes | The key to which the input value is assigned in the returned form object. |
placeholder | string | No | The placeholder helper text. |
The following subset of UI Kit Radio group props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
options | Array<Option> | Array<{ isDisabled: boolean; label: string; name: string; value: string; }> | Yes | An array of objects, each object is mapped onto a Radio element within the group. Name must be unique to the group. |
defaultValue | string | null | No | Sets the initial selected value on the RadioGroup . |
isRequired | boolean | No | Sets the required state of all Radio elements in the group. Should only be set when using within a Form component. |
name | string | Yes | Sets the name prop on each of the Radio elements in the group. |
The following subset of UI Kit Select props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
defaultValue | Option | Option[] | null | No | The default value of the select. |
options | (Option | Group) [] | No | Array of options that populate the select menu. |
placeholder | string | No | Placeholder for the select value. |
isRequired | boolean | No | Indicates that the field is a required field. |
name | string | Yes | Name of the input (optional: without this, no input will be rendered). |
The following subset of UI Kit Textfield props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
defaultValue | string | number | No | The default value of the text field. |
isRequired | boolean | No | Set required for form that the field is part of. |
name | string | Yes | Name of the input element. |
placeholder | string | No | Placeholder text to display in the text field whenever it is empty. |
The following subset of UI Kit Text area props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
defaultValue | string | No | The default value of the text area. |
isRequired | boolean | No | Sets whether the field is required for form that the field is part of. |
name | string | Yes | Name of the input form control. |
placeholder | string | No | The placeholder within the text area. |
The following subset of UI Kit User picker props can be used in the configuration:
Name | Type | Required | Description |
---|---|---|---|
isMulti | boolean | No | Whether the user can select multiple users from the list. Defaults to false . |
isRequired | boolean | No | Indicates to the user whether or not a value is required in this field to submit the form. If a field is required, an asterisk appears at the end of that field’s label. |
name | string | Yes | The key to which the input value is assigned in the returned form object. If isMulti is
true , the submitted value is an array of strings; otherwise, it is a string. |
defaultValue | string | No | The initial user to display. The value should be an Atlassian account ID. |
description | string | No | The text description of the user picker field. |
placeholder | string | No | The placeholder helper text. |
A macro with configuration could look like this:
1 2import React from "react"; import ForgeReconciler, { useProductContext } from "@forge/react"; import { Label, Text, Textfield, Select } from "@forge/react"; const options = [ { name: 'color', value: 'red', label: 'Red' }, { name: 'color', value: 'blue', label: 'Blue' }, { name: 'color', value: 'yellow', label: 'Yellow' }, { name: 'color', value: 'green', label: 'Green' }, { name: 'color', value: 'black', label: 'Black' }, ]; const Config = () => { return ( <> <Label>Name</Label> <Textfield name="name" /> <Label>Favorite color</Label> <Select name="color" options={options} defaultValue={options[0]} placeholder="Select color" isRequired /> </> ) } const App = () => { const context = useProductContext(); const config = context?.extension.config; const name = config?.name const favoriteColor = config?.color; return ( <Text> {name || "Fetching name..."}'s favorite color is: ${favoriteColor || "Unselected"} </Text> ) }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> ); ForgeReconciler.addConfig(<Config />);
Rate this page: