Angle Docs

AngleBootstrap 4 Admin Template + React

Thank you for purchasing Angle - Bootstrap 4 Admin Template + React.
If you have any question about this product and beyond the scope of this help file, please feel free to write us using the support button.


Thanks so much!

Introduction

This document aims to explain the best way to work with the product and its components.

- All the best and enjoy coding.

Getting started tips

  • Do not start from scratch, use an existing asset and modify it to learn how it works.
  • Explore the sources for ideas and sample code.
  • Use Firebug or Chrome Developer Tools to find bugs on your website. Using one of those tools will help you to save time analyzing the site and finding elements structure, like classes, id or tags
    • Quick tip: open your site with Chrome, press F12 and go to console tab, reload your page and if something goes wrong you will see your page errors in red text.
  • In case of errors, someone might have seen it too, you can try a Google search for a quick fix.

Important Opening the index.html with a double click (i.e. using file:// protocol) will show you only a blank page because there’s no server that response to the requests made for each view in order to display the app interface.

Technologies used

This template is based on the following technologies. Follow the links for each one of them in order to get more information:

Structure

Before starting to customize the template, here is the project files organization structure:

+---build
+---node_modules
+---public
|   +---img
|   +---locales
|   +---themes
+---src
    +---components
    |   +---Blog
    |   +---Charts
    |   +---Common
    |   +---Dashboard
    |   +---Ecommerce
    |   +---Elements
    |   +---Extras
    |   +---Forms
    |   +---Forum
    |   +---Layout
    |   +---Maps
    |   +---Pages
    |   +---Tables
    |   +---Widgets
    +---styles
        +---app
        |   +---charts
        |   +---common
        |   +---documentation
        |   +---elements
        |   +---extras
        |   +---forms
        |   +---layout
        |   +---maps
        |   +---tables
        +---bootstrap
        +---themes

This structure is based on the provided by the create-react-app project. There are more files in the structure, we will list the main files in order to describe the application workflow based on the order they are imported.

The application is bootstrapped in file public/index.html, this file includes the main application files compiled.

The application main file is src/index.js and it imports the App module and the translation setup.

The file App.js is where the main App module is defined and is used as the root element that starts the application, here is also imported the rest of the modules like routes, styles and global vendor dependencies

Routes are defined in file Routex.js that imports all components that are related to views displayed from the sidebar links.

Vendor.js imports global dependencies like modernizr, styles, icon fonts, etc.

Main components folder
Component Description
Blog Components used for the Blog views
Charts Components used for the Chart views
Common Common components used by other components
Dashboard Components used for the Dashboard views
Ecommerce Components used for the Ecommerce views
Elements Components used for the Elements views
Extras Components used for the Extras views
Forms Components used for the Forms views
Forum Components used for the Forum views
Layout Components used as a base to build the app layout
Maps Components used for the Maps views
Pages Components used for the Pages views (login, register, etc)
Tables Components used for the Tables views
Widgets Components used for the Widgets views

Build

Installing tools

The following steps are intended to be an orientation guide, if you are not experienced with this you will need to learn a bit more about it from Google :)

Once you have all tools installed

  • Open a console/terminal and run npm install to install application dependencies

  • Finally run npm run start to start the application development server.

If everything goes fine, you should see the messages in the terminal telling you the application has been compiled and the server is running.

Open your browser and go to http://localhost:3000

Building for production

The following will compile the application for the production:

npm run build

This will generate the compiled files under the folder build

Check the User Guide online to know more about the create-react-app project.

If your application is not served from the root, before compilation, set the environment variable PUBLIC_URL and then run compilation.

Example:

If your app is served from http://example.com/some/path then use:

set PUBLIC_URL=/some/path
npm run build

Usage

Adding new components

You can add new components by adding a new folder in src/components

For example, src/components/MyComp

Then create there a new file named MyComp.js with the component code.

For example,

import React, { Component } from 'react';
import ContentWrapper from '../Layout/ContentWrapper';

class MyComp extends Component {
    render() {
        return (
            <ContentWrapper>
                {/* view content here */}
            </ContentWrapper>
        );
    }
}

export default MyComp;

You can make use of stateless component too, as seen in other examples in the project.

Adding new routes

You will need now to make the component accessible to the application by adding a route that loads the component. To do that open Routes.js and import the component and add a new route entry like this

// To use static load of routes
import MyComp from './components/MyComp/MyComp';
...
<Route path="/mycomp" component={MyComp}/>

// To use lazy load of routes
const MyComp = lazy(() => import('./components/MyComp/MyComp'));
...
<Route path="/mycomp" mycomp={waitFor(MyComp)}/>

Check other routes in the project to see where the add the Route tag correctly

Finally, you need to add an entry to the sidebar in order to provide a link for the new route created.

