NOTE
Reference of additions from widget intro note, summary of private feature integration doc
Creating a New Widget
Base template: quartz/widgets/base/widget-base.scss
- Create directory:
{dir}/widgets/{widget-name}/ - Create
component.tsx- exports a Preact component that renders static HTML with data attributes - Create
script.inline.ts- client-side script that hydrates the widget usingcreateWidgetScripthelper - Create
style.inline.scss- styles for the widget- Scope widget styles under
.widget-{name}to avoid unintentional leaks into other portions of the page - Use
contain: layout style;to the root class to prevent style leaks - Variables can be imported from higher-level SCSS to theme widgets alongside the site
- Scope widget styles under
- Create
index.ts- exportsWidgetDefinitionwith Component, script, css, selector, and scriptName - Register in
{dir}/widgets/registry.ts- add import and entry toquartzWidgetsobject
Usage in MDX
import { WidgetName } from '@widgets/{widget-name}'
import { ContentWidget } from '@content/widgets/{widget-name}'
<WidgetName prop1="value" prop2={123} />
<ContentWidget config={[1, 2, 3]} />PDF Viewer Example
import { PDFViewer } from '@widgets/pdf-viewer'
<PDFViewer
src="/assets/document.pdf"
title="My Document"
height="800px"
/>Widget Styling Guidelines
When creating or modifying widget styles, follow these conventions to ensure consistency and proper theming:
CSS Structure
Required CSS Properties
.widget-{name} {
// Isolation - REQUIRED to prevent widget styles from affecting page layout
contain: layout style;
// Positioning
position: relative;
// Spacing - use these standard values
margin: 1rem 0;
padding: 1rem;
// Theme-aware colors - use var() references
background-color: var(--light);
color: var(--darkgray);
border: 1px solid var(--lightgray);
border-radius: 8px;
}