刘光辉
9 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
<script setup lang="ts">
import type { BuiltinThemeType } from '@vben/types';
 
import { Palette } from '@vben/icons';
import { COLOR_PRESETS, preferences, updatePreferences } from '@vben/preferences';
 
import { VbenIconButton } from '@vben-core/shadcn-ui';
 
defineOptions({
  name: 'AuthenticationColorToggle',
});
 
function handleUpdate(colorPrimary: string, type: BuiltinThemeType) {
  updatePreferences({
    theme: {
      colorPrimary,
      builtinType: type,
    },
  });
}
</script>
 
<template>
  <div class="group relative flex items-center overflow-hidden">
    <div class="flex w-0 overflow-hidden transition-all duration-500 ease-out group-hover:w-60">
      <template v-for="preset in COLOR_PRESETS" :key="preset.color">
        <VbenIconButton class="flex-center flex-shrink-0" @click="handleUpdate(preset.color, preset.type)">
          <div :style="{ backgroundColor: preset.color }" class="flex-center relative size-5 rounded-full hover:scale-110">
            <svg v-if="preferences.theme.builtinType === preset.type" class="h-3.5 w-3.5 text-white" height="1em" viewBox="0 0 15 15" width="1em">
              <path
                clip-rule="evenodd"
                d="M11.467 3.727c.289.189.37.576.181.865l-4.25 6.5a.625.625 0 0 1-.944.12l-2.75-2.5a.625.625 0 0 1 .841-.925l2.208 2.007l3.849-5.886a.625.625 0 0 1 .865-.181"
                fill="currentColor"
                fill-rule="evenodd" />
            </svg>
          </div>
        </VbenIconButton>
      </template>
    </div>
 
    <VbenIconButton>
      <Palette class="text-primary size-4" />
    </VbenIconButton>
  </div>
</template>