Skip to content

Commit 94891bc

Browse files
fix: add guide to embed Prisma Studio in Next.js (#7079)
* fix: add guide intro * feat: refine guide * enhance: add finishing touches to guide * Optimised images with calibre/image-actions * fix: add coderabbit nits * fix: add note for peer deps issue * fix: add a callout to the YT video * fix: update video link --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 6014b51 commit 94891bc

5 files changed

Lines changed: 535 additions & 3 deletions

File tree

content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ toc: true
1010

1111
Prisma Studio can be embedded in your own application via the [`@prisma/studio-core`](https://www.npmjs.com/package/@prisma/studio-core) package.
1212

13-
It gives you `Studio` a React component which renders Prisma Studio for your database. The `Studio` component accepts an _executor_ which accesses a `/studio` endpoint in your backend. The backend uses your API key to identify the correct Prisma Postgres instance and sends the SQL query to it.
13+
It provides `Studio`, a React component which renders Prisma Studio for your database. The `Studio` component accepts an executor that calls a `/studio` endpoint in your backend. The backend uses your `DATABASE_URL` (connection string) to connect to the correct Prisma Postgres instance and execute the SQL query.
1414

1515
:::tip
1616
If you want to see what embedded Studio looks like, **[check out the demo](https://github.com/prisma/studio-core-demo) on GitHub**!
@@ -57,6 +57,7 @@ Here's what a minimal implementation looks like:
5757
import { Studio } from "@prisma/studio-core/ui";
5858
import { createPostgresAdapter } from "@prisma/studio-core/data/postgres-core";
5959
import { createStudioBFFClient } from "@prisma/studio-core/data/bff";
60+
import "@prisma/studio-core/ui/index.css"
6061

6162
function App() {
6263
const adapter = useMemo(() => {
@@ -86,6 +87,7 @@ Here's what an implementation with custom headers/payload looks like:
8687
import { Studio } from "@prisma/studio-core/ui";
8788
import { createPostgresAdapter } from "@prisma/studio-core/data/postgres-core";
8889
import { createStudioBFFClient } from "@prisma/studio-core/data/bff";
90+
import "@prisma/studio-core/ui/index.css"
8991

9092
function App() {
9193
const adapter = useMemo(() => {
@@ -113,6 +115,61 @@ function App() {
113115
}
114116
```
115117

118+
### Custom styling
119+
120+
You can customize the look and feel of Prisma Studio so that it matches your application’s design. This is done by passing a custom theme to the `Studio` component. A theme is simply a set of CSS variables that define colors, spacing, and other style properties for both light and dark modes.
121+
122+
Here's an example of applying a custom theme:
123+
124+
```tsx
125+
import { Studio } from "@prisma/studio-core/ui";
126+
import { createPostgresAdapter } from "@prisma/studio-core/data/postgres-core";
127+
import { createStudioBFFClient } from "@prisma/studio-core/data/bff";
128+
import "@prisma/studio-core/ui/index.css";
129+
130+
const customTheme = `
131+
@layer base {
132+
:root {
133+
--background: 0 0% 100%;
134+
--foreground: 20 14.3% 4.1%;
135+
--primary: 47.9 95.8% 53.1%;
136+
--primary-foreground: 26 83.3% 14.1%;
137+
--border: 20 5.9% 90%;
138+
--input: 20 5.9% 90%;
139+
--ring: 20 14.3% 4.1%;
140+
--radius: 0rem;
141+
}
142+
143+
.dark {
144+
--background: 20 14.3% 4.1%;
145+
--foreground: 60 9.1% 97.8%;
146+
--primary: 47.9 95.8% 53.1%;
147+
--primary-foreground: 26 83.3% 14.1%;
148+
--border: 12 6.5% 15.1%;
149+
--input: 12 6.5% 15.1%;
150+
--ring: 35.5 91.7% 32.9%;
151+
}
152+
}
153+
`;
154+
155+
function App() {
156+
const adapter = useMemo(() => {
157+
const executor = createStudioBFFClient({
158+
url: "http://localhost:4242/studio",
159+
});
160+
return createPostgresAdapter({ executor });
161+
}, []);
162+
163+
return (
164+
<Layout>
165+
<Studio theme={customTheme} adapter={adapter} />
166+
</Layout>
167+
);
168+
}
169+
```
170+
171+
With this setup, Studio inherits your custom colors, borders, and typography rules, making it feel like a natural part of your app rather than a separate tool. You can define as many or as few variables as you need depending on the level of customization you want.
172+
116173
### Concepts
117174

118175
Here's an overview of the key concepts in your frontend:
@@ -123,7 +180,7 @@ Here's an overview of the key concepts in your frontend:
123180

124181
## Backend setup
125182

126-
Your backend needs to expose a `/studio` endpoint, that's where the frontend sends its requests. The implementation of this endpoint uses the `createAccelerateHttpClient` function that can be imported from the `@prisma/studio-core`.
183+
Your backend needs to expose a `/studio` endpoint where the frontend sends its requests. The implementation below uses `createPrismaPostgresHttpClient` from `@prisma/studio-core`.
127184

128185
The backend also needs to have access to the Prisma Postgres API key, we recommend setting it as an environment variable as a best practice.
129186

@@ -234,7 +291,7 @@ sequenceDiagram
234291
235292
When you want to authenticate the users of your app against Prisma Studio, you can do that by adding custom logic around your embedded Prisma Studio version.
236293
237-
On the frontend, you xan ensure yo pass the `Authorization` header and other data (e.g. a user ID) when creating the executor:
294+
On the frontend, you can ensure to pass the `Authorization` header and other data (e.g. a user ID) when creating the executor:
238295
239296
```tsx
240297
const executor = createStudioBFFClient({

0 commit comments

Comments
 (0)