@aconex/styleguide v2.2.1
Aconex Styleguide
The styleguide is installed as an npm dependency of your UI library.
Starter template
Use the starter template to get an idea of the basic project setup for configuring and using the styleguide: https://github.com/Aconex/styleguide-starter.
Working with your UI library
Install
styleguideas a dependency in your project.npm install --save @aconex/styleguideConfigure the styleguide's options:
Configure the styleguide's page and navigation titles from your UI library's
package.json. For example:{ "name": "ui-library", "version": "1.0.0", "styleguide": { "title": "My styleguide" } }Then supply the path to your UI library and demo routing before starting the styleguide:
const styleguide = require( '@aconex/styleguide' ); styleguide .config( { uiLibrary: './path/to/ui-library', demos: function(expressApp, express) { // ... } } ) .start();
uiLibrary: path pointing to your UI library.demos: a function for configuration of custom routes for the styleguide. It will be called with the styleguide's express instance, andexpressitself.At a minimum, the
/demoroute should be configured. For an example configuration, see theindex.jsfromstyleguide-starter. In this example, a/staticroute is configured for serving static CSS and JS files and a/demoroute renders a handlebars template for a given demo file.Then browse to http://localhost:3080 in your browser to view the styleguide.
Create styleguide content.
The documentation for a component is written in a
guide.mdfile. There should be one guide file for each component.To generate the styleguide's navigation, it looks for a
navigation.guide.jsonfile. Take the following example of a folder and file structure.Folder structure
src | +-- components | | | +-- calendar | | |-- calendar.guide.md | | +-- calendar.demo.html | | | +-- datepicker | |-- datepicker.guide.md | +-- datepicker.demo.html | +-- navigation.guide.jsonnavigation.guide.json:
{ "sections": [ { "title": "Components", "items": [ { "title": "Calendar", "path": "components/calendar", keywords: "calendar date" }, { "title": "Datepicker", "path": "components/datepicker", keywords: "datepicker date" } ] } ] }In this example, the navigation menu will contain a Components section with 2 items in it: Calendar and Datepicker.
The
keywordsproperty is optional and used for the sidebar's search. If supplied, it should contain a space separated list of keywords relevant to that component.The contents of the
guide.mdfile will be rendered when navigating to a particular component. Inside theguide.md, you can embed the contents of ademo.html.For example, navigating to
components/calendarwill rendercalendar.guide.md. Incalendar.guide.mdyou can insert the calendar demo with--$ calendar.demo $--.
Publishing
The styleguide exposes an executable styleguide-publish to simplify publishing to RHCloud. The simplest way to use this is to add a script to your UI library's package.json.
This example will prepare files from the src folder of your UI library for publishing to an RHCloud app named sg3. The files will be output to a publish folder, ready for pushing to RHCloud.
"scripts": {
"publish": "styleguide-publish --app sg3 --ui-library ./src --output ./publish"
}Contributing
Please see CONTRIBUTING.md.