Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Languages

Pick the language the code is written in, so its tokens take the right colours.

One block per language
Plain text, shown as written.
  Indentation is kept.
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}
async function load(id) {
  const res = await fetch(`/api/invoices/${id}`);
  if (!res.ok) throw new Error("Not found");
  return res.json(); // 200
}
public sealed record Invoice(string Number, long AmountPaise)
{
    public bool IsLarge => AmountPaise > 1_000_000;
}
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest first
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'
POST /api/webhooks HTTP/1.1
Host: api.example.com
Content-Type: application/json

{ "url": "https://example.com/hook", "active": true }
<!-- A card -->
<div class="card" id="plan">
  <a href="/pricing" disabled>Pricing &amp; plans</a>
</div>
<app-button tone="primary">Save</app-button>
.card:hover {
  color: #0a7;
  margin: 0 12px;
  z-index: 200 !important;
}
Show code
<app-code-block code="@Model.Source" language="Text"></app-code-block>
<app-code-block code="@Model.Source" language="Json"></app-code-block>
<app-code-block code="@Model.Source" language="Js"></app-code-block>
<app-code-block code="@Model.Source" language="Cs"></app-code-block>
<app-code-block code="@Model.Source" language="Sql"></app-code-block>
<app-code-block code="@Model.Source" language="Bash"></app-code-block>
<app-code-block code="@Model.Source" language="Http"></app-code-block>
<app-code-block code="@Model.Source" language="Html"></app-code-block>
<app-code-block code="@Model.Source" language="Razor"></app-code-block>
<app-code-block code="@Model.Source" language="Css"></app-code-block>

Line numbers

Number the lines when a reader must point at one, such as a line of a query that failed.

Numbered paid invoices query
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest first
Show code
<app-code-block code="@Model.Source" language="Sql" line-numbers="true" label="Paid invoices"></app-code-block>

Wrapped lines

Wrap a long command or payload when scrolling sideways would hide the part a reader needs to copy.

A long shell command
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'
Show code
<app-code-block code="@Model.Source" language="Bash" wrap="true"></app-code-block>

Every option

Every value of every prop, one cell each.

code: any string

code="corepack pnpm add @webority/ui-react"
corepack pnpm add @webority/ui-react

language: text, json, js, cs, sql, bash, http, html, razor or css

language="text" (default)
Plain text, shown as written.
  Indentation is kept.
language="json"
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}
language="js"
async function load(id) {
  const res = await fetch(`/api/invoices/${id}`);
  if (!res.ok) throw new Error("Not found");
  return res.json(); // 200
}
language="cs"
public sealed record Invoice(string Number, long AmountPaise)
{
    public bool IsLarge => AmountPaise > 1_000_000;
}
language="sql"
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest first
language="bash"
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'
language="http"
POST /api/webhooks HTTP/1.1
Host: api.example.com
Content-Type: application/json

{ "url": "https://example.com/hook", "active": true }
language="html"
<!-- A card -->
<div class="card" id="plan">
  <a href="/pricing" disabled>Pricing &amp; plans</a>
</div>
language="razor"
<app-button tone="primary">Save</app-button>
language="css"
.card:hover {
  color: #0a7;
  margin: 0 12px;
  z-index: 200 !important;
}

lineNumbers: true or false

line-numbers="true"
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest first
line-numbers="false" (default)
SELECT TOP 10 Number, AmountPaise
FROM Invoices
WHERE Status = 'Paid' AND CreatedDateTimeUtc >= @since
ORDER BY AmountPaise DESC; -- biggest first

wrap: true or false

wrap="true"
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'
wrap="false" (default)
# Deploy the staging build
export ENV=staging
curl -X POST "$API/deploy/staging/build" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"env":"staging","notify":["ops@example.com"],"rollbackOnFailure":true}'

label: any string

label="webhook.json"
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}
label left out, the header names the language
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}

copyLabel: any string

copy-label="Copy" (default)
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}
copy-label="Copy query"
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}

copiedLabel: any string

copied-label="Copied" (default, shown after a copy)
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}
copied-label="Done" (shown after a copy)
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}

className: any string

class="extra-class": extra class on the root, no look of its own (React: className)
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}

Guidance

What to do, and what to avoid.

Use it when

  • A code sample, request, response or payload people read and copy.
  • An API key or command to paste.

Reach for something else when

  • A short value in a sentence. → the code element
  • Copying a single value with no code around it. → AppCopyButton
  • Editing code. → a code editor

Reference

Try every prop, read the full list, and check keyboard and screen reader behaviour.

text json js cs sql bash http html razor css
Sample for the language One line
{
  "event": "invoice.paid",
  "id": "evt_01HZX",
  "amountPaise": 1250000,
  "paid": true,
  "note": null
}
React, generated from the controls
<AppCodeBlock code={source} language="json" lineNumbers label="webhook.json" />
Razor, the same props
<app-code-block code="@Model.Source" language="Json" line-numbers="true" label="webhook.json"></app-code-block>

7 props. The 5 most used come first.

Used on most screens 5 props

PropTypeDefaultDescription
codedefault tag content string tag content The source text. A single trailing newline is dropped.
languagedefault text text | json | js | cs | sql | bash | http | html | razor | css text What to colour; text shows it as written.
line-numbersdefault false bool false Number the lines. The numbers are not copied or selected.
wrapdefault false bool false Wrap long lines instead of scrolling sideways.
labeldefault - string - The header title, such as webhook.json, and the code region's accessible name. Without it the header names the language.

Less common 2 props

PropTypeDefaultDescription
copy-labeldefault Copy string Copy The copy button's label. It reads Copy when left out.
copied-labeldefault Copied string Copied The copy button's label for two seconds after a copy. It reads Copied when left out.

Screen reader

3 notes
  • The label is the code region's accessible name; without it the header names the language.
  • The copy button reads copyLabel, and for two seconds after a copy it reads copiedLabel.
  • Line numbers are not copied or selected.