diff options
author | 2025-06-05 12:45:02 +0000 | |
---|---|---|
committer | 2025-06-05 12:45:02 +0000 | |
commit | ee1d83ccf2ede53cb7198d7694545704ba14d410 (patch) | |
tree | 0b93dc64c37a394baf2f50539afcef6471c0f566 | |
download | astro-examples/toolbar-app.tar.gz astro-examples/toolbar-app.tar.zst astro-examples/toolbar-app.zip |
Sync from 0947a69192ad6820970902c7c951fb0cf31fcf4bexamples/toolbar-app
-rw-r--r-- | .codesandbox/Dockerfile | 1 | ||||
-rw-r--r-- | .gitignore | 21 | ||||
-rw-r--r-- | README.md | 40 | ||||
-rw-r--r-- | package.json | 21 | ||||
-rw-r--r-- | src/app.ts | 16 | ||||
-rw-r--r-- | src/integration.ts | 17 | ||||
-rw-r--r-- | tsconfig.json | 7 |
7 files changed, 123 insertions, 0 deletions
diff --git a/.codesandbox/Dockerfile b/.codesandbox/Dockerfile new file mode 100644 index 000000000..c3b5c81a1 --- /dev/null +++ b/.codesandbox/Dockerfile @@ -0,0 +1 @@ +FROM node:18-bullseye diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..abe03335e --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# dependencies +node_modules/ + +# production build +dist + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/README.md b/README.md new file mode 100644 index 000000000..8b879a01e --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Astro Starter Kit: Toolbar App + +```sh +npm create astro@latest -- --template toolbar-app +``` + +[](https://stackblitz.com/github/withastro/astro/tree/latest/examples/toolbar-app) +[](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/toolbar-app) +[](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/toolbar-app/devcontainer.json) + +> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun! + +## 🚀 Project Structure + +Inside of your Astro project, you'll see the following folders and files: + +```text +/ +├── app.ts +├── integration.ts +└── package.json +``` + +The logic of your app is in the appropriately named `app.ts` file. This is where the vast majority of your toolbar app logic will live. + +The `integration.ts` file is a simple Astro integration file that will be used to add your app into the toolbar. + +## 🧞 Commands + +All commands are run from the root of the project, from a terminal: + +| Command | Action | +| :-------------- | :------------------------------------------------- | +| `npm install` | Installs dependencies | +| `npm run dev` | Watch for changes and build your app automatically | +| `npm run build` | Build your app to `./dist/` | + +## 👀 Want to learn more? + +Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). diff --git a/package.json b/package.json new file mode 100644 index 000000000..56c232081 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "@example/toolbar-app", + "type": "module", + "version": "0.0.1", + "peerDependencies": { + "astro": "^4.6.1" + }, + "scripts": { + "build": "tsc", + "dev": "tsc --watch", + "prepublish": "npm run build" + }, + "exports": { + ".": "./dist/integration.js", + "./app": "./dist/app.js" + }, + "devDependencies": { + "@types/node": "^18.17.8", + "astro": "^5.9.0" + } +} diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 000000000..72bd4772d --- /dev/null +++ b/src/app.ts @@ -0,0 +1,16 @@ +import { defineToolbarApp } from 'astro/toolbar'; + +// Guide: https://docs.astro.build/en/recipes/making-toolbar-apps/ +// API Reference: https://docs.astro.build/en/reference/dev-toolbar-app-reference/ +export default defineToolbarApp({ + init(canvas) { + const astroWindow = document.createElement('astro-dev-toolbar-window'); + + const text = document.createElement('p'); + text.textContent = 'Hello, Astro!'; + + astroWindow.append(text); + + canvas.append(astroWindow); + }, +}); diff --git a/src/integration.ts b/src/integration.ts new file mode 100644 index 000000000..81597cf6e --- /dev/null +++ b/src/integration.ts @@ -0,0 +1,17 @@ +import { fileURLToPath } from 'node:url'; +import type { AstroIntegration } from 'astro'; + +// API Reference: https://docs.astro.build/en/reference/integrations-reference/ +export default { + name: 'my-astro-integration', + hooks: { + 'astro:config:setup': ({ addDevToolbarApp }) => { + addDevToolbarApp({ + id: "my-toolbar-app", + name: "My Toolbar App", + icon: "🚀", + entrypoint: fileURLToPath(new URL('./app.js', import.meta.url)) + }); + }, + }, +} satisfies AstroIntegration; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..281fb7f92 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "astro/tsconfigs/strict", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} |