The Hello World template is a minimal example app that demonstrates components and design tokens from the Canva App UI Kit, as well as an Apps SDK API method. You can use it as a base to build your own Canva app.
This article shows you how to install the Hello World template, run it locally, and start building your own app.
Step 1: Create a new app using the Hello World template
-
Install the Canva CLI(opens in a new tab or window) globally:
npm install -g @canva/cli@latestSHELL -
Log in to the Canva CLI. This command opens an access request page in your browser:
canva loginSHELL -
Click Allow to grant the Canva CLI permission to manage your Canva apps.
-
Copy the confirmation code from your browser and paste it into the Canva CLI input.
-
Use the following command to create a new app using the Hello World template:
canva apps create --template "hello_world"SHELL -
The setup process guides you through the remaining settings:
- Choose the audience for your app.
- Enter a name for your app.
- Choose whether to initialize a git repository for your project.
- Choose whether your project should use npm to install its dependencies.
After the setup process has completed, the output lists the steps for running the new app. For example:
cd example-hello-world-appnpm start
- Replace
example-hello-world-app
with your app's name.
Step 2: Preview your app
Run the app locally to see a preview.
-
In your app's root directory, start the app. The
example-hello-world-app
directory name will vary based on your app's name.cd example-hello-world-appnpm startSHELLAfter the app starts, the
Development URL (Frontend)
andBase URL (Backend)
local addresses are shown in the output. -
In Your apps(opens in a new tab or window), select your app, then Configure your app > App source > Development URL.
-
Under Configure your app > App source > Development URL confirm that the
Development URL (Frontend)
address matches the address shown in the Development URL field. -
Locate the Preview button at the top right of the page, and click it to open a new tab that loads the Canva editor. A preview of your app loads in the sidebar.
-
Click Open if prompted. This message only appears when using an app for the first time.
You can now try adding more components, tokens, and methods in the following step, or go to Step 4 to set up your app back end.
Step 3. Customize your app
The app should now be running locally. In the preview, you can see the minimal Canva app. Clicking the Do something cool button creates a new text element in the design.
You can customize the app using more UI Kit components, design tokens, and API methods.
The Hello World template imports the useAddElement
method from the utils
directory. This is a utility from the Apps SDK starter kit(opens in a new tab or window). Utilities combine several Apps SDK API methods together into one practical method.
The following example customizes the Hello World template by adding the ability to change text color and size in the design. It uses the following:
- A
PaintRollerIcon
from the App UI Kit icon set. - The
secondary
color design token. - The
editContent
API method.
-
In your IDE, open the
src/app.tsx
file. -
Add
PaintRollerIcon
to the@canva/app-ui-kit
import.import { Button, Rows, Text, PaintRollerIcon } from "@canva/app-ui-kit";TSX -
Import the
editContent
method:import { editContent } from "@canva/design";TSX -
Add the
editContent
method, and create the following:- A callback with the required
contentType
andtarget
properties. - The
session
object, and async
method for managing content change. - A loop to search through the content items in the design using the
readPlaintext
andformatParagraph
methods:
export const App = () => {const addElement = useAddElement();const onClick = () => {addElement({type: "text",children: ["Hello world!"],});};async function editOnClick() {await editContent({contentType: "richtext",target: "current_page"},async (session) => {for (const content of session.contents) {const plaintext = content.readPlaintext();content.formatParagraph({ index: 0,length: plaintext.length},{ fontWeight: "bold",fontSize: 30,color: "#008008"});}await session.sync();});}TSX - A callback with the required
-
Create a new button component after the existing Do something cool button, using the
secondary
design variant and adding thePaintRollerIcon
:<Button variant="secondary" onClick={editOnClick} icon={(() => <PaintRollerIcon />)} stretch>{intl.formatMessage({defaultMessage: "Change the content",description: "Change the color and size of text content in the design when pressed.",})}</Button>TSX
When you click on the new button, the text content in the design changes color and size.
Step 4. Connect to a backend
To add more capabilities to your new app, connect the app to your backend. For more information, see Using a backend.
Step 5. Add user authentication
Update your app to add user authentication. You can use frictionless or OAuth authentication:
- Frictionless: To implement frictionless authentication, add App ID and JWT verification middleware to your app. This approach uses the
auth.getCanvaUserToken()
method to receive a JWT. For more information, see JSON Web Tokens. For an example, see the authentication example(opens in a new tab or window) in thecanva-apps-sdk-starter-kit
repository. - OAuth: Alternatively, you can configure your app to use OAuth authentication through a third-party service.
Localization
To localize this template for all supported locales:
- Ensure that the app has otherwise been localized in accordance with the recommended localization workflow.
- Use the latest version of the
@canva/app-components
package.
Literal strings added to a SearchableListView
component will be localized automatically as long as your app follows the localization workflow and uses the latest version of @canva/app-components
.
Next steps
Once your app is ready, submit it on the Developer Portal. For more information, see Submitting apps.