JSFiddle - React, Tailwind, and code Playground

HTML

<section class="container">
    <div id="box" class="show-front">
        <figure class="front">1</figure>
        <figure class="back">2</figure>
        <figure class="right">3</figure>
        <figure class="left">4</figure>
        <figure class="top">5</figure>
        <figure class="bottom">6</figure>
    </div>
</section>

<section id="options">
    <p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id="up">Up</button>
        <br/><br/>
        <button id="left">Left</button>
        <button id="right">Right</button>
        <br/><br/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id="down">Down</button>
    </p>
</section>

CSS

.container {
    width: 150px;
    height: 100px;
    position: relative;
    margin: 25px auto 25px auto;
    perspective: 600px;
}

#box {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    transition: transform 1s;
}

#box figure {
    display: block;
    position: absolute;
    border: 1px solid black;
    line-height: 98px;
    font-size: 45px;
    text-align: center;
    font-weight: bold;
    color: white;
}

figure {
    margin: 0;
}

#box .front,
#box .back {
    width: 148px;
    height: 98px;
}

#box .right,
#box .left {
    width: 48px;
    height: 98px;
    left: 50px;
}

#box .top,
#box .bottom {
    width: 148px;
    height: 48px;
    top: 25px;
    line-height: 48px;
}

#box .front {
    background: hsla(000, 100%, 50%, 0.7);
}

#box .back {
    background: hsla(160, 100%, 50%, 0.7);
}

#box .right {
    background: hsla(120, 100%, 50%, 0.7);
}

#box .left {
    background: hsla(180, 100%, 50%, 0.7);
}

#box .top {
    background: hsla(240, 100%, 50%, 0.7);
}

#box .bottom {
    background: hsla(300, 100%, 50%, 0.7);
}

#box .front {
    transform: translateZ(25px);
	
}

#box .back {
    transform: rotateX(180deg) translateZ(25px);
}

#box .right {
    transform: rotateY(90deg) translateZ(75px);
}

#box .left {
    transform: rotateY(-90deg) translateZ(75px);
}

#box .top {
    transform: rotateX(90deg) translateZ(50px);
}

#box .bottom {
    transform: rotateX(-90deg) translateZ(50px);
}

#box.show-front {
    transform: translateZ(-50px);
}

#box.show-front-2 {
    transform: translateZ(-50px) rotateZ(90deg);
}

#box.show-front-3 {
    transform: translateZ(-50px) rotateZ(180deg);
}

#box.show-front-4 {
    transform: translateZ(-50px) rotateZ(270deg);
}

#box.show-back {
    transform: translateZ(-50px) rotateX(180deg);
}

#box.show-back-2 {
    transform: translateZ(-50px) rotateX(180deg) rotateZ(-90deg);
}

#box.show-back-3 {
    transform: translateZ(-50px) rotateX(180deg)...

JavaScript

$('document').ready(function() {

    var rots = [];
    var tr = "translateZ(-50px)";

    function transform() {
        var tf = "translateZ(-50px)";
        rots.forEach(function(rot) {
            tf += " rotate" + rot[0] + "(" + rot[1] + "deg)";
        });
        console.log(tf);
        $("#box").css("transform", tf);
    }

    function addRot(axis,angle) {
        if (rots.length==0 || rots[0][0]!=axis) {
            rots.unshift([axis,angle]);
        } else {
            rots[0][1]+=angle;
        }
        transform();
    }
    
    $('#up').bind('click', function() {
        addRot('X',90);
    });

    $('#down').bind('click', function() {
        addRot('X',-90);
    });

    $('#right').bind('click', function() {
        addRot('Y',90);
    });

    $('#left').bind('click', function() {
        addRot('Y',-90);
    });

    $(window).bind('keyup', function(event) {
        switch (event.keyCode) {
            case 37: // left
                $('#left').click();
                break;

            case 38: // up
                $('#up').click();
                break;

            case 39: // right
                $('#right').click();
                break;

            case 40: // down
                $('#down').click();
                break;
        }
    });
    
});