Categories
Uncategorized

Loader ES6

The following is the implementation of a simple Javascript (ES6) loader.

<script>
  const load = () => {
    let width = 0;
    const id = setInterval(() => {
      if (width === 100)
        clearInterval(id);
      else
        document.getElementById('bar').style.width = `${++width}%`;
    }, 10);
  };
</script>
<div id="loader" style="height: 100px; width: 600px; border: 1px solid #000;">
  <div id="bar" style="background-color: green; width: 0; height: 100px;" class="">
  </div>
</div>
<button onclick="load()">Load</button>

Demo

Categories
Uncategorized

Add Events ES6

In the example below, we create a button and attach a click event to it.

const button = document.createElement('button');
 button.innerHTML = 'Click';
 document.body.appendChild(button);
 const test = (val) => {
   console.log('clicked ' + val);
 };
 button.addEventListener('click', test.bind(this, 'test'));

Demo

Categories
Uncategorized

Flexbox – Div at end of row

The following lines of code demonstrate how to align a div at the end of the flexbox row when you want to display the rest of the them at the start.
flexbox

Categories
Uncategorized

Unit testing method called with parameters

The following two unit tests demonstrate the scenario where you would want to write a unit test to verify whether a method was called with the required parameters. It also tests how many times a method was invoked by passing a mock method.

Categories
Uncategorized

Allow arrow functions as properties in React Components using eslint

If you don’t configure your .eslintrc file, then you might see this “Parsing error: Unexpected token =” when you do the following in your react components.

class HomeComponent extends Component {
  
  state = {
    term: '',
  };

  setTerm = (term) => {
    this.setState({ term });
  };

  ...
}

To use arrow functions as properties in React components you can do the following.

Categories
Uncategorized

Add Stylelint to webpack

Adding stylelint to your project has many advantages that range from being able to throw warnings and errors when the styling rules (CSS, SASS-SCSS) are broken, to being able to fix most of your warnings automatically with a single command.

Categories
Uncategorized

How to create an arrow content separator in CSS

Lets say you want to draw something similar to the following using only CSS.

Categories
Uncategorized

Material Modal using CSS3

The following code tries to mimic the look and feel of the modal from Google’s Material Design using CSS3.

Categories
Uncategorized

Restart service if website is down with cronjob

This can be easily achieved on a linux server with the help of a cronjob.

Open up your terminal and edit your cronjobs list using sudo crontab -e.

Categories
Uncategorized

Divide CSS3 Grid into fixed equal columns

Defining a fixed set of equal width items for each row in a grid can be done using the grid-template-columns property in CSS3.