To do that, add in src/Menu.js a new menu entry with the information for your menu.

Example

const Menu = [
    /* heading elements */
    {
        // text to show
        heading: 'Heading Text',
        // translation key
        translate: 'sidebar.heading.KEY'
    },
    /* menu items elements */
    {
        // text to show
        name: 'Item Text',
        // class name to show icon
        icon: 'icon-class',
        // route path (not used on items with submenu)
        path: 'routepath',
        // translation key
        translate: 'sidebar.item.KEY',
        // shows a Badge right next to the text
        label: { value: 10, color: 'success' },
        // list of submenu items
        submenu: [{
                ... Same format as menu items
            }
    }
    ...

Vendor assets

Vendor assets can be installed using the Node Package Manager (npm). The following command shows how to install a package so it becomes part of the project

npm install package-name --save

If you don't add the --save flag, the package won't be saved as a dependecy in package.json and it will be only available in your local project.

Once the command ends, files will be available in the node_modules folder and ready to be imported into your application code.

If the package is used globally you can import files using the file Vendor.js

To use a package locally in your new component, you can import the files directly into the code in your component file.

Note about jQuery

If a component requires jQuery you must add the following:

import $ from 'jquery';

Layout classes

Layout can be changed via the following classed applied to the body tag:

Class name Description
.layout-fixed Makes navbars become fixed while the user can scroll only content
.layout-boxed Limits the width of the main wrapper element
.aside-collapsed Condenses the sidebar showing only icons
.aside-collapsed-text Condenses the sidebar showing icons and Text
.aside-toggle used internally for mobiles to hide the sidebar off screen
.offsidebar-open used internally to display the offsidebar component (formally the right sidebar)

Translation

The translation system uses the i18next module.

The file src/i18n.js contains the setup for the module and what it does is to load the translations files located under folder public/locales

This modules simplifies the translation system by loading translate references from a JSON file and replacing the content where the reference has been used.

Example

import { translate, Trans } from 'react-i18next';

<Trans i18nKey='dashboard.WELCOME'></Trans>

Where the i18key values corresponds to an entry in each json file according the current language selected.

Themes

All available theme source files (SCSS) can be found under folder src\styles\themes, which contains the following files according to each color combination

theme-a.scss
theme-b.scss
theme-c.scss
theme-d.scss
theme-e.scss
theme-f.scss
theme-g.scss
theme-h.scss

Those themes are managed by REDUX and a middleware (src/store/middlewares/themes.middleware.js) which loads the compiled version of each file (CSS) into the template.

Compiled version are placed in folder public/themes

Since it's not possible to load the content of a file in create-react-app, the use of themes has a different workflow to compile the files. When working with themes, use the following command:

npm run build-themes

This command will compile the files and will watch changes to recompile again.

Default Theme

To set a default theme open you need to set it in the initialState of themeReducer in file src/store\reducers/themes.reducers.js like this:

  const initialState = {
      path: 'themes/theme-e.css'
  }

Note that selected themes are automatically saved to localStorage, if you set one as default, but there's another already saved, the saved path will be used instead.

Horizontal Menu

You can enable the horizontal menu following the next instructions:

  • Open the file src/Routes.js and make sure to import the BaseHorizontal component at the top

    import BaseHorizontal from './components/Layout/BaseHorizontal';
  • Then, replace the Base component with the BaseHorizontal component in the render method of the Route componen

The menu of the horizontal header is declared in file components/Layout/HeaderHorizontal.js and is limited to a few entries for demo purposes only.

RTL

RTL is based on rtlcss plugin using a custom loader that allows to change the application styles into an RTL representation.

To enable RTL open the file webpack.config.extend.js and uncommment the following snippet which enabled the rtlcss loader to process styles:

const isDev = webpackConfig.mode === 'development'
const sassRegex = /\.(scss|sass)$/.toString();
webpackConfig.module.rules[2].oneOf.some((rule, idx) => {
    if (rule.test && rule.test.toString() === sassRegex) {
        webpackConfig.module.rules[2].oneOf[idx][isDev ? 'use' : 'loader'].splice(
            webpackConfig.module.rules[2].oneOf[idx][isDev ? 'use' : 'loader'].length - 1,
            0,
            rtlcssLoader)
        return true;
    }
});

Now you can run "npm run start" and the project should be served with their styles converted to RTL.

Heroku

It's necessary to make some changes to the project for this. First, create the following files used by Heroku to run a server and place this new files in the root folder of the project

Procfile

web: node server.js

server.js

var express = require('express');
var app = express();
var path = require('path');

app.use(express.static(path.resolve(__dirname, 'buid')));

app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'buid', 'index.html'));
});

app.listen(process.env.PORT || 9090);

