Bitbucket modules
Common modules
Compass modules
Confluence modules
Jira modules
Jira Service Management modules
Rovo modules (Preview)

Macro

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.

Example of a macro

Properties

PropertyTypeRequiredDescription
key

string

Yes

A key for the module, which other modules can refer to. Must be unique within the manifest.

Regex: ^[a-zA-Z0-9_-]+$

functionstringRequired if using UI Kit 1 or triggers.A reference to the function module that defines the module.
resourcestringRequired 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 function property if you are using a hosted function module for your resolver.

Set the endpoint property if you are using Forge remote to integrate with a remote back end.

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.
titlestring or i18n objectYes

The title of the macro. In Confluence, this is displayed in the editor.

The i18n object allows for translation and is available to participants of the Internationalization for Forge EAP. See i18n object.

iconstring

The icon displayed next to the title.


For custom UI and UI Kit apps, the icon property accepts a relative path from a declared resource. Alternatively, you can also use an absolute URL to a self-hosted icon. See Icons for more information.

If no icon is provided, or if there's an issue preventing the icon from loading, a generic app icon will be displayed.

categoriesstring[]The categories of the macro. In Confluence, this is used for categorisation in the macro browser.
  • formatting
  • confluence-content
  • media
  • visuals
  • navigation
  • external-content
  • communication
  • reporting
  • admin
  • development
descriptionstring or i18n object

The description of the macro. In Confluence, this is displayed in the editor.

The i18n object allows for translation and is available to participants of the Internationalization for Forge EAP. See i18n object.

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 block or inline element in the editor. 'block' type is used by default.

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.

i18n object

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.

KeyTypeRequiredDescription
i18nstringYesA key referencing a translated string in the translation files. For more details, see Translations.

Extension context

UI Kit and Custom UI

PropertyTypeDescription
typestringThe type of the module (macro).
content.idstringA string that represents the unique identifier of the `content` object
space.idstringA string that represents the unique identifier of the `space` object.
space.keystringA string that represents the unique key of the `space` object.
isEditingbooleanIndicates whether the macro is opened in the editor or not.
referencesReferenceEntity[]An array of reference entities (if any).

UI Kit 1

PropertyTypeDescription
typestringThe type of the module (macro).
exportTypestringThe 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

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.

Example of configuring a Forge macro

Manifest declaration

You will need to add config: true property in your manifest.yml. For example:

1
2
modules:
  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 for a UI Kit macro app

Create the configuration

Configuration is stored in key-value pairs corresponding to each Form component.

  1. In your src/frontend/index.jsx file, create a component that constructs the configuration of the UI Kit components you're using:
1
2
import React from 'react';
import { Label, Textfield } from '@forge/react';

const Config = () => {
  return (
    <> 
      <Label>First Name</Label>
      <Textfield name="firstName"/>
    </>
  );
};
  1. At the bottom of the src/frontend/index.jsx file, call the addConfig method on ForgeReconciler with your config element. Ensure you have ForgeReconciler imported at the top.
1
2
import 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.

Use the configuration

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
2
import 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 />);

Configuration for a custom UI macro app

Create the configuration for a custom UI app

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.

  1. In a static/hello-world/src/Config.js file, create a function component that constructs the configuration of the UI Kit components you're using:
1
2
import React from 'react';
import { Label, Textfield } from '@forge/react';

const Config = () => {
  return (
    <> 
      <Label>First Name</Label>
      <Textfield name="firstName"/>
    </>
  );
};

export default Config;
  1. In the 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
2
import 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 />);

Use the configuration for a custom UI app

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
2
import 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;

Supported components with limited properties

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:

Label

To label the fields in the configuration panel, use the Label component:

NameTypeRequiredDescription
childrenstringNoContent of the label.

Checkbox group

The following subset of UI Kit Checkbox group props can be used in the configuration:

NameTypeRequiredDescription
optionsArray<{ label: string; value: string; isDisabled?: boolean; }>YesAn array of objects, each object is mapped onto a Checkbox element within the group.
defaultValueArray<string>NoSets the initial selected value on the CheckboxGroup.
isRequiredbooleanNoSets the required state of all Radio elements in the group. Should only be set when using within a Form component.
namestringYesSets the name prop on each of the Checkbox elements in the group.

Date picker

The following subset of UI Kit Date picker props can be used in the configuration:

NameTypeRequiredDescription
defaultValuestringNoThe initial date value to display. It should be formatted as 'YYYY-MM-DD'.
isRequiredbooleanNoIndicates 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.
namestringYesThe key to which the input value is assigned in the returned form object.
placeholderstringNoThe placeholder helper text.

Radio group

The following subset of UI Kit Radio group props can be used in the configuration:

NameTypeRequiredDescription
optionsArray<Option> | Array<{ isDisabled: boolean; label: string; name: string; value: string; }>YesAn array of objects, each object is mapped onto a Radio element within the group. Name must be unique to the group.
defaultValuestring | nullNoSets the initial selected value on the RadioGroup.
isRequiredbooleanNoSets the required state of all Radio elements in the group. Should only be set when using within a Form component.
namestringYesSets the name prop on each of the Radio elements in the group.

Select

The following subset of UI Kit Select props can be used in the configuration:

NameTypeRequiredDescription
defaultValueOption | Option[] | nullNoThe default value of the select.
options(Option | Group) []NoArray of options that populate the select menu.
placeholderstringNoPlaceholder for the select value.
isRequiredbooleanNoIndicates that the field is a required field.
namestringYesName of the input (optional: without this, no input will be rendered).

Textfield

The following subset of UI Kit Textfield props can be used in the configuration:

NameTypeRequiredDescription
defaultValuestring | numberNoThe default value of the text field.
isRequiredbooleanNoSet required for form that the field is part of.
namestringYesName of the input element.
placeholderstringNoPlaceholder text to display in the text field whenever it is empty.

Text area

The following subset of UI Kit Text area props can be used in the configuration:

NameTypeRequiredDescription
defaultValuestringNoThe default value of the text area.
isRequiredbooleanNoSets whether the field is required for form that the field is part of.
namestringYesName of the input form control.
placeholderstringNoThe placeholder within the text area.

User picker

The following subset of UI Kit User picker props can be used in the configuration:

NameTypeRequiredDescription
isMultibooleanNoWhether the user can select multiple users from the list. Defaults to false.
isRequiredbooleanNoIndicates 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.
namestringYesThe 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.
defaultValuestringNoThe initial user to display. The value should be an Atlassian account ID.
descriptionstringNoThe text description of the user picker field.
placeholderstringNoThe placeholder helper text.

Example

A macro with configuration could look like this:

1
2
import 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 />);

Tutorial

Rate this page: