Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Support title prop in code block

Joshen Lim4a1943c3670e
diff --git a/apps/docs/components/CodeBlock/CodeBlock.tsx b/apps/docs/components/CodeBlock/CodeBlock.tsx
index 06f656e4c31..32450a02aec 100644
--- a/apps/docs/components/CodeBlock/CodeBlock.tsx
+++ b/apps/docs/components/CodeBlock/CodeBlock.tsx
@@ -1,7 +1,8 @@
+import { FC } from 'react'
+import CopyToClipboard from 'react-copy-to-clipboard'
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'
import monokaiCustomTheme from './CodeBlock.utils'
import { Button, IconCheck, IconCopy } from 'ui'
-import CopyToClipboard from 'react-copy-to-clipboard'
import js from 'react-syntax-highlighter/dist/cjs/languages/hljs/javascript'
import ts from 'react-syntax-highlighter/dist/cjs/languages/hljs/typescript'
@@ -14,16 +15,25 @@ import { useState } from 'react'
import { useTheme } from '../Providers'
interface Props {
- lang: 'js' | 'jsx' | 'sql' | 'py' | 'bash' | 'ts' | 'dart'
- startingLineNumber?: number
+ title?: string
+ language: 'js' | 'jsx' | 'sql' | 'py' | 'bash' | 'ts' | 'dart'
hideCopy?: boolean
+ hideLineNumbers?: boolean
className?: string
- children?: string
- size?: 'small' | 'medium' | 'large'
value?: string
+ children?: string
}
-function CodeBlock(props: Props) {
+const CodeBlock: FC<Props> = ({
+ title,
+ language,
+ className,
+ value,
+ children,
+ hideCopy = false,
+ hideLineNumbers = false,
+}) => {
+ console.log('CodeBlock', { title })
const { isDarkMode } = useTheme()
const monokaiTheme = monokaiCustomTheme(isDarkMode)
@@ -36,13 +46,9 @@ function CodeBlock(props: Props) {
}, 1000)
}
- let lang = props.lang
- ? props.lang
- : props.className
- ? props.className.replace('language-', '')
- : 'js'
+ let xxxlang = language ? language : className ? className.replace('language-', '') : 'js'
// force jsx to be js highlighted
- if (lang === 'jsx') lang = 'js'
+ if (xxxlang === 'jsx') xxxlang = 'js'
SyntaxHighlighter.registerLanguage('js', js)
SyntaxHighlighter.registerLanguage('ts', ts)
SyntaxHighlighter.registerLanguage('py', py)
@@ -54,18 +60,25 @@ function CodeBlock(props: Props) {
const large = false
// don't show line numbers if bash == lang
- const showLineNumbers = lang !== 'bash'
+ const showLineNumbers = hideLineNumbers || xxxlang !== 'bash'
return (
- <div className="relative">
- {props.className ? (
+ <div className="relative my-2">
+ {title && (
+ <div className="rounded-t-md bg-scale-300 py-2 px-4 border-b border-scale-500 text-blue-1100">
+ {title}
+ </div>
+ )}
+ {className ? (
<SyntaxHighlighter
- language={lang}
+ language={xxxlang}
wrapLines={true}
style={monokaiTheme}
- className={`code-block rounded-lg border p-4 !my-2 !bg-scale-300 w-full ${
- !showLineNumbers ? 'pl-6' : ''
- }`}
+ className={[
+ 'code-block border p-4 w-full !my-0 !bg-scale-300',
+ `${!title ? '!rounded-md' : '!rounded-t-none !rounded-b-md'}`,
+ `${!showLineNumbers ? 'pl-6' : ''}`,
+ ].join(' ')}
customStyle={{
fontSize: large ? 18 : 13,
lineHeight: large ? 1.5 : 1.4,
@@ -86,14 +99,20 @@ function CodeBlock(props: Props) {
paddingBottom: '4px',
}}
>
- {(props.value || props.children)?.trimEnd()}
+ {(value || children)?.trimEnd()}
</SyntaxHighlighter>
) : (
- <code>{props.value || props.children}</code>
+ <code>{value || children}</code>
)}
- {!props.hideCopy && (props.value || props.children) && props.className ? (
- <div className={`${isDarkMode ? 'dark' : ''} absolute right-2 top-2`}>
- <CopyToClipboard text={props.value || props.children}>
+ {!hideCopy && (value || children) && className ? (
+ <div
+ className={[
+ 'absolute right-2',
+ `${isDarkMode ? 'dark' : ''}`,
+ `${!title ? 'top-2' : 'top-[3.25rem]'}`,
+ ].join(' ')}
+ >
+ <CopyToClipboard text={value || children}>
<Button
type="default"
icon={copied ? <IconCheck /> : <IconCopy />}
diff --git a/apps/docs/docs/guides/with-angular.mdx b/apps/docs/docs/guides/with-angular.mdx
index 2db189b097a..5bb2b471908 100644
--- a/apps/docs/docs/guides/with-angular.mdx
+++ b/apps/docs/docs/guides/with-angular.mdx
@@ -44,7 +44,7 @@ And finally we want to save the environment variables in the `environment.ts` fi
All we need are the API URL and the `anon` key that you copied [earlier](#get-the-api-keys).
These variables will be exposed on the browser, and that's completely fine since we have [Row Level Security](/docs/guides/auth#row-level-security) enabled on our Database.
-```ts title="environment.ts"
+```ts title=environment.ts
export const environment = {
production: false,
supabaseUrl: 'YOUR_SUPABASE_URL',
@@ -54,7 +54,7 @@ export const environment = {
Now that we have the API credentials in place, let's create a **SupabaseService** with `ng g s supabase` to initialize the Supabase client and implement functions to communicate with the Supabase API.
-```ts title="src/app/supabase.service.ts"
+```ts title=src/app/supabase.service.ts
import { Injectable } from '@angular/core'
import {
AuthChangeEvent,
@@ -82,10 +82,7 @@ export class SupabaseService {
_session: AuthSession | null = null
constructor() {
- this.supabase = createClient(
- environment.supabaseUrl,
- environment.supabaseKey
- )
+ this.supabase = createClient(environment.supabaseUrl, environment.supabaseKey)
}
get session() {
@@ -103,9 +100,7 @@ export class SupabaseService {
.single()
}
- authChanges(
- callback: (event: AuthChangeEvent, session: Session | null) => void
- ) {
+ authChanges(callback: (event: AuthChangeEvent, session: Session | null) => void) {
return this.supabase.auth.onAuthStateChange(callback)
}
@@ -143,7 +138,7 @@ Optionally, update [src/styles.css](https://raw.githubusercontent.com/supabase/s
Let's set up an Angular component to manage logins and sign ups. We'll use Magic Links, so users can sign in with their email without using passwords.
Create an **AuthComponent** with `ng g c auth` Angular CLI command.
-```ts title="src/app/auth/auth.component.ts"
+```ts title=src/app/auth/auth.component.ts
import { Component, OnInit } from '@angular/core'
import { FormBuilder } from '@angular/forms'
import { SupabaseService } from '../supabase.service'
@@ -186,7 +181,7 @@ export class AuthComponent implements OnInit {
}
```
-```html title="src/app/auth/auth.component.html"
+```html title=src/app/auth/auth.component.html
<div class="row flex-center flex">
<div class="col-6 form-widget" aria-live="polite">
<h1 class="header">Supabase + Angular</h1>
@@ -221,7 +216,7 @@ export class AuthComponent implements OnInit {
Users also need a way to edit their profile details and manage their accounts after signing in.
Create an **AccountComponent** with the `ng g c account` Angular CLI command.
-```ts title="src/app/account/account.component.ts"
+```ts title=src/app/account/account.component.ts
import { Component, Input, OnInit } from '@angular/core'
import { FormBuilder } from '@angular/forms'
import { AuthSession } from '@supabase/supabase-js'
@@ -245,10 +240,7 @@ export class AccountComponent implements OnInit {
avatar_url: '',
})
- constructor(
- private readonly supabase: SupabaseService,
- private formBuilder: FormBuilder
- ) {}
+ constructor(private readonly supabase: SupabaseService, private formBuilder: FormBuilder) {}
async ngOnInit(): Promise<void> {
await this.getProfile()
@@ -314,12 +306,8 @@ export class AccountComponent implements OnInit {
}
```
-```html title="src/app/account/account.component.html"
-<form
- [formGroup]="updateProfileForm"
- (ngSubmit)="updateProfile()"
- class="form-widget"
->
+```html title=src/app/account/account.component.html
+<form [formGroup]="updateProfileForm" (ngSubmit)="updateProfile()" class="form-widget">
<div>
<label for="email">Email</label>
<input id="email" type="text" [value]="session.user.email" disabled />
@@ -349,7 +337,7 @@ export class AccountComponent implements OnInit {
Now that we have all the components in place, let's update **AppComponent**:
-```ts title="src/app/app.component.ts"
+```ts title=src/app/app.component.ts
import { Component, OnInit } from '@angular/core'
import { SupabaseService } from './supabase.service'
@@ -371,7 +359,7 @@ export class AppComponent implements OnInit {
}
```
-```html title="src/app/app.component.html"
+```html title=src/app/app.component.html
<div class="container" style="padding: 50px 0 100px 0">
<app-account *ngIf="session; else auth" [session]="session"></app-account>
<ng-template #auth>
@@ -382,7 +370,7 @@ export class AppComponent implements OnInit {
`app.module.ts` also needs to be modified to include the `ReactiveFormsModule` from the `@angular/forms` package.
-```ts title="src/app/app.module.ts"
+```ts title=src/app/app.module.ts
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
@@ -393,12 +381,7 @@ import { ReactiveFormsModule } from '@angular/forms'
import { AvatarComponent } from './avatar/avatar.component'
@NgModule({
- declarations: [
- AppComponent,
- AuthComponent,
- AccountComponent,
- AvatarComponent,
- ],
+ declarations: [AppComponent, AuthComponent, AccountComponent, AvatarComponent],
imports: [BrowserModule, ReactiveFormsModule],
providers: [],
bootstrap: [AppComponent],
@@ -425,7 +408,7 @@ Every Supabase project is configured with [Storage](/docs/guides/storage) for ma
Let's create an avatar for the user so that they can upload a profile photo.
Create an **AvatarComponent** with `ng g c avatar` Angular CLI command.
-```ts title="src/app/avatar/avatar.component.ts"
+```ts title=src/app/avatar/avatar.component.ts
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser'
import { SupabaseService } from '../supabase.service'
@@ -448,10 +431,7 @@ export class AvatarComponent implements OnInit {
@Output() upload = new EventEmitter<string>()
- constructor(
- private readonly supabase: SupabaseService,
- private readonly dom: DomSanitizer
- ) {}
+ constructor(private readonly supabase: SupabaseService, private readonly dom: DomSanitizer) {}
ngOnInit(): void {}
@@ -459,9 +439,7 @@ export class AvatarComponent implements OnInit {
try {
const { data } = await this.supabase.downLoadImage(path)
if (data instanceof Blob) {
- this._avatarUrl = this.dom.bypassSecurityTrustResourceUrl(
- URL.createObjectURL(data)
- )
+ this._avatarUrl = this.dom.bypassSecurityTrustResourceUrl(URL.createObjectURL(data))
}
} catch (error) {
if (error instanceof Error) {
@@ -494,7 +472,7 @@ export class AvatarComponent implements OnInit {
}
```
-```html title="src/app/avatar/avatar.component.html"
+```html title=src/app/avatar/avatar.component.html
<div>
<img
*ngIf="_avatarUrl"
@@ -504,11 +482,7 @@ export class AvatarComponent implements OnInit {
style="height: 150px; width: 150px"
/>
</div>
-<div
- *ngIf="!_avatarUrl"
- class="avatar no-image"
- style="height: 150px; width: 150px"
-></div>
+<div *ngIf="!_avatarUrl" class="avatar no-image" style="height: 150px; width: 150px"></div>
<div style="width: 150px">
<label class="button primary block" for="single">
{{ uploading ? 'Uploading ...' : 'Upload' }}
@@ -528,21 +502,16 @@ export class AvatarComponent implements OnInit {
And then we can add the widget on top of the **AccountComponent** html template:
-```html title="src/app/account.component.html"
-<form
- [formGroup]="updateProfileForm"
- (ngSubmit)="updateProfile()"
- class="form-widget"
->
- <app-avatar [avatarUrl]="this.avatarUrl" (upload)="updateAvatar($event)">
- </app-avatar>
+```html title=src/app/account.component.html
+<form [formGroup]="updateProfileForm" (ngSubmit)="updateProfile()" class="form-widget">
+ <app-avatar [avatarUrl]="this.avatarUrl" (upload)="updateAvatar($event)"> </app-avatar>
<!-- input fields -->
</form>
```
And add an `updateAvatar` function along with an `avatarUrl` getter to the **AccountComponent** typescript file:
-```ts title="src/app/account.component.ts"
+```ts title=src/app/account.component.ts
@Component({
selector: 'app-account',
templateUrl: './account.component.html',