All files / src/features/theme/ui ThemePreference.vue

83.33% Statements 5/6
100% Branches 12/12
66.66% Functions 2/3
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116            1x     1x         2x                 1x                                                                                                                                                                                        
<script setup lang="ts">
import {
  useThemeStore,
  type StorefrontTheme,
} from "../model/theme";
 
const theme = useThemeStore();
 
function selectTheme(value: StorefrontTheme) {
  theme.setTheme(value);
}
</script>
 
<template>
  <fieldset class="theme-selector">
    <legend>页面气质</legend>
    <p>同一套设计语言,两种克制的浏览气候。</p>
    <label>
      <input
        type="radio"
        name="storefront-theme"
        value="subai"
        :checked="theme.theme === 'subai'"
        @change="selectTheme('subai')"
      />
      <span>
        <strong>素白</strong>
        <small>清楚、稳定,让商品保持原貌。</small>
      </span>
    </label>
    <label>
      <input
        type="radio"
        name="storefront-theme"
        value="qinghe"
        :checked="theme.theme === 'qinghe'"
        @change="selectTheme('qinghe')"
      />
      <span>
        <strong>青荷</strong>
        <small>清润、自然,为浏览增加一点呼吸。</small>
      </span>
    </label>
  </fieldset>
</template>
 
<style scoped>
.theme-selector {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
}
 
.theme-selector legend {
  margin: 0 0 var(--pj-space-3);
  font-size: var(--pj-font-size-md);
  font-weight: 650;
}
 
.theme-selector > p {
  margin: 0 0 var(--pj-space-4);
  color: var(--pj-color-muted);
  font-size: var(--pj-font-size-sm);
}
 
.theme-selector label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--pj-space-3);
  align-items: start;
  padding-block: var(--pj-space-3);
  border-top: 1px solid var(--pj-color-line);
  cursor: pointer;
}
 
.theme-selector label:last-child {
  border-bottom: 1px solid var(--pj-color-line);
}
 
.theme-selector label:has(input:checked) {
  background:
    color-mix(
      in srgb,
      var(--pj-color-accent-soft) 18%,
      transparent
    );
}
 
.theme-selector label:has(input:checked) small {
  color: var(--pj-text-primary);
}
 
.theme-selector input {
  width: 1rem;
  height: 1rem;
  margin: 0.25rem 0 0;
  accent-color: var(--pj-color-accent);
}
 
.theme-selector label > span {
  display: grid;
  gap: var(--pj-space-1);
}
 
.theme-selector strong {
  color: var(--pj-color-text);
  font-weight: 600;
}
 
.theme-selector small {
  color: var(--pj-color-muted);
  line-height: 1.5;
}
</style>