Synergy is a front-end framework for creating modular, configurable and scalable UI components
CSS JavaScript
Clone or download

README.md

GitHub license GitHub license npm version npm version

A front-end framework for creating modular, configurable and scalable UI components

Useful Wiki Pages

View SassDoc Documentation | View JSDoc Documentation

Overview

Synergy provides powerful APIs to help you create configurable modules in Sass, JavaScript and/or React:

Synergy is ideal for creating your presentational React components when using the Container Component Pattern (learn more)

Synergy also povides tools allowing you to combine the above aspects together to create a Synergy Module. Each aspect can work independently and exists as a separate file with a specific role:

These are the core concepts of a UI module.

|-- modules
|   |-- accordion
|   |   |-- accordion.js
|   |   |-- accordion.json
|   |   |-- accordion.jsx
|   |   |-- accordion.scss

Synergy modules can be configured and scaled without having to touch the module's source code

A Synergy module is composed of Components. Both Modules and Components can have Modifiers.

Using Synergy, you can create themes and control your entire project's UI from a single JSON file by passing custom options and parameters to your modules.

Learn more about creating themes

Example

Using Synergy to create a basic accordion module which will be configured by accordion.json - Learn more about this example

Structure

|-- UI
|   |-- modules
|   |   |-- accordion
|   |   |   |-- accordion.js
|   |   |   |-- accordion.json
|   |   |   |-- accordion.jsx
|   |   |   |-- accordion.scss
|   |-- app.scss
|   |-- app.{js|jsx}

Fundamental Styles (accordion.scss)

Learn more about module styles

@import '../../node_modules/Synergy/dist/synergy';

@import 'accordion.json';

@mixin accordion($custom: ()) {

    $config: config($accordion, $custom);

    @include module {
        @include component('panel') {
            &:not(:last-child) {
                margin-bottom: this('panel', 'vertical-rhythm');
            }

            @include modifier('active') {
                @include component('toggle') {
                    transform: rotate(90deg);
                }

                @include component('content') {
                    display: block;
                }
            }
        }

        @include component('title', (
            'display': block,
            'cursor': pointer
        ));

        @include component('toggle', (
            'float': right
        ));

        @include component('content', (
            'display': none
        ));
    }
}

Accordion Interface - JSX (accordion.jsx)

Learn more about module interfaces

import React from 'react';
import { Module, Component } from 'Synergy';

import config from './accordion.json';

const Accordion = ({ panels, ...props }) => (
    <Module name={config.name} {...props}>
        {panels.map(({title, content}, index) => (
            <Component name="panel" key={index}>
                <Component name="title" onClick={toggle}>
                    <Component name='toggle' /> {title}
                </Component>
                <Component name="content">{content}</Component>
            </Component>
        ))}
    </Module>
);

export default Accordion;

function toggle(event) {
    const panel = event.target.closest('[data-component="panel"]');

    panel.modifier('active', 'toggle');
}

You could move the toggle interaction (and any other module interactions) into a separate accordion.js file

Accordion Interface - Plain JavaScript (accordion.js)

import { Synergy } from 'Synergy';

import config from './accordion.json';

export default function accordion() {
    Synergy(config.name, accordion => {
        accordion.component('panel', panel => {
            panel.component('title', title => {
                title.addEventListener('click', toggle.bind(panel), false);
            });
        });
    });
}

function toggle() {
    this.modifier('active', 'toggle');
}

Accordion Configuration (accordion.json)

Learn more about module configuration

This is where cosmetic (and hence configurable) styles are applied to the module and its components

{
    "accordion": {
        "name": "accordion",
        "panel": {
            "vertical-rhythm": 0
        },
        "title": {
            "background": "transparent",
            "color": "#444444",
            "border": "1px solid rgba(black, 0.15)",
            "border-radius": 0,
            "padding": "1em",
            "transition": "0.4s",
            "hover": {
                "background": "#2E3882",
                "color": "white",
                "component(toggle)": {
                    "color": "white"
                }
            },
            "active": {
                "background": "#2E3882",
                "color": "white",
                "border-color": "transparent",
                "border-radius": 0,
                "component(toggle)": {
                    "color": "white"
                }
            }
        },
        "content": {
            "background": "white",
            "color": "#444444",
            "border": "1px solid rgba(black, 0.15)",
            "border-radius": 0,
            "padding": "1.5em"
        },
        "toggle": {
            "color": "rgba(black, 0.4)",
            "transition": "0.4s"
        }
    }
}

Loading Styles (app.scss)

@import '/modules/accordion/accordion';

@include accordion();
With Custom Options
@import '/modules/accordion/accordion';

@include accordion((
    'panel': (
        'vertical-rhythm': 2em
    ),
    'title': (
        'background': #06d2ff,
        'color': white
    )
));

Render Using React (app.jsx)

<div id="demo"></div>
import React from 'react';
import ReactDOM from 'react-dom';

import Accordion from './modules/accordion/accordion.jsx';

ReactDOM.render(
    <Accordion panels={[
        {title: 'foo', content: 'bar'},
        {title: 'fizz', content: 'buzz'},
    ]} />, 

    document.getElementById('demo')
);

Or Initialise Using Plain HTML/JavaScript (app.js)

<div class="accordion">
    <div class="accordion_panel">
        <div class="accordion_title">
            <div class="accordion_toggle"></div> foo
        </div>
        <div class="accordion_content">bar</div>
    </div>
    <div class="accordion_panel">
        <div class="accordion_title">
            <div class="accordion_toggle"></div> fizz
        </div>
        <div class="accordion_content">buzz</div>
    </div>
</div>
import accordion from './modules/accordion/accordion.js';

accordion();

Creating a Theme

Using Synergy, you can create themes and control your entire project's UI from a single JSON file by passing custom options and parameters to your modules.

Learn more about creating themes

Changelog

Version 3.10.3

Released: 1st July 2018

Release Notes
  • Updating to node-sass 4.9.0
  • Fixing regression bugs as a result of node-sass update

Version 3.10.2

Released: 25th June 2018

Release Notes
  • Bug fixes

Version 3.10.1

Released: 25th June 2018

Release Notes
  • Bug fixes

Version 3.10.0

Released: 20th June 2018

Release Notes
  • Added callback functions to component and modifier DOM methods
  • Allowing <Component>'s to accept event handlers as props
  • Allow passing of custom HTML tag to <Module>
  • Set module modifiers by passing as empty prop
  • Adding <Wrapper> and <Group> components
  • Specify list of CSS classes to add via empty prop
  • Allow passing of CSS through Sass map istead of through @content
  • Adding sub-component Sass mixin
  • Adding pseudo-state Sass mixin
  • Adding Synergize class (extends React.Component)
  • Dynamically fetch <Component> onClick event from window.Synergy object
  • Option to render content by passing as content prop
  • Set <Module> as another module by passing module name as prop
  • Dynamically set tag prop on module if name prop is valid HTML tag
  • Get HTML attributes from props
  • Components now render with a data-component attribute
  • Allow passing of data-attributes to module
  • Append content before/after module through before and after props
  • Removing Bower
  • General refactoring, syntax improvements and bug fixes