Skip to main content
Version: Kiawah (2.7.0)

Legal Center Embed

Show your ToughClicks legal center inside your own site, under your own header and footer, instead of linking to the hosted legal center page. Available from version 2.7.0 of the JavaScript library.

You can either drop in the <toughclicks-legal-center> element, which renders the document list and each document for you, or read the content with the headless content API and build your own pages.

The embed is a separate entry of the library, so pages that only show clickwrap packets don't download it. No client token is needed: a legal center is public. Only published documents marked as visible in the legal center are shown, the same as on the hosted page.

Add the element​

With the CDN script:

<script src="https://cdn.toughclicks.com/lib/{version}/toughclicks-legal-center.umd.js"></script>

<toughclicks-legal-center slug="your-legal-center-slug"></toughclicks-legal-center>

With npm, importing the legal center entry registers the element:

import '@toughclicks/js-client-sdk/legal-center';

To find your slug, open your organization in the management portal and click View Legal Center:

  • Without a custom domain, it opens app.toughclicks.com/legal-center/{slug}. The slug is the last part of that address.
  • With a custom domain, it opens your domain, whose address doesn't contain the slug. Look it up at https://api.toughclicks.com/api/v1/legalCenter/domain?host={your legal center host} (the slug field of the answer), or ask ToughClicks support.

The legal-center subpath works with tools that read the package's exports (Node, current bundlers, TypeScript node16 or bundler) and with older ones (TypeScript node10, Jest before 28, webpack 4).

The element shows the published documents, grouped as in the management portal (collapsible groups stay collapsible). It opens each document with its version number, published date and a version selector. When documents have effective dates, it opens the version currently in effect and marks a version that takes effect later as "(upcoming)". You don't need toughclicks.css for it.

The element uses your legal center's brand color, chosen as on the hosted page in light mode: the advanced Primary Color if one is set, else the theme's brand color (organization › Legal Center › Theme). A center last saved before version 2.7.0 uses its Primary Color. The other Legal Center settings apply only to the hosted page: other colors, fonts, custom CSS, custom header and footer, navigation links, and the show/hide options. Style the element with the properties below instead.

Attributes​

AttributeDescription
slugRequired. Your legal center's slug.
documentShow only this document (its slug, e.g. privacy-policy). The document list is hidden; the version selector still works. Use it to put each document on its own page of your site.
environmentproduction (default) or staging, with the same rules as the environment argument of the constructor.
routingWhere the open document is kept: query (default), hash or none. See Navigation.
param-prefixPrefix of the address parameters, tc- by default. See Two elements on one page.
heading-levelLevel of the element's main heading, 1 to 6. Defaults to 2, so it sits under your page's own h1.

The element keeps the open document and version in the page's address. Readers can share and bookmark a document, and the browser's Back and Forward buttons work:

routingAddress of version 2 of the privacy policy
query (default)/legal?tc-document=privacy-policy&tc-version=2
hash/legal#tc-document=privacy-policy&tc-version=2
noneNot in the address. The browser's Back button leaves the page instead of returning to the list.

The rest of your address is kept, including other query parameters and your path. Links are real links, so Ctrl/Cmd-click opens a document in a new tab. With none the documents are buttons, because a link to a new tab would only open the list. Use hash if your server or router does not accept unknown query parameters on that page. Use none if your single-page app manages the address itself.

