Last activity on 3 March 2021
  • 43
  • 17
  • 88951
composer require sitegeist/monocle

An living-styleguide for Neos that is based on the actual fusion-code


An living-styleguide for Neos that is based on the actual fusion-code

Release Date
17.03.2021 16:21:22
Requires (dev)
GPL-3.0-or-later d5196fbbc47563132baabde23ee0acd1ce57bc2e



A living styleguide for Neos

This package adds a styleguide module to Neos that renders the Fusion prototypes in isolation that are annotated with @styleguide.

Authors & Sponsors

The development and the public-releases of this package is generously sponsored by our employer

Living Styleguide

The Monocle-Module uses the real Fusion-code to render the annotated prototypes in isolation. That way the styleguide is always up to date and cannot diverge over time from the real codebase.

The Monocle was defined with Atomic-Design and pure Fusion without Fluid in mind but the implementation is Coding-Style and Template-Engine agnostic. You can use Monocle to render Fluid based Prototypes without any limitation.


Sitegeist.Monocle is available via packagist. "sitegeist/monocle" : "~4.0" to the require section of the composer.json or run composer require sitegeist/monocle.

We use semantic-versioning so every breaking change will increase the major-version number.


Create items for the styleguide

To render a prototype as a styleguide-item it simply has to be annotated:

