JSFiddle - React, Tailwind, and code Playground

by Сергей Тарасевич

HTML

<div class="row">
  <div class="color" data-background="ffffff" data-style="background1"></div>
  <div class="color" data-background="000000" data-style="background2"></div>
  <div class="color" data-background="00ff00" data-style="background3"></div>
  <div class="color" data-background="EDff00" data-style="background4"></div>
  <div class="color" data-background="FFA700" data-style="background5"></div>
  <div class="color" data-background="ff0000" data-style="background6"></div>
  <div class="color" data-background="ff00ff" data-style="background7"></div>
  <div class="color" data-background="0000ff" data-style="background8"></div>
</div>

CSS

.row {
  background: #a0a0a0;
  border-radius: 15px;
  box-shadow: 0 4px 8px -4px rgba(0, 0, 0, 0.25);
  display: inline-block;
  font-size: 0;
  margin: 10px;
  padding: 3px;
}

.color {
  border: 2px solid transparent;
  border-radius: 50%;
  display: inline-block;
  font-size: 0;
  opacity: 0.3;
  height: 20px;
  width: 20px;
}

.color:hover {
  opacity: 0.6;
}

.color.active {
  border: 2px solid #ffffff;
  box-shadow: 0 0 5px 0px rgba(0, 0, 0, 0.5);
  opacity: 1;
}

.color > div {
  border-radius: 50%;
  box-shadow: inset 0 0 20px 0px rgba(0, 0, 0, 0.26);
  cursor: pointer;
  display: block;
  height: 20px;
  width: 20px;
}

.background1 {
  background: #ffffff;
}

.background2 {
  background: #000000;
}

.background3 {
  background: #00ff00;
}

.background4 {
  background: #EDff00;
}

.background5 {
  background: #FFA700;
}

.background6 {
  background: #ff0000;
}

.background7 {
  background: #ff00ff;
}

.background8 {
  background: #0000ff;
}

JavaScript

var STYLE = {
  a: $(document),
  cookie: {
    set: function(a, b, c) {
      var e;
      if (c) {
        var d = new Date();
        d.setTime(d.getTime() + (c * 24 * 60 * 60 * 1000));
        e = " ; expires=" + d.toGMTString();

      } else {
        e = "";

      }
      document.cookie = a + " = " + b + e + "; path=/";

    },
    get: function(a) {
      var b = a + "=",
        d = document.cookie.split(';');

      for (var i = 0; i < d.length; i++) {
        var c = d[i];

        while (c.charAt(0) === ' ') {
          c = c.substring(1, c.length);

        }

        if (c.indexOf(b) === 0) {
          return c.substring(b.length, c.length);

        }

      }
      return null;

    },
    del: function(a) {
      STYLE.cookie.set(a, "", -1);

    }

  },
  ready: function() {
    $('[data-background]').each(function() {
      var a = $(this);
      a.html('<div style="background: #' + a.data('background') + ';"></div>');
    });

    var b = STYLE.cookie.get('body_style');
    if (undefined !== b) {
      STYLE.cookie.set('body_style', b, 365);
      $('body').removeAttr('class').addClass(b);
      $('[data-style="' + b + '"]').addClass('active');

    }

  }

}

STYLE.a.on('click', '[data-background]', function() {
  var a = $(this).data('style');
  if (a !== STYLE.cookie.get('body_style')) {
    STYLE.cookie.set('body_style', a, 365);
    $('body').removeAttr('class').addClass($(this).data('style'));
    $('[data-style]').removeClass('active');
    $(this).addClass('active');
  }

}).ready(function() {
  STYLE.ready();

});