Preferences.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div class="content preferences-tab">
  3. <p class="control is-expanded checkbox-control">
  4. <input type="checkbox" id="nightmode" v-model="localNightmode" />
  5. <label for="nightmode">
  6. <span></span>
  7. <p>Use nightmode</p>
  8. </label>
  9. </p>
  10. <button class="button is-primary" @click="saveChangesPreferences()">
  11. Save changes
  12. </button>
  13. </div>
  14. </template>
  15. <script>
  16. import { mapState, mapActions } from "vuex";
  17. export default {
  18. data() {
  19. return {
  20. localNightmode: false
  21. };
  22. },
  23. computed: mapState({
  24. nightmode: state => state.user.preferences.nightmode
  25. }),
  26. methods: {
  27. saveChangesPreferences() {
  28. if (this.localNightmode !== this.nightmode)
  29. this.changeNightmodeLocal();
  30. },
  31. changeNightmodeLocal() {
  32. localStorage.setItem("nightmode", this.localNightmode);
  33. this.changeNightmode(this.localNightmode);
  34. },
  35. ...mapActions("user/preferences", ["changeNightmode"])
  36. }
  37. };
  38. </script>
  39. <style lang="scss" scoped>
  40. @import "../../../styles/global.scss";
  41. .checkbox-control {
  42. input[type="checkbox"] {
  43. opacity: 0;
  44. position: absolute;
  45. }
  46. label {
  47. display: flex;
  48. flex-direction: row;
  49. align-items: center;
  50. span {
  51. cursor: pointer;
  52. width: 24px;
  53. height: 24px;
  54. background-color: $white;
  55. display: inline-block;
  56. border: 1px solid $dark-grey-2;
  57. position: relative;
  58. border-radius: 3px;
  59. }
  60. p {
  61. margin-left: 10px;
  62. }
  63. }
  64. input[type="checkbox"]:checked + label span::after {
  65. content: "";
  66. width: 18px;
  67. height: 18px;
  68. left: 2px;
  69. top: 2px;
  70. border-radius: 3px;
  71. background-color: $musare-blue;
  72. position: absolute;
  73. }
  74. }
  75. </style>