Documenting with Astro/MDX
This guide explains how to document design decisions and tokens in your documentation using the built-in Astro components provided by the @noodlestan/designer-shows package.
Example:
<ShowDecision d="Brand Color Set" layout="column" size="xs" value="oklch" /><ShowDecision d="Sizing Space Scale" layout="column" size="xs" />
Setup
Dependencies
The following packages are required:
- @noodlestan/designer-decisions
- @noodlestan/designer-functions
- @noodlestan/designer-integration-astro
- @noodlestan/designer-shows
npm install @noodlestan/designer-decisions @noodlestan/designer-functions \ @noodlestan/designer-integration-astro \ @noodlestan/designer-shows
Configuring Designer Decisions
Create a directory to store your decision data and add a Designer Decisions configuration file in the root of your project.
Directorydata/
- …
Directorysrc/
- …
- astro.config.mjs
- dd.config.mjs
- package.json
The minimum required configuration specifies one or more DecisionSource from which to load decision data (DecisionInput).
import { defineConfig } from '@noodlestan/designer-functions';
import { DEMO_DATA, SAMPLE_DATA } from '@noodlestan/designer-decisions';
export default defineConfig({ store: { decisions: [SAMPLE_DATA, DEMO_DATA, './data'], },});
In this example we configured the Designer Decisions Sample and Demo Data decision sources, as well as a local data/
directory for you to add more decisions.
In the API / Configuration section you can find all configuration options and helpers.
Add the Astro Integration
What our Astro integration does:
- Connects our
<Show*/>
components to the decision store; - Injecting Designer Decision styles into the page;
- Auto-refresh of the page when decision data changes;
- An entry point to configuring visualizations.
Add to your Astro config configuration, preferably after other integrations.
import { defineConfig } from 'astro/config';import starlight from '@astrojs/starlight';import designerDecisionsIntegration from '@noodlestan/designer-integration-astro';
export default defineConfig({ ... integrations: [ starlight({ title: ... ... }), designerDecisionsIntegration(), ],});
Decision data
Create some decision files in your local ./data
directory.
Directorydata/
Directorydecisions/
- color.json
- space.json
- …
- astro.config.mjs
- package.json
You can skip this step for now and use some of the decisions from the Sample and Demo Data sources.
Rendering decisions in MDX
Import the components you want to use and provide them with the decision name.
In this example we are using the <ShowDecision/> component to render both a ColorValueDecision and a ColorSetDecision, both from the DEMO_DATA
source.
import { ShowDecision } from '@noodlestan/designer-shows/astro';
<ShowDecision d="Action Color" size="m" /><ShowDecision d="Brand Color Set" layout="column" size="s" />
In the Astro integration docs you can find a comprehensive set of components for rendering decisions in different scenarios and layouts.
For instance, the <ShowDecisionCard/> component composes decision visualization, value, and details in a single layout.
import { ShowDecisionCard } from '@noodlestan/designer-shows/astro';
<ShowDecisionCard d="Action Color" />
Used for buttons, links and navigation
For:
- Link Foreground
- Action Background
- Action Foreground
- Action Border
- Navigation Item Background
Not For:
- Non-interactive elements
Customizing value and visualization
All decision components expose common props that provide a high degree of control over how the decisions are rendered:
value
- hide or format the decision valueviz
- hide or configure the visualizationoptions
- visualization options passed down to the viz components (🚧 link)
Formatting the decision value
With some decision types, you may want to display their value in specific formats. The value
prop is passed down to the specific decision component to control how the value is displayed.
For instance, the ShowColorValue components can display the color value in one or more color spaces.
<ShowDecision d="Action Color" value={['rgb', 'oklch']} size="m" />
Hiding the decision value
In this example we are hiding the decision value and rendering its visualization under a custom label.
<label>Brand Blue</label><ShowDecision d="Brand Blue" value={false} size="l" />
Choosing a different visualization
Some decision types can be rendered using different visualizations.
The viz
prop is passed down to value components to determine which visualization is used.
For instance, the ShowSpaceViz component can represent a space value with a few different shapes.
<ShowDecision d="Avatar Minimum Size" viz="circle" /><ShowDecision d="Card Thumb Minimum Size" viz="square" />
Configuring visualization options
(🚧 links)
Some visualization primitives expose also an options
prop.
In this example we are rendering the same color decision using two different modes: fg
and bg
.
In both cases we are providing a contrast
color. We also set the custom content
for the first one, and switch to text
mode on the second.
<ShowDecision ... viz="fg" options={{ contrast: '#000000', content: 'Hello' }} /><ShowDecision ... viz="bg" options={{ contrast: '#FFFFFF', mode: 'text' }} />
Hiding the visualization
In this example we are hiding the visualization and rendering its value next to a custom label.
RGB: <ShowDecision d="Brand Pink" viz={false} value="hsl" />
RGB