@writechoice/components
v0.5.0
Published
Portable WriteChoice MDX components (framework-agnostic React + a single stylesheet).
Keywords
Readme
@writechoice/components
Portable, framework-agnostic React components extracted from the WriteChoice
Docusaurus template. They work in any project that renders React inside
.md/.mdx (Docusaurus, Next.js, Vite, Astro, etc.) — no Docusaurus runtime
required.
Install
npm install @writechoice/componentsPeer dependencies: react and react-dom (>=18).
Usage
Import the single stylesheet once (e.g. in your app root / MDX provider):
import "@writechoice/components/styles.css";Then use the components:
import { Callout, Steps, CardList, Accordion } from "@writechoice/components";Docusaurus (one-line setup)
In Docusaurus you can skip the manual CSS import and MDX registration. Just add
the bundled plugin to docusaurus.config.js:
plugins: ['@writechoice/components/docusaurus'],It auto-loads the stylesheet and registers every component globally, so you can
use <Callout>, <Steps>, <Card>, etc. in any .mdx with no imports. The
plugin is optional and Docusaurus-only — it adds no dependency and other
bundlers (Vite, Next, …) never load it.
It also applies default table styles (full-width, horizontal scroll). To turn them off, pass an option:
plugins: [
['@writechoice/components/docusaurus', { tableStyles: false }],
],Outside Docusaurus, the table styles are opt-in:
import "@writechoice/components/tables.css";Theming
The stylesheet already ships sensible default design tokens (theme.css), so
components render correctly with no extra setup. To re-theme, override any token
in your own :root (loaded after the package styles):
:root {
--primary-color: #6b5bff;
}Dark mode
Dark variants are defined under [data-theme="dark"] (same convention as
Docusaurus). Toggle dark mode by setting that attribute on <html>:
document.documentElement.setAttribute("data-theme", "dark");Components included (portable set)
| Component | Notes |
|-----------|-------|
| Accordion / AccordionGroup | Collapsible content (<details> based). |
| Callout | type: info, tip/success, warning, danger, note, transpara, support, training. |
| Card | Card with an icon or image (title, description, icon, image/imageDark, link, compact). Swaps imageDark in dark mode. |
| CardList | Grid container (cols prop). Render Card/BadgeCard/APICard children inside. |
| BadgeCard | Card with a badge/tag in the header (title, tag, description, link). |
| APICard | Card with a colored HTTP method tag (title, method/type, description, link). |
| Image | Responsive image (src, srcDark, width/size, border, noShadow). Swaps srcDark in dark mode. |
| Video | Video player — direct MP4 or YouTube embed (src, width, autoPlay, alt). |
| Request / Response | Titled, syntax-highlighted code example (title; code as child). |
| CodeBlock | Standalone code block with highlighting + copy button (language, title). |
| Steps | Numbered steps from heading children (titleSize, hideNumbers). |
| DownloadButton | File download button (title, url, icon). |
| Parameter | API parameter doc (name, type, required, default). |
| Checklist | Interactive checklist, persisted to localStorage. |
| Hint | Hover tooltip (hint, placement). |
| Searchbar | Client-side filter/highlight wrapper for tables/cards/accordions. |
| Feedback | Floating feedback form (uses EmailJS — keys are hardcoded; edit Feedback.jsx to use your own). |
Notes / differences from the Docusaurus version
- All
@docusaurus/*,@site/*and@theme/*couplings were removed. DownloadButton/icons:useBaseUrlwas dropped — image icon paths are used as-is, so pass absolute or already-resolved paths.Feedbackwas converted from a CSS Module to plain (namespaced) classes so it fits the single-stylesheet model.- Per-component
import "./x.css"were removed in favor of the singlestyles.cssentry. - Base design tokens that used to come from the Docusaurus theme (Infima +
custom.css) are now shipped as defaults intheme.css. Calloutbackgrounds/borders were painted by Infima's.alertclass in Docusaurus; those rules are now self-contained incallouts.css.- Cosmetic only: heading/parameter
hash-linkanchor icons (the link-on-hover glyph) came from the Docusaurus theme and are not included — the anchors still work, they're just not shown as an icon. Card/Imagedark-mode image swapping useduseColorMode; it now uses a small portable hook that readsdata-themeon<html>(no provider needed).BadgeCard/APICard/Card@docusaurus/Linkbecame a plain<a href>, anduseBaseUrlwas dropped (asset paths are used as-is).Request/Response: in Docusaurus these rendered into a side panel synced to the page scroll (via a TOC override + site context). That panel doesn't exist outside the site, so they now render inline as titled, highlighted code blocks (powered byprism-react-renderer).
All components from the template are now ported — nothing is left behind.