prototype(Vendor.Package:Components.Headline) < prototype(Neos.Fusion:Component) {

    # styleguide annotation to define title, description and props for the styleguide
    @styleguide {
        title = 'My Custom Prototype'
        description = 'A Prototype ....'
        props {
            content = 'Hello World'
        propSets {
            headline-2 {
                tagName = 'h2'
                content = 'Alternate styleguide content for h2'

    # normal fusion props and renderer
    tagName = 'h1'
    content = ''

    renderer = afx`
        <Neos.Fusion:Tag tagName={props.tagName}>{props.content}</Neos:Fusion:Tag>

The styleguide will render the items without the usual context. The site, documenNode and node context variables are not present inside the styleguide rendering by intention.

That way it is ensured that your prototypes rely only on the fusion path for rendering and are not affected by editor data. This is important for reliable testing of components.

To map an actual content-node on a component-prototype use a separate fusion prototype.

prototype(Vendor.Package:Content.Headline) < prototype(Neos.Neos:ContentComponent){
    content = ${q(node).property('title')}

    renderer = Vendor.Package:Components.Headline {
        @apply.props = ${props}

That way the rendering prototype is completely separated from the mapping prototype and therefore highly reusable.

The distinction between rendering- and mapping-prototypes can be compared to presentational-components vs. container-components in the ReactJS world.

Preview Configuration

Some configuration is available to configure the preview.

        # The fusion path that renders the preview.
        # the available context is has the values
        #  - sitePackageKey
        #  - prototypeName
        #  - propSet
        #  - props
        fusionRootPath: '/<Sitegeist.Monocle:Preview.Page>'

        # The fusion prototype that is rendered initially
        # Optional: Will default to the first found prototype
        defaultPrototypeName: 'Vendor.Site:Prototype'

        # The query selector that is used to extract the component html
        # from the preview to the html-view.
        # Optional: Default is 'body'
        sourceQuerySelector: 'body'

To include your styles and scripts into the preview you can extend the Sitegeist.Monocle:Preview.Page prototype the same way you would customize Neos.Neos:Page.

// Add stylesheets to to the preview-prototype
prototype(Sitegeist.Monocle:Preview.Page) {
    head {
        stylesheets.main = Vendor.Site:Resources.Styles
        javascripts.main = Vendor.Site:Resources.Scripts

    bodyScripts = Vendor.Site:Resources.BodyScripts {
        @position = 'before closingBodyTag'


To configure the available viewport presets you can alter the following configuration.

          label: 'xtra small'
          width: 400
          height: 600
          label: 'medium'
          width: 600
          height: 400
          label: 'wide'
          width: 800
          height: 600


If you have translations in your component you can configure the available locales via settings

          label: 'English'
          fallback: ['en_UK', 'en']
           label: 'German'
           fallback: ['de', 'en']
          label: 'French'

Hotkeys (experimental)

Some elements of Monocle can be controlled via keyboard. All hotkeys in use can be configured via Settings. It seems though, this is not always working reliably - so please be aware, that you might experience strange side effects, when overriding the default hotkey configuration.

        openNavigation: 'ctrl+f'
        closeNavigation: 'esc'
        navigateUp: 'up's
        navigateDown: 'down'
        openPreviewInNewWindow: 'ctrl+space'


At the heart of Monocles navigation mechanism sits the prototype selector. In this component you'll find all components that are annotated with @styleguide, grouped by configurable criteria.

A possible configuration for such a group looks like this:

          position: 100
          match: Components?\.Base
          label: Base
          icon: icon-minus
          color: '#AAA'

Under the configuration path Sitegeist.Monocle.preview.structure, you can define an arbitrary number of component groups. Each group consists of:

  • A label, which will be displayed as such in the UI
  • An icon, that is attached to each component in the group
  • A color, that will be applied to the icon
  • A matcher - a regular expression that will be applied to the non-package part of the components prototype name and thus determines the affiliation of a component to the configured group.

Monocle ships with a default structure configuration that tries to represent an Atomic-Design-like structure. So, the configuration consists of defaults for atoms, molecules, organisms and templates.

Each component that doesn't match any of the configured groups will instead be put into the unknown group.

Hide components

If you do not want to display components, you can define hiddenPrototypeNamePatterns as follows:

      - 'Vendor.Site:*'
      - 'Another.Vendor.Site:Prototype'

Specific components can be "unhidden" even if they match one of the hiddenPrototypeNamePatterns patterns:

      - 'Vendor.Site:Some.Component.ThatShouldBeShown'
      - 'Another.Vendor.Site:Prototype.ThatShouldBeShown'

This allows for including prototypes of packages selectively.

Site-specific configuration

All configurations can be overwritten for each selected site package.

                label: 'extra wide'
                width: 1600
                height: 1000


Sitegeist.Monocle brings some fusion-prototypes that you can use or adjust to your needs.


The prototype Sitegeist.Monocle:Preview.Page renders the preview view for a prototype, to do so it uses Sitegeist.Monocle:Preview.Prototype below. You can extend this prototype to add your styles and scripts as you would with Neos.Neos:Page.

prototype(Sitegeist.Monocle:Preview.Page) {
    head {
        metaViewport = '<meta name="viewport" content="width=device-width">'

        stylesheets.main =  Neos.Fusion:Tag {
           tagName = 'link'
           attributes.rel = 'stylesheet'
           attributes.href = Neos.Fusion:ResourceUri {
               path = 'resource://Vendor.Site/Public/Styles/main.css'

        javascripts.main = Neos.Fusion:Tag {
           tagName = 'script'
           attributes.src = Neos.Fusion:ResourceUri {
               path = 'resource://Vendor.Site/Public/JavaScript/main.js'

You have to add the same header informations to Sitegeist.Monocle:Preview.Page AND to Neos.Neos:Page to make ensure the rendered result in the styleguide is identical to the frontend. To do it is recommended to centralize those in fusion-components.


The prototype Sitegeist.Monocle:Preview.Prototype is used to render a single prototype with applied styleguide props. This is useful if you want to provide the result as prop to the preview of another prototype.

The prototyoe allows to specify the following options:

  • prototypeName: string The name of the prototyoe
  • propSet: string the name of the propSet that is applied in addition to the default props
  • props: array key => value pairs that are applied in addition to the defaultProps and the propSet

The following example shows how the Sitegeist.Monocle:Preview.Prototype can be used to render a preview inside of a styleguide prop:

prototype(Vendor.Site:Container) {
        props.content = Sitegeist.Monocle:Preview.Prototype {
            prototypeName = 'Vendor.Site:Item'
            propSet = 'large'

Simulate API-Endpoints

Monocle has fusion-prototypes to simulate json api responses for components.


Generic data uri implementation that expects type and content as string

    endpointUrl = Sitegeist.Monocle:DataUri {
        content = '{"hello":"world"}'
        type = 'application/json'

The DataUri-Prototypes will encode the content as base64. Attention: Data Uris do not accept url-parameters. If you frontend code adds arguments to the mock you have to be aware of that.

For convenience special prototypes for json and text exist:

  • Sitegeist.Monocle:DataUri.Json: And endpoint-mock with media-type application/json that will pass content trough Json.stringify
  • Sitegeist.Monocle:DataUri.Text: And endpoint-mock with media-type text/plain


Create an uri to an monocle endpoint that returns the passed content with the given type

    endpointUrl = Sitegeist.Monocle:MirrorUri {
        content = '{"hello":"world"}'
        type = 'application/json'

Attention: Browsers will often crop the urls to a maximal length, be aware of that if you mock large json-structures.

For convenience special prototypes for json and text exist:

  • Sitegeist.Monocle:MirrorUri.Json: And endpoint-mock with media-type application/json that accepts RawArray data
  • Sitegeist.Monocle:MirrorUri.Text: And endpoint-mock with media-type text/plain


Create an URI that will return the content of the file and the contentType for the given key.

    endpointUrl = Sitegeist.Monocle:StaticUri {
        key = 'example'

The path and content type for each key are configured via Settings:

          path: 'resource://Vendor.Package/Private/Json/example.json'
          contentType: 'application/json'

Mocking Uris inside the styleguide

prototype(Vendor.Package:Component.SearchExample) < prototype(Neos.Fusion:Component) {
	@styleguide {
		props {
			endpointUrl = Sitegeist.Monocle:DataUri.Json {
				content = Neos.Fusion:RawArray {
					term = 'hamburch'
					suggestedTerm = 'hamburg'

	endpointUrl = null

	renderer = afx`
		<div data-endpoint-url={props.endpointUrl} />

Props & Prop Editors

While previewing Fusion prototypes the Monocle UI offers a mechanism to override certain properties of that prototype in an ad-hoc fashion. This allows you to quickly examine whether your prototype works in certain unforseen configurations (longer or shorter text for instance).

Monocle will try to reproduce the API of your prototype from multiple sources and will offer all props as editable that can be plausibly associated with a specific editor configuration. By default, Monocle will scan the @styleguide.props path in your fusion code for prop values. If your prototype happens to be a Neos.Fusion:Component (which in most cases it'll likely be), Monocle also scans all default values of your Component props.

Given a prop value, Monocle will check its type and provide a fitting editor configuration. Below is a table for all standard cases:

Value Type Editor
string (with less than 81 characters) TextField
string (with more than 80 characters) TextArea
int or float TextField
boolean CheckBox

Additionally, if you need more control over which editor is used you may include a custom configuration under the @styleguide.options.propEditors path in your fusion code:

prototype(Vendor.Package:MyAlertComponent) < prototype(Neos.Fusion:Component) {
	@styleguide {
        options {
            propEditors {
                severity {
                    editor = 'Sitegeist.Monocle/Props/Editors/SelectBox'
                    editorOptions {
                        options {
                            info {
                                label = 'Info'
                                value = 'info'
                            success {
                                label = 'Success'
                                value = 'success'
                            warning {
                                label = 'Warning'
                                value = 'warning'
                            error {
                                label = 'Error'
                                value = 'error'

An overview of available editors can be found under [PropEditors].

If you are using PackageFactory.AtomicFusion.PropTypes then check out Sitegeist.Monocle.PropTypes. This package automatically generates editor configurations that that fit your PropTypes.

Fusion Object Tree Caching

Monocle will cache the fusion code for every site package. To invalidate this cache the the Fusion directories of all packages are monitored and changes trigger the flushing of the fusion-cache.

The setting Sitegeist.Monocle.fusion.enableObjectTreeCache enables the caching in Monocle by default.


The monocle Routes are included automatically via Settings.


Monocle comes with four privilege targets to control access.

  • Sitegeist.Monocle:Backend.Styleguide : call the backend module that will open the styleguide
  • Sitegeist.Monocle:Styleguide.Api : request informations about prototypes etc. via api (used from the module)
  • Sitegeist.Monocle:Styleguide.Preview : show a preview for a prototype
  • Sitegeist.Monocle:Styleguide.Module : show the styleguide

Policies for different Contexts

  • In Production-context all monocle privileges are by default granted to the group Neos.Neos:AbstractEditor. That way only backend-uses can see the styleguide.
  • In Development-context the Sitegeist.Monocle:Styleguide privileges are granted to the group Neos.Flow:Everybody. That way the Styleguide can be accessed without any database via url .
  • For integration into ci-processes you grant access to the privileges Sitegeist.Monocle:Styleguide.Preview and Sitegeist.Monocle:Styleguide.Api to the ci-system.


We will gladly accept contributions. Please send us pull requests.

The content of the readme is provided by Github
The same vendor provides 26 package(s).