@aconex/styleguide
v2.2.1
Published
Aconex Core Styleguide
Downloads
19
Keywords
Readme
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
styleguide
as a dependency in your project.
npm install --save @aconex/styleguide
- Configure 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, andexpress
itself.
At a minimum, the /demo
route should be configured. For an example configuration, see the index.js
from styleguide-starter
. In this example, a /static
route is configured for serving static CSS and JS files and a /demo
route 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.md
file. There should be one guide file for each component.
To generate the styleguide's navigation, it looks for a navigation.guide.json
file. 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.json
navigation.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 keywords
property 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.md
file will be rendered when navigating to a particular component. Inside the guide.md
, you can embed the contents of a demo.html
.
For example, navigating to components/calendar
will render calendar.guide.md
. In calendar.guide.md
you 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
.