<script>
  let value;
  let counter = 0;

  const increaseCounter = () => {
    counter++;
  };
  const decreaseCounter = () => {
    counter = counter < 1 ? 0 : counter - 1;
  };

  const handleChange = (e) => {
    value = e.target.value;
    console.log(value);
  };
</script>

<div class="stepper">
  <div
    class="button decrease"
    on:click={decreaseCounter}
    tabindex="0"
    role="button"
    on:keydown={(e) => e.key === "Enter" && decreaseCounter()}
  >
    -
  </div>
  <div class="number">
    <input class="number-text" type="text" bind:value={counter} on:input={handleChange} />
  </div>
  <div
    class="button increase"
    on:click={increaseCounter}
    tabindex="0"
    role="button"
    on:keydown={(e) => e.key === "Enter" && decreaseCounter()}
  >
    +
  </div>
</div>

<style>
  .stepper {
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    border: solid 1px #7b819e;
    box-sizing: border-box;
    padding: 0px;
  }
  .number {
    width: 40px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: solid 1px #7b819e;
    border-right: solid 1px #7b819e;
    color: #4a4d5d;
  }
  .number-text {
    box-sizing: border-box;
    width: 40px;
    height: 100%;
    border: none;
    font-size: 20px;
    text-align: center;
  }
  .number-text:focus {
    outline: none;
  }
  .button {
    width: 40px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: #7b819e;
    cursor: pointer;
    box-sizing: border-box;
    padding: 0px;
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera and Firefox */
  }
  .button:hover {
    background-color: #4759ba;
    color: #fff;
  }
  .button:active {
    background-color: #6a7bdd;
  }
  .increase {
    border-radius: 0px 3px 3px 0px;
  }
  .decrease {
    border-radius: 3px 0px 0px 3px;
  }
</style>