package.json

This file already exist, so only edit and change the script : "postinstall-heroku" to "postinstall", like this:

  "scripts": {
    ...
    "postinstall": "npm run build"
  }

Finally, follow this steps to deploy this application to Heroku:

  1. Login into Heroku with your credentials

    heroku login

  2. Init a new GIT repo with command

    git init

  3. Create your application with

    heroku create app-name

  4. Add project files

    git add .

  5. Commit project files

    git commit -m "initial commit"

  6. Run

    heroku config:set NPM_CONFIG_PRODUCTION=false

  7. Push project to Heroku with command:

    git push heroku master

  8. If everything went fine, open the app with command

    heroku open

Seed Project

This project is an application skeleton. You can use it to quickly bootstrap your ReactJS webapp projects and dev environment for these projects. The seed app doesn't do much and has most of the feature removed so you can add them as per your needs just following the full-features version as example.

This project is provided in order to start with the template using a different approach. Usually, templates will come with all features working and you need to remove them one by one in the way you don't need them. With the seed project you can start adding custom features and others from the full project to make grow your app. Since the files and structure is the same for the full and seed versions, you can save time using comparison tools that allows to apply changes from full features project into the seed project.

jQuery and Wrapper script

Starting from version 4.1, this template doesn't need jQuery as a mandatory dependency for core files, this means it is only required when using jQuery based plugins for some features included.
Seed project versions no more include jQuery by default..

The wrapper.js (~ 7k minified) is a new script introduced to emulate some specific jQuery functions used in the template. This made possible to significantly cut the refactoring changes in the code, keeping it readable in a jQuery way and avoiding extra bytes, mainly when loops are repeatedly used to work with multiple elements.

Important The Wrapper script is NOT a replacement for jQuery. All methods were designed for an adequate and specific use and they don't do a deep validation on the arguments provided. It's suggested NOT to use this library extensively. Instead, use pure JS or you might even need jQuery.

Redux

Redux is used mainly to manage application settings to change the layout options and themes. It's organized by files per actions, reducers and middleware so you can easily remove them or add more according to your application needs.

Redux files are placed under src/store folder. In this folder you will find the following files:

+---store
    +---actions
    |   +---actions.js
    |   +---setting.actions.js
    |   +---theme.actions.js
    +---middlewares
    |   +---middlewares.js
    |   +---setting.middleware.js
    |   +---theme.middleware.js
    +---reducers
    |   +---reducers.js
    |   +---setting.reducer.js
    |   +---theme.reducer.js
    +---persisted.store.js
    +---store.js

The file store.js is imported into the index.js file which makes the store parts of the application by using the component from react-redux. Removing that will remove Redux from the project automatically.

Notice that for each folder, there's a main file (actions/actions.js, reducers/reducers.js and middlewares/middlewares.js) which are the ones who import and exports each scripts to the rest of the application.

// src/index.js
...
import { Provider } from 'react-redux';
...
import configureStore from './store/store';
const store = configureStore();

ReactDOM.render(
    <Provider store={store}>
        <App />
    </Provider>,
    document.getElementById('app')
);

We have created reducers for settings which contains state of the current layout options, like fixed, boxed, sidebar collapsed, and also the toggle for sidebar offcanvas on mobile and the sidebar user block. And for themes, which contains a single state with the current theme selected.

We have also used middlewares in order to hook into the redux state changes to modify the classes from dom elements (mainly body) and to change active the theme.

The main use of Redux is done in the Offsidebar component, which provides the demo for layout settings and themes, in file src/components/Layout/Offsidebar.js.

Container components where omitted from the store structure as they don't match exactly our requirements but you can add them easily and import into your custom components.

Persisted states

In order to save the settings selected and the active theme, we have included a custom script named persisted.store.js. This script automatically saves the entire application state to the browser storage, and restores it when the app loads.

In order to apply the states from the storage the first time the application loads, is necessary to talk to middlewares we are who modify classes in the body. To achieve this, the middleware exports a method that receives the state and acts accordingly. If you add states that don't perform changes in the Dom outside the app root element, you can omit this as it's not necessary.

Since not all state are suitable to be saved, we have used a black list that prevent some state to be saved, for example, the state used to toggle the sidebar on mobile.

The code that filter

/* Export a method to save state on each store update */
export const saveState = (state) => {
    try {
        let stateFilter = JSON.parse(JSON.stringify(state)); // deep clone
        ['offsidebarOpen', 'asideToggled', 'horizontal'] // states which we don't want to persist.
        .forEach(item => delete stateFilter.settings[item])
        const rawState = JSON.stringify(stateFilter);
        localStorage.setItem(STORAGE_KEY, rawState);
    } catch (err) {
        // Ignore write errors.
    }
};