Links inside a document to its own sections (#section-3) scroll to that section and keep it in the address, so a link such as /legal?tc-document=terms#section-3 opens at that section.

After each navigation, keyboard focus moves to the new heading, so screen reader and keyboard users land on the document they opened. Changing the version keeps focus on the version selector, and the new version is announced.

Two elements on one page​

Two elements with the same routing would share the same address parameters. For example, a full legal center plus a footer element showing one document. Give one of them another prefix:

<toughclicks-legal-center slug="acme"></toughclicks-legal-center>
<!-- ...in the footer -->
<toughclicks-legal-center slug="acme" document="privacy-policy" param-prefix="footer-"></toughclicks-legal-center>

The element logs a console warning when two elements share their parameters.

Styling​

The element renders in a shadow root: your page's CSS cannot break it by accident, and its CSS does not touch your page. Text color, font family and font size are inherited from your page. Muted text and borders are derived from the text color, so they work on light and dark pages.

Links in documents and the breadcrumb use the text color and are underlined in your brand color. If the brand color has less than 3:1 contrast against your background, the underline uses the text color instead, so links stay recognizable. The document list's rows are not underlined: each shows a chevron, and on hover a background and a brand-colored bar. The change summary has a brand-colored bar.

The variable names are those of the hosted legal center's styling contract (version 1, see Legal Center Styling Contract), so one set of variables themes both. A few are used only by the embed; they are marked below.

CSS custom properties​

Set these on the element, or on any ancestor such as :root:

PropertyDefaultUsed for
--tc-color-brandYour legal center's Primary Color, else #2563EBLink underlines, accents. The underline needs at least 3:1 against your background
--tc-color-textInheritedText
--tc-color-linkThe text colorLink text. Pick a color with at least 4.5:1 contrast against your background. (On the hosted page the default is a contrast-safe shade of the brand color.)
--tc-color-link-hover--tc-color-linkLink text on hover
--tc-color-list-hover-bgThe text color at 6%Background of a hovered document in the list
--tc-color-backgroundTransparentElement background
--tc-color-surfaceTransparentDocument list, version selector
--tc-color-mutedThe text color at 72%Dates, descriptions, breadcrumb
--tc-color-borderThe text color at 18%Borders, table cells
--tc-font-bodyInheritedBody text
--tc-font-heading--tc-font-bodyHeadings
--tc-font-size-baseInheritedBase font size
--tc-line-height1.6Body line height
--tc-radius8pxCorners
--tc-content-widthNone (full width)Maximum width, centered
toughclicks-legal-center {
--tc-color-brand: #0f766e;
--tc-font-heading: "Source Serif 4", serif;
--tc-content-width: 760px;
}

On a dark background​

The defaults follow your page's text color. To match your dark theme exactly, set the muted, border and brand colors too. A brand color that works on white is often too dark on a dark page:

.dark toughclicks-legal-center {
--tc-color-brand: #5eead4;
--tc-color-muted: #cbd5e1;
--tc-color-border: #334155;
--tc-color-surface: #1e293b;
}

Colors set in the document editor (text and highlight colors) are kept. If your page is dark, check documents that use them: dark text or a light highlight can be hard to read there. Adjust those documents, or give the element a light --tc-color-background.

Parts​

Anything else can be styled with ::part():

/* Your page already has a title */
toughclicks-legal-center::part(hub-header) {
display: none;
}

toughclicks-legal-center::part(document-link):hover {
background: #f3f4f6;
}
PartElement
containerWrapper of everything
hub, hub-header (embed only), logo, title, descriptionThe document list view and its heading
nav, group, group-summary, group-header (also group-title), document-list, document-item, document-linkThe document list
empty"No documents available"
document, breadcrumbs, back-linkA document view and its way back to the list
document-header, document-title, document-meta, change-summaryThe document's heading, version and dates
version-label, version-selectThe version selector (shown when there is more than one version)
document-bodyThe document's text
loading"Loading…", shown on the first load and when a document takes a moment to open
error, status, status-title, status-text, status-link, retry-buttonEmpty, not found and error messages

Events​

The element fires these events. They bubble, so you can listen on document. With TypeScript, event.detail is typed.

EventdetailWhen
tc-legal-center-load{ center, document } (document is null on the list)A view finished rendering
tc-legal-center-navigate{ document, version }The reader opened another document or version
tc-legal-center-error{ code, message }A view could not be loaded

Visitors only see plain-language messages, such as "These documents can't be shown right now." The reason, for example a wrong slug or environment, is in the error event's message and in the browser console.

For example, to keep the page title in step:

document.addEventListener('tc-legal-center-load', (event) => {
const { center, document: doc } = event.detail;
document.title = doc ? `${doc.displayName} | ${center.name}` : `Legal | ${center.name}`;
});

Headless content API​

To build your own legal pages, read the same content from the legal center entry. With the CDN script it is window.ToughClicksLegalCenter.

import {
getCenter,
listDocuments,
getDocument,
listVersions,
TCLegalCenterErrorCode,
} from '@toughclicks/js-client-sdk/legal-center';

// { id, slug, name, description, logoUrl, brandColor }
const center = await getCenter('acme');

// Published documents: { groups, ungroupedDocuments, documents }
// Each document is { id, slug, displayName }; `documents` lists them all in display order.
const { groups, documents } = await listDocuments('acme');

// One document. The latest version unless you ask for one (by version number or id).
const doc = await getDocument('acme', 'privacy-policy', { version: '2' });
// doc.version = { id, versionNumber, publishedAt, contents, effectiveAt?, changeSummary? }
// doc.versions = every published version, newest first, without contents
// Without { version }: the current version (doc.currentVersionId). That is the API's own choice
// when it sends one; otherwise, once versions carry effectiveAt, the one with the latest effective
// time (effectiveAt, else publishedAt) not in the future, or, if every version takes effect later,
// the one that takes effect first. Dates are shown in UTC, like the hosted page.

// Just the versions
const versions = await listVersions('acme', 'privacy-policy');

Every call takes an optional last argument { environment, signal }. environment works like the element's attribute. signal is an AbortSignal: aborting it rejects the call with an AbortError, and cancels the request unless another call is waiting for the same response.

  • Browser only. The API runs in the browser. Called on a server (for example during server-side rendering), it rejects with UNSUPPORTED_ENVIRONMENT.
  • Dates are ISO 8601 strings.
  • effectiveAt and changeSummary are part of the types but not sent by the API yet; until they are, they are undefined. changeSummary is plain text, not HTML: insert it as text and keep its line breaks (for example with white-space: pre-line).
  • contents is HTML. ToughClicks sanitizes it when it is saved and again in the browser with an allowlist.
    • Kept: the document's structure and its text formatting: colors, fonts, alignment, indentation, line height, underline and strike-through, spacing (no negative values), list style, vertical alignment, the width and height of images and tables, and PNG, JPEG, GIF and WebP images embedded in the document.
    • Removed: scripts and event handlers, any formatting that positions or layers content, forms, SVG and MathML, popovers, autoplay, links other than https://, http://, mailto:, tel: and #section, and every class except tc- ones.
    • Ids and names get a user-content- prefix, and links to sections inside the document are rewritten to match.
    • If you insert it into your page yourself, run it through your own HTML sanitizer as well, or use the element, which does this for you.
  • Responses are reused for 60 seconds within a page, up to 50 of them. Call clearCache() to fetch them again.

Errors​

Failed calls reject with a TCLegalCenterError that has a code and the HTTP status (0 when the request got no answer):

codeMeaning
CENTER_NOT_FOUNDNo legal center has this slug
DOCUMENT_NOT_FOUNDNo published document has this slug in the legal center
VERSION_NOT_FOUNDThe document has no published version with this number or id
ORGANIZATION_INACTIVEThe organization is deactivated, so its legal center is not available
INVALID_ARGUMENTA slug or option is not valid; nothing was requested
REQUEST_FAILEDThe API could not be reached or answered with an error. Try again later
UNSUPPORTED_ENVIRONMENTCalled outside a browser
try {
const doc = await getDocument('acme', 'old-terms');
} catch (error) {
if (error.code === TCLegalCenterErrorCode.documentNotFound) {
showNotFoundPage();
} else {
throw error;
}
}

Limits​

  • Labels and messages, including the error messages visitors see, are in English. Dates are formatted for your page's language (<html lang>).
  • A document shows its 1000 newest published versions.