Rendering Decisions in Docs
Setup
🚧 This guide is for @noodlestan/designer-shows/astro
components and requires a working
Astro website. You can create a website similar
to this one using the Starlight theme in
a matter of minutes.
This guide presents a simple way to document design decisions and tokens in your documentation pages.
Example:
Dependencies
The following packages are required:
- @noodlestan/designer-decisions
- @noodlestan/designer-functions
- @noodlestan/designer-schemas
- @noodlestan/designer-shows
Decision data
Populate your design decisions data source. 🚧
As illustrated in the Capturing Design Decisions guide, you can simply create one or more JSON files anywhere in your project.
Directorydata/
Directorydecisions/
- color.json
- space.json
- …
Decision loader
Create a file to declare the loader.
We will use the all-in-one createDecisionLoader(), providing it with:
- The schemas for the built-in decision models https://github.com/noodlestan/designer/blob/main/packages/libs/designer-schemas/src/constants.ts
- A directory to load decision data from.
- A function to resolve the physical location of node modules containing the schemas.
API 🚧🚧 Banner: Help appreciated: how to provide a package resolution default?
The loader is an async function that returns a decision store. We will pass this store directly to our Astro components for them to retrieve decision data and resolve decision values.
Rendering decisions in MDX
Retrieve the decision store
and pass it to the components along with the decision name.
In this example we are using the <ShowDecision/> component to render both a ColorValueDecision and a ColorSetDecision. It selects the appropriate component according to the decision type and both visualizes and renders its value.
Using built-in components
In the Components reference you will find a comprehensive set of components for rendering decisions in different scenarios and layouts.
For instance, the <ShowDecisionCard/> can also render all, or some, of the decision details.
Used for buttons, links and navigation
Intended For:
- Link Foreground
- Action Background
- Action Foreground
- Action Border
- Navigation Item Background
Not For:
- Non-interactive elements
Creating custom components
In the Components reference you will also find a comprehensive set of primitives that render specific decision types and decision values, as well as a few helpful layouts and atoms.
You can reuse these built-in components to create your own, composing any layout of your choice, with total control over styling. You can also merge data from other sources, add custom logic, and format values as you wish.
In this example, we compose the <ShowColorValue/> and the <ShowDecisionUsage/> atom within the standard <DecisionCard/> layout.
Use the new component directly in your MDX files.
Resolve decision values
You can also resolve decision values by calling value()
on the decision object.
This code block demonstrates how you can use a decision value to build your own visualization.